Skip to content

Commit

Permalink
feat(button): add 'raised' button
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbien committed Nov 1, 2022
1 parent acaacd8 commit f49a107
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
41 changes: 41 additions & 0 deletions src/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ Default.story = {
name: 'default'
};

export function Raised() {
return (
<div id='default-buttons'>
<Button variant='raised'>Default</Button>
<br />
<Button variant='raised' primary>
Primary
</Button>
<br />
<Button variant='raised' disabled>
Disabled
</Button>
<br />
<Button variant='raised' active>
Active
</Button>
<br />
<Button variant='raised' square>
<span role='img' aria-label='recycle'>
♻︎
</span>
</Button>
<br />
<Button variant='raised' fullWidth>
Full width
</Button>
<br />
<Button variant='raised' size='sm'>
Size small
</Button>
<Button variant='raised' size='lg'>
Size large
</Button>
</div>
);
}

Raised.story = {
name: 'raised'
};

export function Flat() {
return (
<Window>
Expand Down
18 changes: 14 additions & 4 deletions src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ButtonProps = {
type?: string;
} & (
| {
variant?: 'default' | 'flat' | 'thin';
variant?: 'default' | 'raised' | 'flat' | 'thin';
}
| {
/** @deprecated Use `thin` */
Expand Down Expand Up @@ -146,11 +146,21 @@ export const StyledButton = styled.button<StyledButtonProps>`
`}
${active
? createBorderStyles({ invert: true })
: createBorderStyles({ invert: false })}
? createBorderStyles({
style: variant === 'raised' ? 'window' : 'button',
invert: true
})
: createBorderStyles({
style: variant === 'raised' ? 'window' : 'button',
invert: false
})}
}
&:active:before {
${!disabled && createBorderStyles({ invert: true })}
${!disabled &&
createBorderStyles({
style: variant === 'raised' ? 'window' : 'button',
invert: true
})}
}
&:focus:after,
&:active:after {
Expand Down
14 changes: 4 additions & 10 deletions src/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const StyledNumberInputWrapper = styled.div`
align-items: center;
`;

const StyledButton = styled(Button)<Pick<NumberInputProps, 'variant'>>`
const StyledButton = styled(Button)`
width: 30px;
padding: 0;
flex-shrink: 0;
Expand All @@ -40,13 +40,6 @@ const StyledButton = styled(Button)<Pick<NumberInputProps, 'variant'>>`
`
: css`
height: 50%;
&:before {
border-left-color: ${({ theme }) => theme.borderLight};
border-top-color: ${({ theme }) => theme.borderLight};
box-shadow: inset 1px 1px 0px 1px
${({ theme }) => theme.borderLightest},
inset -1px -1px 0 1px ${({ theme }) => theme.borderDark};
}
`}
`;

Expand Down Expand Up @@ -159,6 +152,7 @@ const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
handleClick(-step);
}, [handleClick, step]);

const buttonVariant = variant === 'flat' ? 'flat' : 'raised';
return (
<StyledNumberInputWrapper
className={className}
Expand All @@ -181,15 +175,15 @@ const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
<StyledButtonWrapper variant={variant}>
<StyledButton
data-testid='increment'
variant={variant}
variant={buttonVariant}
disabled={disabled || readOnly}
onClick={stepUp}
>
<StyledButtonIcon invert />
</StyledButton>
<StyledButton
data-testid='decrement'
variant={variant}
variant={buttonVariant}
disabled={disabled || readOnly}
onClick={stepDown}
>
Expand Down
9 changes: 1 addition & 8 deletions src/Select/Select.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const StyledNativeSelect = styled.select`

export const StyledDropdownButton = styled(Button).attrs(() => ({
'aria-hidden': 'true'
}))<CommonSelectStyleProps>`
}))<Omit<CommonSelectStyleProps, 'variant'>>`
width: 30px;
padding: 0;
flex-shrink: 0;
Expand All @@ -121,13 +121,6 @@ export const StyledDropdownButton = styled(Button).attrs(() => ({
`
: css`
height: 100%;
&:before {
border-left-color: ${({ theme }) => theme.borderLight};
border-top-color: ${({ theme }) => theme.borderLight};
box-shadow: inset 1px 1px 0px 1px
${({ theme }) => theme.borderLightest},
inset -1px -1px 0 1px ${({ theme }) => theme.borderDark};
}
`}
${({ native = false, variant = 'default' }) =>
native &&
Expand Down
2 changes: 1 addition & 1 deletion src/Select/useSelectCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const useSelectCommon = <T,>({
$disabled={disabled}
native={native}
tabIndex={-1}
variant={variant}
variant={variant === 'flat' ? 'flat' : 'raised'}
>
<StyledDropdownIcon data-testid='select-icon' $disabled={disabled} />
</StyledDropdownButton>
Expand Down

0 comments on commit f49a107

Please sign in to comment.