@registrucentras/rc-ses-react-components 2.7.2 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/phosphorIcons.d.ts +24 -0
- package/dist/components/common/Accordion/hooks/useAccordionController.d.ts +2 -1
- package/dist/components/common/Accordion/index.d.ts +18 -4
- package/dist/components/common/Accordion/types/AccordionControllerState.d.ts +1 -0
- package/dist/components/common/Card/index.d.ts +3 -0
- package/dist/components/common/CheckboxMark/index.d.ts +8 -0
- package/dist/components/common/DataPagination/components/ExpandButton.d.ts +7 -0
- package/dist/components/common/DataPagination/components/PaginationButton.d.ts +2 -1
- package/dist/components/common/DataPagination/index.d.ts +13 -3
- package/dist/components/common/DataPagination/paginationModel.d.ts +4 -0
- package/dist/components/common/Divider/index.d.ts +6 -0
- package/dist/components/common/EmptyState/index.d.ts +21 -0
- package/dist/components/common/IconWithSquareBackground/index.d.ts +2 -2
- package/dist/components/common/ImageCard/index.d.ts +5 -0
- package/dist/components/common/LinkTile/index.d.ts +11 -0
- package/dist/components/common/RadioMark/index.d.ts +8 -0
- package/dist/components/common/StepCard/StepCardFooter/index.d.ts +1 -1
- package/dist/components/common/TitleBlock/types.d.ts +4 -2
- package/dist/components/form/components/FormControlWrapper/index.d.ts +2 -1
- package/dist/components/form/inputs/Datepicker/RangeDatepicker.d.ts +23 -0
- package/dist/components/form/inputs/Datepicker/SingleDatepicker.d.ts +24 -0
- package/dist/components/form/inputs/Datepicker/components/CalendarViewsHeader.d.ts +18 -0
- package/dist/components/form/inputs/Datepicker/index.d.ts +10 -14
- package/dist/components/form/inputs/Datepicker/rangeModel.d.ts +4 -0
- package/dist/components/form/inputs/FileDropzone.d.ts +2 -2
- package/dist/components/form/inputs/RadioButtonGroup.d.ts +1 -0
- package/dist/components/form/inputs/Select/Select.styles.d.ts +84 -0
- package/dist/components/form/inputs/Select/components/OptionCheckbox.d.ts +2 -1
- package/dist/components/form/inputs/TextField.d.ts +27 -12
- package/dist/components/form/inputs/TextField.styles.d.ts +101 -0
- package/dist/components/layout/ServiceWizardStepper/stepperTokens.d.ts +5 -0
- package/dist/components/loaders/Loader/index.d.ts +12 -9
- package/dist/components/overlays/BottomSheet/index.d.ts +3 -2
- package/dist/components/overlays/Dialog/index.d.ts +1 -1
- package/dist/components/storybook/FileUploadTokenPreview.d.ts +4 -0
- package/dist/components/storybook/TabsTokenPreview.d.ts +3 -0
- package/dist/components/storybook/TokenDocs.d.ts +74 -0
- package/dist/library/index.d.ts +30 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +2 -2
- package/dist/registrucentras-rc-ses-react-components.js +11144 -8374
- package/dist/theme/backdropTokens.d.ts +6 -0
- package/dist/theme/borderTokens.d.ts +33 -0
- package/dist/theme/cards.d.ts +42 -73
- package/dist/theme/colorTokens.d.ts +146 -0
- package/dist/theme/effectTokens.d.ts +9 -0
- package/dist/theme/layoutTokens.d.ts +12 -0
- package/dist/theme/light/MuiAccordion.d.ts +2 -2
- package/dist/theme/light/MuiAccordionSummary.d.ts +19 -0
- package/dist/theme/light/MuiButton.d.ts +7 -0
- package/dist/theme/light/MuiInputBase.d.ts +2 -0
- package/dist/theme/light/MuiPickerPopper.d.ts +3 -0
- package/dist/theme/light/MuiTypography.d.ts +0 -14
- package/dist/theme/palette.d.ts +8 -0
- package/dist/theme/sizeTokens.d.ts +20 -0
- package/dist/theme/spacingRoleBasedTokens.d.ts +38 -0
- package/dist/theme/spacingTokens.d.ts +97 -0
- package/dist/theme/tokenTheme.d.ts +13 -0
- package/dist/theme/typographyTokens.d.ts +104 -0
- package/package.json +2 -2
- package/src/assets/icons/phosphorIcons.ts +11 -0
- package/src/components/common/Accordion/hooks/useAccordionController.tsx +39 -7
- package/src/components/common/Accordion/index.test.tsx +132 -0
- package/src/components/common/Accordion/index.tsx +302 -25
- package/src/components/common/Accordion/types/AccordionControllerState.ts +1 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +8 -3
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +3 -2
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.test.tsx +3 -3
- package/src/components/common/AdvancedList/components/AdvancedListItemShell/index.tsx +23 -19
- package/src/components/common/AdvancedList/index.test.tsx +4 -2
- package/src/components/common/Alert/index.tsx +10 -6
- package/src/components/common/Badge/index.tsx +50 -37
- package/src/components/common/Button/index.tsx +12 -10
- package/src/components/common/Card/index.tsx +6 -1
- package/src/components/common/CardShell/index.test.tsx +16 -6
- package/src/components/common/CheckboxMark/index.tsx +86 -0
- package/src/components/common/DataPagination/components/DataPaginationSkeleton.tsx +9 -7
- package/src/components/common/DataPagination/components/ExpandButton.tsx +48 -0
- package/src/components/common/DataPagination/components/PaginationButton.tsx +48 -21
- package/src/components/common/DataPagination/index.test.tsx +229 -12
- package/src/components/common/DataPagination/index.tsx +135 -60
- package/src/components/common/DataPagination/paginationModel.ts +35 -0
- package/src/components/common/Divider/index.test.tsx +33 -0
- package/src/components/common/Divider/index.tsx +52 -0
- package/src/components/common/EmptyState/index.test.tsx +56 -0
- package/src/components/common/EmptyState/index.tsx +211 -0
- package/src/components/common/FilterChip/index.tsx +24 -19
- package/src/components/common/IconWithCircularBackground.tsx +24 -6
- package/src/components/common/IconWithSquareBackground/index.test.tsx +14 -2
- package/src/components/common/IconWithSquareBackground/index.tsx +36 -17
- package/src/components/common/ImageCard/index.test.tsx +16 -0
- package/src/components/common/ImageCard/index.tsx +54 -1
- package/src/components/common/LinkTile/index.test.tsx +57 -0
- package/src/components/common/LinkTile/index.tsx +136 -0
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +39 -23
- package/src/components/common/ListWithIcons/index.test.tsx +20 -9
- package/src/components/common/ListWithIcons/index.tsx +6 -6
- package/src/components/common/Popover/index.tsx +11 -1
- package/src/components/common/RadioMark/index.tsx +76 -0
- package/src/components/common/SegmentedControl/components/SegmentButton/index.tsx +49 -25
- package/src/components/common/SegmentedControl/index.tsx +10 -6
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +7 -5
- package/src/components/common/SelectableCardList/index.test.tsx +8 -6
- package/src/components/common/SelectionMarks.test.tsx +92 -0
- package/src/components/common/ServiceLinks/ServiceLinkItem/index.tsx +20 -11
- package/src/components/common/ServiceLinks/index.tsx +3 -3
- package/src/components/common/SideNav/SideNavLayout.tsx +6 -1
- package/src/components/common/SideNav/components/SideNavPill.tsx +24 -12
- package/src/components/common/SideNav/components/SideNavPillList.tsx +18 -12
- package/src/components/common/SideNav/components/SideNavRow.tsx +22 -15
- package/src/components/common/SideNav/index.tsx +10 -9
- package/src/components/common/Snackbar/config.ts +27 -8
- package/src/components/common/Snackbar/index.tsx +39 -16
- package/src/components/common/StepCard/StepCardFooter/index.tsx +28 -6
- package/src/components/common/StepCard/index.tsx +18 -6
- package/src/components/common/Switch/index.tsx +10 -4
- package/src/components/common/Tabs/TabPanel.tsx +6 -3
- package/src/components/common/Tabs/TabsWrapper.tsx +15 -7
- package/src/components/common/TitleBlock/index.test.tsx +14 -17
- package/src/components/common/TitleBlock/index.tsx +120 -15
- package/src/components/common/TitleBlock/types.ts +4 -2
- package/src/components/common/Tooltip/index.tsx +32 -3
- package/src/components/form/components/FormControlWrapper/index.tsx +43 -14
- package/src/components/form/inputs/CheckboxFormControl.tsx +25 -13
- package/src/components/form/inputs/Datepicker/RangeDatepicker.tsx +356 -0
- package/src/components/form/inputs/Datepicker/SingleDatepicker.tsx +207 -0
- package/src/components/form/inputs/Datepicker/components/CalendarViewsHeader.tsx +335 -0
- package/src/components/form/inputs/Datepicker/components/RcSesDatepickerCalendarHeader.tsx +22 -10
- package/src/components/form/inputs/Datepicker/index.test.tsx +23 -18
- package/src/components/form/inputs/Datepicker/index.tsx +20 -150
- package/src/components/form/inputs/Datepicker/rangeModel.test.ts +35 -0
- package/src/components/form/inputs/Datepicker/rangeModel.ts +25 -0
- package/src/components/form/inputs/FileDropzone.tsx +73 -46
- package/src/components/form/inputs/FileUpload.tsx +25 -16
- package/src/components/form/inputs/NumberStepper.tsx +36 -14
- package/src/components/form/inputs/PhoneInputFormControl/components/AutocompleteInput.tsx +10 -5
- package/src/components/form/inputs/PhoneInputFormControl/components/ListboxComponent.tsx +7 -1
- package/src/components/form/inputs/PhoneInputFormControl/components/PopperComponent.tsx +5 -2
- package/src/components/form/inputs/PhoneInputFormControl/components/RowComponent.tsx +9 -5
- package/src/components/form/inputs/PhoneInputFormControl/index.tsx +48 -24
- package/src/components/form/inputs/RadioButtonGroup.tsx +14 -6
- package/src/components/form/inputs/Select/Select.styles.ts +76 -0
- package/src/components/form/inputs/Select/components/OptionCheckbox.tsx +6 -33
- package/src/components/form/inputs/Select/index.tsx +124 -86
- package/src/components/form/inputs/SimpleCheckbox.tsx +10 -3
- package/src/components/form/inputs/TextField.presets.test.tsx +284 -0
- package/src/components/form/inputs/TextField.styles.ts +96 -0
- package/src/components/form/inputs/TextField.test.tsx +153 -0
- package/src/components/form/inputs/TextField.tsx +315 -42
- package/src/components/layout/Footer/index.test.tsx +1 -1
- package/src/components/layout/Footer/index.tsx +17 -7
- package/src/components/layout/ServiceFormActions.tsx +5 -1
- package/src/components/layout/ServiceFormContainer/AccordionFormContainer/index.tsx +3 -3
- package/src/components/layout/ServiceHeader.tsx +19 -19
- package/src/components/layout/ServiceWizardStepper/ServiceWizardStepper.css +10 -10
- package/src/components/layout/ServiceWizardStepper/StepConnector.tsx +8 -5
- package/src/components/layout/ServiceWizardStepper/components/CustomStepIcon.tsx +22 -7
- package/src/components/layout/ServiceWizardStepper/components/HorizontalStepperButton.tsx +15 -11
- package/src/components/layout/ServiceWizardStepper/components/StyledStepLabel.tsx +28 -11
- package/src/components/layout/ServiceWizardStepper/stepperTokens.ts +8 -0
- package/src/components/loaders/FullPageLoader/index.test.tsx +18 -7
- package/src/components/loaders/FullPageLoader/index.tsx +14 -9
- package/src/components/loaders/Loader/index.tsx +48 -17
- package/src/components/overlays/BottomSheet/index.test.tsx +36 -3
- package/src/components/overlays/BottomSheet/index.tsx +54 -21
- package/src/components/overlays/Dialog/index.tsx +5 -23
- package/src/components/overlays/Drawer/index.tsx +29 -14
- package/src/components/overlays/Modal/index.tsx +46 -8
- package/src/components/storybook/FileUploadTokenPreview.tsx +68 -0
- package/src/components/storybook/TabsTokenPreview.tsx +58 -0
- package/src/components/storybook/TokenDocs.tsx +347 -0
- package/src/examples/MultipleStepForm/components/TermsAndConditionsForm.tsx +5 -1
- package/src/i18n/namespaces/input/en.json +48 -4
- package/src/i18n/namespaces/input/lt.json +48 -4
- package/src/library/index.ts +50 -0
- package/src/stories/atoms/Badge.stories.tsx +2 -1
- package/src/stories/atoms/Button.stories.tsx +124 -6
- package/src/stories/atoms/CheckboxMark.stories.tsx +79 -0
- package/src/stories/atoms/Divider.stories.tsx +129 -0
- package/src/stories/atoms/FilterChip.stories.tsx +9 -1
- package/src/stories/atoms/IconWithSquareBackground.stories.tsx +7 -7
- package/src/stories/atoms/Icons.stories.tsx +1 -1
- package/src/stories/atoms/NumberStepper.stories.tsx +44 -0
- package/src/stories/atoms/PhoneInput.stories.tsx +42 -0
- package/src/stories/atoms/RadioMark.stories.tsx +132 -0
- package/src/stories/atoms/Select.stories.tsx +139 -2
- package/src/stories/atoms/SimpleCheckbox.stories.tsx +74 -0
- package/src/stories/atoms/Switch.stories.tsx +46 -1
- package/src/stories/atoms/TextField.stories.tsx +508 -0
- package/src/stories/atoms/Tooltip.stories.tsx +5 -0
- package/src/stories/fixtures/foundations/Borders.stories.tsx +84 -0
- package/src/stories/fixtures/foundations/Effects.stories.tsx +204 -0
- package/src/stories/fixtures/foundations/Layout.stories.tsx +76 -0
- package/src/stories/fixtures/foundations/Sizes.stories.tsx +42 -0
- package/src/stories/fixtures/foundations/Spacing.stories.tsx +48 -0
- package/src/stories/fixtures/foundations/Typography.stories.tsx +49 -0
- package/src/stories/foundations/Borders.stories.tsx +179 -0
- package/src/stories/foundations/Colors.stories.tsx +253 -0
- package/src/stories/foundations/Effects.stories.tsx +116 -0
- package/src/stories/foundations/Layout.stories.tsx +177 -0
- package/src/stories/foundations/Sizes.stories.tsx +123 -0
- package/src/stories/foundations/Spacing.stories.tsx +159 -0
- package/src/stories/foundations/ThemeAdapter.stories.tsx +389 -0
- package/src/stories/foundations/Typography.stories.tsx +148 -0
- package/src/stories/molecules/Alert.stories.tsx +18 -0
- package/src/stories/molecules/Breadcrumbs.stories.tsx +51 -0
- package/src/stories/molecules/Card.stories.tsx +1 -1
- package/src/stories/molecules/CardShell.stories.tsx +1 -0
- package/src/stories/molecules/DatePicker.stories.tsx +133 -3
- package/src/stories/molecules/EmptyState.stories.tsx +106 -0
- package/src/stories/molecules/FormControlWrapper.stories.tsx +59 -0
- package/src/stories/molecules/LinkTile.stories.tsx +151 -0
- package/src/stories/molecules/ListWithIcons.stories.tsx +27 -2
- package/src/stories/molecules/RadioButtonGroup.stories.tsx +23 -0
- package/src/stories/molecules/SegmentedControl.stories.tsx +62 -1
- package/src/stories/molecules/Tabs.stories.tsx +4 -0
- package/src/stories/molecules/TitleBlock.stories.tsx +16 -16
- package/src/stories/organisms/Accordion.stories.tsx +132 -0
- package/src/stories/organisms/AdvancedListItemShell.stories.tsx +63 -23
- package/src/stories/organisms/BottomSheet.stories.tsx +48 -1
- package/src/stories/organisms/DataPagination.stories.tsx +127 -3
- package/src/stories/organisms/Dialog.stories.tsx +13 -0
- package/src/stories/organisms/FileDropzone.stories.tsx +6 -0
- package/src/stories/organisms/FileUpload.stories.tsx +4 -0
- package/src/stories/organisms/Footer.stories.tsx +20 -0
- package/src/stories/organisms/Modal.stories.tsx +53 -0
- package/src/stories/organisms/ServiceHeader.stories.tsx +25 -3
- package/src/stories/organisms/ServiceLinks.stories.tsx +1 -1
- package/src/stories/organisms/ServiceWizardStepper.stories.tsx +37 -1
- package/src/stories/organisms/SideNav.stories.tsx +8 -1
- package/src/theme/backdropTokens.test.ts +11 -0
- package/src/theme/backdropTokens.ts +11 -0
- package/src/theme/borderTokens.test.ts +59 -0
- package/src/theme/borderTokens.ts +36 -0
- package/src/theme/cards.ts +28 -28
- package/src/theme/colorTokens.test.ts +66 -0
- package/src/theme/colorTokens.ts +87 -0
- package/src/theme/effectTokens.test.ts +29 -0
- package/src/theme/effectTokens.ts +11 -0
- package/src/theme/layoutTokens.test.ts +42 -0
- package/src/theme/layoutTokens.ts +14 -0
- package/src/theme/light/MuiAccordion.tsx +30 -26
- package/src/theme/light/MuiAccordionDetails.ts +10 -5
- package/src/theme/light/MuiAccordionSummary.tsx +31 -17
- package/src/theme/light/MuiAlert.tsx +42 -65
- package/src/theme/light/MuiAutocomplete.ts +14 -7
- package/src/theme/light/MuiBreadcrumbs.tsx +17 -9
- package/src/theme/light/MuiButton.tsx +213 -204
- package/src/theme/light/MuiCard.tsx +5 -4
- package/src/theme/light/MuiCheckbox.ts +45 -14
- package/src/theme/light/MuiChip.tsx +3 -1
- package/src/theme/light/MuiDialog.ts +45 -6
- package/src/theme/light/MuiFormControl.ts +19 -9
- package/src/theme/light/MuiFormControlLabel.ts +16 -25
- package/src/theme/light/MuiFormGroup.ts +29 -26
- package/src/theme/light/MuiFormHelperText.ts +15 -4
- package/src/theme/light/MuiFormLabel.ts +20 -20
- package/src/theme/light/MuiInputBase.ts +49 -84
- package/src/theme/light/MuiOutlinedInput.ts +50 -6
- package/src/theme/light/MuiPagination.ts +21 -21
- package/src/theme/light/MuiPickerPopper.ts +17 -0
- package/src/theme/light/MuiPickersLayout.ts +63 -34
- package/src/theme/light/MuiPickersOutlinedInput.ts +38 -38
- package/src/theme/light/MuiPopover.ts +3 -1
- package/src/theme/light/MuiRadio.tsx +35 -52
- package/src/theme/light/MuiStepper.ts +21 -17
- package/src/theme/light/MuiSwitch.tsx +27 -23
- package/src/theme/light/MuiTab.tsx +27 -18
- package/src/theme/light/MuiTableCell.ts +4 -2
- package/src/theme/light/MuiTabs.tsx +11 -9
- package/src/theme/light/MuiTooltip.ts +2 -1
- package/src/theme/light/MuiTypography.tsx +0 -17
- package/src/theme/light/index.tsx +2 -0
- package/src/theme/light/themePalette.tsx +1 -0
- package/src/theme/palette.tsx +9 -0
- package/src/theme/sizeTokens.test.ts +37 -0
- package/src/theme/sizeTokens.ts +21 -0
- package/src/theme/spacingRoleBasedTokens.ts +41 -0
- package/src/theme/spacingTokens.test.ts +58 -0
- package/src/theme/spacingTokens.ts +114 -0
- package/src/theme/tokenTheme.test.tsx +402 -0
- package/src/theme/tokenTheme.ts +429 -0
- package/src/theme/tokens.css +476 -0
- package/src/theme/tokens.test.ts +174 -0
- package/src/theme/typographyTokens.test.ts +120 -0
- package/src/theme/typographyTokens.ts +119 -0
- package/dist/theme/spacing.d.ts +0 -4
- package/src/stories/foundations/Colors.mdx +0 -127
- package/src/theme/spacing.ts +0 -5
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CSSProperties,
|
|
3
|
+
type CssVarsTheme,
|
|
4
|
+
type Theme,
|
|
5
|
+
type ThemeOptions,
|
|
6
|
+
createTheme,
|
|
7
|
+
} from '@mui/material/styles'
|
|
8
|
+
|
|
9
|
+
import legacyTheme from '@/theme/light'
|
|
10
|
+
import legacyPalette, { common } from '@/theme/palette'
|
|
11
|
+
|
|
12
|
+
import './tokens.css'
|
|
13
|
+
import { type RcSesNamedTypographyVariant, typographyTokens } from './typographyTokens'
|
|
14
|
+
|
|
15
|
+
/** Keep color-scheme configuration inside the adapter until dark tokens exist. */
|
|
16
|
+
export type RcSesTokenThemeOptions = Omit<ThemeOptions, 'cssVariables' | 'colorSchemes'>
|
|
17
|
+
|
|
18
|
+
export type RcSesNativeTheme = Theme & {
|
|
19
|
+
typography: Theme['typography'] & Record<RcSesNamedTypographyVariant, CSSProperties>
|
|
20
|
+
} & Pick<
|
|
21
|
+
CssVarsTheme,
|
|
22
|
+
| 'cssVarPrefix'
|
|
23
|
+
| 'rootSelector'
|
|
24
|
+
| 'colorSchemeSelector'
|
|
25
|
+
| 'defaultColorScheme'
|
|
26
|
+
| 'getCssVar'
|
|
27
|
+
| 'getColorSchemeSelector'
|
|
28
|
+
| 'shouldSkipGeneratingVar'
|
|
29
|
+
| 'vars'
|
|
30
|
+
| 'colorSchemes'
|
|
31
|
+
| 'generateStyleSheets'
|
|
32
|
+
| 'generateSpacing'
|
|
33
|
+
| 'generateThemeVars'
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
const cssVarPrefix = 'rc-mui'
|
|
37
|
+
const token = (name: string, fallback: string) => `var(--rc-${name}, ${fallback})`
|
|
38
|
+
const inputRadius = token('radius-input', '0.5rem')
|
|
39
|
+
const spacingPrimitives = new Set([
|
|
40
|
+
0, 2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 36, 40, 48, 64, 80, 96,
|
|
41
|
+
])
|
|
42
|
+
const colorFamilies = {
|
|
43
|
+
primary: 'cyans',
|
|
44
|
+
secondary: 'greens',
|
|
45
|
+
grey: 'neutrals',
|
|
46
|
+
warning: 'yellows',
|
|
47
|
+
error: 'red',
|
|
48
|
+
} as const
|
|
49
|
+
|
|
50
|
+
function spacingLength(pixels: number, fallback: string): string {
|
|
51
|
+
const absolute = Math.abs(pixels)
|
|
52
|
+
const absoluteFallback = pixels < 0 ? fallback.replace(/^-/, '') : fallback
|
|
53
|
+
const baseFallback = /rem$/.test(fallback) ? '0.5rem' : '8px'
|
|
54
|
+
const value = spacingPrimitives.has(absolute)
|
|
55
|
+
? token(`space-${absolute}`, absoluteFallback)
|
|
56
|
+
: `calc(${token('space-8', baseFallback)} * ${absolute / 8})`
|
|
57
|
+
// Preserve the identity value; multiplication by zero can be unitless in sx.
|
|
58
|
+
if (pixels === 0) return fallback
|
|
59
|
+
return pixels < 0 ? `calc(-1 * ${value})` : value
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function tokenSpacing(factor: number | string): string {
|
|
63
|
+
return typeof factor === 'string'
|
|
64
|
+
? factor
|
|
65
|
+
: spacingLength(factor * 8, `${factor * 8}px`)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
69
|
+
return (
|
|
70
|
+
typeof value === 'object' &&
|
|
71
|
+
value !== null &&
|
|
72
|
+
Object.getPrototypeOf(value) === Object.prototype
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function mapTree<T>(value: T, transform: (key: string, item: unknown) => unknown): T {
|
|
77
|
+
if (Array.isArray(value))
|
|
78
|
+
return value.map((item: unknown) => mapTree(item, transform)) as T
|
|
79
|
+
if (typeof value === 'function') {
|
|
80
|
+
const callback = value as (...args: unknown[]) => unknown
|
|
81
|
+
return ((...args: unknown[]) => mapTree(callback(...args), transform)) as T
|
|
82
|
+
}
|
|
83
|
+
if (!isPlainObject(value)) return value
|
|
84
|
+
return Object.fromEntries(
|
|
85
|
+
Object.entries(value)
|
|
86
|
+
.map(([key, item]) => [key, transform(key, mapTree(item, transform))])
|
|
87
|
+
.filter(([, item]) => item !== undefined),
|
|
88
|
+
) as T
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const colorReferences = new Map<string, string>([
|
|
92
|
+
[common.white, token('color-white', common.white)],
|
|
93
|
+
])
|
|
94
|
+
Object.entries(colorFamilies).forEach(([family, collection]) => {
|
|
95
|
+
const shades = legacyPalette[family as keyof typeof legacyPalette]
|
|
96
|
+
Object.entries(shades).forEach(([shade, value]) => {
|
|
97
|
+
if (shade !== 'main')
|
|
98
|
+
colorReferences.set(
|
|
99
|
+
value.toLowerCase(),
|
|
100
|
+
token(`color-${collection}-${shade}`, value),
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const typographyRoles = {
|
|
106
|
+
h1: 'heading-h1',
|
|
107
|
+
h2: 'heading-h2',
|
|
108
|
+
h3: 'heading-h3',
|
|
109
|
+
h4: 'heading-h4',
|
|
110
|
+
h5: 'heading-h5',
|
|
111
|
+
body1: 'body-regular',
|
|
112
|
+
body2: 'body-small',
|
|
113
|
+
caption: 'body-caption',
|
|
114
|
+
subtitle1: 'body-lead',
|
|
115
|
+
subtitle2: 'body-micro',
|
|
116
|
+
button: 'button-regular',
|
|
117
|
+
overline: 'body-micro',
|
|
118
|
+
} as const
|
|
119
|
+
|
|
120
|
+
// Figma text-style weights that differ from the legacy variant weights.
|
|
121
|
+
const textStyleFontWeights = { h5: 600 } as const
|
|
122
|
+
|
|
123
|
+
function typographyStyle<T>(style: T, role: string): T {
|
|
124
|
+
return mapTree(style, (key, value) => {
|
|
125
|
+
if (
|
|
126
|
+
(key === 'fontSize' || key === 'lineHeight' || key === 'letterSpacing') &&
|
|
127
|
+
(typeof value === 'number' || typeof value === 'string')
|
|
128
|
+
) {
|
|
129
|
+
const fallback =
|
|
130
|
+
typeof value === 'number' && key === 'fontSize' ? `${value}px` : String(value)
|
|
131
|
+
const tokenKeyMap: Record<string, string> = {
|
|
132
|
+
fontSize: 'font-size',
|
|
133
|
+
lineHeight: 'line-height',
|
|
134
|
+
letterSpacing: 'letter-spacing',
|
|
135
|
+
}
|
|
136
|
+
const tokenKey = tokenKeyMap[key] || key
|
|
137
|
+
return token(
|
|
138
|
+
`typography-${tokenKey}-${role}`,
|
|
139
|
+
role === 'heading-h1'
|
|
140
|
+
? `var(--rc-mui-h1-fallback-${key}, ${fallback})`
|
|
141
|
+
: fallback,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
return value
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Opt-in native MUI CSS-variable theme. The raw palette and numeric shape stay
|
|
150
|
+
* usable by existing JS consumers; MUI's generated CSS resolves from DS tokens.
|
|
151
|
+
* RcSesTheme remains the unchanged legacy fallback.
|
|
152
|
+
*/
|
|
153
|
+
export function createRcSesTokenTheme(
|
|
154
|
+
options: RcSesTokenThemeOptions = {},
|
|
155
|
+
): RcSesNativeTheme {
|
|
156
|
+
const { typography: typographyInput, ...otherOptions } = options
|
|
157
|
+
const fallback = createTheme(legacyTheme, otherOptions)
|
|
158
|
+
// MUI evaluates typography callbacks in the first argument, but only deep-merges
|
|
159
|
+
// later arguments. Resolve that supported input before merging into the base.
|
|
160
|
+
const customTypography =
|
|
161
|
+
typeof typographyInput === 'function'
|
|
162
|
+
? typographyInput(fallback.palette)
|
|
163
|
+
: typographyInput
|
|
164
|
+
const typography = {
|
|
165
|
+
...legacyTheme.typography,
|
|
166
|
+
// Preserve the named styles from SAV-6985 without guessing font attributes.
|
|
167
|
+
headingCardTitle: {
|
|
168
|
+
fontSize: typographyTokens['font-size-heading-card-title'],
|
|
169
|
+
lineHeight: typographyTokens['line-height-heading-card-title'],
|
|
170
|
+
letterSpacing: typographyTokens['letter-spacing-heading-card-title'],
|
|
171
|
+
},
|
|
172
|
+
bodyLarge: {
|
|
173
|
+
fontSize: typographyTokens['font-size-body-large'],
|
|
174
|
+
lineHeight: typographyTokens['line-height-body-large'],
|
|
175
|
+
},
|
|
176
|
+
buttonCompact: {
|
|
177
|
+
fontSize: typographyTokens['font-size-button-compact'],
|
|
178
|
+
lineHeight: typographyTokens['line-height-button-compact'],
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
const typographySlots = { ...legacyTheme.components?.MuiTypography?.styleOverrides }
|
|
182
|
+
Object.entries(typographyRoles).forEach(([variant, role]) => {
|
|
183
|
+
const variantKey = variant as keyof typeof typographyRoles
|
|
184
|
+
// H1 media rules retain only private var() fallbacks, never competing sizes.
|
|
185
|
+
const style = mapTree(typography[variantKey], (key, value) => {
|
|
186
|
+
if (!isPlainObject(value)) return value
|
|
187
|
+
return Object.fromEntries(
|
|
188
|
+
Object.entries(value).flatMap(([property, amount]) => {
|
|
189
|
+
if (
|
|
190
|
+
property !== 'fontSize' &&
|
|
191
|
+
property !== 'lineHeight' &&
|
|
192
|
+
property !== 'letterSpacing'
|
|
193
|
+
)
|
|
194
|
+
return [[property, amount]]
|
|
195
|
+
return variant === 'h1' ? [[`--rc-mui-h1-fallback-${property}`, amount]] : []
|
|
196
|
+
}),
|
|
197
|
+
)
|
|
198
|
+
})
|
|
199
|
+
const fontWeight =
|
|
200
|
+
textStyleFontWeights[variantKey as keyof typeof textStyleFontWeights]
|
|
201
|
+
typography[variantKey] = {
|
|
202
|
+
...typographyStyle(style, role),
|
|
203
|
+
letterSpacing:
|
|
204
|
+
typographyTokens[`letter-spacing-${role}` as keyof typeof typographyTokens],
|
|
205
|
+
...(fontWeight === undefined ? {} : { fontWeight }),
|
|
206
|
+
}
|
|
207
|
+
const slot = typographySlots[variantKey as keyof typeof typographySlots]
|
|
208
|
+
if (slot) {
|
|
209
|
+
Object.assign(typographySlots, {
|
|
210
|
+
[variant]: mapTree(slot, (key, value) =>
|
|
211
|
+
key === 'fontSize' ||
|
|
212
|
+
key === 'lineHeight' ||
|
|
213
|
+
key === 'letterSpacing' ||
|
|
214
|
+
(key === 'fontWeight' &&
|
|
215
|
+
(fontWeight !== undefined ||
|
|
216
|
+
customTypography?.[variantKey]?.fontWeight !== undefined))
|
|
217
|
+
? undefined
|
|
218
|
+
: value,
|
|
219
|
+
),
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
const components = {
|
|
224
|
+
...legacyTheme.components,
|
|
225
|
+
MuiTypography: {
|
|
226
|
+
...legacyTheme.components?.MuiTypography,
|
|
227
|
+
styleOverrides: typographySlots,
|
|
228
|
+
},
|
|
229
|
+
}
|
|
230
|
+
const adapted = createTheme(
|
|
231
|
+
{ ...legacyTheme, typography, components },
|
|
232
|
+
{
|
|
233
|
+
components: {
|
|
234
|
+
MuiButton: {
|
|
235
|
+
styleOverrides: { root: { borderRadius: token('radius-button', '0.5rem') } },
|
|
236
|
+
},
|
|
237
|
+
MuiCard: {
|
|
238
|
+
styleOverrides: { root: { borderRadius: token('radius-card', '1rem') } },
|
|
239
|
+
},
|
|
240
|
+
MuiPopover: {
|
|
241
|
+
styleOverrides: {
|
|
242
|
+
paper: { boxShadow: token('elevation-md', fallback.shadows[8]) },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
MuiDialog: {
|
|
246
|
+
styleOverrides: {
|
|
247
|
+
paper: { boxShadow: token('elevation-lg', fallback.shadows[24]) },
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
MuiSnackbarContent: {
|
|
251
|
+
styleOverrides: {
|
|
252
|
+
root: { boxShadow: token('elevation-lg', fallback.shadows[6]) },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
MuiInputBase: {
|
|
256
|
+
styleOverrides: {
|
|
257
|
+
root: {
|
|
258
|
+
borderRadius: inputRadius,
|
|
259
|
+
'&.Mui-focused': {
|
|
260
|
+
'.MuiOutlinedInput-notchedOutline': {
|
|
261
|
+
borderRadius: inputRadius,
|
|
262
|
+
},
|
|
263
|
+
'&.Mui-error': {
|
|
264
|
+
'.MuiOutlinedInput-notchedOutline': {
|
|
265
|
+
borderRadius: inputRadius,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
MuiOutlinedInput: {
|
|
273
|
+
styleOverrides: {
|
|
274
|
+
root: {
|
|
275
|
+
borderRadius: inputRadius,
|
|
276
|
+
'.MuiOutlinedInput-notchedOutline': {
|
|
277
|
+
borderRadius: inputRadius,
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
MuiAutocomplete: {
|
|
283
|
+
styleOverrides: {
|
|
284
|
+
paper: {
|
|
285
|
+
boxShadow: token('elevation-md', '0px 4px 16px 0px rgba(0, 0, 0, 0.08)'),
|
|
286
|
+
},
|
|
287
|
+
root: {
|
|
288
|
+
'.MuiOutlinedInput-root': {
|
|
289
|
+
borderRadius: inputRadius,
|
|
290
|
+
'.MuiOutlinedInput-notchedOutline': { borderRadius: inputRadius },
|
|
291
|
+
'&.Mui-focused': {
|
|
292
|
+
borderRadius: inputRadius,
|
|
293
|
+
'.MuiOutlinedInput-notchedOutline': { borderRadius: inputRadius },
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
MuiPickersOutlinedInput: {
|
|
300
|
+
styleOverrides: {
|
|
301
|
+
root: {
|
|
302
|
+
borderRadius: inputRadius,
|
|
303
|
+
'.MuiPickersOutlinedInput-notchedOutline': {
|
|
304
|
+
borderRadius: inputRadius,
|
|
305
|
+
},
|
|
306
|
+
'&.Mui-focused': {
|
|
307
|
+
'.MuiPickersOutlinedInput-notchedOutline': {
|
|
308
|
+
borderRadius: inputRadius,
|
|
309
|
+
},
|
|
310
|
+
'&.Mui-error': {
|
|
311
|
+
'.MuiPickersOutlinedInput-notchedOutline': {
|
|
312
|
+
borderRadius: inputRadius,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
...otherOptions,
|
|
323
|
+
...(customTypography === undefined ? {} : { typography: customTypography }),
|
|
324
|
+
},
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
const theme = createTheme({
|
|
328
|
+
...options,
|
|
329
|
+
palette: undefined,
|
|
330
|
+
cssVariables: {
|
|
331
|
+
nativeColor: true,
|
|
332
|
+
cssVarPrefix,
|
|
333
|
+
colorSchemeSelector: 'data-rc-color-scheme',
|
|
334
|
+
},
|
|
335
|
+
colorSchemes: { light: { palette: fallback.palette } },
|
|
336
|
+
typography: adapted.typography,
|
|
337
|
+
components: adapted.components,
|
|
338
|
+
spacing: options.spacing ?? tokenSpacing,
|
|
339
|
+
shape: fallback.shape,
|
|
340
|
+
breakpoints: fallback.breakpoints,
|
|
341
|
+
direction: fallback.direction,
|
|
342
|
+
mixins: fallback.mixins,
|
|
343
|
+
shadows: fallback.shadows,
|
|
344
|
+
transitions: fallback.transitions,
|
|
345
|
+
zIndex: fallback.zIndex,
|
|
346
|
+
}) as RcSesNativeTheme
|
|
347
|
+
|
|
348
|
+
const bindings = new Map<string, string>()
|
|
349
|
+
const bind = (palettePath: string, name: string) => {
|
|
350
|
+
const parts = palettePath.split('.')
|
|
351
|
+
let value: unknown = fallback.palette
|
|
352
|
+
let custom: unknown = options.palette
|
|
353
|
+
parts.forEach((part) => {
|
|
354
|
+
value = isPlainObject(value) ? value[part] : undefined
|
|
355
|
+
custom = isPlainObject(custom) ? custom[part] : undefined
|
|
356
|
+
})
|
|
357
|
+
if (typeof value === 'string' && custom === undefined) {
|
|
358
|
+
bindings.set(`--${cssVarPrefix}-palette-${parts.join('-')}`, token(name, value))
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
Object.entries(colorFamilies).forEach(([family, collection]) => {
|
|
362
|
+
const shades = legacyPalette[family as keyof typeof legacyPalette]
|
|
363
|
+
Object.keys(shades)
|
|
364
|
+
.filter((shade) => shade !== 'main')
|
|
365
|
+
.forEach((shade) => bind(`${family}.${shade}`, `color-${collection}-${shade}`))
|
|
366
|
+
bind(`${family}.main`, `color-${collection}-500`)
|
|
367
|
+
;(['light', 'dark'] as const).forEach((shade) => {
|
|
368
|
+
const value =
|
|
369
|
+
fallback.palette[family as 'primary' | 'secondary' | 'warning' | 'error'][shade]
|
|
370
|
+
const reference = colorReferences.get(value?.toLowerCase())
|
|
371
|
+
const customColor =
|
|
372
|
+
options.palette?.[family as 'primary' | 'secondary' | 'warning' | 'error']
|
|
373
|
+
if (
|
|
374
|
+
reference &&
|
|
375
|
+
(!isPlainObject(customColor) || !Object.hasOwn(customColor, shade))
|
|
376
|
+
) {
|
|
377
|
+
bindings.set(`--${cssVarPrefix}-palette-${family}-${shade}`, reference)
|
|
378
|
+
}
|
|
379
|
+
})
|
|
380
|
+
})
|
|
381
|
+
;['dark', 'light', 'ghost'].forEach((family) => {
|
|
382
|
+
Object.keys(legacyPalette.grey).forEach((shade) =>
|
|
383
|
+
bind(`${family}.${shade}`, `color-neutrals-${shade === 'main' ? '500' : shade}`),
|
|
384
|
+
)
|
|
385
|
+
})
|
|
386
|
+
;['primary', 'secondary', 'warning', 'error', 'success', 'info'].forEach((family) => {
|
|
387
|
+
const palette = fallback.palette[family as 'primary']
|
|
388
|
+
bind(
|
|
389
|
+
`${family}.contrastText`,
|
|
390
|
+
palette.contrastText === common.white ? 'color-text-inverse' : 'color-text-default',
|
|
391
|
+
)
|
|
392
|
+
})
|
|
393
|
+
const semanticBindings = {
|
|
394
|
+
'primary.main': 'control-selected',
|
|
395
|
+
'text.primary': 'text-default',
|
|
396
|
+
'text.secondary': 'text-secondary',
|
|
397
|
+
'text.disabled': 'text-disabled',
|
|
398
|
+
'background.default': 'surface-base',
|
|
399
|
+
'background.paper': 'surface-raised',
|
|
400
|
+
divider: 'border-subtle',
|
|
401
|
+
'common.white': 'text-inverse',
|
|
402
|
+
'action.active': 'text-secondary',
|
|
403
|
+
'action.disabled': 'text-disabled',
|
|
404
|
+
'action.disabledBackground': 'control-disabled',
|
|
405
|
+
'success.main': 'status-success-icon',
|
|
406
|
+
'success.light': 'status-success-bg',
|
|
407
|
+
'success.dark': 'status-success-text',
|
|
408
|
+
'info.main': 'status-info-icon',
|
|
409
|
+
'info.light': 'status-info-bg',
|
|
410
|
+
'info.dark': 'status-info-text',
|
|
411
|
+
}
|
|
412
|
+
Object.entries(semanticBindings).forEach(([palettePath, name]) =>
|
|
413
|
+
bind(palettePath, `color-${name}`),
|
|
414
|
+
)
|
|
415
|
+
bind('action.hover', 'color-overlays-black-4')
|
|
416
|
+
bind('action.selected', 'color-overlays-black-8')
|
|
417
|
+
if (options.shape?.borderRadius === undefined)
|
|
418
|
+
bindings.set(`--${cssVarPrefix}-shape-borderRadius`, token('radius-4', '4px'))
|
|
419
|
+
|
|
420
|
+
// Bind at CSS emission rather than replacing theme.palette strings. This
|
|
421
|
+
// preserves alpha()/decomposeColor() callers and native MUI theme.vars.
|
|
422
|
+
const { generateStyleSheets } = theme
|
|
423
|
+
if (!generateStyleSheets) throw new Error('MUI CSS variables are unavailable')
|
|
424
|
+
theme.generateStyleSheets = () =>
|
|
425
|
+
generateStyleSheets().map((sheet) =>
|
|
426
|
+
mapTree(sheet, (key, value) => bindings.get(key) ?? value),
|
|
427
|
+
)
|
|
428
|
+
return theme
|
|
429
|
+
}
|