Skip to content

Commit

Permalink
feat(component): add mobileWidth prop to Button (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
deini authored Aug 21, 2020
1 parent 11b1dff commit f04e120
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/big-design/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>, Ma
iconOnly?: React.ReactNode;
iconRight?: React.ReactNode;
isLoading?: boolean;
mobileWidth?: 'auto' | '100%';
variant?: 'primary' | 'secondary' | 'subtle';
}

Expand Down Expand Up @@ -57,9 +58,10 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(({ className, s
));

const defaultProps = {
actionType: 'normal' as 'normal',
actionType: 'normal' as const,
isLoading: false,
variant: 'primary' as 'primary',
mobileWidth: '100%' as const,
variant: 'primary' as const,
};

Button.displayName = 'Button';
Expand Down
5 changes: 3 additions & 2 deletions packages/big-design/src/components/Button/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const StyledButton = styled.button<ButtonProps & MarginProps>`
user-select: none;
vertical-align: middle;
white-space: nowrap;
width: 100%;
width: ${({ mobileWidth }) => (mobileWidth === 'auto' ? 'auto' : '100%')};
&:focus {
outline: none;
Expand All @@ -48,7 +48,8 @@ export const StyledButton = styled.button<ButtonProps & MarginProps>`
}
& + .bd-button {
margin-top: ${({ theme }) => theme.spacing.xSmall};
margin-top: ${({ mobileWidth, theme }) => mobileWidth === '100%' && theme.spacing.xSmall};
margin-left: ${({ mobileWidth, theme }) => mobileWidth === 'auto' && theme.spacing.xSmall};
${({ theme }) => theme.breakpoints.tablet} {
margin-top: ${({ theme }) => theme.spacing.none};
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/PropTables/ButtonPropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const buttonProps: Prop[] = [
defaultValue: 'false',
description: 'Used to determine if component is in a loading state.',
},
{
name: 'mobileWidth',
types: ['auto', '100%'],
defaultValue: '100%',
description: 'Determines the width in mobile viewport.',
},
{
name: 'variant',
types: ['primary', 'secondary', 'subtle'],
Expand Down

0 comments on commit f04e120

Please sign in to comment.