-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add ListItem component (#13128)
* feat(app): add ListItem component
- Loading branch information
Showing
4 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from 'react' | ||
import { DIRECTION_COLUMN, Flex, SPACING } from '@opentrons/components' | ||
import { StyledText } from '../text' | ||
import { ListItem } from '.' | ||
import type { Story, Meta } from '@storybook/react' | ||
|
||
export default { | ||
title: 'ODD/Atoms/ListItem', | ||
argTypes: { | ||
type: { | ||
control: { | ||
type: 'select', | ||
options: ['error', 'noActive', 'success', 'warning'], | ||
}, | ||
}, | ||
}, | ||
} as Meta | ||
|
||
const ListItemTemplate: Story<React.ComponentProps<typeof ListItem>> = args => ( | ||
<ListItem {...args} /> | ||
) | ||
|
||
export const Item = ListItemTemplate.bind({}) | ||
Item.args = { | ||
type: 'noActive', | ||
children: ( | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}> | ||
<StyledText as="p"> | ||
Slot Component: Replace me using the component panel. | ||
</StyledText> | ||
<StyledText as="p"> | ||
Slot Component: Replace me using the component panel. | ||
</StyledText> | ||
<StyledText as="p"> | ||
Slot Component: Replace me using the component panel. | ||
</StyledText> | ||
</Flex> | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as React from 'react' | ||
|
||
import { | ||
BORDERS, | ||
COLORS, | ||
renderWithProviders, | ||
SPACING, | ||
} from '@opentrons/components' | ||
|
||
import { ListItem } from '..' | ||
|
||
const render = (props: React.ComponentProps<typeof ListItem>) => | ||
renderWithProviders(<ListItem {...props} />) | ||
|
||
describe('ListItem', () => { | ||
let props: React.ComponentProps<typeof ListItem> | ||
|
||
beforeEach(() => { | ||
props = { | ||
type: 'error', | ||
children: <div>mock listitem content</div>, | ||
} | ||
}) | ||
|
||
it('should render correct style - error', () => { | ||
const [{ getByText, getByTestId }] = render(props) | ||
getByText('mock listitem content') | ||
const listItem = getByTestId('ListItem_error') | ||
expect(listItem).toHaveStyle(`backgroundColor: ${COLORS.red3}`) | ||
expect(listItem).toHaveStyle( | ||
`padding: ${SPACING.spacing16} ${SPACING.spacing24}` | ||
) | ||
expect(listItem).toHaveStyle(`borderRadius: ${BORDERS.borderRadiusSize3}`) | ||
}) | ||
it('should render correct style - noActive', () => { | ||
props.type = 'noActive' | ||
const [{ getByText, getByTestId }] = render(props) | ||
getByText('mock listitem content') | ||
const listItem = getByTestId('ListItem_noActive') | ||
expect(listItem).toHaveStyle(`backgroundColor: ${COLORS.light1}`) | ||
expect(listItem).toHaveStyle( | ||
`padding: ${SPACING.spacing16} ${SPACING.spacing24}` | ||
) | ||
expect(listItem).toHaveStyle(`borderRadius: ${BORDERS.borderRadiusSize3}`) | ||
}) | ||
it('should render correct style - success', () => { | ||
props.type = 'success' | ||
const [{ getByText, getByTestId }] = render(props) | ||
getByText('mock listitem content') | ||
const listItem = getByTestId('ListItem_success') | ||
expect(listItem).toHaveStyle(`backgroundColor: ${COLORS.green3}`) | ||
expect(listItem).toHaveStyle( | ||
`padding: ${SPACING.spacing16} ${SPACING.spacing24}` | ||
) | ||
expect(listItem).toHaveStyle(`borderRadius: ${BORDERS.borderRadiusSize3}`) | ||
}) | ||
it('should render correct style - warning', () => { | ||
props.type = 'warning' | ||
const [{ getByText, getByTestId }] = render(props) | ||
getByText('mock listitem content') | ||
const listItem = getByTestId('ListItem_warning') | ||
expect(listItem).toHaveStyle(`backgroundColor: ${COLORS.yellow3}`) | ||
expect(listItem).toHaveStyle( | ||
`padding: ${SPACING.spacing16} ${SPACING.spacing24}` | ||
) | ||
expect(listItem).toHaveStyle(`borderRadius: ${BORDERS.borderRadiusSize3}`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react' | ||
|
||
import { BORDERS, COLORS, Flex, SPACING } from '@opentrons/components' | ||
|
||
import type { StyleProps } from '@opentrons/components' | ||
|
||
export type ListItemType = 'error' | 'noActive' | 'success' | 'warning' | ||
|
||
interface ListItemProps extends StyleProps { | ||
/** ListItem state type */ | ||
type: ListItemType | ||
/** ListItem contents */ | ||
children: React.ReactNode | ||
} | ||
|
||
const LISTITEM_PROPS_BY_TYPE: Record< | ||
ListItemType, | ||
{ backgroundColor: string } | ||
> = { | ||
error: { | ||
backgroundColor: COLORS.red3, | ||
}, | ||
noActive: { | ||
backgroundColor: COLORS.light1, | ||
}, | ||
success: { | ||
backgroundColor: COLORS.green3, | ||
}, | ||
warning: { | ||
backgroundColor: COLORS.yellow3, | ||
}, | ||
} | ||
|
||
export function ListItem(props: ListItemProps): JSX.Element { | ||
const { type, children, ...styleProps } = props | ||
const listItemProps = LISTITEM_PROPS_BY_TYPE[type] | ||
|
||
return ( | ||
<Flex | ||
data-testid={`ListItem_${type}`} | ||
width="100%" | ||
height="max-content" | ||
padding={`${SPACING.spacing16} ${SPACING.spacing24}`} | ||
backgroundColor={listItemProps.backgroundColor} | ||
borderRadius={BORDERS.borderRadiusSize3} | ||
{...styleProps} | ||
> | ||
{children} | ||
</Flex> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters