-
Notifications
You must be signed in to change notification settings - Fork 179
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(odd): Large Button #12317
Merged
Merged
feat(odd): Large Button #12317
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
app/src/atoms/buttons/OnDeviceDisplay/LargeButton.stories.tsx
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,37 @@ | ||
import * as React from 'react' | ||
import { LargeButton } from '.' | ||
import type { Story, Meta } from '@storybook/react' | ||
|
||
export default { | ||
title: 'ODD/Atoms/Buttons/LargeButton', | ||
argTypes: { onClick: { action: 'clicked' } }, | ||
} as Meta | ||
|
||
const LargeButtonTemplate: Story< | ||
React.ComponentProps<typeof LargeButton> | ||
> = args => <LargeButton {...args} /> | ||
|
||
export const PrimaryLargeButton = LargeButtonTemplate.bind({}) | ||
PrimaryLargeButton.args = { | ||
buttonText: 'Button text', | ||
buttonType: 'primary', | ||
disabled: false, | ||
} | ||
export const SecondaryLargeButton = LargeButtonTemplate.bind({}) | ||
SecondaryLargeButton.args = { | ||
buttonText: 'Button text', | ||
buttonType: 'secondary', | ||
disabled: false, | ||
} | ||
export const AlertLargeButton = LargeButtonTemplate.bind({}) | ||
AlertLargeButton.args = { | ||
buttonText: 'Button text', | ||
buttonType: 'alert', | ||
disabled: false, | ||
} | ||
export const CustomIconLargeButton = LargeButtonTemplate.bind({}) | ||
CustomIconLargeButton.args = { | ||
buttonText: 'Button text', | ||
buttonType: 'primary', | ||
iconName: 'restart', | ||
} |
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,130 @@ | ||
import * as React from 'react' | ||
import { css } from 'styled-components' | ||
import { | ||
TYPOGRAPHY, | ||
COLORS, | ||
SPACING, | ||
BORDERS, | ||
NewPrimaryBtn, | ||
styleProps, | ||
DIRECTION_ROW, | ||
Icon, | ||
} from '@opentrons/components' | ||
import { StyledText } from '../../text' | ||
import type { IconName, StyleProps } from '@opentrons/components' | ||
|
||
type LargeButtonTypes = 'primary' | 'secondary' | 'alert' | ||
interface LargeButtonProps extends StyleProps { | ||
onClick: () => void | ||
buttonType: LargeButtonTypes | ||
buttonText: React.ReactNode | ||
iconName?: IconName | ||
disabled?: boolean | ||
} | ||
|
||
export function LargeButton(props: LargeButtonProps): JSX.Element { | ||
const { onClick, buttonType, buttonText, iconName, disabled } = props | ||
const buttonProps = { | ||
onClick, | ||
disabled, | ||
} | ||
|
||
const LARGE_BUTTON_PROPS_BY_TYPE: Record< | ||
LargeButtonTypes, | ||
{ | ||
defaultBackgroundColor: string | ||
activeBackgroundColor: string | ||
defaultColor: string | ||
iconColor: string | ||
} | ||
> = { | ||
secondary: { | ||
defaultColor: COLORS.darkBlackEnabled, | ||
defaultBackgroundColor: COLORS.foundationalBlue, | ||
// TODO(jr, 3/20/23): replace these hex codes with the color constants | ||
activeBackgroundColor: '#99b1d2', | ||
iconColor: COLORS.blueEnabled, | ||
}, | ||
alert: { | ||
defaultColor: COLORS.red_one, | ||
defaultBackgroundColor: COLORS.red_three, | ||
activeBackgroundColor: '#c8acad', | ||
iconColor: COLORS.red_one, | ||
}, | ||
primary: { | ||
defaultColor: COLORS.white, | ||
defaultBackgroundColor: COLORS.blueEnabled, | ||
activeBackgroundColor: '#2160ca', | ||
iconColor: COLORS.white, | ||
}, | ||
} | ||
|
||
const LARGE_BUTTON_STYLE = css` | ||
text-align: ${TYPOGRAPHY.textAlignLeft}; | ||
color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType].defaultColor}; | ||
background-color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType] | ||
.defaultBackgroundColor}; | ||
cursor: default; | ||
border-radius: ${BORDERS.size_four}; | ||
box-shadow: none; | ||
padding: ${SPACING.spacing5} ${SPACING.spacing5} 2.4375rem; | ||
line-height: ${TYPOGRAPHY.lineHeight20}; | ||
text-transform: ${TYPOGRAPHY.textTransformNone}; | ||
${TYPOGRAPHY.pSemiBold} | ||
|
||
${styleProps} | ||
&:focus { | ||
background-color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType] | ||
.activeBackgroundColor}; | ||
box-shadow: none; | ||
} | ||
&:hover { | ||
border: none; | ||
box-shadow: none; | ||
background-color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType] | ||
.defaultBackgroundColor}; | ||
color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType].defaultColor}; | ||
} | ||
&:focus-visible { | ||
box-shadow: 0 0 0 ${SPACING.spacingS} ${COLORS.fundamentalsFocus}; | ||
} | ||
|
||
&:active { | ||
background-color: ${LARGE_BUTTON_PROPS_BY_TYPE[buttonType] | ||
.activeBackgroundColor}; | ||
} | ||
|
||
&:disabled { | ||
background-color: ${COLORS.darkBlack_twenty}; | ||
color: ${COLORS.darkBlackEnabled}${COLORS.opacity55HexCode}; | ||
} | ||
` | ||
return ( | ||
<NewPrimaryBtn | ||
{...buttonProps} | ||
css={LARGE_BUTTON_STYLE} | ||
aria-label={`LargeButton_${buttonType}`} | ||
flexDirection={DIRECTION_ROW} | ||
> | ||
<StyledText | ||
fontSize="2rem" | ||
fontWeight={TYPOGRAPHY.fontWeightSemiBold} | ||
paddingBottom="4.6875rem" | ||
jerader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lineHeight="2.625rem" | ||
> | ||
{buttonText} | ||
</StyledText> | ||
<Icon | ||
name={iconName ?? 'play'} | ||
aria-label={`LargeButton_${iconName ?? 'play'}`} | ||
color={ | ||
disabled | ||
? COLORS.darkBlack_sixty | ||
: LARGE_BUTTON_PROPS_BY_TYPE[buttonType].iconColor | ||
} | ||
width="1.875rem" | ||
height="1.875rem" | ||
/> | ||
</NewPrimaryBtn> | ||
) | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/atoms/buttons/OnDeviceDisplay/__tests__/LargeButton.test.tsx
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,63 @@ | ||
import * as React from 'react' | ||
import { renderWithProviders, COLORS } from '@opentrons/components' | ||
|
||
import { LargeButton } from '../LargeButton' | ||
|
||
const render = (props: React.ComponentProps<typeof LargeButton>) => { | ||
return renderWithProviders(<LargeButton {...props} />)[0] | ||
} | ||
|
||
describe('LargeButton', () => { | ||
let props: React.ComponentProps<typeof LargeButton> | ||
beforeEach(() => { | ||
props = { | ||
onClick: jest.fn(), | ||
buttonType: 'primary', | ||
buttonText: 'large button', | ||
} | ||
}) | ||
it('renders the default button and it works as expected', () => { | ||
const { getByText, getByRole } = render(props) | ||
getByText('large button').click() | ||
expect(props.onClick).toHaveBeenCalled() | ||
expect(getByRole('button')).toHaveStyle( | ||
`background-color: ${COLORS.blueEnabled}` | ||
) | ||
}) | ||
it('renders the alert button', () => { | ||
props = { | ||
...props, | ||
buttonType: 'alert', | ||
} | ||
const { getByRole } = render(props) | ||
expect(getByRole('button')).toHaveStyle( | ||
`background-color: ${COLORS.red_three}` | ||
) | ||
}) | ||
it('renders the secondary button', () => { | ||
props = { | ||
...props, | ||
buttonType: 'secondary', | ||
} | ||
const { getByRole } = render(props) | ||
expect(getByRole('button')).toHaveStyle( | ||
`background-color: ${COLORS.foundationalBlue}` | ||
) | ||
}) | ||
it('renders the button as disabled', () => { | ||
props = { | ||
...props, | ||
disabled: true, | ||
} | ||
const { getByRole } = render(props) | ||
expect(getByRole('button')).toBeDisabled() | ||
}) | ||
it('renders custom icon in the button', () => { | ||
props = { | ||
...props, | ||
iconName: 'restart', | ||
} | ||
const { getByLabelText } = render(props) | ||
getByLabelText('LargeButton_restart') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { LargeButton } from './LargeButton' | ||
export { MediumButtonRounded } from './MediumButtonRounded' | ||
export { SmallButton } from './SmallButton' | ||
export { TabbedButton } from './TabbedButton' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Context section, this large button component uses different icons for each button.
I think we need to pass IconName as a props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops good catch! I will add that, thank you!