diff --git a/packages/twake-mui/src/lib/overrides.tsx b/packages/twake-mui/src/lib/overrides.tsx index c8e88510..279bdc90 100644 --- a/packages/twake-mui/src/lib/overrides.tsx +++ b/packages/twake-mui/src/lib/overrides.tsx @@ -2,6 +2,7 @@ import { accordionSummaryClasses } from '@mui/material/AccordionSummary' import { alertClasses } from '@mui/material/Alert' import { buttonClasses } from '@mui/material/Button' import { checkboxClasses } from '@mui/material/Checkbox' +import { chipClasses } from '@mui/material/Chip' import { dialogTitleClasses } from '@mui/material/DialogTitle' import { formHelperTextClasses } from '@mui/material/FormHelperText' import { formLabelClasses } from '@mui/material/FormLabel' @@ -677,9 +678,53 @@ export const overrides: NonNullable = { }, MuiChip: { styleOverrides: { - root: { - '&.square': { - borderRadius: radius.md + root: ({ theme }) => { + const { action } = theme.vars.palette + return { + '&.square': { + borderRadius: radius.md + }, + variants: [ + { + props: { variant: 'ghost', color: 'default' }, + style: { + color: theme.vars.palette.text.primary, + backgroundColor: theme.vars.palette.background.default, + // The action colours are translucent, so they go over the rest colour + [`&.${chipClasses.clickable}:hover`]: { + backgroundColor: theme.vars.palette.background.default, + backgroundImage: `linear-gradient(${action.hover}, ${action.hover})` + }, + [`&.${chipClasses.focusVisible}`]: { + backgroundColor: theme.vars.palette.background.default, + backgroundImage: `linear-gradient(${action.focus}, ${action.focus})` + } + } + }, + ...radioColors.map(color => ({ + props: { variant: 'ghost' as const, color }, + style: { + color: theme.vars.palette[color].main, + backgroundColor: theme.alpha( + theme.vars.palette[color].main, + action.ghostOpacity + ), + [`& .${chipClasses.icon}, & .${chipClasses.deleteIcon}`]: { + color: 'inherit' + }, + // MUI's coloured chips switch the delete icon to contrastText + [`& .${chipClasses.deleteIcon}:hover, & .${chipClasses.deleteIcon}:active`]: + { color: 'inherit' }, + [`&.${chipClasses.clickable}:hover, &.${chipClasses.focusVisible}`]: + { + backgroundColor: theme.alpha( + theme.vars.palette[color].main, + action.hoverGhostOpacity + ) + } + } + })) + ] } } } diff --git a/packages/twake-mui/src/lib/types.ts b/packages/twake-mui/src/lib/types.ts index 5f218c26..46e2c31d 100644 --- a/packages/twake-mui/src/lib/types.ts +++ b/packages/twake-mui/src/lib/types.ts @@ -136,6 +136,12 @@ declare module '@mui/material/Alert' { } } +declare module '@mui/material/Chip' { + interface ChipPropsVariantOverrides { + ghost: true + } +} + declare module '@mui/material/Button' { interface ButtonPropsVariantOverrides { ghost: true diff --git a/packages/twake-mui/src/stories/Chip.stories.tsx b/packages/twake-mui/src/stories/Chip.stories.tsx index 23bc3a0b..14e3ab73 100644 --- a/packages/twake-mui/src/stories/Chip.stories.tsx +++ b/packages/twake-mui/src/stories/Chip.stories.tsx @@ -26,7 +26,7 @@ const meta: Meta = { }, variant: { control: 'select', - options: ['filled', 'outlined'] + options: ['filled', 'outlined', 'ghost'] }, disabled: { control: 'boolean' @@ -62,7 +62,7 @@ export const Screenshot: Story = { 'warning', 'info' ] as const - const variants = ['filled', 'outlined'] as const + const variants = ['filled', 'outlined', 'ghost'] as const const squareProps = [false, true] as const const sizeProps = ['small', 'medium'] as const @@ -88,7 +88,7 @@ export const Screenshot: Story = { {variants.map(variant => ( - +