diff --git a/packages/co-design-core/src/components/Chips/Chip.style.ts b/packages/co-design-core/src/components/Chips/Chip.style.ts index f9b5344b..ca4780a2 100644 --- a/packages/co-design-core/src/components/Chips/Chip.style.ts +++ b/packages/co-design-core/src/components/Chips/Chip.style.ts @@ -9,7 +9,7 @@ export const sizes = { xlarge: 40, }; -const iconSizes = { +const checkIconSizes = { xsmall: 10, small: 12, medium: 14, @@ -17,6 +17,14 @@ const iconSizes = { xlarge: 18, }; +const closeIconSizes = { + xsmall: 14, + small: 16, + medium: 18, + large: 20, + xlarge: 22, +}; + const padding = { xsmall: 16, small: 20, @@ -33,6 +41,14 @@ const checkedPadding = { xlarge: 15, }; +const deletablePadding = { + xsmall: 7.5, + small: 10, + medium: 11.5, + large: 13, + xlarge: 15, +}; + interface ChipStyles { radius: CoRadius | number; size: CoSize; @@ -72,15 +88,26 @@ export default createStyles((theme, { radius, size, color }: ChipStyles, getRef) }, }, - iconWrapper: { + checkWrapper: { + display: 'inline-block', + verticalAlign: 'middle', ref: iconWrapper, color: theme.palettes[color][theme.colorScheme === 'dark' ? 3 : 5], - width: getFieldValue(size, iconSizes), - maxWidth: getFieldValue(size, iconSizes), - height: getFieldValue(size, iconSizes), + width: getFieldValue(size, checkIconSizes), + maxWidth: getFieldValue(size, checkIconSizes), + height: getFieldValue(size, checkIconSizes), marginRight: theme.spacing.small, + overflow: 'hidden', + }, + + closeWrapper: { display: 'inline-block', verticalAlign: 'middle', + ref: iconWrapper, + width: getFieldValue(size, closeIconSizes), + maxWidth: getFieldValue(size, closeIconSizes), + height: getFieldValue(size, closeIconSizes), + marginLeft: theme.spacing.small, overflow: 'hidden', }, @@ -103,11 +130,23 @@ export default createStyles((theme, { radius, size, color }: ChipStyles, getRef) paddingLeft: getFieldValue(size, checkedPadding), paddingRight: getFieldValue(size, checkedPadding), border: `1px solid ${theme.palettes[color][theme.colorScheme === 'dark' ? 3 : 5]}`, + color: theme.palettes[color][theme.colorScheme === 'dark' ? 3 : 5], + }, + + deletable: { + paddingLeft: getFieldValue(size, deletablePadding), + paddingRight: getFieldValue(size, deletablePadding), }, checkIcon: { - width: getFieldValue(size, iconSizes), - height: getFieldValue(size, iconSizes) / 1.1, + width: getFieldValue(size, checkIconSizes), + height: getFieldValue(size, checkIconSizes) / 1.1, + display: 'block', + }, + + deleteIcon: { + width: getFieldValue(size, closeIconSizes), + height: getFieldValue(size, closeIconSizes) / 1.1, display: 'block', }, diff --git a/packages/co-design-core/src/components/Chips/Chip.tsx b/packages/co-design-core/src/components/Chips/Chip.tsx index 79a21abe..695e138f 100644 --- a/packages/co-design-core/src/components/Chips/Chip.tsx +++ b/packages/co-design-core/src/components/Chips/Chip.tsx @@ -4,6 +4,7 @@ import { CoComponentProps, CoPalette, CoSize, CoRadius, useCoTheme, ClassNames } import { View } from '../View'; import { CheckboxIcon } from './CheckboxIcon'; import useStyles from './Chip.style'; +import CloseIcon from './CloseIcon'; export type ChipStylesNames = ClassNames; @@ -55,6 +56,10 @@ export interface ChipProps extends CoComponentProps, Omit( checked, defaultChecked, onChange, + onDelete, co, overrideStyles, ...props @@ -83,6 +89,7 @@ export const Chip = forwardRef( const uuid = useId(id); const theme = useCoTheme(); const _color = color || theme.primaryColor; + const { classes, cx } = useStyles({ radius, size, color: _color }, { overrideStyles, name: __staticSelector }); const [value, setValue] = useUncontrolled({ @@ -105,13 +112,21 @@ export const Chip = forwardRef( ref={ref} {...props} /> -