@yahoo/uds 3.59.0-beta.1 → 3.59.0-beta.2
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/cli/bin/uds-darwin-arm64-baseline +0 -0
- package/cli/bin/uds-darwin-x64 +0 -0
- package/cli/bin/uds-linux-arm64 +0 -0
- package/cli/bin/uds-linux-x64-baseline +0 -0
- package/dist/components/Box.d.ts +2 -2
- package/dist/components/Box.d.ts.map +1 -1
- package/dist/components/Divider/Divider.d.cts +2 -2
- package/dist/components/Divider/Divider.d.ts +2 -2
- package/dist/components/Divider/DividerCore.d.cts +2 -2
- package/dist/components/Divider/DividerCore.d.ts +2 -2
- package/dist/components/Divider/DividerInternal.d.cts +2 -2
- package/dist/components/Divider/DividerInternal.d.ts +2 -2
- package/dist/components/FormLabel.d.ts +2 -2
- package/dist/components/HStack.d.ts +2 -2
- package/dist/components/Icon.d.ts +2 -2
- package/dist/components/Link.d.ts +2 -2
- package/dist/components/Text.d.cts +5 -5
- package/dist/components/Text.d.cts.map +1 -1
- package/dist/components/Text.d.ts +8 -8
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/VStack.d.ts +2 -2
- package/dist/components/VStack.d.ts.map +1 -1
- package/dist/components/client/AnimateHeightChange.d.cts +2 -2
- package/dist/components/client/AnimateHeightChange.d.ts +2 -2
- package/dist/components/client/Avatar/Avatar.d.cts +2 -2
- package/dist/components/client/Avatar/Avatar.d.cts.map +1 -1
- package/dist/components/client/Avatar/Avatar.d.ts +2 -2
- package/dist/components/client/Avatar/AvatarIcon.d.cts +2 -2
- package/dist/components/client/Avatar/AvatarIcon.d.cts.map +1 -1
- package/dist/components/client/Avatar/AvatarIcon.d.ts +2 -2
- package/dist/components/client/Avatar/AvatarImage.d.cts +2 -2
- package/dist/components/client/Avatar/AvatarImage.d.ts +2 -2
- package/dist/components/client/Avatar/AvatarText.d.cts +2 -2
- package/dist/components/client/Avatar/AvatarText.d.ts +2 -2
- package/dist/components/client/IconButton.d.cts +2 -2
- package/dist/components/client/IconButton.d.ts +2 -2
- package/dist/components/client/IconButton.d.ts.map +1 -1
- package/dist/components/client/Input/Input.d.cts +2 -2
- package/dist/components/client/Input/Input.d.ts +2 -2
- package/dist/components/client/Input/InputHelpText.d.cts +2 -2
- package/dist/components/client/Input/InputHelpText.d.cts.map +1 -1
- package/dist/components/client/Input/InputHelpText.d.ts +2 -2
- package/dist/components/client/Input/InputHelpTextInternal.d.cts +4 -4
- package/dist/components/client/Input/InputHelpTextInternal.d.cts.map +1 -1
- package/dist/components/client/Input/InputHelpTextInternal.d.ts +4 -4
- package/dist/components/client/Menu/Menu.Content.d.cts +2 -2
- package/dist/components/client/Menu/Menu.Content.d.ts +2 -2
- package/dist/components/client/Menu/Menu.Divider.d.cts +2 -2
- package/dist/components/client/Menu/Menu.Divider.d.ts +2 -2
- package/dist/components/client/Menu/Menu.Item.d.cts +2 -2
- package/dist/components/client/Menu/Menu.ItemBase.d.cts +2 -2
- package/dist/components/client/Menu/Menu.ItemBase.d.ts +2 -2
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +2 -2
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +2 -2
- package/dist/components/client/Menu/Menu.Provider.d.cts +2 -2
- package/dist/components/client/Menu/Menu.Provider.d.ts +2 -2
- package/dist/components/client/Menu/Menu.Trigger.d.cts +2 -2
- package/dist/components/client/Menu/Menu.Trigger.d.ts +2 -2
- package/dist/components/client/Pressable.d.cts +2 -2
- package/dist/components/client/Pressable.d.ts +2 -2
- package/dist/components/client/Pressable.d.ts.map +1 -1
- package/dist/components/client/Radio/RadioGroupStore.d.ts +2 -2
- package/dist/components/client/SpringMotionConfig.d.cts +3 -3
- package/dist/components/client/SpringMotionConfig.d.ts +3 -3
- package/dist/components/client/SpringMotionConfig.d.ts.map +1 -1
- package/dist/components/experimental/Spinner.d.cts +2 -2
- package/dist/components/experimental/Spinner.d.cts.map +1 -1
- package/dist/components/experimental/Spinner.d.ts +2 -2
- package/dist/components/experimental/Table.d.cts +2 -2
- package/dist/components/experimental/Table.d.ts +2 -2
- package/dist/components/experimental/client/Accordion.d.cts +2 -2
- package/dist/components/experimental/client/Accordion.d.cts.map +1 -1
- package/dist/components/experimental/client/Accordion.d.ts +2 -2
- package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.cts +2 -2
- package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.ts +2 -2
- package/dist/components/experimental/client/Modal.d.cts +3 -3
- package/dist/components/experimental/client/Modal.d.cts.map +1 -1
- package/dist/components/experimental/client/Modal.d.ts +3 -3
- package/dist/components/experimental/client/Popover.d.cts +3 -3
- package/dist/components/experimental/client/Popover.d.cts.map +1 -1
- package/dist/components/experimental/client/Popover.d.ts +3 -3
- package/dist/components/experimental/client/Tabs.d.cts +3 -3
- package/dist/components/experimental/client/Tabs.d.ts +6 -6
- package/dist/components/experimental/client/Toast.d.cts +2 -2
- package/dist/components/experimental/client/Toast.d.ts +2 -2
- package/dist/providers/ColorModeProvider.d.cts +4 -4
- package/dist/providers/ColorModeProvider.d.cts.map +1 -1
- package/dist/providers/ColorModeProvider.d.ts +4 -4
- package/dist/providers/ColorModeProvider.d.ts.map +1 -1
- package/dist/providers/ScaleModeProvider.d.cts +4 -4
- package/dist/providers/ScaleModeProvider.d.cts.map +1 -1
- package/dist/providers/ScaleModeProvider.d.ts +4 -4
- package/dist/providers/ScaleModeProvider.d.ts.map +1 -1
- package/dist/providers/ThemeProvider.d.cts +2 -2
- package/dist/providers/ThemeProvider.d.cts.map +1 -1
- package/dist/providers/ThemeProvider.d.ts +2 -2
- package/dist/styles/styler.d.cts +33 -33
- package/dist/styles/styler.d.ts +33 -33
- package/dist/styles/stylerTypes.d.ts.map +1 -1
- package/dist/tailwind/tailwind.config.d.ts +3 -3
- package/dist/tailwind/tailwindPlugin.d.ts +3 -3
- package/dist/tailwind/utils/getMotionStyles.d.cts +1 -1
- package/dist/tailwind/utils/getMotionStyles.d.ts +1 -1
- package/dist/tokens/automation/utils/getConfigVariantProperties.d.cts +2 -2
- package/dist/tokens/automation/utils/getConfigVariantProperties.d.cts.map +1 -1
- package/dist/tokens/automation/utils/getConfigVariantProperties.d.ts +2 -2
- package/dist/tokens/automation/utils/getConfigVariantProperties.d.ts.map +1 -1
- package/dist/tokens/types.d.cts.map +1 -1
- package/dist/tokens/types.d.ts.map +1 -1
- package/dist/utils/intersperse.d.cts +2 -2
- package/dist/utils/intersperse.d.ts +2 -2
- package/package.json +1 -3
- package/cli/FlattenButtonVariant.mock.tsx +0 -17
- package/src/components/Box.tsx +0 -181
- package/src/components/Divider/Divider.tsx +0 -44
- package/src/components/Divider/DividerCore.tsx +0 -101
- package/src/components/Divider/DividerInternal.tsx +0 -56
- package/src/components/Divider/index.ts +0 -1
- package/src/components/FormLabel.tsx +0 -66
- package/src/components/HStack.tsx +0 -53
- package/src/components/Icon.tsx +0 -82
- package/src/components/IconSlot.tsx +0 -82
- package/src/components/Image.tsx +0 -162
- package/src/components/Link.tsx +0 -134
- package/src/components/Text.tsx +0 -272
- package/src/components/VStack.tsx +0 -53
- package/src/components/client/AnimateHeightChange.tsx +0 -50
- package/src/components/client/Avatar/Avatar.tsx +0 -31
- package/src/components/client/Avatar/AvatarIcon.tsx +0 -103
- package/src/components/client/Avatar/AvatarImage.tsx +0 -147
- package/src/components/client/Avatar/AvatarText.tsx +0 -88
- package/src/components/client/Avatar/index.ts +0 -4
- package/src/components/client/Avatar/utils.ts +0 -105
- package/src/components/client/Badge.tsx +0 -133
- package/src/components/client/Button.tsx +0 -312
- package/src/components/client/Checkbox.tsx +0 -377
- package/src/components/client/Chip/Chip.tsx +0 -81
- package/src/components/client/Chip/ChipBase.tsx +0 -151
- package/src/components/client/Chip/ChipButton.tsx +0 -54
- package/src/components/client/Chip/ChipDismissible.tsx +0 -90
- package/src/components/client/Chip/ChipLink.tsx +0 -60
- package/src/components/client/Chip/ChipToggle.tsx +0 -79
- package/src/components/client/Chip/index.ts +0 -5
- package/src/components/client/IconButton.tsx +0 -198
- package/src/components/client/Input/Input.tsx +0 -323
- package/src/components/client/Input/InputHelpText.tsx +0 -52
- package/src/components/client/Input/InputHelpTextInternal.tsx +0 -81
- package/src/components/client/Input/index.ts +0 -2
- package/src/components/client/Menu/Menu.Content.tsx +0 -391
- package/src/components/client/Menu/Menu.Divider.tsx +0 -102
- package/src/components/client/Menu/Menu.Item.tsx +0 -114
- package/src/components/client/Menu/Menu.ItemBase.tsx +0 -265
- package/src/components/client/Menu/Menu.ItemCheckbox.tsx +0 -197
- package/src/components/client/Menu/Menu.Provider.tsx +0 -154
- package/src/components/client/Menu/Menu.Trigger.tsx +0 -119
- package/src/components/client/Menu/Menu.index.tsx +0 -9
- package/src/components/client/Menu/Menu.tsx +0 -2
- package/src/components/client/Menu/index.ts +0 -7
- package/src/components/client/Menu/utils/transformAriakitPlacement.ts +0 -66
- package/src/components/client/Pressable.tsx +0 -194
- package/src/components/client/Radio/Radio.tsx +0 -351
- package/src/components/client/Radio/RadioGroupProvider.tsx +0 -122
- package/src/components/client/Radio/RadioGroupStore.tsx +0 -56
- package/src/components/client/Radio/index.ts +0 -2
- package/src/components/client/Radio/useRadioGroup.ts +0 -149
- package/src/components/client/SpringMotionConfig.tsx +0 -151
- package/src/components/client/Switch.tsx +0 -377
- package/src/components/client/index.ts +0 -30
- package/src/components/client/motionFeatures/domAnimation.ts +0 -2
- package/src/components/client/motionFeatures/domMax.ts +0 -2
- package/src/components/experimental/Spinner.tsx +0 -30
- package/src/components/experimental/Table.mocks.tsx +0 -38
- package/src/components/experimental/Table.tsx +0 -239
- package/src/components/experimental/client/Accordion.tsx +0 -77
- package/src/components/experimental/client/AvoidMotionLibraryProvider.tsx +0 -10
- package/src/components/experimental/client/Modal.tsx +0 -68
- package/src/components/experimental/client/Popover.tsx +0 -63
- package/src/components/experimental/client/SwitchV2.tsx +0 -343
- package/src/components/experimental/client/Tabs.tsx +0 -106
- package/src/components/experimental/client/Toast.tsx +0 -186
- package/src/components/experimental/client/index.ts +0 -15
- package/src/components/experimental/index.ts +0 -48
- package/src/components/index.ts +0 -41
- package/src/defaultTokensConfig.ts +0 -31
- package/src/fixtures/index.ts +0 -638
- package/src/fixtures/macros/typesToConstants.ts +0 -42
- package/src/fixtures/utils/getScaleModeRamp.ts +0 -48
- package/src/fixtures/utils/getTailwindAsUdsColors.ts +0 -115
- package/src/flags.ts +0 -45
- package/src/hooks/useForkRef.ts +0 -34
- package/src/hooks/useNestedBorderRadius.ts +0 -138
- package/src/hooks/useRtl.ts +0 -64
- package/src/index.ts +0 -4
- package/src/providers/ColorModeProvider.tsx +0 -21
- package/src/providers/ScaleModeProvider.tsx +0 -29
- package/src/providers/ThemeProvider.tsx +0 -26
- package/src/styles/styler.ts +0 -194
- package/src/styles/stylerTypes.ts +0 -81
- package/src/styles/toast.css +0 -0
- package/src/styles/variants.ts +0 -1351
- package/src/tailwind/base/addColorModeVars.ts +0 -23
- package/src/tailwind/base/addColorModeVarsV2.ts +0 -57
- package/src/tailwind/base/addFontFaceDeclarations.ts +0 -13
- package/src/tailwind/base/addFontVars.ts +0 -9
- package/src/tailwind/base/addMotionVars.ts +0 -9
- package/src/tailwind/base/addScaleModeVars.ts +0 -33
- package/src/tailwind/base/types.ts +0 -8
- package/src/tailwind/components/getButtonStyles.ts +0 -240
- package/src/tailwind/components/getFocusRingStyles.ts +0 -32
- package/src/tailwind/components/getGroupedTextStyles.ts +0 -29
- package/src/tailwind/components/getHitTargetStyles.ts +0 -23
- package/src/tailwind/components/getIconButtonStyles.ts +0 -49
- package/src/tailwind/components/getIconStyles.ts +0 -13
- package/src/tailwind/components/getInputStyles.ts +0 -20
- package/src/tailwind/components/getResponsiveTextStyles.ts +0 -161
- package/src/tailwind/components/types.ts +0 -14
- package/src/tailwind/components/utils.ts +0 -73
- package/src/tailwind/defaultTailwindThemeAsUdsConfig.ts +0 -78
- package/src/tailwind/postcss.config.ts +0 -6
- package/src/tailwind/purger/index.ts +0 -1
- package/src/tailwind/tailwind.config.ts +0 -50
- package/src/tailwind/tailwind.d.ts +0 -5
- package/src/tailwind/tailwindPlugin.ts +0 -724
- package/src/tailwind/theme/getFontFamilyTheme.ts +0 -28
- package/src/tailwind/tsMorph.ts +0 -1
- package/src/tailwind/uds.css +0 -3
- package/src/tailwind/utils/addFontsPlugin.ts +0 -17
- package/src/tailwind/utils/getColorModeStyles.ts +0 -21
- package/src/tailwind/utils/getFontFaceDeclarations.ts +0 -12
- package/src/tailwind/utils/getFontStyles.ts +0 -38
- package/src/tailwind/utils/getMotionStyles.ts +0 -35
- package/src/tailwind/utils/getScaleModeStyles.ts +0 -23
- package/src/tailwind/utils/getShadowPresetValues.ts +0 -133
- package/src/tailwind/utils/getShadowStyles.ts +0 -26
- package/src/tailwind/utils/getShadowVars.ts +0 -40
- package/src/tailwind/utils/index.ts +0 -9
- package/src/tokens/automation/configs/avatar.ts +0 -297
- package/src/tokens/automation/configs/badge.ts +0 -306
- package/src/tokens/automation/configs/checkbox.ts +0 -226
- package/src/tokens/automation/configs/chip.ts +0 -521
- package/src/tokens/automation/configs/divider.ts +0 -112
- package/src/tokens/automation/configs/index.ts +0 -10
- package/src/tokens/automation/configs/input.ts +0 -496
- package/src/tokens/automation/configs/link.ts +0 -183
- package/src/tokens/automation/configs/menu.ts +0 -344
- package/src/tokens/automation/configs/radio.ts +0 -225
- package/src/tokens/automation/configs/switch.ts +0 -323
- package/src/tokens/automation/index.ts +0 -5
- package/src/tokens/automation/mapTextVariantFixtureToValue.ts +0 -8
- package/src/tokens/automation/properties.ts +0 -433
- package/src/tokens/automation/types/ComponentConfig.ts +0 -116
- package/src/tokens/automation/types/ComponentDB.ts +0 -1
- package/src/tokens/automation/types/ComponentStyles.ts +0 -47
- package/src/tokens/automation/types/index.ts +0 -2
- package/src/tokens/automation/utils/cartesianProduct.ts +0 -13
- package/src/tokens/automation/utils/coalesceConfigVariant.ts +0 -49
- package/src/tokens/automation/utils/defaults.ts +0 -29
- package/src/tokens/automation/utils/generateKeyFromFlatConfigPath.ts +0 -15
- package/src/tokens/automation/utils/generateSchemaKey.ts +0 -29
- package/src/tokens/automation/utils/getConfigComponentVariant.ts +0 -28
- package/src/tokens/automation/utils/getConfigVariantComponentStatesMatrix.ts +0 -40
- package/src/tokens/automation/utils/getConfigVariantProperties.ts +0 -32
- package/src/tokens/automation/utils/getConfigVariantPseudoStates.ts +0 -70
- package/src/tokens/automation/utils/getConfigVariants.ts +0 -73
- package/src/tokens/automation/utils/index.ts +0 -939
- package/src/tokens/automation/utils/mapColorFixtureToValue.ts +0 -34
- package/src/tokens/automation/utils/subcomponents.ts +0 -13
- package/src/tokens/automation/utils/variableData.ts +0 -79
- package/src/tokens/automation/utils/variantConfigGuards.ts +0 -17
- package/src/tokens/configs/borderRadius.ts +0 -23
- package/src/tokens/configs/borderWidth.ts +0 -17
- package/src/tokens/configs/button.ts +0 -888
- package/src/tokens/configs/colorMode.ts +0 -14
- package/src/tokens/configs/font.ts +0 -9
- package/src/tokens/configs/iconButton.ts +0 -28
- package/src/tokens/configs/motion.ts +0 -135
- package/src/tokens/configs/palette.ts +0 -124
- package/src/tokens/configs/scaleMode.ts +0 -28
- package/src/tokens/configs/shadow.ts +0 -286
- package/src/tokens/configs/sizes.ts +0 -23
- package/src/tokens/configs/spectrum.ts +0 -729
- package/src/tokens/configs/typography.ts +0 -417
- package/src/tokens/configs/yosConfig.ts +0 -7651
- package/src/tokens/consts/buttonMotionTokens.ts +0 -99
- package/src/tokens/consts/cssTokens.ts +0 -110
- package/src/tokens/consts/defaultModes.ts +0 -15
- package/src/tokens/consts/fontDeclarationsMap.ts +0 -509
- package/src/tokens/index.ts +0 -15
- package/src/tokens/parseButtonVariants.ts +0 -59
- package/src/tokens/parseTokens.ts +0 -122
- package/src/tokens/types.ts +0 -1882
- package/src/tokens/utils/entries.ts +0 -14
- package/src/tokens/utils/fromEntries.ts +0 -11
- package/src/tokens/utils/mapValues.ts +0 -15
- package/src/types.ts +0 -2
- package/src/utils/assertUnreachable.ts +0 -6
- package/src/utils/composeRefs.ts +0 -23
- package/src/utils/createSlot.tsx +0 -131
- package/src/utils/entries.ts +0 -6
- package/src/utils/falsyToString.ts +0 -3
- package/src/utils/getMotionVar.ts +0 -18
- package/src/utils/intersperse.ts +0 -45
- package/src/utils/mapValues.ts +0 -15
- package/src/utils/mergeSlotProps.ts +0 -70
|
@@ -1,939 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
ComponentConfig,
|
|
5
|
-
ComponentStateConfig,
|
|
6
|
-
LayerConfig,
|
|
7
|
-
PossibleStates,
|
|
8
|
-
SubComponentConfig,
|
|
9
|
-
VariantConfig,
|
|
10
|
-
VariantConfigWithComponentStates,
|
|
11
|
-
VariantConfigWithProperties,
|
|
12
|
-
} from '@yahoo/uds/tokens';
|
|
13
|
-
import type {
|
|
14
|
-
ConfigurablePropertiesName,
|
|
15
|
-
SelectedConfigurableProperty,
|
|
16
|
-
} from '@yahoo/uds/tokens/automation/properties';
|
|
17
|
-
import { configurableProperties } from '@yahoo/uds/tokens/automation/properties';
|
|
18
|
-
import { isFunction, lowerCase, mergeWith } from 'lodash';
|
|
19
|
-
|
|
20
|
-
import { generateSchemaKey } from './generateSchemaKey';
|
|
21
|
-
|
|
22
|
-
type ThemeFn = (path: string) => string;
|
|
23
|
-
|
|
24
|
-
type SchemaStateValue<T = any> = {
|
|
25
|
-
type: string;
|
|
26
|
-
valueType: 'alias' | 'custom';
|
|
27
|
-
value: T; // You might want to define a more specific type here
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type VariableState = {
|
|
31
|
-
rest: SchemaStateValue;
|
|
32
|
-
} & {
|
|
33
|
-
[K in PossibleStates]?: SchemaStateValue;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Map our "states" to pseudo-classes (hover => :hover, pressed => :active, etc.).
|
|
38
|
-
* Adjust or extend as needed.
|
|
39
|
-
*/
|
|
40
|
-
const statePseudoMap: Record<PossibleStates | 'rest', string> = {
|
|
41
|
-
rest: '',
|
|
42
|
-
hover: ':hover:not(:has(:disabled))',
|
|
43
|
-
pressed: ':active:not(:has(:disabled))',
|
|
44
|
-
focused: ':focus',
|
|
45
|
-
'focus-within': ':focus-within',
|
|
46
|
-
// TODO: some of these are very specific to input we need to find a way to make them generic
|
|
47
|
-
invalid: ':has(input[aria-invalid="true"])',
|
|
48
|
-
'focused-keyboard': ':focus-visible',
|
|
49
|
-
visited: ':visited',
|
|
50
|
-
readonly: ':has(input:read-only)',
|
|
51
|
-
disabled: ':has(:disabled)',
|
|
52
|
-
|
|
53
|
-
// Compound selectors
|
|
54
|
-
'invalid&hover': ':has(input[aria-invalid="true"]):hover:not(:has(:disabled))',
|
|
55
|
-
'invalid&pressed': ':has(input[aria-invalid="true"]):active:not(:has(:disabled))',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const statePseudoMapDocsMode: Record<PossibleStates | 'rest', string> = {
|
|
59
|
-
rest: '',
|
|
60
|
-
hover: 'hover',
|
|
61
|
-
pressed: 'active',
|
|
62
|
-
focused: 'focus',
|
|
63
|
-
'focus-within': 'focus-within',
|
|
64
|
-
invalid: 'has-input-invalid',
|
|
65
|
-
'focused-keyboard': 'focus-visible',
|
|
66
|
-
visited: 'visited',
|
|
67
|
-
readonly: 'input-readonly',
|
|
68
|
-
disabled: 'has-disabled',
|
|
69
|
-
|
|
70
|
-
// Compound selectors
|
|
71
|
-
'invalid&hover': 'has-input-invalid-and-hover',
|
|
72
|
-
'invalid&pressed': 'has-input-invalid-and-active',
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export function findFixtureType(
|
|
76
|
-
property: SelectedConfigurableProperty<ConfigurablePropertiesName, string>,
|
|
77
|
-
variantKey: string,
|
|
78
|
-
): string {
|
|
79
|
-
const defaultValue = property.defaults[variantKey];
|
|
80
|
-
const typeOfFixture = property.typeOfFixture;
|
|
81
|
-
// find the corresponding fixture type
|
|
82
|
-
let index = 0;
|
|
83
|
-
property.values.forEach((arrayOfValues, i) => {
|
|
84
|
-
if (arrayOfValues.includes(defaultValue)) {
|
|
85
|
-
index = i;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return typeOfFixture[index];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// We define a helper to produce the minimal shape at runtime
|
|
92
|
-
// TODO: the return type shouldn't be `any` we need to have some sort of type safety for this, at least, just the shape
|
|
93
|
-
export function toMinimalDbConfigObject<C extends ComponentConfig>(config: C): any {
|
|
94
|
-
const result: any = {};
|
|
95
|
-
// 1) "defaults"
|
|
96
|
-
// For each variant -> use the "default" if it is in `options`
|
|
97
|
-
const defaultsObj: any = {};
|
|
98
|
-
for (const variantKey in config.variants) {
|
|
99
|
-
const v = config.variants[variantKey];
|
|
100
|
-
// For runtime, we trust the user that "v.default" is in "v.options"
|
|
101
|
-
defaultsObj[variantKey] = v.default;
|
|
102
|
-
}
|
|
103
|
-
result.defaults = defaultsObj;
|
|
104
|
-
|
|
105
|
-
result.variables = {};
|
|
106
|
-
// for each variant key
|
|
107
|
-
for (const variantKey in config.variants) {
|
|
108
|
-
const variantConfig = config.variants[variantKey];
|
|
109
|
-
// for each variant option
|
|
110
|
-
for (const variantOption of variantConfig.options) {
|
|
111
|
-
// if we have componentStates
|
|
112
|
-
if ((variantConfig as VariantConfigWithComponentStates<string>).componentStates) {
|
|
113
|
-
const componentStates = (variantConfig as VariantConfigWithComponentStates<string>)
|
|
114
|
-
.componentStates;
|
|
115
|
-
// for each component state key
|
|
116
|
-
for (const componentStateKey in componentStates) {
|
|
117
|
-
const componentState = componentStates[componentStateKey];
|
|
118
|
-
// for each component state option
|
|
119
|
-
for (const componentStateOption of componentState.options) {
|
|
120
|
-
// for each layer key
|
|
121
|
-
for (const layerKey in componentState.layers) {
|
|
122
|
-
const layer = componentState.layers[layerKey];
|
|
123
|
-
// for each prop
|
|
124
|
-
const schemaKey = generateSchemaKey({
|
|
125
|
-
variantKey,
|
|
126
|
-
variantValue: variantOption,
|
|
127
|
-
stateKey: componentStateKey,
|
|
128
|
-
stateValue: componentStateOption,
|
|
129
|
-
layer: layerKey,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
result.variables[schemaKey] = {};
|
|
133
|
-
for (const propKey in layer.properties) {
|
|
134
|
-
const prop = layer.properties[propKey];
|
|
135
|
-
// if the property has component states
|
|
136
|
-
// TODO: create a concrete type instead of using `any`
|
|
137
|
-
const variableObject: any = {
|
|
138
|
-
[propKey]: {
|
|
139
|
-
// for each pseudo state
|
|
140
|
-
rest: {
|
|
141
|
-
type: findFixtureType(prop, variantOption),
|
|
142
|
-
valueType: 'alias',
|
|
143
|
-
value: prop.defaults[variantOption],
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
if (prop.pseudoStates) {
|
|
148
|
-
for (const pseudoState of prop.pseudoStates) {
|
|
149
|
-
variableObject[propKey][pseudoState] = {
|
|
150
|
-
type: findFixtureType(prop, variantOption),
|
|
151
|
-
valueType: 'alias',
|
|
152
|
-
value: prop.defaults[variantOption],
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// add it to the result
|
|
157
|
-
result.variables[schemaKey] = {
|
|
158
|
-
...result.variables[schemaKey],
|
|
159
|
-
...variableObject,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// we don't have component states
|
|
167
|
-
else {
|
|
168
|
-
// for each layer key
|
|
169
|
-
for (const layerKey in (variantConfig as VariantConfigWithProperties).layers) {
|
|
170
|
-
const layer = (variantConfig as VariantConfigWithProperties).layers[layerKey];
|
|
171
|
-
// for each prop
|
|
172
|
-
const schemaKey = generateSchemaKey({
|
|
173
|
-
variantKey,
|
|
174
|
-
variantValue: variantOption,
|
|
175
|
-
layer: layerKey,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
result.variables[schemaKey] = {};
|
|
179
|
-
for (const propKey in layer.properties) {
|
|
180
|
-
const prop = layer.properties[propKey];
|
|
181
|
-
// if the property has component states
|
|
182
|
-
// TODO: create a concrete type instead of using `any`
|
|
183
|
-
const variableObject: any = {
|
|
184
|
-
[propKey]: {
|
|
185
|
-
rest: {
|
|
186
|
-
type: findFixtureType(prop, variantOption),
|
|
187
|
-
valueType: 'alias',
|
|
188
|
-
value: prop.defaults[variantOption],
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
if (prop.pseudoStates) {
|
|
193
|
-
for (const pseudoState of prop.pseudoStates) {
|
|
194
|
-
variableObject[propKey][pseudoState] = {
|
|
195
|
-
type: findFixtureType(prop, variantOption),
|
|
196
|
-
valueType: 'alias',
|
|
197
|
-
value: prop.defaults[variantOption],
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// add it to the result
|
|
202
|
-
result.variables[schemaKey] = {
|
|
203
|
-
...result.variables[schemaKey],
|
|
204
|
-
...variableObject,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// if we have sub components
|
|
213
|
-
if (config.subComponents) {
|
|
214
|
-
const { subComponents } = config;
|
|
215
|
-
for (const subComponentKey in subComponents) {
|
|
216
|
-
// for each variant key
|
|
217
|
-
for (const variantKey in subComponents[subComponentKey].variants) {
|
|
218
|
-
const variantConfig = subComponents[subComponentKey].variants[variantKey];
|
|
219
|
-
// add to the defaults
|
|
220
|
-
result.defaults[variantKey] = variantConfig.default;
|
|
221
|
-
// for each variant option
|
|
222
|
-
for (const variantOption of variantConfig.options) {
|
|
223
|
-
// if we have componentStates
|
|
224
|
-
if ((variantConfig as VariantConfigWithComponentStates<string>).componentStates) {
|
|
225
|
-
const componentStates = (variantConfig as VariantConfigWithComponentStates<string>)
|
|
226
|
-
.componentStates;
|
|
227
|
-
// for each component state key
|
|
228
|
-
for (const componentStateKey in componentStates) {
|
|
229
|
-
const componentState = componentStates[componentStateKey];
|
|
230
|
-
// for each component state option
|
|
231
|
-
for (const componentStateOption of componentState.options) {
|
|
232
|
-
// for each layer key
|
|
233
|
-
for (const layerKey in componentState.layers) {
|
|
234
|
-
const layer = componentState.layers[layerKey];
|
|
235
|
-
// for each prop
|
|
236
|
-
const schemaKey = generateSchemaKey({
|
|
237
|
-
variantKey,
|
|
238
|
-
variantValue: variantOption,
|
|
239
|
-
stateKey: componentStateKey,
|
|
240
|
-
stateValue: componentStateOption,
|
|
241
|
-
layer: layerKey,
|
|
242
|
-
subComponentName: subComponentKey,
|
|
243
|
-
});
|
|
244
|
-
result.variables[schemaKey] = {};
|
|
245
|
-
for (const propKey in layer.properties) {
|
|
246
|
-
const prop = layer.properties[propKey];
|
|
247
|
-
// if the property has component states
|
|
248
|
-
// TODO: create a concrete type instead of using `any`
|
|
249
|
-
const variableObject: any = {
|
|
250
|
-
[propKey]: {
|
|
251
|
-
rest: {
|
|
252
|
-
type: findFixtureType(prop, variantOption),
|
|
253
|
-
valueType: 'alias',
|
|
254
|
-
value: prop.defaults[variantOption],
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
if (prop.pseudoStates) {
|
|
259
|
-
for (const pseudoState of prop.pseudoStates) {
|
|
260
|
-
variableObject[propKey][pseudoState] = {
|
|
261
|
-
type: findFixtureType(prop, variantOption),
|
|
262
|
-
valueType: 'alias',
|
|
263
|
-
value: prop.defaults[variantOption],
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// add it to the result
|
|
268
|
-
result.variables[schemaKey] = {
|
|
269
|
-
...result.variables[schemaKey],
|
|
270
|
-
...variableObject,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
// we don't have component states
|
|
278
|
-
else {
|
|
279
|
-
// for each layer key
|
|
280
|
-
for (const layerKey in (variantConfig as VariantConfigWithProperties).layers) {
|
|
281
|
-
const layer = (variantConfig as VariantConfigWithProperties).layers[layerKey];
|
|
282
|
-
// for each prop
|
|
283
|
-
const schemaKey = generateSchemaKey({
|
|
284
|
-
variantKey,
|
|
285
|
-
variantValue: variantOption,
|
|
286
|
-
layer: layerKey,
|
|
287
|
-
subComponentName: subComponentKey,
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
result.variables[schemaKey] = {};
|
|
291
|
-
for (const propKey in layer.properties) {
|
|
292
|
-
const prop = layer.properties[propKey];
|
|
293
|
-
// if the property has component states
|
|
294
|
-
// TODO: create a concrete type instead of using `any`
|
|
295
|
-
const variableObject: any = {
|
|
296
|
-
[propKey]: {
|
|
297
|
-
rest: {
|
|
298
|
-
type: findFixtureType(prop, variantOption),
|
|
299
|
-
valueType: 'alias',
|
|
300
|
-
value: prop.defaults[variantOption],
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
};
|
|
304
|
-
if (prop.pseudoStates) {
|
|
305
|
-
for (const pseudoState of prop.pseudoStates) {
|
|
306
|
-
variableObject[propKey][pseudoState] = {
|
|
307
|
-
type: findFixtureType(prop, variantOption),
|
|
308
|
-
valueType: 'alias',
|
|
309
|
-
value: prop.defaults[variantOption],
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
// add it to the result
|
|
314
|
-
result.variables[schemaKey] = {
|
|
315
|
-
...result.variables[schemaKey],
|
|
316
|
-
...variableObject,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export function generateClassName({
|
|
330
|
-
componentName,
|
|
331
|
-
variantKey,
|
|
332
|
-
variantValue,
|
|
333
|
-
layer,
|
|
334
|
-
layerOptionalPseudoSelector,
|
|
335
|
-
subComponentName,
|
|
336
|
-
stateKey,
|
|
337
|
-
stateValue,
|
|
338
|
-
}: {
|
|
339
|
-
componentName: string;
|
|
340
|
-
variantKey: string;
|
|
341
|
-
variantValue?: string;
|
|
342
|
-
layer: string;
|
|
343
|
-
layerOptionalPseudoSelector?: string;
|
|
344
|
-
subComponentName?: string;
|
|
345
|
-
stateKey?: string;
|
|
346
|
-
stateValue?: string;
|
|
347
|
-
}): string {
|
|
348
|
-
let className = '';
|
|
349
|
-
if (subComponentName) {
|
|
350
|
-
className = `uds-${lowerCase(componentName)}-${lowerCase(subComponentName)}-${lowerCase(variantKey)}`;
|
|
351
|
-
} else {
|
|
352
|
-
className = `uds-${lowerCase(componentName)}-${lowerCase(variantKey)}`;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (variantValue) {
|
|
356
|
-
className = `${className}-${lowerCase(variantValue)}`;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (stateKey && stateValue) {
|
|
360
|
-
className = `${className}-${lowerCase(stateKey)}-${lowerCase(stateValue)}`;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
className = `${className}-${lowerCase(layer)}`;
|
|
364
|
-
|
|
365
|
-
if (layerOptionalPseudoSelector) {
|
|
366
|
-
className = `${className}${layerOptionalPseudoSelector}`;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return className.replaceAll(/\s+/g, '-');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export function generateDeclaration({
|
|
373
|
-
componentName,
|
|
374
|
-
variantKey,
|
|
375
|
-
variantValue,
|
|
376
|
-
layer,
|
|
377
|
-
layerOptionalPseudoSelector,
|
|
378
|
-
subComponentName,
|
|
379
|
-
stateKey,
|
|
380
|
-
stateValue,
|
|
381
|
-
schema,
|
|
382
|
-
propertyKey,
|
|
383
|
-
originalPropertyDefinition,
|
|
384
|
-
theme,
|
|
385
|
-
currentStyles,
|
|
386
|
-
previewOptions,
|
|
387
|
-
}: {
|
|
388
|
-
componentName: string;
|
|
389
|
-
variantKey: string;
|
|
390
|
-
variantValue: string;
|
|
391
|
-
layer: string;
|
|
392
|
-
layerOptionalPseudoSelector?: string; // only gets applied to non root layers
|
|
393
|
-
subComponentName?: string;
|
|
394
|
-
stateKey?: string;
|
|
395
|
-
stateValue?: string;
|
|
396
|
-
// TODO: define and use a type for the Schema
|
|
397
|
-
schema: unknown;
|
|
398
|
-
propertyKey: string;
|
|
399
|
-
originalPropertyDefinition: SelectedConfigurableProperty<ConfigurablePropertiesName, any>;
|
|
400
|
-
theme: ThemeFn;
|
|
401
|
-
currentStyles: Readonly<Record<string, Record<string, string>>>;
|
|
402
|
-
previewOptions?: {
|
|
403
|
-
generatePseudoStateClassModifier?: boolean;
|
|
404
|
-
};
|
|
405
|
-
}) {
|
|
406
|
-
/// Logic for generating the class names:
|
|
407
|
-
/// If its the root layer
|
|
408
|
-
/// - if we have component states
|
|
409
|
-
/// - We need to combine the class that has the variant and the class that has the component state
|
|
410
|
-
/// => example: '.uds-chip-toggle-variant-primary-root.uds-chip-toggle-variant-active-off-root'
|
|
411
|
-
/// - else
|
|
412
|
-
/// - We only need one class for the root layer
|
|
413
|
-
/// => example: '.uds-chip-link-variant-primary-root'
|
|
414
|
-
/// If its not the root layer
|
|
415
|
-
/// - We need to nest the child layer under the root layer
|
|
416
|
-
/// - if we have component states
|
|
417
|
-
/// - The child layer should only have the variant and its value present since the root layer already has the component state present
|
|
418
|
-
/// => example: '.uds-chip-toggle-variant-primary-root.uds-chip-toggle-variant-active-off-root .uds-chip-toggle-variant-primary-icon'
|
|
419
|
-
/// - If we dont have component state
|
|
420
|
-
/// => example: '.uds-chip-dismissible-variant-primary-root .uds-chip-dismissible-variant-primary-icon'
|
|
421
|
-
/// Note: The classes should match what's on `autoVariants.ts`
|
|
422
|
-
const schemaKey = generateSchemaKey({
|
|
423
|
-
variantKey,
|
|
424
|
-
variantValue,
|
|
425
|
-
layer,
|
|
426
|
-
subComponentName,
|
|
427
|
-
stateKey,
|
|
428
|
-
stateValue,
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
let className = generateClassName({
|
|
432
|
-
componentName,
|
|
433
|
-
variantKey,
|
|
434
|
-
variantValue,
|
|
435
|
-
layer,
|
|
436
|
-
subComponentName,
|
|
437
|
-
stateKey,
|
|
438
|
-
stateValue,
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
// @ts-expect-error - fix the types later
|
|
442
|
-
const propertySelectedValueInSchema = schema.variables[schemaKey][propertyKey] as VariableState;
|
|
443
|
-
|
|
444
|
-
if (!propertySelectedValueInSchema) {
|
|
445
|
-
if (schemaKey === 'size/md/root' && propertyKey === 'spacingHorizontal') {
|
|
446
|
-
// @ts-expect-error - log
|
|
447
|
-
console.log({ componentName, schemaKey, propertyKey }, schema.variables);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
throw new Error(
|
|
451
|
-
`Prop definition (${componentName} - ${schemaKey} - ${propertyKey}) not found, this is not expected, please report the bug to the UDS team`,
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
const styles: Record<string, Record<string, string>> = {};
|
|
456
|
-
// loop through the property states
|
|
457
|
-
for (const stateStr in propertySelectedValueInSchema) {
|
|
458
|
-
const state = stateStr as keyof VariableState;
|
|
459
|
-
const pseudo = statePseudoMap[state] ?? '';
|
|
460
|
-
const schemaValueForState = propertySelectedValueInSchema[state] as SchemaStateValue;
|
|
461
|
-
|
|
462
|
-
let fullClassName = ``;
|
|
463
|
-
if (layer === 'root') {
|
|
464
|
-
// We need to nest the component state classes under the variant classes
|
|
465
|
-
if (stateKey && stateValue) {
|
|
466
|
-
// We need to nest the component state classes under the variant class
|
|
467
|
-
const rootVariantClass = generateClassName({
|
|
468
|
-
componentName,
|
|
469
|
-
variantKey,
|
|
470
|
-
variantValue,
|
|
471
|
-
layer,
|
|
472
|
-
subComponentName,
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
className = generateClassName({
|
|
476
|
-
componentName,
|
|
477
|
-
variantKey,
|
|
478
|
-
layer,
|
|
479
|
-
subComponentName,
|
|
480
|
-
stateKey,
|
|
481
|
-
stateValue,
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
fullClassName = `.${rootVariantClass}${pseudo}.${className}`;
|
|
485
|
-
} else {
|
|
486
|
-
fullClassName = `.${className}${pseudo}`;
|
|
487
|
-
}
|
|
488
|
-
} else {
|
|
489
|
-
const rootVariantClassName = generateClassName({
|
|
490
|
-
componentName,
|
|
491
|
-
variantKey,
|
|
492
|
-
variantValue,
|
|
493
|
-
layer: 'root',
|
|
494
|
-
subComponentName,
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
if (stateKey && stateValue) {
|
|
498
|
-
const rootVariantClassNameWithComponentState = generateClassName({
|
|
499
|
-
componentName,
|
|
500
|
-
variantKey,
|
|
501
|
-
layer: 'root',
|
|
502
|
-
subComponentName,
|
|
503
|
-
stateKey,
|
|
504
|
-
stateValue,
|
|
505
|
-
});
|
|
506
|
-
// the layer class name should not have component states, but we need the variant key and value
|
|
507
|
-
className = generateClassName({
|
|
508
|
-
componentName,
|
|
509
|
-
variantKey,
|
|
510
|
-
variantValue,
|
|
511
|
-
layer,
|
|
512
|
-
layerOptionalPseudoSelector,
|
|
513
|
-
subComponentName,
|
|
514
|
-
});
|
|
515
|
-
fullClassName = `.${rootVariantClassName}${pseudo}.${rootVariantClassNameWithComponentState} .${className}`;
|
|
516
|
-
} else {
|
|
517
|
-
fullClassName = `.${rootVariantClassName}${pseudo} .${className}`;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const getTheCssPropertyValue = (
|
|
522
|
-
schemaStateValue: SchemaStateValue,
|
|
523
|
-
propertyName: keyof typeof configurableProperties,
|
|
524
|
-
theme: ThemeFn,
|
|
525
|
-
existingValue?: string,
|
|
526
|
-
): string => {
|
|
527
|
-
const { value, type } = schemaStateValue;
|
|
528
|
-
const propertyConfig = configurableProperties[propertyName];
|
|
529
|
-
|
|
530
|
-
let newValue: string;
|
|
531
|
-
if (configurableProperties[propertyName].customValueRenderer) {
|
|
532
|
-
newValue = configurableProperties[propertyName].customValueRenderer(
|
|
533
|
-
schemaStateValue,
|
|
534
|
-
schema,
|
|
535
|
-
theme,
|
|
536
|
-
);
|
|
537
|
-
} else {
|
|
538
|
-
const twThemePath = configurableProperties[propertyName].twThemePath(
|
|
539
|
-
// @ts-expect-error - fix the types later
|
|
540
|
-
type,
|
|
541
|
-
String(value),
|
|
542
|
-
);
|
|
543
|
-
newValue = theme(twThemePath);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// If this property should be concatenated with existing values and we have an existing value
|
|
547
|
-
if (propertyConfig.concatenate && existingValue) {
|
|
548
|
-
const delimiter = propertyConfig.concatenationDelimiter || ', ';
|
|
549
|
-
return `${existingValue}${delimiter}${newValue}`;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return newValue;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
// we need to get the property definition from the typescript object
|
|
556
|
-
// because we need to know the property name (not just the fixture type)
|
|
557
|
-
const { cssProperties, extendedProperties: extendedPropertiesGetter } =
|
|
558
|
-
configurableProperties[originalPropertyDefinition.name];
|
|
559
|
-
const cssDeclarations: Record<string, string> = {};
|
|
560
|
-
|
|
561
|
-
// Extended properties can either be a hardcoded array of strings or a function that returns an array of strings.
|
|
562
|
-
const isExtendedPropertiesFunction = isFunction(extendedPropertiesGetter);
|
|
563
|
-
const extendedProperties = isExtendedPropertiesFunction
|
|
564
|
-
? extendedPropertiesGetter({ componentName, subComponentName, layer, propertyKey })
|
|
565
|
-
: extendedPropertiesGetter;
|
|
566
|
-
|
|
567
|
-
if (extendedProperties && extendedProperties.length) {
|
|
568
|
-
if (
|
|
569
|
-
!isExtendedPropertiesFunction &&
|
|
570
|
-
(typeof cssProperties === 'string' ||
|
|
571
|
-
(Array.isArray(cssProperties) && cssProperties.length > 0))
|
|
572
|
-
) {
|
|
573
|
-
throw new Error(
|
|
574
|
-
'Invalid configuration: cssProperties should not be configured when extendedProperties are defined. Please update your property configuration accordingly.',
|
|
575
|
-
);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
for (const extendedProp of extendedProperties) {
|
|
579
|
-
const originalPropertyDefinition = configurableProperties[extendedProp];
|
|
580
|
-
const cssPropertiesRef = originalPropertyDefinition.cssProperties;
|
|
581
|
-
|
|
582
|
-
if (typeof cssPropertiesRef === 'string') {
|
|
583
|
-
const existingValue = currentStyles?.[fullClassName]?.[cssPropertiesRef];
|
|
584
|
-
|
|
585
|
-
cssDeclarations[cssPropertiesRef] = getTheCssPropertyValue(
|
|
586
|
-
schemaValueForState,
|
|
587
|
-
extendedProp,
|
|
588
|
-
theme,
|
|
589
|
-
existingValue,
|
|
590
|
-
);
|
|
591
|
-
} else if (Array.isArray(cssPropertiesRef)) {
|
|
592
|
-
for (const cssProp of cssPropertiesRef) {
|
|
593
|
-
const existingValue = currentStyles?.[fullClassName]?.[cssProp];
|
|
594
|
-
|
|
595
|
-
cssDeclarations[cssProp] = getTheCssPropertyValue(
|
|
596
|
-
schemaValueForState,
|
|
597
|
-
extendedProp,
|
|
598
|
-
theme,
|
|
599
|
-
existingValue,
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
} else {
|
|
605
|
-
if (typeof cssProperties === 'string') {
|
|
606
|
-
// Check if we already have a value for this CSS property
|
|
607
|
-
const existingValue = currentStyles?.[fullClassName]?.[cssProperties];
|
|
608
|
-
|
|
609
|
-
cssDeclarations[cssProperties] = getTheCssPropertyValue(
|
|
610
|
-
schemaValueForState,
|
|
611
|
-
originalPropertyDefinition.name,
|
|
612
|
-
theme,
|
|
613
|
-
existingValue,
|
|
614
|
-
);
|
|
615
|
-
} else if (Array.isArray(cssProperties)) {
|
|
616
|
-
for (const cssProp of cssProperties) {
|
|
617
|
-
const existingValue = currentStyles?.[fullClassName]?.[cssProp];
|
|
618
|
-
|
|
619
|
-
cssDeclarations[cssProp] = getTheCssPropertyValue(
|
|
620
|
-
schemaValueForState,
|
|
621
|
-
originalPropertyDefinition.name,
|
|
622
|
-
theme,
|
|
623
|
-
existingValue,
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (!styles[fullClassName]) {
|
|
630
|
-
styles[fullClassName] = {
|
|
631
|
-
...cssDeclarations,
|
|
632
|
-
...styles[fullClassName],
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// todo rename to prefix
|
|
637
|
-
if (previewOptions?.generatePseudoStateClassModifier) {
|
|
638
|
-
const pseudoPrefixClass = statePseudoMapDocsMode[state] ?? '';
|
|
639
|
-
|
|
640
|
-
if (pseudoPrefixClass.length > 0 && stateStr !== 'root') {
|
|
641
|
-
// Add !important to all CSS declarations for docs mode to ensure they override pseudo-class styles
|
|
642
|
-
const importantCssDeclarations = Object.fromEntries(
|
|
643
|
-
Object.entries(cssDeclarations).map(([prop, value]) => [prop, `${value} !important`]),
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
styles[`.${pseudoPrefixClass}${fullClassName}`.replace(pseudo, '')] = {
|
|
647
|
-
...importantCssDeclarations,
|
|
648
|
-
...styles[`.${pseudoPrefixClass}${fullClassName}`.replace(pseudo, '')],
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return styles;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
export function generateStyles<C extends ComponentConfig>(
|
|
658
|
-
config: C,
|
|
659
|
-
schema: any,
|
|
660
|
-
theme: ThemeFn,
|
|
661
|
-
previewOptions?: {
|
|
662
|
-
generatePseudoStateClassModifier: boolean;
|
|
663
|
-
},
|
|
664
|
-
): Record<string, Record<string, string>> {
|
|
665
|
-
function deepMerge<T extends object, U extends object>(target: T, source: U): T & U {
|
|
666
|
-
return mergeWith({}, target, source);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
let componentName = config.label.toLowerCase();
|
|
670
|
-
if (config.overrideComponentName) {
|
|
671
|
-
componentName = config.overrideComponentName.toLowerCase();
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
let styles: Record<string, Record<string, string>> = {};
|
|
675
|
-
for (const variantKey in config.variants) {
|
|
676
|
-
const variantConfig = config.variants[variantKey];
|
|
677
|
-
// for each variant option
|
|
678
|
-
for (const variantOption of variantConfig.options) {
|
|
679
|
-
// if we have componentStates
|
|
680
|
-
if ((variantConfig as VariantConfigWithComponentStates<string>).componentStates) {
|
|
681
|
-
const componentStates = (variantConfig as VariantConfigWithComponentStates<string>)
|
|
682
|
-
.componentStates;
|
|
683
|
-
// for each component state key
|
|
684
|
-
for (const componentStateKey in componentStates) {
|
|
685
|
-
const componentState = componentStates[componentStateKey];
|
|
686
|
-
// for each component state option
|
|
687
|
-
for (const componentStateOption of componentState.options) {
|
|
688
|
-
// for each layer key
|
|
689
|
-
for (const layerKey in componentState.layers) {
|
|
690
|
-
const layer = componentState.layers[layerKey];
|
|
691
|
-
// for each prop
|
|
692
|
-
for (const propertyKey in layer.properties) {
|
|
693
|
-
const originalPropertyDefinition = layer.properties[propertyKey];
|
|
694
|
-
const declarations = generateDeclaration({
|
|
695
|
-
componentName,
|
|
696
|
-
variantKey,
|
|
697
|
-
variantValue: variantOption,
|
|
698
|
-
stateKey: componentStateKey,
|
|
699
|
-
stateValue: componentStateOption,
|
|
700
|
-
layer: layerKey,
|
|
701
|
-
layerOptionalPseudoSelector: layer.pseudoSelector,
|
|
702
|
-
propertyKey,
|
|
703
|
-
originalPropertyDefinition,
|
|
704
|
-
theme,
|
|
705
|
-
schema,
|
|
706
|
-
currentStyles: styles,
|
|
707
|
-
previewOptions,
|
|
708
|
-
});
|
|
709
|
-
styles = deepMerge(styles, declarations);
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
// we don't have component states
|
|
716
|
-
else {
|
|
717
|
-
// for each layer key
|
|
718
|
-
for (const layerKey in (variantConfig as VariantConfigWithProperties).layers) {
|
|
719
|
-
const layer = (variantConfig as VariantConfigWithProperties).layers[layerKey];
|
|
720
|
-
|
|
721
|
-
for (const propertyKey in layer.properties) {
|
|
722
|
-
const originalPropertyDefinition = layer.properties[propertyKey];
|
|
723
|
-
const declarations = generateDeclaration({
|
|
724
|
-
componentName,
|
|
725
|
-
variantKey,
|
|
726
|
-
variantValue: variantOption,
|
|
727
|
-
layer: layerKey,
|
|
728
|
-
layerOptionalPseudoSelector: layer.pseudoSelector,
|
|
729
|
-
propertyKey,
|
|
730
|
-
originalPropertyDefinition,
|
|
731
|
-
theme,
|
|
732
|
-
schema,
|
|
733
|
-
currentStyles: styles,
|
|
734
|
-
previewOptions,
|
|
735
|
-
});
|
|
736
|
-
styles = deepMerge(styles, declarations);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// if we have sub components
|
|
744
|
-
if (config.subComponents) {
|
|
745
|
-
const { subComponents } = config;
|
|
746
|
-
for (const subComponentKey in subComponents) {
|
|
747
|
-
// for each variant key
|
|
748
|
-
for (const variantKey in subComponents[subComponentKey].variants) {
|
|
749
|
-
const variantConfig = subComponents[subComponentKey].variants[variantKey];
|
|
750
|
-
// for each variant option
|
|
751
|
-
for (const variantOption of variantConfig.options) {
|
|
752
|
-
// if we have componentStates
|
|
753
|
-
if ((variantConfig as VariantConfigWithComponentStates<string>).componentStates) {
|
|
754
|
-
const componentStates = (variantConfig as VariantConfigWithComponentStates<string>)
|
|
755
|
-
.componentStates;
|
|
756
|
-
// for each component state key
|
|
757
|
-
for (const componentStateKey in componentStates) {
|
|
758
|
-
const componentState = componentStates[componentStateKey];
|
|
759
|
-
// for each component state option
|
|
760
|
-
for (const componentStateOption of componentState.options) {
|
|
761
|
-
// for each layer key
|
|
762
|
-
for (const layerKey in componentState.layers) {
|
|
763
|
-
const layer = componentState.layers[layerKey];
|
|
764
|
-
for (const propertyKey in layer.properties) {
|
|
765
|
-
const originalPropertyDefinition = layer.properties[propertyKey];
|
|
766
|
-
const declarations = generateDeclaration({
|
|
767
|
-
componentName,
|
|
768
|
-
variantKey,
|
|
769
|
-
variantValue: variantOption,
|
|
770
|
-
stateKey: componentStateKey,
|
|
771
|
-
stateValue: componentStateOption,
|
|
772
|
-
subComponentName: subComponentKey,
|
|
773
|
-
layer: layerKey,
|
|
774
|
-
layerOptionalPseudoSelector: layer.pseudoSelector,
|
|
775
|
-
propertyKey,
|
|
776
|
-
originalPropertyDefinition,
|
|
777
|
-
theme,
|
|
778
|
-
schema,
|
|
779
|
-
currentStyles: styles,
|
|
780
|
-
previewOptions,
|
|
781
|
-
});
|
|
782
|
-
styles = deepMerge(styles, declarations);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
// we don't have component states
|
|
789
|
-
else {
|
|
790
|
-
// for each layer key
|
|
791
|
-
for (const layerKey in (variantConfig as VariantConfigWithProperties).layers) {
|
|
792
|
-
const layer = (variantConfig as VariantConfigWithProperties).layers[layerKey];
|
|
793
|
-
// for each prop
|
|
794
|
-
for (const propertyKey in layer.properties) {
|
|
795
|
-
// if the property has component states
|
|
796
|
-
const originalPropertyDefinition = layer.properties[propertyKey];
|
|
797
|
-
const declarations = generateDeclaration({
|
|
798
|
-
componentName,
|
|
799
|
-
subComponentName: subComponentKey,
|
|
800
|
-
variantKey,
|
|
801
|
-
variantValue: variantOption,
|
|
802
|
-
layer: layerKey,
|
|
803
|
-
layerOptionalPseudoSelector: layer.pseudoSelector,
|
|
804
|
-
propertyKey,
|
|
805
|
-
originalPropertyDefinition,
|
|
806
|
-
theme,
|
|
807
|
-
schema,
|
|
808
|
-
currentStyles: styles,
|
|
809
|
-
previewOptions,
|
|
810
|
-
});
|
|
811
|
-
styles = deepMerge(styles, declarations);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
return styles;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
export function createConfigurableProperty<
|
|
824
|
-
C extends ConfigurablePropertiesName,
|
|
825
|
-
O extends string,
|
|
826
|
-
T extends (typeof configurableProperties)[C]['possibleFixtures'],
|
|
827
|
-
V extends readonly (readonly string[])[] = readonly (readonly string[])[],
|
|
828
|
-
>(prop: {
|
|
829
|
-
name: C;
|
|
830
|
-
typeOfFixture: T;
|
|
831
|
-
values: V;
|
|
832
|
-
defaults: { [K in O]: V[number][number] };
|
|
833
|
-
label: string;
|
|
834
|
-
pseudoStates?: PossibleStates[];
|
|
835
|
-
supportsCustom?: boolean;
|
|
836
|
-
}): SelectedConfigurableProperty<C, O, T, V> {
|
|
837
|
-
return prop;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
/**
|
|
841
|
-
* @deprecated use the new functions instead
|
|
842
|
-
*/
|
|
843
|
-
export function createVariantConfig<
|
|
844
|
-
O extends string,
|
|
845
|
-
T extends Record<string, SelectedConfigurableProperty<ConfigurablePropertiesName, O>>,
|
|
846
|
-
>(config: {
|
|
847
|
-
label: string;
|
|
848
|
-
description: string;
|
|
849
|
-
isConfigurable: boolean;
|
|
850
|
-
default: O;
|
|
851
|
-
options: readonly O[];
|
|
852
|
-
properties: T;
|
|
853
|
-
}): VariantConfig<O> {
|
|
854
|
-
return config;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
export function createComponentStateConfig(config: {
|
|
858
|
-
label: string;
|
|
859
|
-
options: string[];
|
|
860
|
-
layers: {
|
|
861
|
-
root: LayerConfig;
|
|
862
|
-
} & Record<string, LayerConfig>;
|
|
863
|
-
}): ComponentStateConfig {
|
|
864
|
-
return config;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
export function createVariantConfigWithProperties(config: {
|
|
868
|
-
label: string;
|
|
869
|
-
description: string;
|
|
870
|
-
isConfigurable: boolean;
|
|
871
|
-
default: string;
|
|
872
|
-
options: readonly string[];
|
|
873
|
-
layers: {
|
|
874
|
-
root: LayerConfig;
|
|
875
|
-
} & Record<string, LayerConfig>;
|
|
876
|
-
}): VariantConfigWithProperties {
|
|
877
|
-
return config;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
export function createVariantConfigWithComponentStates(config: {
|
|
881
|
-
label: string;
|
|
882
|
-
description: string;
|
|
883
|
-
isConfigurable: boolean;
|
|
884
|
-
default: string;
|
|
885
|
-
options: readonly string[];
|
|
886
|
-
componentStates: Record<string, ComponentStateConfig>;
|
|
887
|
-
}): VariantConfigWithComponentStates {
|
|
888
|
-
return config;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
export function createComponentStates(config: {
|
|
892
|
-
label: string;
|
|
893
|
-
options: string[];
|
|
894
|
-
layers: {
|
|
895
|
-
root: LayerConfig;
|
|
896
|
-
} & Record<string, LayerConfig>;
|
|
897
|
-
}): ComponentStateConfig {
|
|
898
|
-
return config;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
export function createLayerConfig(config: {
|
|
902
|
-
label: string;
|
|
903
|
-
// a pseudo selector to apply to the layer (example placeholder on input)
|
|
904
|
-
pseudoSelector?: string;
|
|
905
|
-
properties: Readonly<
|
|
906
|
-
Record<string, SelectedConfigurableProperty<ConfigurablePropertiesName, string>>
|
|
907
|
-
>;
|
|
908
|
-
}): LayerConfig {
|
|
909
|
-
return config;
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
export function createSubComponentConfig(config: {
|
|
913
|
-
label: string;
|
|
914
|
-
description: string;
|
|
915
|
-
overrideComponentName?: string;
|
|
916
|
-
variants: Record<string, VariantConfigWithProperties | VariantConfigWithComponentStates>;
|
|
917
|
-
}): SubComponentConfig {
|
|
918
|
-
return config;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
export type { SchemaStateValue };
|
|
922
|
-
export { cartesianProduct } from './cartesianProduct';
|
|
923
|
-
export { coalesceConfigVariant } from './coalesceConfigVariant';
|
|
924
|
-
export { getConfigDefaultValue, isConfigDefaultValue } from './defaults';
|
|
925
|
-
export { generateKeyFromFlatConfigPath } from './generateKeyFromFlatConfigPath';
|
|
926
|
-
export { generateSchemaKey } from './generateSchemaKey';
|
|
927
|
-
export {
|
|
928
|
-
getConfigVariantComponentStates,
|
|
929
|
-
getConfigVariantComponentStatesMatrix,
|
|
930
|
-
} from './getConfigVariantComponentStatesMatrix';
|
|
931
|
-
export { getConfigVariantProperties } from './getConfigVariantProperties';
|
|
932
|
-
export { getConfigVariantPseudoStates } from './getConfigVariantPseudoStates';
|
|
933
|
-
export { getConfigVariants } from './getConfigVariants';
|
|
934
|
-
export { getConfigSubcomponents } from './subcomponents';
|
|
935
|
-
export {
|
|
936
|
-
getConfigPseudoStateVariables,
|
|
937
|
-
getConfigPseudoStateVariablesWithSetter,
|
|
938
|
-
setConfigPseudoStateVariable,
|
|
939
|
-
} from './variableData';
|