Skip to content

Commit

Permalink
feat: Optional fullwidth prop for Button (#681)
Browse files Browse the repository at this point in the history
* feat: Optional fullwidth prop for Button

* Remove unneccessary import
  • Loading branch information
AndyEPhipps authored Nov 1, 2024
1 parent 75d1180 commit e94bc57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/Atoms/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ const StyledButton = styled.button`
text-decoration: none;
}
${({ color, theme }) => (color ? theme.buttonColors(color) : theme.buttonColors('red'))};
@media ${({ theme }) => theme.allBreakpoints('M')} {
width: auto;
width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')};
}
@media ${({ theme }) => theme.allBreakpoints('L')} {
width: auto;
width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')};
padding: ${spacing('md')} ${spacing('l')};
margin: 0 auto ${spacing('l')};
}
`;

const Button = React.forwardRef(({ children, wrapper = false, ...rest }, ref) => (
<StyledButton {...rest} as={wrapper ? 'span' : 'button'} ref={ref}>
const Button = React.forwardRef(({
children, wrapper = false, fullWidth = false, ...rest
}, ref) => (
<StyledButton {...rest} as={wrapper ? 'span' : 'button'} ref={ref} fullWidth={fullWidth}>
{children}
</StyledButton>
));

Button.propTypes = {
children: PropTypes.node.isRequired,
wrapper: PropTypes.bool // Buttons as span
wrapper: PropTypes.bool, // Buttons as span
fullWidth: PropTypes.bool
};

export default Button;
4 changes: 4 additions & 0 deletions src/components/Atoms/Button/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
```js
<Button wrapper>My button as a span</Button>
```

```js
<Button type="button" fullWidth>Full-width button</Button>
```

0 comments on commit e94bc57

Please sign in to comment.