Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Buttons): Support now default, inherit, secondary color for Text variant #2678

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions react/Buttons/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const variants = ['primary', 'secondary', 'ghost', 'text']
const propsArr = [{}, { disabled: true }, { busy: true }]

;

<Grid container>
{propsArr.map(props =>
<Grid item xs={12} sm={4} className="u-mb-1" key={JSON.stringify(props)}>
Expand Down Expand Up @@ -163,7 +162,7 @@ import Grid from 'cozy-ui/transpiled/react/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'

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

;

Expand Down Expand Up @@ -192,7 +191,7 @@ import Grid from 'cozy-ui/transpiled/react/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'

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

;

Expand Down Expand Up @@ -221,7 +220,7 @@ import Grid from 'cozy-ui/transpiled/react/Grid'
import Paper from 'cozy-ui/transpiled/react/Paper'

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

;

Expand Down
32 changes: 28 additions & 4 deletions react/Buttons/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,27 @@ import MuiButton from '@material-ui/core/Button'
import Icon from '../Icon'
import SpinnerIcon from '../Icons/Spinner'

const CUSTOM_COLORS = ['success', 'error', 'warning', 'info']

const DefaultButton = forwardRef(
({ className, color, label, busy, disabled, endIcon, ...props }, ref) => {
(
{ variant, className, color, label, busy, disabled, endIcon, ...props },
ref
) => {
const customColor = CUSTOM_COLORS.includes(color) ? color : 'primary'
const _color =
variant === 'text' && !CUSTOM_COLORS.includes(color) ? color : 'primary'

return (
<MuiButton
{...props}
variant={variant}
ref={ref}
className={cx({ [`customColor-${color}`]: color }, className)}
color="primary"
className={cx(
{ [`customColor-${customColor}`]: customColor },
className
)}
color={_color}
disabled={disabled || busy}
endIcon={
busy ? (
Expand All @@ -30,6 +43,7 @@ const DefaultButton = forwardRef(
)
}
)

DefaultButton.displayName = 'DefaultButton'

DefaultButton.defaultProps = {
Expand Down Expand Up @@ -76,11 +90,21 @@ const Buttons = forwardRef(({ variant, className = '', ...props }, ref) => {
return <DefaultButton className={className} {...props} ref={ref} />
}
})

Buttons.displayName = 'Buttons'

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

Buttons.defaultProps = {
Expand Down
Loading
Loading