From 54094a223c4169c20f50b472d0e0d75d6bc0329b Mon Sep 17 00:00:00 2001 From: koji Date: Sat, 16 Mar 2024 11:27:41 -0400 Subject: [PATCH] fix(app): add info type to Chip component (#14631) * fix(app): add info type to Chip component --- app/src/atoms/Chip/Chip.stories.tsx | 39 +++++++--------------- app/src/atoms/Chip/__tests__/Chip.test.tsx | 31 +++++++++++++++++ app/src/atoms/Chip/index.tsx | 14 +++++++- app/src/atoms/SelectField/Select.tsx | 2 +- 4 files changed, 57 insertions(+), 29 deletions(-) diff --git a/app/src/atoms/Chip/Chip.stories.tsx b/app/src/atoms/Chip/Chip.stories.tsx index 5b2c5704585..3909f479d49 100644 --- a/app/src/atoms/Chip/Chip.stories.tsx +++ b/app/src/atoms/Chip/Chip.stories.tsx @@ -6,6 +6,15 @@ import type { Story, Meta } from '@storybook/react' export default { title: 'ODD/Atoms/Chip', + argTypes: { + type: { + options: ['basic', 'error', 'info', 'neutral', 'success', 'warning'], + control: { + type: 'select', + }, + defaultValue: 'basic', + }, + }, component: Chip, parameters: touchScreenViewport, } as Meta @@ -25,32 +34,8 @@ const Template: Story = ({ ...args }) => ( ) -export const Basic = Template.bind({}) -Basic.args = { +export const ChipComponent = Template.bind({}) +ChipComponent.args = { type: 'basic', - text: 'Basic chip text', -} - -export const Error = Template.bind({}) -Error.args = { - type: 'error', - text: 'Not connected', -} - -export const Success = Template.bind({}) -Success.args = { - type: 'success', - text: 'Connected', -} - -export const Warning = Template.bind({}) -Warning.args = { - type: 'warning', - text: 'Missing 1 module', -} - -export const Neutral = Template.bind({}) -Neutral.args = { - type: 'neutral', - text: 'Not connected', + text: 'Chip component', } diff --git a/app/src/atoms/Chip/__tests__/Chip.test.tsx b/app/src/atoms/Chip/__tests__/Chip.test.tsx index a10a92e62ab..d0115028b90 100644 --- a/app/src/atoms/Chip/__tests__/Chip.test.tsx +++ b/app/src/atoms/Chip/__tests__/Chip.test.tsx @@ -152,4 +152,35 @@ describe('Chip', () => { const icon = screen.getByLabelText('icon_mockError') expect(icon).toHaveStyle(`color: ${COLORS.red60}`) }) + + it('should render text, icon, bgcolor with info colors', () => { + props = { + text: 'mockInfo', + type: 'info', + } + render(props) + const chip = screen.getByTestId('Chip_info') + const chipText = screen.getByText('mockInfo') + expect(chip).toHaveStyle(`background-color: ${COLORS.blue35}`) + expect(chip).toHaveStyle(`border-radius: ${BORDERS.borderRadius40}`) + expect(chipText).toHaveStyle(`color: ${COLORS.blue60}`) + const icon = screen.getByLabelText('icon_mockInfo') + expect(icon).toHaveStyle(`color: ${COLORS.blue60}`) + }) + + it('should render text, icon, no bgcolor with info colors and bg false', () => { + props = { + background: false, + text: 'mockInfo', + type: 'info', + } + render(props) + const chip = screen.getByTestId('Chip_info') + const chipText = screen.getByText('mockInfo') + expect(chip).toHaveStyle(`background-color: ${COLORS.transparent}`) + expect(chip).toHaveStyle(`border-radius: ${BORDERS.borderRadius40}`) + expect(chipText).toHaveStyle(`color: ${COLORS.blue60}`) + const icon = screen.getByLabelText('icon_mockInfo') + expect(icon).toHaveStyle(`color: ${COLORS.blue60}`) + }) }) diff --git a/app/src/atoms/Chip/index.tsx b/app/src/atoms/Chip/index.tsx index d63c6c15a31..3e7a12741a2 100644 --- a/app/src/atoms/Chip/index.tsx +++ b/app/src/atoms/Chip/index.tsx @@ -15,7 +15,13 @@ import { StyledText } from '../text' import type { IconName, StyleProps } from '@opentrons/components' -export type ChipType = 'basic' | 'error' | 'neutral' | 'success' | 'warning' +export type ChipType = + | 'basic' + | 'error' + | 'info' + | 'neutral' + | 'success' + | 'warning' interface ChipProps extends StyleProps { /** Display background color? */ @@ -49,6 +55,12 @@ const CHIP_PROPS_BY_TYPE: Record< iconColor: COLORS.red60, textColor: COLORS.red60, }, + info: { + backgroundColor: COLORS.blue35, + borderRadius: BORDERS.borderRadius40, + iconColor: COLORS.blue60, + textColor: COLORS.blue60, + }, neutral: { backgroundColor: `${COLORS.black90}${COLORS.opacity20HexCode}`, borderRadius: BORDERS.borderRadius40, diff --git a/app/src/atoms/SelectField/Select.tsx b/app/src/atoms/SelectField/Select.tsx index 92192c264bb..f0f49389b92 100644 --- a/app/src/atoms/SelectField/Select.tsx +++ b/app/src/atoms/SelectField/Select.tsx @@ -43,7 +43,7 @@ export function Select(props: SelectComponentProps): JSX.Element { ...styles, borderRadius: BORDERS.borderRadiusFull, border: BORDERS.lineBorder, - width: props.width != null ? props.width : 'auto', + width: props.width ?? 'auto', height: SPACING.spacing16, borderColor: COLORS.grey30, boxShadow: 'none',