Skip to content

Commit

Permalink
aplicando full width no botão
Browse files Browse the repository at this point in the history
  • Loading branch information
davimattos committed Jan 30, 2021
1 parent e4d4e62 commit 6e9880d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import * as S from './styles'
export type ButtonProps = {
children?: React.ReactNode
size?: 'small' | 'medium' | 'large'
fullWidth?: boolean
}

const Button = ({ children, size = 'medium' }: ButtonProps) => (
<S.Wrapper size={size}>{!!children && <span>{children}</span>}</S.Wrapper>
const Button = ({ children, size = 'medium', fullWidth }: ButtonProps) => (
<S.Wrapper size={size} fullWidth={fullWidth}>
{!!children && <span>{children}</span>}
</S.Wrapper>
)

export default Button
8 changes: 6 additions & 2 deletions src/components/Button/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled, { css, DefaultTheme } from 'styled-components'
import { ButtonProps } from '.'

type WrapperProps = Pick<ButtonProps, 'size'>
type WrapperProps = Pick<ButtonProps, 'size' | 'fullWidth'>

const wrapperModifiers = {
small: (theme: DefaultTheme) => css`
Expand All @@ -17,17 +17,21 @@ const wrapperModifiers = {
height: 5rem;
font-size: ${theme.font.sizes.medium};
padding: ${theme.spacings.xxsmall} ${theme.spacings.xlarge};
`,
fullWidth: () => css`
width: 100%;
`
}

export const Wrapper = styled.button<WrapperProps>`
${({ theme, size }) => css`
${({ theme, size, fullWidth }) => css`
background: linear-gradient(180deg, #ff5f5f 0%, #f062c0 50%);
color: ${theme.colors.white};
border: 0;
border-radius: ${theme.border.radius};
padding: ${theme.spacings.xxsmall};
${!!size && wrapperModifiers[size](theme)}
${!!fullWidth && wrapperModifiers.fullWidth}
`}
`
7 changes: 7 additions & 0 deletions src/components/Button/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ describe('<Button />', () => {
'font-size': '1.2rem'
})
})

it('should render a full width version', () => {
renderWithTheme(<Button fullWidth>Click Me</Button>)
expect(screen.getByRole('button', { name: /Click Me/i })).toHaveStyle({
width: '100%'
})
})
})

0 comments on commit 6e9880d

Please sign in to comment.