@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,42 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { Project } from 'ts-morph';
|
|
4
|
-
|
|
5
|
-
const typesFile = path.resolve(__dirname, '../../tokens/types.ts');
|
|
6
|
-
const iconsTypeFile = path.resolve(__dirname, '../../../../icons/src/types.ts');
|
|
7
|
-
|
|
8
|
-
const project = new Project();
|
|
9
|
-
const typeFile = project.addSourceFileAtPath(typesFile);
|
|
10
|
-
|
|
11
|
-
/** Ensure the @yahoo/uds-icons/types are accessible when generating fixtures */
|
|
12
|
-
const iconTypesFile = project.addSourceFileAtPath(iconsTypeFile);
|
|
13
|
-
/** Remove imports from icon types since we are going to manually add to uds types so they are accessible */
|
|
14
|
-
typeFile.getImportDeclarations().forEach((importDeclaration) => {
|
|
15
|
-
const isIconType = importDeclaration.getModuleSpecifierValue() === '@yahoo/uds-icons/types';
|
|
16
|
-
if (isIconType) {
|
|
17
|
-
importDeclaration.remove();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
/** Add icon types directly to uds types so they are accessible */
|
|
21
|
-
typeFile.addStatements(iconTypesFile.getFullText());
|
|
22
|
-
|
|
23
|
-
export function typesToConstants<TypeToReturn>(typeName: string): TypeToReturn[] {
|
|
24
|
-
const typeAlias = typeFile.getTypeAliasOrThrow(typeName);
|
|
25
|
-
const type = typeAlias.getType();
|
|
26
|
-
|
|
27
|
-
// Handle string literal types
|
|
28
|
-
if (type.isUnion()) {
|
|
29
|
-
return type
|
|
30
|
-
.getUnionTypes()
|
|
31
|
-
.map((t) => t.getLiteralValue() as TypeToReturn)
|
|
32
|
-
.filter(Boolean);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Handle object types
|
|
36
|
-
const properties = type.getProperties();
|
|
37
|
-
if (properties.length > 0) {
|
|
38
|
-
return properties.map((prop) => prop.getName() as TypeToReturn);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
throw new Error(`Unsupported type: ${typeName}`);
|
|
42
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { BorderRadius, BorderWidth, ScaleMode } from '@yahoo/uds/tokens';
|
|
2
|
-
|
|
3
|
-
import { scaleMode } from '../../tokens/configs/scaleMode';
|
|
4
|
-
import { entries } from '../../utils/entries';
|
|
5
|
-
|
|
6
|
-
const borderWidthMap = {
|
|
7
|
-
xSmall: scaleMode.xSmall.borderWidth,
|
|
8
|
-
small: scaleMode.small.borderWidth,
|
|
9
|
-
medium: scaleMode.medium.borderWidth,
|
|
10
|
-
large: scaleMode.large.borderWidth,
|
|
11
|
-
xLarge: scaleMode.xLarge.borderWidth,
|
|
12
|
-
xxLarge: scaleMode.xxLarge.borderWidth,
|
|
13
|
-
xxxLarge: scaleMode.xxxLarge.borderWidth,
|
|
14
|
-
} as Record<ScaleMode, Record<BorderWidth, number>>;
|
|
15
|
-
|
|
16
|
-
const borderRadiusMap = {
|
|
17
|
-
xSmall: scaleMode.xSmall.borderRadius,
|
|
18
|
-
small: scaleMode.small.borderRadius,
|
|
19
|
-
medium: scaleMode.medium.borderRadius,
|
|
20
|
-
large: scaleMode.large.borderRadius,
|
|
21
|
-
xLarge: scaleMode.xLarge.borderRadius,
|
|
22
|
-
xxLarge: scaleMode.xxLarge.borderRadius,
|
|
23
|
-
xxxLarge: scaleMode.xxxLarge.borderRadius,
|
|
24
|
-
} as Record<ScaleMode, Record<BorderRadius, number>>;
|
|
25
|
-
|
|
26
|
-
export function getBorderWidthRamp(scaleMode: ScaleMode) {
|
|
27
|
-
return entries(borderWidthMap.large).reduce(
|
|
28
|
-
(prev, [alias, baseBorderWidth]) => {
|
|
29
|
-
return {
|
|
30
|
-
...prev,
|
|
31
|
-
[alias]: borderWidthMap[scaleMode][alias] - baseBorderWidth,
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
{} as Record<BorderWidth, number>,
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getBorderRadiusRamp(scaleMode: ScaleMode) {
|
|
39
|
-
return entries(borderRadiusMap.large).reduce(
|
|
40
|
-
(prev, [alias, baseBorderRadius]) => {
|
|
41
|
-
return {
|
|
42
|
-
...prev,
|
|
43
|
-
[alias]: borderRadiusMap[scaleMode][alias] - baseBorderRadius,
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
{} as Record<BorderRadius, number>,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
|
|
3
|
-
import type tailwindColors from 'tailwindcss/colors';
|
|
4
|
-
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette';
|
|
5
|
-
|
|
6
|
-
import { lightSpectrum } from '../../tokens/configs/spectrum';
|
|
7
|
-
import { SPECTRUM_COLOR_PREFIX } from '../../tokens/consts/cssTokens';
|
|
8
|
-
import type { SpectrumConfig } from '../../tokens/types';
|
|
9
|
-
import { entries } from '../../utils/entries';
|
|
10
|
-
import { mapValues } from '../../utils/mapValues';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Bun isn't working with deleting object properties via esm import so we need to use node's require.
|
|
14
|
-
* The object properties are being deleted to avoid logging Tailwind deprecation warnings.
|
|
15
|
-
* https://github.com/nuxt/ui/issues/809#issuecomment-1921810965
|
|
16
|
-
*/
|
|
17
|
-
const _require = createRequire(import.meta.url);
|
|
18
|
-
|
|
19
|
-
const tailwindColorsConfig = _require('tailwindcss/colors.js') as typeof tailwindColors;
|
|
20
|
-
|
|
21
|
-
type KeyValueMap = Record<string, string>;
|
|
22
|
-
type Rgb = { r: number; g: number; b: number };
|
|
23
|
-
const udsLightColors = spaceSeparatedRgbToRgbObject(lightSpectrum);
|
|
24
|
-
|
|
25
|
-
function spaceSeparatedRgbToRgbObject(spectrum: SpectrumConfig) {
|
|
26
|
-
const flatConfig = flattenColorPalette(spectrum);
|
|
27
|
-
return mapValues<KeyValueMap, (val: string) => Rgb>(flattenColorPalette(flatConfig), (val) => {
|
|
28
|
-
const [red, green, blue] = val.split(' ');
|
|
29
|
-
return {
|
|
30
|
-
r: Number(red),
|
|
31
|
-
g: Number(green),
|
|
32
|
-
b: Number(blue),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function hexToRgb(hex: string) {
|
|
38
|
-
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
39
|
-
return result
|
|
40
|
-
? {
|
|
41
|
-
r: parseInt(result[1], 16),
|
|
42
|
-
g: parseInt(result[2], 16),
|
|
43
|
-
b: parseInt(result[3], 16),
|
|
44
|
-
}
|
|
45
|
-
: null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getDiffColor(a: Rgb, b: Rgb) {
|
|
49
|
-
return Math.sqrt(Math.pow(a.r - b.r, 2) + Math.pow(a.g - b.g, 2) + Math.pow(a.b - b.b, 2));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const getClosestUdsColor = (targetColor: string) => {
|
|
53
|
-
// Convert target color from hex string to RGB values
|
|
54
|
-
const targetRgb = hexToRgb(targetColor);
|
|
55
|
-
|
|
56
|
-
let closestDistance = null;
|
|
57
|
-
let closestColor: string[] = [];
|
|
58
|
-
|
|
59
|
-
for (const [name, color] of entries(udsLightColors)) {
|
|
60
|
-
const varName = `rgb(var(--${SPECTRUM_COLOR_PREFIX}-${name}))`;
|
|
61
|
-
const distance = getDiffColor(color, targetRgb!);
|
|
62
|
-
if (closestDistance === null || distance < closestDistance) {
|
|
63
|
-
closestDistance = distance;
|
|
64
|
-
closestColor = [varName];
|
|
65
|
-
} else if (closestDistance === distance) {
|
|
66
|
-
closestColor.push(varName);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return closestColor[0];
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
type DeprecatedTailwindHue = 'lightBlue' | 'warmGray' | 'trueGray' | 'coolGray' | 'blueGray';
|
|
74
|
-
type TailwindHue = Exclude<keyof typeof tailwindColors, DeprecatedTailwindHue>;
|
|
75
|
-
type TailwindHueStep = keyof (typeof tailwindColors)['gray'];
|
|
76
|
-
|
|
77
|
-
export function getTailwindAsUdsColors() {
|
|
78
|
-
const tailwindColorsAsUds = {} as Record<TailwindHue, Record<TailwindHueStep, string>>;
|
|
79
|
-
|
|
80
|
-
/** Avoid logging deprecation warnings */
|
|
81
|
-
// @ts-expect-error ts doesn't like deleting properties from an object
|
|
82
|
-
delete tailwindColorsConfig['lightBlue'];
|
|
83
|
-
// @ts-expect-error ts doesn't like deleting properties from an object
|
|
84
|
-
delete tailwindColorsConfig['warmGray'];
|
|
85
|
-
// @ts-expect-error ts doesn't like deleting properties from an object
|
|
86
|
-
delete tailwindColorsConfig['trueGray'];
|
|
87
|
-
// @ts-expect-error ts doesn't like deleting properties from an object
|
|
88
|
-
delete tailwindColorsConfig['coolGray'];
|
|
89
|
-
// @ts-expect-error ts doesn't like deleting properties from an object
|
|
90
|
-
delete tailwindColorsConfig['blueGray'];
|
|
91
|
-
|
|
92
|
-
for (const [name, colorOrConfig] of entries(tailwindColorsConfig)) {
|
|
93
|
-
if (typeof colorOrConfig === 'object') {
|
|
94
|
-
if (
|
|
95
|
-
name === 'lightBlue' ||
|
|
96
|
-
name === 'warmGray' ||
|
|
97
|
-
name === 'trueGray' ||
|
|
98
|
-
name === 'coolGray' ||
|
|
99
|
-
name === 'blueGray'
|
|
100
|
-
) {
|
|
101
|
-
continue;
|
|
102
|
-
} else {
|
|
103
|
-
for (const [shade, color] of entries(colorOrConfig)) {
|
|
104
|
-
if (!tailwindColorsAsUds[name]) {
|
|
105
|
-
tailwindColorsAsUds[name] = {} as Record<TailwindHueStep, string>;
|
|
106
|
-
}
|
|
107
|
-
tailwindColorsAsUds[name][shade] = getClosestUdsColor(color);
|
|
108
|
-
}
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return tailwindColorsAsUds;
|
|
115
|
-
}
|
package/src/flags.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const isNode = typeof process !== 'undefined';
|
|
2
|
-
|
|
3
|
-
interface FeatureFlags {
|
|
4
|
-
/**
|
|
5
|
-
* Setting to true enables a specialized cache for calls to getStyle(),
|
|
6
|
-
* which can improve performance of component render times.
|
|
7
|
-
* @default false
|
|
8
|
-
**/
|
|
9
|
-
useGetStylesCache?: boolean;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Setting to true skips twMerge for calls to cx(),
|
|
13
|
-
* which can improve performance of component render times.
|
|
14
|
-
* @default false
|
|
15
|
-
**/
|
|
16
|
-
skipTailwindMerge?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** UDS feature flags */
|
|
20
|
-
let featureFlags: FeatureFlags = {
|
|
21
|
-
/**
|
|
22
|
-
* Note: some env variables are prefixed with "NEXT_PUBLIC_" so NextJS can
|
|
23
|
-
* inline those values into client code.
|
|
24
|
-
* See https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables*/
|
|
25
|
-
useGetStylesCache: isNode
|
|
26
|
-
? process.env.NEXT_PUBLIC_UDS_FEATURE_USE_STYLE_CACHE === 'true'
|
|
27
|
-
: false,
|
|
28
|
-
skipTailwindMerge: isNode
|
|
29
|
-
? process.env.NEXT_PUBLIC_UDS_FEATURE_SKIP_TAILWIND_MERGE === 'true'
|
|
30
|
-
: false,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Sets/overrides feature flags
|
|
35
|
-
* @param flags Flag overrides
|
|
36
|
-
* @returns Updated feature flags
|
|
37
|
-
*/
|
|
38
|
-
const updateFeatureFlags = (flags: Partial<FeatureFlags>) => {
|
|
39
|
-
featureFlags = { ...featureFlags, ...flags };
|
|
40
|
-
return featureFlags;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const getFeatureFlags = () => featureFlags;
|
|
44
|
-
|
|
45
|
-
export { type FeatureFlags, getFeatureFlags, updateFeatureFlags };
|
package/src/hooks/useForkRef.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { MutableRefObject, Ref, RefCallback } from 'react';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
|
|
4
|
-
const setRef = <T>(
|
|
5
|
-
ref: MutableRefObject<T | null> | ((instance: T | null) => void) | null | undefined,
|
|
6
|
-
value: T | null,
|
|
7
|
-
) => {
|
|
8
|
-
if (typeof ref === 'function') {
|
|
9
|
-
ref(value);
|
|
10
|
-
} else if (ref) {
|
|
11
|
-
ref.current = value;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const useForkRef = <Instance>(
|
|
16
|
-
...refs: Array<Ref<Instance> | undefined>
|
|
17
|
-
): RefCallback<Instance> | null => {
|
|
18
|
-
/**
|
|
19
|
-
* This will create a new function if the refs passed to this hook change and are all defined.
|
|
20
|
-
* This means react will call the old forkRef with `null` and the new forkRef
|
|
21
|
-
* with the ref. Cleanup naturally emerges from this behavior.
|
|
22
|
-
*/
|
|
23
|
-
return useMemo(() => {
|
|
24
|
-
if (refs.every((ref) => ref == null)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return (instance) => {
|
|
29
|
-
refs.forEach((ref) => {
|
|
30
|
-
setRef(ref, instance);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}, [refs]);
|
|
34
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { BorderRadius } from '@yahoo/uds/tokens';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 🐍 Generate border radius that works nicely with the parents border-radius
|
|
5
|
-
*
|
|
6
|
-
* When nesting elements with border radius, using the same radius value for both
|
|
7
|
-
* parent and child creates an awkward visual gap in the corners (known as the "snake belly" effect).
|
|
8
|
-
*
|
|
9
|
-
* The solution is to make the inner element's border radius smaller than the parent's
|
|
10
|
-
* by subtracting the spacing between elements. This creates a smooth transition between the nested elements.
|
|
11
|
-
*
|
|
12
|
-
* For common spacing values ('px', 0.5, 1, 2, 2.5, 3, 3.5, 4), we use calc() to subtract the spacing.
|
|
13
|
-
* For other cases, we use simpler Tailwind classes that work well visually.
|
|
14
|
-
*
|
|
15
|
-
* We use CSS max() to ensure the border radius never gets too small, which is especially
|
|
16
|
-
* important for small spacing values. For example, with spacing=2px and a large border radius,
|
|
17
|
-
* the calculated value might become too small to look good. max() ensures we maintain
|
|
18
|
-
* a minimum border radius that scales with the parent's border radius size.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* Parent: border-radius: 8px, spacing: 4px
|
|
22
|
-
* Child: max(2px, calc(8px - 4px)) // Ensures minimum of 2px
|
|
23
|
-
*
|
|
24
|
-
* @link https://cloudfour.com/thinks/the-math-behind-nesting-rounded-corners
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
export const useNestedBorderRadius = ({
|
|
28
|
-
borderRadius,
|
|
29
|
-
spacing,
|
|
30
|
-
}: {
|
|
31
|
-
borderRadius: BorderRadius;
|
|
32
|
-
spacing?: string;
|
|
33
|
-
}) => {
|
|
34
|
-
// Handle undefined or zero spacing
|
|
35
|
-
if (spacing === undefined || spacing === '0') {
|
|
36
|
-
switch (borderRadius) {
|
|
37
|
-
case 'xs':
|
|
38
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xs)_-_var(--uds-border-width-thin))]';
|
|
39
|
-
case 'sm':
|
|
40
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-sm)_-_var(--uds-border-width-thin))]';
|
|
41
|
-
case 'md':
|
|
42
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-md)_-_var(--uds-border-width-thin))]';
|
|
43
|
-
case 'lg':
|
|
44
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-lg)_-_var(--uds-border-width-thin))]';
|
|
45
|
-
case 'xl':
|
|
46
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_var(--uds-border-width-thin))]';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (spacing === 'px' || spacing === '0.5') {
|
|
51
|
-
switch (borderRadius) {
|
|
52
|
-
case 'xs':
|
|
53
|
-
return '[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_2px))]';
|
|
54
|
-
case 'sm':
|
|
55
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_2px))]';
|
|
56
|
-
case 'md':
|
|
57
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_2px))]';
|
|
58
|
-
case 'lg':
|
|
59
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_2px))]';
|
|
60
|
-
case 'xl':
|
|
61
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xl)_-_2px))]';
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (spacing === '1' || spacing === '1.5') {
|
|
66
|
-
switch (borderRadius) {
|
|
67
|
-
case 'xs':
|
|
68
|
-
return '[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]';
|
|
69
|
-
case 'sm':
|
|
70
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]';
|
|
71
|
-
case 'md':
|
|
72
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]';
|
|
73
|
-
case 'lg':
|
|
74
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]';
|
|
75
|
-
case 'xl':
|
|
76
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_4px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_4px)]';
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (spacing === '2' || spacing === '2.5') {
|
|
81
|
-
switch (borderRadius) {
|
|
82
|
-
case 'xs':
|
|
83
|
-
return '[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_8px))]';
|
|
84
|
-
case 'sm':
|
|
85
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_8px))]';
|
|
86
|
-
case 'md':
|
|
87
|
-
return '[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_8px))]';
|
|
88
|
-
case 'lg':
|
|
89
|
-
return '[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-lg)_-_8px))]';
|
|
90
|
-
case 'xl':
|
|
91
|
-
return '[&>*:first-child]:rounded-t-[calc(var(--uds-border-radius-xl)_-_8px)] [&>*:last-child]:rounded-b-[calc(var(--uds-border-radius-xl)_-_8px)]';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (spacing === '3' || spacing === '3.5') {
|
|
96
|
-
switch (borderRadius) {
|
|
97
|
-
case 'xs':
|
|
98
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-xs)_-_6px))]';
|
|
99
|
-
case 'sm':
|
|
100
|
-
return '[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-sm)_-_6px))]';
|
|
101
|
-
case 'md':
|
|
102
|
-
return '[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-md)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-md)_-_6px))]';
|
|
103
|
-
case 'lg':
|
|
104
|
-
return '[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_6px))]';
|
|
105
|
-
case 'xl':
|
|
106
|
-
return '[&>*:first-child]:rounded-t-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))] [&>*:last-child]:rounded-b-[min(20px,calc(var(--uds-border-radius-xl)_-_6px))]';
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (spacing === '4') {
|
|
111
|
-
switch (borderRadius) {
|
|
112
|
-
case 'xs':
|
|
113
|
-
return '[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_16px))]';
|
|
114
|
-
case 'sm':
|
|
115
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_16px))]';
|
|
116
|
-
case 'md':
|
|
117
|
-
return '[&>*:first-child]:rounded-t-[max(4px,calc(var(--uds-border-radius-md)_-_16px))] [&>*:last-child]:rounded-b-[max(4px,calc(var(--uds-border-radius-md)_-_16px))]';
|
|
118
|
-
case 'lg':
|
|
119
|
-
return '[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-lg)_-_16px))]';
|
|
120
|
-
case 'xl':
|
|
121
|
-
return '[&>*:first-child]:rounded-t-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))] [&>*:last-child]:rounded-b-[max(6px,calc(var(--uds-border-radius-xl)_-_16px))]';
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Fallback for other spacing values
|
|
126
|
-
switch (borderRadius) {
|
|
127
|
-
case 'xs':
|
|
128
|
-
return '[&>*:first-child]:rounded-t-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))] [&>*:last-child]:rounded-b-[max(1px,calc(var(--uds-border-radius-xs)_-_4px))]';
|
|
129
|
-
case 'sm':
|
|
130
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-sm)_-_4px))]';
|
|
131
|
-
case 'md':
|
|
132
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-md)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-md)_-_4px))]';
|
|
133
|
-
case 'lg':
|
|
134
|
-
return '[&>*:first-child]:rounded-t-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))] [&>*:last-child]:rounded-b-[max(2px,calc(var(--uds-border-radius-lg)_-_4px))]';
|
|
135
|
-
case 'xl':
|
|
136
|
-
return '[&>*:first-child]:rounded-t-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))] [&>*:last-child]:rounded-b-[min(18px,calc(var(--uds-border-radius-xl)_-_4px))]';
|
|
137
|
-
}
|
|
138
|
-
};
|
package/src/hooks/useRtl.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
interface UseRtlOptions {
|
|
4
|
-
/** Optional explicit RTL value that takes precedence over detected direction */
|
|
5
|
-
explicit?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Gets the current RTL state from document direction
|
|
10
|
-
*/
|
|
11
|
-
export const getDocumentDirection = (): boolean => {
|
|
12
|
-
if (typeof document === 'undefined') {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const direction = getComputedStyle(document.documentElement).direction;
|
|
16
|
-
return direction === 'rtl';
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Creates a mutation observer to watch for direction changes
|
|
21
|
-
*/
|
|
22
|
-
export const createDirectionObserver = (callback: () => void): MutationObserver => {
|
|
23
|
-
const observer = new MutationObserver((mutations) => {
|
|
24
|
-
const hasDirectionChange = mutations.some(
|
|
25
|
-
(mutation) => mutation.type === 'attributes' && mutation.attributeName === 'dir',
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (hasDirectionChange) {
|
|
29
|
-
callback();
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
observer.observe(document.documentElement, {
|
|
34
|
-
attributes: true,
|
|
35
|
-
attributeFilter: ['dir'],
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
return observer;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Hook to detect RTL context from document direction or explicit override
|
|
43
|
-
* @default reads from document direction
|
|
44
|
-
*/
|
|
45
|
-
export const useRtl = (options?: UseRtlOptions): boolean => {
|
|
46
|
-
const [isRtl, setIsRtl] = useState(getDocumentDirection);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
// Handle explicit RTL override
|
|
50
|
-
if (options?.explicit) {
|
|
51
|
-
setIsRtl(options.explicit);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Watch for direction changes in document
|
|
56
|
-
const observer = createDirectionObserver(() => {
|
|
57
|
-
setIsRtl(getDocumentDirection());
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return () => observer.disconnect();
|
|
61
|
-
}, [options?.explicit]);
|
|
62
|
-
|
|
63
|
-
return isRtl;
|
|
64
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ColorMode } from '@yahoo/uds/tokens';
|
|
2
|
-
import { DEFAULT_COLOR_MODE } from '@yahoo/uds/tokens';
|
|
3
|
-
import { createContext, useContext } from 'react';
|
|
4
|
-
|
|
5
|
-
interface ColorModeProviderProps extends React.PropsWithChildren {
|
|
6
|
-
value?: ColorMode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const ColorModeContext = createContext<ColorMode>(DEFAULT_COLOR_MODE);
|
|
10
|
-
|
|
11
|
-
function useColorMode() {
|
|
12
|
-
return useContext(ColorModeContext);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function ColorModeProvider({ value = DEFAULT_COLOR_MODE, children }: ColorModeProviderProps) {
|
|
16
|
-
return <ColorModeContext.Provider value={value}>{children}</ColorModeContext.Provider>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
ColorModeProvider.displayName = 'ColorModeProvider';
|
|
20
|
-
|
|
21
|
-
export { ColorModeContext, ColorModeProvider, type ColorModeProviderProps, useColorMode };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { ScaleMode } from '@yahoo/uds/tokens';
|
|
2
|
-
import { DEFAULT_SCALE_MODE } from '@yahoo/uds/tokens';
|
|
3
|
-
import { createContext, useContext } from 'react';
|
|
4
|
-
|
|
5
|
-
interface ScaleModeProviderProps extends React.PropsWithChildren {
|
|
6
|
-
value?: ScaleMode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const ScaleModeContext = createContext<ScaleMode>(DEFAULT_SCALE_MODE);
|
|
10
|
-
|
|
11
|
-
function useScaleMode() {
|
|
12
|
-
const context = useContext(ScaleModeContext);
|
|
13
|
-
if (!context) {
|
|
14
|
-
return DEFAULT_SCALE_MODE;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return context;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function ScaleModeProvider({ value, children }: ScaleModeProviderProps) {
|
|
21
|
-
const scaleMode = useScaleMode();
|
|
22
|
-
return (
|
|
23
|
-
<ScaleModeContext.Provider value={value ?? scaleMode}>{children}</ScaleModeContext.Provider>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
ScaleModeProvider.displayName = 'ScaleModeProvider';
|
|
28
|
-
|
|
29
|
-
export { ScaleModeContext, ScaleModeProvider, type ScaleModeProviderProps, useScaleMode };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { cx, getStyles } from '../styles/styler';
|
|
2
|
-
import type { ColorMode, ScaleMode } from '../tokens';
|
|
3
|
-
import { DEFAULT_COLOR_MODE, DEFAULT_SCALE_MODE } from '../tokens';
|
|
4
|
-
|
|
5
|
-
interface ThemeProviderProps extends React.PropsWithChildren {
|
|
6
|
-
colorMode?: ColorMode;
|
|
7
|
-
scaleMode?: ScaleMode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function ThemeProvider({
|
|
11
|
-
children,
|
|
12
|
-
colorMode = DEFAULT_COLOR_MODE,
|
|
13
|
-
scaleMode = DEFAULT_SCALE_MODE,
|
|
14
|
-
}: ThemeProviderProps) {
|
|
15
|
-
return (
|
|
16
|
-
<div
|
|
17
|
-
className={cx('contents', getStyles({ colorMode, scaleMode, backgroundColor: 'primary' }))}
|
|
18
|
-
>
|
|
19
|
-
{children}
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
ThemeProvider.displayName = 'ThemeProvider';
|
|
25
|
-
|
|
26
|
-
export { ThemeProvider, type ThemeProviderProps };
|