Skip to content

Commit 238ff27

Browse files
author
Alunara
committed
refactor: use (typed) mapping instead of nested ternary
1 parent c2978d0 commit 238ff27

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

packages/curve-ui-kit/src/shared/ui/TabsSwitcher.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import Tabs, { type TabsProps } from '@mui/material/Tabs'
22
import Tab, { type TabProps } from '@mui/material/Tab'
33
import { TabSwitcherVariants, TABS_VARIANT_CLASSES, TABS_HEIGHT_CLASSES } from '../../themes/tabs'
44
import Typography, { type TypographyProps } from '@mui/material/Typography'
5+
import type { TypographyVariantKey } from '@ui-kit/themes/typography'
6+
7+
const defaultTextVariants = {
8+
small: 'buttonS',
9+
medium: 'buttonM',
10+
large: 'headingMBold',
11+
} as const satisfies Record<keyof typeof TABS_HEIGHT_CLASSES, TypographyVariantKey>
512

613
export type TabOption<T> = Pick<TabProps, 'label' | 'disabled' | 'icon' | 'sx'> & {
714
value: T
@@ -27,26 +34,22 @@ export const TabsSwitcher = <T extends string | number>({
2734
value,
2835
textVariant,
2936
...props
30-
}: TabsSwitcherProps<T>) => {
31-
const defaultTextVariant = size === 'small' ? 'buttonS' : size === 'medium' ? 'buttonM' : 'headingMBold'
32-
33-
return (
34-
<Tabs
35-
variant={muiVariant}
36-
textColor="inherit"
37-
value={value ?? false}
38-
onChange={(_, newValue) => onChange?.(newValue)}
39-
className={`${TABS_VARIANT_CLASSES[variant]} ${TABS_HEIGHT_CLASSES[size]}`}
40-
{...props}
41-
>
42-
{options.map(({ value, label, ...props }) => (
43-
<Tab
44-
key={value}
45-
value={value}
46-
label={<Typography variant={textVariant ?? defaultTextVariant}>{label}</Typography>}
47-
{...props}
48-
/>
49-
))}
50-
</Tabs>
51-
)
52-
}
37+
}: TabsSwitcherProps<T>) => (
38+
<Tabs
39+
variant={muiVariant}
40+
textColor="inherit"
41+
value={value ?? false}
42+
onChange={(_, newValue) => onChange?.(newValue)}
43+
className={`${TABS_VARIANT_CLASSES[variant]} ${TABS_HEIGHT_CLASSES[size]}`}
44+
{...props}
45+
>
46+
{options.map(({ value, label, ...props }) => (
47+
<Tab
48+
key={value}
49+
value={value}
50+
label={<Typography variant={textVariant ?? defaultTextVariants[size]}>{label}</Typography>}
51+
{...props}
52+
/>
53+
))}
54+
</Tabs>
55+
)

0 commit comments

Comments
 (0)