Skip to content

Commit

Permalink
fix: ChipProps thanks to @0xAlunara
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 30, 2025
1 parent 43ee75c commit ebbef25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
32 changes: 12 additions & 20 deletions packages/curve-ui-kit/src/themes/chip/mui-chip-overrides.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
declare module '@mui/material/Chip' {
export interface ChipPropsColorOverrides {
// used both for badges and chips
active: true
import '@mui/material/Chip'

// colors usually for badges
alert: true
default: true
highlight: true
warning: true
accent: true
export type ChipColors = 'active' | 'alert' | 'default' | 'highlight' | 'warning' | 'accent' | 'inactive'
type DisabledChipColors = 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning'

// colors usually for chips
inactive: true
}
type NewChipColorOverrides = { [key in ChipColors]: true }
type DisabledChipColorsOverrides = { [key in DisabledChipColors]: false }

export interface ChipPropsSizeOverrides {
extraSmall: true
small: true
medium: true
large: true
extraLarge: true
}
type ChipSizes = 'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge'
type ChipSizeOverrides = { [key in ChipSizes]: true }

declare module '@mui/material/Chip' {
export interface ChipPropsColorOverrides extends NewChipColorOverrides, DisabledChipColorsOverrides {}

export interface ChipPropsSizeOverrides extends ChipSizeOverrides {}

export interface ChipPropsVariantOverrides {
filled: false
Expand Down
12 changes: 7 additions & 5 deletions packages/curve-ui-kit/src/themes/chip/mui-chip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Components } from '@mui/material'
import type { ChipProps } from '@mui/material/Chip'
import type { ChipProps } from '@mui/material/Chip/Chip'
import { DesignSystem } from '@ui-kit/themes/design'
import { Grays } from '@ui-kit/themes/design/0_primitives'
import { TypographyVariantKey } from '@ui-kit/themes/typography'
Expand All @@ -13,7 +13,9 @@ const { Sizing, IconSize } = SizesAndSpaces

type ChipSizeDefinition = { font: TypographyVariantKey; height: Responsive }

const chipSizes: Record<ChipProps['size'], ChipSizeDefinition> = {
type ChipSizes = NonNullable<ChipProps['size']>

const chipSizes: Record<ChipSizes, ChipSizeDefinition> = {
extraSmall: { font: 'bodyXsBold', height: IconSize.md },
small: { font: 'buttonXs', height: IconSize.md },
medium: { font: 'buttonXs', height: Sizing.md },
Expand All @@ -22,7 +24,7 @@ const chipSizes: Record<ChipProps['size'], ChipSizeDefinition> = {
}

// overrides for clickable chips
const chipSizeClickable: Record<ChipProps['size'], Partial<ChipSizeDefinition>> = {
const chipSizeClickable: Record<ChipSizes, Partial<ChipSizeDefinition>> = {
extraSmall: {},
small: { height: Sizing.md },
medium: { font: 'buttonS' },
Expand Down Expand Up @@ -100,14 +102,14 @@ export const defineMuiChip = (
},

...Object.entries(chipSizes).map(([size, { font, height }]) => ({
props: { size: size as ChipProps['size'] },
props: { size: size as ChipSizes },
style: {
...typography[font],
...handleBreakpoints({ height }),
},
})),
...Object.entries(chipSizeClickable).map(([size, { font, height }]) => ({
props: { size: size as ChipProps['size'], clickable: true },
props: { size: size as ChipSizes, clickable: true },
style: {
...(font && typography[font]),
...(height && handleBreakpoints({ height })),
Expand Down
2 changes: 1 addition & 1 deletion packages/curve-ui-kit/src/themes/stories/Chip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Stack from '@mui/material/Stack'
import Typography from '@mui/material/Typography'
import Box from '@mui/material/Box'
import { fn } from '@storybook/test'
import { ChipProps } from '@mui/material/Chip'
import type { ChipProps } from '@mui/material/Chip'

type ChipStoryProps = {
color: ChipProps['color']
Expand Down

0 comments on commit ebbef25

Please sign in to comment.