-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Button component conform to the figma specifications
`import Button from 'cozy-ui/transpiled/react/buttons'`
- Loading branch information
Showing
8 changed files
with
629 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
Oops, something went wrong.