Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yoga): add props to PlanCard.ListItem #694

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions packages/doc/content/components/components/card/plancard-web.mdx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
### Usage

#### Default

```javascript
<PlanCard>
<PlanCard.Tag variant="informative">Recommended for you</PlanCard.Tag>
<PlanCard.Content
title="Basic"
currency="$"
price="99.90"
period="/mo"
>
<PlanCard.Content title="Basic" currency="$" price="99.90" period="/mo">
<PlanCard.List>
<PlanCard.ListItem icon={Checkin} text="2.900 gyms and studios" />
<PlanCard.ListItem icon={Dumbbell} text="1x/day standard access" />
<PlanCard.ListItem icon={User} text="4x/month 1-on-1 sessions" />
<PlanCard.ListItem
icon={
<Icon
as={Star}
height="small"
width="small"
stroke="secondary"
/>
<Icon as={Star} height="small" width="small" stroke="secondary" />
}
text="2x/month premium classes"
/>
Expand All @@ -35,15 +26,17 @@
```

#### List

```javascript
<Box display="flex" gap="xxsmall" overflow="auto" width="100%" justifyContent="center">
<Box
display="flex"
gap="xxsmall"
overflow="auto"
width="100%"
justifyContent="center"
>
<PlanCard>
<PlanCard.Content
title="Basic"
currency="$"
price="99.90"
period="/mo"
>
<PlanCard.Content title="Basic" currency="$" price="99.90" period="/mo">
<PlanCard.List>
<PlanCard.ListItem icon={Checkin} text="2.900 gyms and studios" />
<PlanCard.ListItem icon={Dumbbell} text="1x/day standard access" />
Expand All @@ -54,12 +47,7 @@
</PlanCard.Actions>
</PlanCard>
<PlanCard variant="relax">
<PlanCard.Content
title="Silver"
currency="$"
price="199.90"
period="/mo"
>
<PlanCard.Content title="Silver" currency="$" price="199.90" period="/mo">
<PlanCard.List>
<PlanCard.ListItem icon={Checkin} text="2.900 gyms and studios" />
<PlanCard.ListItem icon={Dumbbell} text="1x/day standard access" />
Expand All @@ -73,7 +61,6 @@
</Box>
```


#### Extra content

Display an extra content before the divider.
Expand All @@ -82,7 +69,7 @@ Display an extra content before the divider.
<PlanCard>
<PlanCard.Content
title="Basic"
extra={(
extra={
<Text
color="hope"
lineHeight="xlarge"
Expand All @@ -91,7 +78,8 @@ Display an extra content before the divider.
>
Free
</Text>
)}>
}
>
<PlanCard.List>
<PlanCard.ListItem icon={Checkin} text="2.900 gyms and studios" />
<PlanCard.ListItem icon={Dumbbell} text="1x/day standard access" />
Expand All @@ -106,6 +94,7 @@ Display an extra content before the divider.
```

#### Title badge

```javascript
<PlanCard>
<PlanCard.Content
Expand All @@ -125,6 +114,7 @@ Display an extra content before the divider.
```

#### Discount

```javascript
<PlanCard discount="SAVE 40%">
<PlanCard.Tag variant="informative">Active</PlanCard.Tag>
Expand All @@ -144,6 +134,37 @@ Display an extra content before the divider.
</PlanCard>
```

#### List item with extra content

```javascript
<PlanCard>
<PlanCard.Content
title="Gold"
currency="$"
price="99.90"
period="/mo"
badgeColor="energy"
>
<PlanCard.List>
<PlanCard.ListItem
icon={Checkin}
truncate={false}
text="List item with the following extra content:"
>
<Box display="flex" gap="small" mt="small">
<Avatar />
</Box>
</PlanCard.ListItem>
<PlanCard.ListItem
icon={Dumbbell}
text="This content should be truncated"
/>
<PlanCard.ListItem icon={User} text="4x/month 1-on-1 sessions" />
</PlanCard.List>
</PlanCard.Content>
</PlanCard>
```

### Props

#### PlanCard
Expand Down
56 changes: 35 additions & 21 deletions packages/yoga/src/Card/web/PlanCard/List.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { isValidElement } from 'react';
import styled, { css, withTheme } from 'styled-components';
import { string, node, shape, oneOfType, func } from 'prop-types';
import { string, node, shape, oneOfType, func, bool } from 'prop-types';

import Text from '../../../Text';
import theme from '../../../Theme/helpers/themeReader';
Expand All @@ -23,7 +23,9 @@ const List = styled.ul`

const IconWrapper = styled.div`
display: flex;
align-items: center;
margin-right: ${cardweb.plan.list.item.icon.margin.right}px;
min-height: ${props => props.theme.yoga.spacing.medium}px;
`;

const Item = styled.li`
Expand All @@ -34,8 +36,8 @@ const Item = styled.li`

const Wrapper = styled(Box)`
display: flex;
flex-direction: column;
min-width: 0;
align-items: center;

${props =>
props.as === 'button' &&
Expand All @@ -58,7 +60,7 @@ const ItemText = styled(Text.Small)`

color: ${card.plan.list.item.font.color};

${truncateStyle}
${props => props.truncate && truncateStyle}
`;

const Button = styled.button`
Expand Down Expand Up @@ -86,15 +88,22 @@ const Button = styled.button`
${truncateStyle}
`;

const ListItem = withTheme(
({ text, icon: Icon, buttonProps, theme: yogaTheme, onClick }) => {
const wrapperProps = onClick
? { as: 'button', type: 'button', onClick }
: {};

return (
<Item>
<Wrapper {...wrapperProps}>
const ListItem = withTheme(props => {
const {
text,
truncate,
icon: Icon,
buttonProps,
theme: yogaTheme,
children,
onClick,
} = props;
const wrapperProps = onClick ? { as: 'button', type: 'button', onClick } : {};

return (
<Item>
<Wrapper {...wrapperProps}>
<Box display="flex" alignItems="flex-start">
{Icon && (
<IconWrapper>
{isValidElement(Icon) ? (
Expand All @@ -108,15 +117,16 @@ const ListItem = withTheme(
)}
</IconWrapper>
)}
<ItemText as="span">{text}</ItemText>
</Wrapper>
{Boolean(Object.keys(buttonProps).length) && (
<Button {...buttonProps} />
)}
</Item>
);
},
);
<ItemText as="span" truncate={truncate}>
{text}
</ItemText>
</Box>
{children}
</Wrapper>
{Boolean(Object.keys(buttonProps).length) && <Button {...buttonProps} />}
</Item>
);
});

List.displayName = 'PlanCard.List';
ListItem.displayName = 'PlanCard.ListItem';
Expand All @@ -131,12 +141,16 @@ ListItem.propTypes = {
buttonProps: shape({}),
/** if provided makes the item clickable */
onClick: func,
children: node,
truncate: bool,
};

ListItem.defaultProps = {
truncate: true,
icon: undefined,
buttonProps: {},
onClick: undefined,
children: undefined,
};

export { List, ListItem };
34 changes: 34 additions & 0 deletions packages/yoga/src/Card/web/PlanCard/List.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import ThemeProvider from '../../../Theme';
import { ListItem } from './List';

const text = '2.900 gyms and studios';

function setup(props) {
render(
<ThemeProvider>
<ListItem text={text} {...props} />
</ThemeProvider>,
);
}

describe('<ListItem />', () => {
it('should display text truncated', () => {
setup();

expect(screen.getByText(text)).toMatchSnapshot();
});

it('should not display text truncated when truncate prop is false', () => {
setup({ truncate: false });

expect(screen.getByText(text)).toMatchSnapshot();
});

it('should display children element', () => {
setup({ children: <ul /> });

expect(screen.getByRole('list')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ListItem /> should display text truncated 1`] = `
.c0 {
margin: 0;
padding: 0;
font-size: 14px;
line-height: 20px;
font-weight: 400;
font-family: Rubik;
color: #231B22;
display: inline-block;
height: 100%;
vertical-align: middle;
color: #231B22;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

<span
class="c0"
>
2.900 gyms and studios
</span>
`;

exports[`<ListItem /> should not display text truncated when truncate prop is false 1`] = `
.c0 {
margin: 0;
padding: 0;
font-size: 14px;
line-height: 20px;
font-weight: 400;
font-family: Rubik;
color: #231B22;
display: inline-block;
height: 100%;
vertical-align: middle;
color: #231B22;
}

<span
class="c0"
>
2.900 gyms and studios
</span>
`;
Loading