Skip to content

Commit

Permalink
feat: New Button component conform to the figma specifications
Browse files Browse the repository at this point in the history
`import Button from 'cozy-ui/transpiled/react/buttons'`
  • Loading branch information
JF-Cozy committed Nov 15, 2021
1 parent 7b4c6e0 commit 46e551b
Show file tree
Hide file tree
Showing 8 changed files with 629 additions and 95 deletions.
3 changes: 2 additions & 1 deletion docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
'../react/InfosBadge/index.jsx',
'../react/GhostFileBadge/index.jsx',
'../react/Button/index.jsx',
'../react/MuiCozyTheme/Buttons',
'../react/Buttons',
'../react/ButtonAction/index.jsx',
'../react/Card/index.jsx',
'../react/Chip/index.jsx',
Expand Down Expand Up @@ -200,6 +200,7 @@ module.exports = {
'../react/BottomNavigation/index.js',
'../react/BottomNavigationAction/index.js',
'../react/Box/index.js',
'../react/MuiCozyTheme/Buttons',
'../react/CardActionArea/index.js',
'../react/CardActions/index.js',
'../react/CardContent/index.js',
Expand Down
204 changes: 204 additions & 0 deletions react/Buttons/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
### Default

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import Icon from 'cozy-ui/transpiled/react/Icon'
import PlusIcon from 'cozy-ui/transpiled/react/Icons/Plus'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'

const variants = ['primary', 'secondary', 'ghost', 'text']
const propsArr = [{}, { disabled: true }, { busy: true }]

;
<>
<Button label="variant" />
<Grid container>
{propsArr.map(props =>
<Grid item xs={12} sm={4} className="u-mb-1" key={JSON.stringify(props)}>
<Stack spacing="s">
<div>{Object.keys(props)[0] || 'default'}</div>
{variants.map(variant =>
<div key={variant + JSON.stringify(props)}>
<Button label={variant} variant={variant} {...props} />
</div>
)}
</Stack>
</Grid>
)}
</Grid>
</>
```

### Sizes

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'

const variants = ['primary', 'secondary', 'ghost', 'text']
const sizes = ['small', 'medium', 'large']

;

<Grid container>
{sizes.map(size =>
<Grid item xs={12} sm={4} className="u-mb-1" key={size}>
<Stack spacing="s">
<div>{size}</div>
{variants.map(variant =>
<div key={variant + size}>
<Button label={variant} variant={variant} size={size} />
</div>
)}
</Stack>
</Grid>
)}
</Grid>
```

### Icons

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'
import PlusIcon from 'cozy-ui/transpiled/react/Icons/Plus'
import Icon from 'cozy-ui/transpiled/react/Icon'
import IconButton from 'cozy-ui/transpiled/react/IconButton'

const variants = ['primary', 'secondary', 'ghost', 'text']
const iconPositions = ['startIcon', 'endIcon']

;

<Grid container>
{iconPositions.map(iconPosition =>
<Grid item xs={12} sm={4} className="u-mb-1" key={iconPosition}>
<Stack spacing="s">
<div>{iconPosition}</div>
{variants.map(variant =>
<div key={variant + iconPosition}>
<Button
label={variant}
variant={variant}
{...({[`${iconPosition}`]: <Icon icon={PlusIcon}/>})}
/>
</div>
)}
</Stack>
</Grid>
)}
<Grid item xs={12} sm={4} className="u-mb-1">
<Stack spacing="s">
<div>label is only icon</div>
{variants.map(variant =>
<div key={variant}>
<Button
className="u-miw-auto"
label={<Icon icon={PlusIcon}/>}
variant={variant}
/>
</div>
)}
</Stack>
</Grid>
</Grid>
```

### Colors

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'

const variants = ['primary', 'secondary', 'ghost', 'text']
const colors = ['success', 'error', 'warning', 'info']

;

<Grid container>
{colors.map(color =>
<Grid item xs={12} sm={6} md={3} className="u-mb-1" key={color}>
<Stack spacing="s">
<div>{color}</div>
{variants.map(variant =>
<div key={variant + color}>
<Button label={variant} variant={variant} color={color} />
</div>
)}
</Stack>
</Grid>
)}
</Grid>
```

### Disabled colors

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'

const variants = ['primary', 'secondary', 'ghost', 'text']
const colors = ['success', 'error', 'warning', 'info']

;

<Grid container>
{colors.map(color =>
<Grid item xs={12} sm={6} md={3} className="u-mb-1" key={color}>
<Stack spacing="s">
<div>{color}</div>
{variants.map(variant =>
<div key={variant + color}>
<Button label={variant} variant={variant} color={color} disabled={true} />
</div>
)}
</Stack>
</Grid>
)}
</Grid>
```

### Busy colors

```jsx
import Button from 'cozy-ui/transpiled/react/Buttons'
import Stack from 'cozy-ui/transpiled/react/Stack'
import Grid from 'cozy-ui/transpiled/react/MuiCozyTheme/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'
import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'

const variants = ['primary', 'secondary', 'ghost', 'text']
const colors = ['success', 'error', 'warning', 'info']

;

<Grid container>
{colors.map(color =>
<Grid item xs={12} sm={6} md={3} className="u-mb-1" key={color}>
<Stack spacing="s">
<div>{color}</div>
{variants.map(variant =>
<div key={variant + color}>
<Button label={variant} variant={variant} color={color} busy={true} />
</div>
)}
</Stack>
</Grid>
)}
</Grid>
```
72 changes: 72 additions & 0 deletions react/Buttons/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react'
import PropTypes from 'prop-types'
import cx from 'classnames'

import MuiButton from '@material-ui/core/Button'

import Icon from '../Icon'
import SpinnerIcon from '../Icons/Spinner'

const DefaultButton = ({
className,
color,
label,
busy,
disabled,
endIcon,
...props
}) => {
return (
<MuiButton
{...props}
className={cx({ [`customColor-${color}`]: color }, className)}
color="primary"
disabled={disabled || busy}
endIcon={
busy ? (
<Icon icon={SpinnerIcon} spin aria-hidden focusable="false" />
) : (
endIcon
)
}
disableElevation={true}
>
{label}
</MuiButton>
)
}

DefaultButton.defaultProps = {
variant: 'contained',
color: 'primary'
}

const Buttons = ({ variant, ...props }) => {
switch (variant) {
case 'ghost':
return <DefaultButton className="ghost" variant="outlined" {...props} />

case 'secondary':
return <DefaultButton variant="outlined" {...props} />

case 'text':
return <DefaultButton variant="text" {...props} />

case 'primary':
return <DefaultButton {...props} />

default:
return <DefaultButton {...props} />
}
}

Buttons.propTypes = {
variant: PropTypes.oneOf(['primary', 'secondary', 'ghost', 'text']),
color: PropTypes.oneOf(['success', 'error', 'warning', 'info'])
}

Buttons.defaultProps = {
variant: 'primary'
}

export default Buttons
84 changes: 1 addition & 83 deletions react/MuiCozyTheme/Buttons/Readme.md
Original file line number Diff line number Diff line change
@@ -1,83 +1 @@
```
import Button from 'cozy-ui/transpiled/react/MuiCozyTheme/Buttons';
import Typography from 'cozy-ui/transpiled/react/Typography';
import Icon from 'cozy-ui/transpiled/react/Icon'
import Stack from 'cozy-ui/transpiled/react/Stack'
import WrenchCircleIcon from 'cozy-ui/transpiled/react/Icons/WrenchCircle'
const ButtonsVariant = ({variant, size }) => {
return (
<div>
<Button variant={variant} size={size}>
<Icon icon={WrenchCircleIcon} className='u-mr-half' />
Default
</Button>
<Button variant={variant} size={size} color="primary" className='u-ml-half'>
<Icon icon={WrenchCircleIcon} className='u-mr-half' />
Primary
</Button>
<Button variant={variant} size={size} color="secondary" className='u-ml-half'>Secondary</Button>
<Button variant={variant} size={size} disabled className='u-ml-half'>Disabled</Button>
<Button variant={variant} size={size} href="#text-buttons" className='u-ml-half'>Link</Button>
</div>
)
}
const StateRadio = ({ name, ...props }) => {
return <input
type='radio'
name={name}
checked={state[name] == props.value}
onChange={() => setState({ [name]: props.value })}
{...props}
/>
}
const Example = ({ size, className }) => {
return (
<Stack spacing='s'>
<div>
<Typography variant='subtitle1' gutterBottom>Text Buttons</Typography>
<ButtonsVariant size={size} />
</div>
<div>
<Typography variant='subtitle1' gutterBottom>Outlined Buttons</Typography>
<ButtonsVariant variant='outlined' size={size}/>
</div>
<div>
<Typography variant='subtitle1' gutterBottom>Contained buttons</Typography>
<ButtonsVariant variant='contained' size={size} />
</div>
</Stack>
)
}
initialState = {
size: 'medium'
};
<>
{true || isTesting()
?
<Stack spacing='l'>
{['small', 'medium', 'large'].map(size => (
<Stack spacing='xs'>
<Typography variant='h3'>{ size }</Typography>
<Example size={size} />
</Stack>
))}
</Stack> :
<Stack spacing='m'>
<div>
<StateRadio value='small' name='size' /> small{' '}
<StateRadio value='medium' name='size' /> medium{' '}
<StateRadio value='large' name='size' /> large
</div>
<div>
<Example size={state.size} />
</div>
</Stack>
}
</>
```
Re-export of @material-ui. See [the official API](https://material-ui.com/api/button/).
Loading

0 comments on commit 46e551b

Please sign in to comment.