@yahoo/uds-mobile 2.24.0-beta.1 → 2.24.0-beta.11
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/README.md +37 -1
- package/dist/components/Avatar/AvatarIcon.cjs +8 -2
- package/dist/components/Avatar/AvatarIcon.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarIcon.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarIcon.js +9 -3
- package/dist/components/Avatar/AvatarIcon.js.map +1 -1
- package/dist/components/Avatar/AvatarImage.cjs +9 -2
- package/dist/components/Avatar/AvatarImage.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarImage.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarImage.js +10 -3
- package/dist/components/Avatar/AvatarImage.js.map +1 -1
- package/dist/components/Avatar/AvatarText.cjs +8 -2
- package/dist/components/Avatar/AvatarText.d.cts.map +1 -1
- package/dist/components/Avatar/AvatarText.d.ts.map +1 -1
- package/dist/components/Avatar/AvatarText.js +9 -3
- package/dist/components/Avatar/AvatarText.js.map +1 -1
- package/dist/components/Avatar/types.d.cts +7 -3
- package/dist/components/Avatar/types.d.cts.map +1 -1
- package/dist/components/Avatar/types.d.ts +7 -3
- package/dist/components/Avatar/types.d.ts.map +1 -1
- package/dist/components/Avatar/useAvatarFontScale.cjs +16 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.cts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts +7 -0
- package/dist/components/Avatar/useAvatarFontScale.d.ts.map +1 -0
- package/dist/components/Avatar/useAvatarFontScale.js +16 -0
- package/dist/components/Avatar/useAvatarFontScale.js.map +1 -0
- package/dist/components/Avatar/utils.cjs +9 -6
- package/dist/components/Avatar/utils.d.cts +2 -2
- package/dist/components/Avatar/utils.d.cts.map +1 -1
- package/dist/components/Avatar/utils.d.ts +2 -2
- package/dist/components/Avatar/utils.d.ts.map +1 -1
- package/dist/components/Avatar/utils.js +9 -6
- package/dist/components/Avatar/utils.js.map +1 -1
- package/dist/components/Button/buttonTheme.cjs +16 -7
- package/dist/components/Button/buttonTheme.d.cts +13 -6
- package/dist/components/Button/buttonTheme.d.cts.map +1 -1
- package/dist/components/Button/buttonTheme.d.ts +13 -6
- package/dist/components/Button/buttonTheme.d.ts.map +1 -1
- package/dist/components/Button/buttonTheme.js +16 -8
- package/dist/components/Button/buttonTheme.js.map +1 -1
- package/dist/components/Button.cjs +25 -11
- package/dist/components/Button.d.cts.map +1 -1
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +25 -11
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Checkbox.cjs +16 -6
- package/dist/components/Checkbox.d.cts.map +1 -1
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/Checkbox.js +16 -6
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/Chip/ChipBase.cjs +24 -21
- package/dist/components/Chip/ChipBase.js +24 -21
- package/dist/components/Chip/ChipBase.js.map +1 -1
- package/dist/components/Icon.cjs +22 -6
- package/dist/components/Icon.d.cts +6 -5
- package/dist/components/Icon.d.cts.map +1 -1
- package/dist/components/Icon.d.ts +6 -5
- package/dist/components/Icon.d.ts.map +1 -1
- package/dist/components/Icon.js +22 -6
- package/dist/components/Icon.js.map +1 -1
- package/dist/components/IconButton.cjs +17 -6
- package/dist/components/IconButton.d.cts +6 -0
- package/dist/components/IconButton.d.cts.map +1 -1
- package/dist/components/IconButton.d.ts +6 -0
- package/dist/components/IconButton.d.ts.map +1 -1
- package/dist/components/IconButton.js +18 -7
- package/dist/components/IconButton.js.map +1 -1
- package/dist/components/Input.cjs +56 -18
- package/dist/components/Input.d.cts +5 -0
- package/dist/components/Input.d.cts.map +1 -1
- package/dist/components/Input.d.ts +5 -0
- package/dist/components/Input.d.ts.map +1 -1
- package/dist/components/Input.js +56 -18
- package/dist/components/Input.js.map +1 -1
- package/dist/components/InputHelpText.cjs +7 -1
- package/dist/components/InputHelpText.d.cts +2 -0
- package/dist/components/InputHelpText.d.cts.map +1 -1
- package/dist/components/InputHelpText.d.ts +2 -0
- package/dist/components/InputHelpText.d.ts.map +1 -1
- package/dist/components/InputHelpText.js +7 -1
- package/dist/components/InputHelpText.js.map +1 -1
- package/dist/components/Link.cjs +16 -1
- package/dist/components/Link.d.cts +6 -0
- package/dist/components/Link.d.cts.map +1 -1
- package/dist/components/Link.d.ts +6 -0
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +16 -1
- package/dist/components/Link.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +18 -10
- package/dist/components/Pagination/Pagination.d.cts +2 -0
- package/dist/components/Pagination/Pagination.d.cts.map +1 -1
- package/dist/components/Pagination/Pagination.d.ts +2 -0
- package/dist/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/components/Pagination/Pagination.js +18 -10
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.cjs +8 -2
- package/dist/components/Pagination/PaginationEllipsis.d.cts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.d.ts.map +1 -1
- package/dist/components/Pagination/PaginationEllipsis.js +9 -3
- package/dist/components/Pagination/PaginationEllipsis.js.map +1 -1
- package/dist/components/Pagination/PaginationItem.cjs +2 -1
- package/dist/components/Pagination/PaginationItem.js +2 -1
- package/dist/components/Pagination/PaginationItem.js.map +1 -1
- package/dist/components/Pagination/PaginationLink.cjs +2 -1
- package/dist/components/Pagination/PaginationLink.js +2 -1
- package/dist/components/Pagination/PaginationLink.js.map +1 -1
- package/dist/components/Pagination/PaginationNext.cjs +3 -1
- package/dist/components/Pagination/PaginationNext.js +3 -1
- package/dist/components/Pagination/PaginationNext.js.map +1 -1
- package/dist/components/Pagination/PaginationPrev.cjs +3 -1
- package/dist/components/Pagination/PaginationPrev.js +3 -1
- package/dist/components/Pagination/PaginationPrev.js.map +1 -1
- package/dist/components/Pagination/paginationContext.d.cts +2 -0
- package/dist/components/Pagination/paginationContext.d.cts.map +1 -1
- package/dist/components/Pagination/paginationContext.d.ts +2 -0
- package/dist/components/Pagination/paginationContext.d.ts.map +1 -1
- package/dist/components/Pagination/paginationContext.js.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.cjs +8 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.cts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.d.ts.map +1 -1
- package/dist/components/Pagination/usePaginationControlStyles.js +9 -2
- package/dist/components/Pagination/usePaginationControlStyles.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +4 -3
- package/dist/components/Radio/Radio.js +4 -3
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Select/Select.cjs +29 -6
- package/dist/components/Select/Select.d.cts +2 -0
- package/dist/components/Select/Select.d.cts.map +1 -1
- package/dist/components/Select/Select.d.ts +2 -0
- package/dist/components/Select/Select.d.ts.map +1 -1
- package/dist/components/Select/Select.js +29 -6
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectContent.cjs +31 -23
- package/dist/components/Select/SelectContent.d.cts.map +1 -1
- package/dist/components/Select/SelectContent.d.ts.map +1 -1
- package/dist/components/Select/SelectContent.js +32 -24
- package/dist/components/Select/SelectContent.js.map +1 -1
- package/dist/components/Select/SelectItem.cjs +25 -15
- package/dist/components/Select/SelectItem.d.cts.map +1 -1
- package/dist/components/Select/SelectItem.d.ts.map +1 -1
- package/dist/components/Select/SelectItem.js +25 -15
- package/dist/components/Select/SelectItem.js.map +1 -1
- package/dist/components/Select/SelectTrigger.cjs +27 -13
- package/dist/components/Select/SelectTrigger.d.cts.map +1 -1
- package/dist/components/Select/SelectTrigger.d.ts.map +1 -1
- package/dist/components/Select/SelectTrigger.js +27 -13
- package/dist/components/Select/SelectTrigger.js.map +1 -1
- package/dist/components/Select/types.d.cts +2 -0
- package/dist/components/Select/types.d.cts.map +1 -1
- package/dist/components/Select/types.d.ts +2 -0
- package/dist/components/Select/types.d.ts.map +1 -1
- package/dist/components/Switch.cjs +31 -14
- package/dist/components/Switch.d.cts.map +1 -1
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +31 -14
- package/dist/components/Switch.js.map +1 -1
- package/dist/components/Tabs/Tab.cjs +8 -4
- package/dist/components/Tabs/Tab.d.cts.map +1 -1
- package/dist/components/Tabs/Tab.d.ts.map +1 -1
- package/dist/components/Tabs/Tab.js +8 -4
- package/dist/components/Tabs/Tab.js.map +1 -1
- package/dist/components/Text.cjs +5 -0
- package/dist/components/Text.d.cts +6 -5
- package/dist/components/Text.d.cts.map +1 -1
- package/dist/components/Text.d.ts +6 -5
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js +5 -0
- package/dist/components/Text.js.map +1 -1
- package/dist/components/UDSProvider.cjs +1 -1
- package/dist/components/UDSProvider.d.cts +4 -3
- package/dist/components/UDSProvider.d.cts.map +1 -1
- package/dist/components/UDSProvider.d.ts +4 -3
- package/dist/components/UDSProvider.d.ts.map +1 -1
- package/dist/components/UDSProvider.js +1 -1
- package/dist/components/UDSProvider.js.map +1 -1
- package/dist/fontScaling/FontScalingContext.cjs +35 -3
- package/dist/fontScaling/FontScalingContext.d.cts +20 -5
- package/dist/fontScaling/FontScalingContext.d.cts.map +1 -1
- package/dist/fontScaling/FontScalingContext.d.ts +20 -5
- package/dist/fontScaling/FontScalingContext.d.ts.map +1 -1
- package/dist/fontScaling/FontScalingContext.js +34 -5
- package/dist/fontScaling/FontScalingContext.js.map +1 -1
- package/dist/fontScaling/androidNonlinearFontScaling.cjs +250 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.cts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts +7 -0
- package/dist/fontScaling/androidNonlinearFontScaling.d.ts.map +1 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js +251 -0
- package/dist/fontScaling/androidNonlinearFontScaling.js.map +1 -0
- package/dist/fontScaling/constants.cjs +37 -3
- package/dist/fontScaling/constants.d.cts +15 -4
- package/dist/fontScaling/constants.d.cts.map +1 -1
- package/dist/fontScaling/constants.d.ts +15 -4
- package/dist/fontScaling/constants.d.ts.map +1 -1
- package/dist/fontScaling/constants.js +37 -4
- package/dist/fontScaling/constants.js.map +1 -1
- package/dist/fontScaling/index.cjs +2 -1
- package/dist/fontScaling/index.d.cts +2 -2
- package/dist/fontScaling/index.d.ts +2 -2
- package/dist/fontScaling/index.js +3 -3
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.cjs +1 -2
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.d.cts +1 -2
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.d.cts.map +1 -1
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.d.ts +1 -2
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.d.ts.map +1 -1
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.js +1 -2
- package/dist/fontScaling/resolveMaxFontSizeMultiplier.js.map +1 -1
- package/dist/fontScaling/types.d.cts +11 -8
- package/dist/fontScaling/types.d.cts.map +1 -1
- package/dist/fontScaling/types.d.ts +11 -8
- package/dist/fontScaling/types.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.cjs +30 -4
- package/dist/fontScaling/useFontScale.d.cts +6 -12
- package/dist/fontScaling/useFontScale.d.cts.map +1 -1
- package/dist/fontScaling/useFontScale.d.ts +6 -12
- package/dist/fontScaling/useFontScale.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.js +31 -6
- package/dist/fontScaling/useFontScale.js.map +1 -1
- package/dist/jest/mocks/styles.cjs +14 -1
- package/dist/jest/mocks/styles.d.cts.map +1 -1
- package/dist/jest/mocks/styles.d.ts.map +1 -1
- package/dist/jest/mocks/styles.js +14 -1
- package/dist/jest/mocks/styles.js.map +1 -1
- package/dist/mobile/generated/fontMetrics.cjs +534 -534
- package/dist/mobile/generated/fontMetrics.js +534 -534
- package/dist/mobile/generated/fontMetrics.js.map +1 -1
- package/dist/portal.cjs +8 -2
- package/dist/portal.d.cts.map +1 -1
- package/dist/portal.d.ts.map +1 -1
- package/dist/portal.js +8 -2
- package/dist/portal.js.map +1 -1
- package/fonts/index.cjs +214 -214
- package/fonts/index.mjs +214 -214
- package/fonts/uds-icons.ttf +0 -0
- package/generated/fontMetrics.ts +534 -534
- package/package.json +2 -2
package/dist/components/Icon.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
|
+
import { useComponentFontScale } from "../fontScaling/useFontScale.js";
|
|
2
3
|
import { useMaxFontSizeMultiplier } from "../fontScaling/useMaxFontSizeMultiplier.js";
|
|
3
4
|
import { getSafeIconCell } from "./Button/buttonTheme.js";
|
|
4
5
|
import { memo, useMemo } from "react";
|
|
@@ -22,10 +23,14 @@ const DEFAULT_PROPS = {
|
|
|
22
23
|
* Uses useUnistyles() for reactive theme access - isolated here so
|
|
23
24
|
* glyph-based icons don't pay the hook overhead.
|
|
24
25
|
*/
|
|
25
|
-
const MulticolorIcon = memo(function MulticolorIcon({ name, size = DEFAULT_PROPS.size, flexShrink = DEFAULT_PROPS.flexShrink, backgroundColor, dangerouslySetSize }) {
|
|
26
|
+
const MulticolorIcon = memo(function MulticolorIcon({ name, size = DEFAULT_PROPS.size, flexShrink = DEFAULT_PROPS.flexShrink, backgroundColor, dangerouslySetSize, maxFontSizeMultiplier, inheritFontScaling = false, allowFontScaling = true, accessible, accessibilityElementsHidden, accessibilityHint, accessibilityLabel = name, accessibilityRole = "image", accessibilityState, accessibilityValue, importantForAccessibility, testID }) {
|
|
26
27
|
const { rt } = useUnistyles();
|
|
27
28
|
const colorScheme = rt.themeName === "dark" ? "dark" : "light";
|
|
28
29
|
const pixelSize = ICON_SIZE_MAP[size];
|
|
30
|
+
const baseSize = dangerouslySetSize ?? pixelSize;
|
|
31
|
+
const controlMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
32
|
+
const fontScaleFactor = useComponentFontScale(allowFontScaling ? inheritFontScaling && maxFontSizeMultiplier === void 0 ? void 0 : controlMaxFontSizeMultiplier : 1, baseSize);
|
|
33
|
+
const renderedSize = Math.round(baseSize * fontScaleFactor);
|
|
29
34
|
const svgKey = `${name}-${colorScheme}-${pixelSize}`;
|
|
30
35
|
const svgContent = svgMap[svgKey];
|
|
31
36
|
if (!svgContent) {
|
|
@@ -37,17 +42,28 @@ const MulticolorIcon = memo(function MulticolorIcon({ name, size = DEFAULT_PROPS
|
|
|
37
42
|
backgroundColor
|
|
38
43
|
});
|
|
39
44
|
return /* @__PURE__ */ jsx(View, {
|
|
45
|
+
accessible,
|
|
46
|
+
accessibilityElementsHidden,
|
|
47
|
+
accessibilityHint,
|
|
48
|
+
accessibilityLabel,
|
|
49
|
+
accessibilityRole,
|
|
50
|
+
accessibilityState,
|
|
51
|
+
accessibilityValue,
|
|
52
|
+
importantForAccessibility,
|
|
53
|
+
testID,
|
|
40
54
|
style: styles.foundation,
|
|
41
55
|
children: /* @__PURE__ */ jsx(SvgXml, {
|
|
42
56
|
xml: svgContent,
|
|
43
|
-
width:
|
|
44
|
-
height:
|
|
57
|
+
width: renderedSize,
|
|
58
|
+
height: renderedSize,
|
|
59
|
+
viewBox: `0 0 ${pixelSize} ${pixelSize}`
|
|
45
60
|
})
|
|
46
61
|
});
|
|
47
62
|
});
|
|
48
|
-
const OutlineOrFillIcon = memo(function OutlineOrFillIcon({ name, size = DEFAULT_PROPS.size, color = DEFAULT_PROPS.color, variant = DEFAULT_PROPS.variant, backgroundColor, borderRadius, borderTopStartRadius, borderTopEndRadius, borderBottomStartRadius, borderBottomEndRadius, borderColor, borderStartColor, borderEndColor, borderTopColor, borderBottomColor, borderWidth, borderVerticalWidth, borderHorizontalWidth, borderStartWidth, borderEndWidth, borderTopWidth, borderBottomWidth, flexShrink = "0", spacingStart, spacingEnd, spacingTop, spacingBottom, spacingHorizontal, spacingVertical, spacing, offsetStart, offsetEnd, offsetTop, offsetBottom, offsetHorizontal, offsetVertical, offset, dangerouslySetColor, dangerouslySetSize, maxFontSizeMultiplier, style, ref, ...props }) {
|
|
63
|
+
const OutlineOrFillIcon = memo(function OutlineOrFillIcon({ name, size = DEFAULT_PROPS.size, color = DEFAULT_PROPS.color, variant = DEFAULT_PROPS.variant, backgroundColor, borderRadius, borderTopStartRadius, borderTopEndRadius, borderBottomStartRadius, borderBottomEndRadius, borderColor, borderStartColor, borderEndColor, borderTopColor, borderBottomColor, borderWidth, borderVerticalWidth, borderHorizontalWidth, borderStartWidth, borderEndWidth, borderTopWidth, borderBottomWidth, flexShrink = "0", spacingStart, spacingEnd, spacingTop, spacingBottom, spacingHorizontal, spacingVertical, spacing, offsetStart, offsetEnd, offsetTop, offsetBottom, offsetHorizontal, offsetVertical, offset, dangerouslySetColor, dangerouslySetSize, maxFontSizeMultiplier, inheritFontScaling = false, style, ref, ...props }) {
|
|
49
64
|
const pixelSize = ICON_SIZE_MAP[size];
|
|
50
|
-
const
|
|
65
|
+
const controlMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
66
|
+
const resolvedMaxFontSizeMultiplier = inheritFontScaling && maxFontSizeMultiplier === void 0 ? void 0 : controlMaxFontSizeMultiplier;
|
|
51
67
|
styles.useVariants({
|
|
52
68
|
color,
|
|
53
69
|
backgroundColor,
|
|
@@ -117,7 +133,7 @@ const OutlineOrFillIcon = memo(function OutlineOrFillIcon({ name, size = DEFAULT
|
|
|
117
133
|
});
|
|
118
134
|
});
|
|
119
135
|
/**
|
|
120
|
-
* **🎨 An icon component using UDS icon fonts**
|
|
136
|
+
* **🎨 An icon component using UDS icon fonts and multicolor SVGs**
|
|
121
137
|
*
|
|
122
138
|
* @description
|
|
123
139
|
* Renders icons from the UDS icon library. Supports multiple variants
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","names":[],"sources":["../../src/components/Icon.tsx"],"sourcesContent":["import type { GlyphName } from '@yahoo/uds-icons/glyphMap';\nimport { glyphMap, glyphNames } from '@yahoo/uds-icons/glyphMap';\nimport type { SvgGlyphKey, SvgGlyphName } from '@yahoo/uds-icons/svgMap';\nimport { svgGlyphNames, svgMap } from '@yahoo/uds-icons/svgMap';\nimport { ICON_SIZE_MAP } from '@yahoo/uds-icons/tokens';\nimport type { IconSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useMemo } from 'react';\nimport type {\n StyleProp,\n Text as RNText,\n TextProps as RNTextProps,\n TextStyle,\n ViewProps,\n} from 'react-native';\nimport { Text, View } from 'react-native';\nimport { SvgXml } from 'react-native-svg';\n// eslint-disable-next-line uds/no-use-unistyles\nimport { useUnistyles } from 'react-native-unistyles';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { styles } from '../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { getSafeIconCell } from './Button/buttonTheme';\n\nconst DEFAULT_PROPS = {\n size: 'md',\n color: 'primary',\n variant: 'outline',\n flexShrink: '0',\n} as const;\n\n/* -------------------------------------------------------------------------- */\n/* Icon Props */\n/* -------------------------------------------------------------------------- */\n\ntype IconName = GlyphName | SvgGlyphName;\n\ninterface IconProps extends Omit<RNTextProps, 'style'> {\n /** Ref to the underlying Text element */\n ref?: Ref<RNText>;\n /** The icon name */\n name: IconName;\n /** Icon size */\n size?: IconSize;\n /** Icon color */\n color?: StyleProps['color'];\n /** Icon variant (outline, fill, multicolor) */\n variant?: IconVariant;\n /**\n * Caps how far the glyph grows with the OS text-size setting. Set null to\n * remove the cap; override app-wide via UDSFontScalingProvider. Multicolor\n * (SVG) icons do not respond to OS font scaling - combine dangerouslySetSize\n * with useFontScale if needed.\n * @default 2\n */\n maxFontSizeMultiplier?: number | null;\n // Background\n backgroundColor?: StyleProps['backgroundColor'];\n // Border\n borderRadius?: StyleProps['borderRadius'];\n borderTopStartRadius?: StyleProps['borderTopStartRadius'];\n borderTopEndRadius?: StyleProps['borderTopEndRadius'];\n borderBottomStartRadius?: StyleProps['borderBottomStartRadius'];\n borderBottomEndRadius?: StyleProps['borderBottomEndRadius'];\n borderColor?: StyleProps['borderColor'];\n borderStartColor?: StyleProps['borderStartColor'];\n borderEndColor?: StyleProps['borderEndColor'];\n borderTopColor?: StyleProps['borderTopColor'];\n borderBottomColor?: StyleProps['borderBottomColor'];\n borderWidth?: StyleProps['borderWidth'];\n borderVerticalWidth?: StyleProps['borderVerticalWidth'];\n borderHorizontalWidth?: StyleProps['borderHorizontalWidth'];\n borderStartWidth?: StyleProps['borderStartWidth'];\n borderEndWidth?: StyleProps['borderEndWidth'];\n borderTopWidth?: StyleProps['borderTopWidth'];\n borderBottomWidth?: StyleProps['borderBottomWidth'];\n // Flex\n flexShrink?: StyleProps['flexShrink'];\n // Spacing\n spacingStart?: StyleProps['spacingStart'];\n spacingEnd?: StyleProps['spacingEnd'];\n spacingTop?: StyleProps['spacingTop'];\n spacingBottom?: StyleProps['spacingBottom'];\n spacingHorizontal?: StyleProps['spacingHorizontal'];\n spacingVertical?: StyleProps['spacingVertical'];\n spacing?: StyleProps['spacing'];\n // Offset\n offsetStart?: StyleProps['offsetStart'];\n offsetEnd?: StyleProps['offsetEnd'];\n offsetTop?: StyleProps['offsetTop'];\n offsetBottom?: StyleProps['offsetBottom'];\n offsetHorizontal?: StyleProps['offsetHorizontal'];\n offsetVertical?: StyleProps['offsetVertical'];\n offset?: StyleProps['offset'];\n /** Icon color override */\n dangerouslySetColor?: string;\n /** Icon font size override */\n dangerouslySetSize?: number;\n /** Optional style override */\n style?: StyleProp<TextStyle>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Multicolor Icon */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Separate component for multicolor SVG icons.\n * Uses useUnistyles() for reactive theme access - isolated here so\n * glyph-based icons don't pay the hook overhead.\n */\nconst MulticolorIcon = memo(function MulticolorIcon({\n name,\n size = DEFAULT_PROPS.size,\n flexShrink = DEFAULT_PROPS.flexShrink,\n backgroundColor,\n dangerouslySetSize,\n}: Omit<IconProps, 'variant'>) {\n // Reactive theme subscription - only multicolor icons need this\n const { rt } = useUnistyles();\n const colorScheme = rt.themeName === 'dark' ? 'dark' : 'light';\n\n const pixelSize = ICON_SIZE_MAP[size];\n const svgKey = `${name}-${colorScheme}-${pixelSize}` as SvgGlyphKey;\n const svgContent = svgMap[svgKey];\n\n if (!svgContent) {\n console.warn(`Multicolor icon \"${svgKey}\" not found`);\n return null;\n }\n\n styles.useVariants({\n flexShrink,\n backgroundColor,\n });\n\n return (\n <View style={styles.foundation as ViewProps['style']}>\n <SvgXml\n xml={svgContent}\n width={dangerouslySetSize ?? pixelSize}\n height={dangerouslySetSize ?? pixelSize}\n />\n </View>\n );\n});\n\nconst OutlineOrFillIcon = memo(function OutlineOrFillIcon({\n name,\n size = DEFAULT_PROPS.size,\n color = DEFAULT_PROPS.color,\n variant = DEFAULT_PROPS.variant,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Flex\n flexShrink = '0',\n // Spacing\n spacingStart,\n spacingEnd,\n spacingTop,\n spacingBottom,\n spacingHorizontal,\n spacingVertical,\n spacing,\n // Offset\n offsetStart,\n offsetEnd,\n offsetTop,\n offsetBottom,\n offsetHorizontal,\n offsetVertical,\n offset,\n // Dangerously set props\n dangerouslySetColor,\n dangerouslySetSize,\n maxFontSizeMultiplier,\n style,\n ref,\n ...props\n}: Omit<IconProps, 'variant'> & { variant?: 'outline' | 'fill' }) {\n const pixelSize = ICON_SIZE_MAP[size];\n // Native scales fontSize and lineHeight together under the cap, so the\n // glyph cell grows proportionally; glyph selection stays at pixelSize.\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n // Glyph-based icons - no useUnistyles needed, styles.useVariants is reactive\n styles.useVariants({\n color,\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Flex\n flexShrink,\n // Spacing\n spacingStart,\n spacingEnd,\n spacingTop,\n spacingBottom,\n spacingHorizontal,\n spacingVertical,\n spacing,\n // Offset\n offsetStart,\n offsetEnd,\n offsetTop,\n offsetBottom,\n offsetHorizontal,\n offsetVertical,\n offset,\n });\n const glyphName = `${name}-${variant}-${pixelSize}`;\n const glyph = (glyphMap as Record<string, string>)[glyphName];\n const textStyles: StyleProp<TextStyle> = useMemo(\n () => [\n {\n fontFamily: 'uds-icons',\n textAlign: 'center',\n textAlignVertical: 'center',\n fontSize: pixelSize,\n lineHeight: getSafeIconCell(pixelSize),\n },\n styles.foundation,\n dangerouslySetColor ? { color: dangerouslySetColor } : undefined,\n dangerouslySetSize\n ? {\n fontSize: dangerouslySetSize,\n lineHeight: getSafeIconCell(dangerouslySetSize),\n }\n : undefined,\n style,\n ],\n [dangerouslySetColor, dangerouslySetSize, style, styles.foundation, pixelSize],\n );\n\n return (\n <Text\n ref={ref}\n accessibilityRole=\"image\"\n accessibilityLabel={name}\n style={textStyles}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n {...props}\n >\n {glyph}\n </Text>\n );\n});\n\n/**\n * **🎨 An icon component using UDS icon fonts**\n *\n * @description\n * Renders icons from the UDS icon library. Supports multiple variants\n * (outline, fill, multicolor) and sizes.\n *\n * @category Display\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Icon } from '@yahoo/uds-mobile/Icon';\n *\n * <Icon name=\"ChevronRight\" size=\"md\" color=\"primary\" />\n * <Icon name=\"Star\" variant=\"fill\" color=\"accent\" />\n * <Icon name=\"Yahoo\" variant=\"multicolor\" />\n * ```\n *\n * @usage\n * - Use name prop to specify the icon\n * - Use variant prop for outline/fill/multicolor\n * - Use size prop for icon size (xs, sm, md, lg, xl)\n *\n * @accessibility\n * - Sets `accessibilityRole=\"image\"` automatically\n * - Icon name is used as accessibility label\n * - For decorative icons, set `accessibilityElementsHidden`\n *\n * @see {@link IconButton} for clickable icons\n * @see {@link IconSlot} for flexible icon rendering in components\n */\nconst Icon = memo(function Icon({ variant, ...props }: IconProps) {\n // Delegate to MulticolorIcon for SVG-based icons (has its own useUnistyles)\n if (variant === 'multicolor') {\n return <MulticolorIcon {...props} />;\n }\n\n return <OutlineOrFillIcon variant={variant} {...props} />;\n});\n\nIcon.displayName = 'Icon';\n\nexport { Icon };\nexport type { IconName, IconProps };\nexport const iconNames = glyphNames;\nexport const multicolorIconNames = svgGlyphNames;\n"],"mappings":";;;;;;;;;;;;;AAyBA,MAAM,gBAAgB;CACpB,MAAM;CACN,OAAO;CACP,SAAS;CACT,YAAY;CACb;;;;;;AAkFD,MAAM,iBAAiB,KAAK,SAAS,eAAe,EAClD,MACA,OAAO,cAAc,MACrB,aAAa,cAAc,YAC3B,iBACA,sBAC6B;CAE7B,MAAM,EAAE,OAAO,cAAc;CAC7B,MAAM,cAAc,GAAG,cAAc,SAAS,SAAS;CAEvD,MAAM,YAAY,cAAc;CAChC,MAAM,SAAS,GAAG,KAAK,GAAG,YAAY,GAAG;CACzC,MAAM,aAAa,OAAO;CAE1B,IAAI,CAAC,YAAY;EACf,QAAQ,KAAK,oBAAoB,OAAO,aAAa;EACrD,OAAO;;CAGT,OAAO,YAAY;EACjB;EACA;EACD,CAAC;CAEF,OACE,oBAAC,MAAD;EAAM,OAAO,OAAO;YAClB,oBAAC,QAAD;GACE,KAAK;GACL,OAAO,sBAAsB;GAC7B,QAAQ,sBAAsB;GAC9B,CAAA;EACG,CAAA;EAET;AAEF,MAAM,oBAAoB,KAAK,SAAS,kBAAkB,EACxD,MACA,OAAO,cAAc,MACrB,QAAQ,cAAc,OACtB,UAAU,cAAc,SAExB,iBAEA,cACA,sBACA,oBACA,yBACA,uBACA,aACA,kBACA,gBACA,gBACA,mBACA,aACA,qBACA,uBACA,kBACA,gBACA,gBACA,mBAEA,aAAa,KAEb,cACA,YACA,YACA,eACA,mBACA,iBACA,SAEA,aACA,WACA,WACA,cACA,kBACA,gBACA,QAEA,qBACA,oBACA,uBACA,OACA,KACA,GAAG,SAC6D;CAChE,MAAM,YAAY,cAAc;CAGhC,MAAM,gCAAgC,yBAAyB,WAAW,sBAAsB;CAEhG,OAAO,YAAY;EACjB;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAEF,MAAM,QAAS,SAAoC,GAD9B,KAAK,GAAG,QAAQ,GAAG;CAwBxC,OACE,oBAAC,MAAD;EACO;EACL,mBAAkB;EAClB,oBAAoB;EACpB,OA3BqC,cACjC;GACJ;IACE,YAAY;IACZ,WAAW;IACX,mBAAmB;IACnB,UAAU;IACV,YAAY,gBAAgB,UAAU;IACvC;GACD,OAAO;GACP,sBAAsB,EAAE,OAAO,qBAAqB,GAAG,KAAA;GACvD,qBACI;IACE,UAAU;IACV,YAAY,gBAAgB,mBAAmB;IAChD,GACD,KAAA;GACJ;GACD,EACD;GAAC;GAAqB;GAAoB;GAAO,OAAO;GAAY;GAAU,CAQ3D;EACjB,uBAAuB;EACvB,GAAI;YAEH;EACI,CAAA;EAET;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCF,MAAM,OAAO,KAAK,SAAS,KAAK,EAAE,SAAS,GAAG,SAAoB;CAEhE,IAAI,YAAY,cACd,OAAO,oBAAC,gBAAD,EAAgB,GAAI,OAAS,CAAA;CAGtC,OAAO,oBAAC,mBAAD;EAA4B;EAAS,GAAI;EAAS,CAAA;EACzD;AAEF,KAAK,cAAc;AAInB,MAAa,YAAY;AACzB,MAAa,sBAAsB"}
|
|
1
|
+
{"version":3,"file":"Icon.js","names":[],"sources":["../../src/components/Icon.tsx"],"sourcesContent":["import type { GlyphName } from '@yahoo/uds-icons/glyphMap';\nimport { glyphMap, glyphNames } from '@yahoo/uds-icons/glyphMap';\nimport type { SvgGlyphKey, SvgGlyphName } from '@yahoo/uds-icons/svgMap';\nimport { svgGlyphNames, svgMap } from '@yahoo/uds-icons/svgMap';\nimport { ICON_SIZE_MAP } from '@yahoo/uds-icons/tokens';\nimport type { IconSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useMemo } from 'react';\nimport type {\n StyleProp,\n Text as RNText,\n TextProps as RNTextProps,\n TextStyle,\n ViewProps,\n} from 'react-native';\nimport { Text, View } from 'react-native';\nimport { SvgXml } from 'react-native-svg';\n// eslint-disable-next-line uds/no-use-unistyles\nimport { useUnistyles } from 'react-native-unistyles';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { styles } from '../../generated/styles';\nimport { useComponentFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { getSafeIconCell } from './Button/buttonTheme';\n\nconst DEFAULT_PROPS = {\n size: 'md',\n color: 'primary',\n variant: 'outline',\n flexShrink: '0',\n} as const;\n\n/* -------------------------------------------------------------------------- */\n/* Icon Props */\n/* -------------------------------------------------------------------------- */\n\ntype IconName = GlyphName | SvgGlyphName;\n\ninterface IconProps extends Omit<RNTextProps, 'style'> {\n /** Ref to the underlying Text element */\n ref?: Ref<RNText>;\n /** The icon name */\n name: IconName;\n /** Icon size */\n size?: IconSize;\n /** Icon color */\n color?: StyleProps['color'];\n /** Icon variant (outline, fill, multicolor) */\n variant?: IconVariant;\n /**\n * Caps how far the icon grows with the OS text-size setting. Applies to both\n * font glyphs and multicolor SVGs. Set null to remove the cap; override\n * app-wide via UDSFontScalingProvider.\n * @default 2\n */\n maxFontSizeMultiplier?: number | null;\n /** @internal Inherit a containing Text node's scaling when no cap is supplied. */\n inheritFontScaling?: boolean;\n // Background\n backgroundColor?: StyleProps['backgroundColor'];\n // Border\n borderRadius?: StyleProps['borderRadius'];\n borderTopStartRadius?: StyleProps['borderTopStartRadius'];\n borderTopEndRadius?: StyleProps['borderTopEndRadius'];\n borderBottomStartRadius?: StyleProps['borderBottomStartRadius'];\n borderBottomEndRadius?: StyleProps['borderBottomEndRadius'];\n borderColor?: StyleProps['borderColor'];\n borderStartColor?: StyleProps['borderStartColor'];\n borderEndColor?: StyleProps['borderEndColor'];\n borderTopColor?: StyleProps['borderTopColor'];\n borderBottomColor?: StyleProps['borderBottomColor'];\n borderWidth?: StyleProps['borderWidth'];\n borderVerticalWidth?: StyleProps['borderVerticalWidth'];\n borderHorizontalWidth?: StyleProps['borderHorizontalWidth'];\n borderStartWidth?: StyleProps['borderStartWidth'];\n borderEndWidth?: StyleProps['borderEndWidth'];\n borderTopWidth?: StyleProps['borderTopWidth'];\n borderBottomWidth?: StyleProps['borderBottomWidth'];\n // Flex\n flexShrink?: StyleProps['flexShrink'];\n // Spacing\n spacingStart?: StyleProps['spacingStart'];\n spacingEnd?: StyleProps['spacingEnd'];\n spacingTop?: StyleProps['spacingTop'];\n spacingBottom?: StyleProps['spacingBottom'];\n spacingHorizontal?: StyleProps['spacingHorizontal'];\n spacingVertical?: StyleProps['spacingVertical'];\n spacing?: StyleProps['spacing'];\n // Offset\n offsetStart?: StyleProps['offsetStart'];\n offsetEnd?: StyleProps['offsetEnd'];\n offsetTop?: StyleProps['offsetTop'];\n offsetBottom?: StyleProps['offsetBottom'];\n offsetHorizontal?: StyleProps['offsetHorizontal'];\n offsetVertical?: StyleProps['offsetVertical'];\n offset?: StyleProps['offset'];\n /** Icon color override */\n dangerouslySetColor?: string;\n /** Icon font size override */\n dangerouslySetSize?: number;\n /** Optional style override */\n style?: StyleProp<TextStyle>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Multicolor Icon */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Separate component for multicolor SVG icons.\n * Uses useUnistyles() for reactive theme access - isolated here so\n * glyph-based icons don't pay the hook overhead.\n */\nconst MulticolorIcon = memo(function MulticolorIcon({\n name,\n size = DEFAULT_PROPS.size,\n flexShrink = DEFAULT_PROPS.flexShrink,\n backgroundColor,\n dangerouslySetSize,\n maxFontSizeMultiplier,\n inheritFontScaling = false,\n allowFontScaling = true,\n accessible,\n accessibilityElementsHidden,\n accessibilityHint,\n accessibilityLabel = name,\n accessibilityRole = 'image',\n accessibilityState,\n accessibilityValue,\n importantForAccessibility,\n testID,\n}: Omit<IconProps, 'variant'>) {\n // Reactive theme subscription - only multicolor icons need this\n const { rt } = useUnistyles();\n const colorScheme = rt.themeName === 'dark' ? 'dark' : 'light';\n\n const pixelSize = ICON_SIZE_MAP[size];\n const baseSize = dangerouslySetSize ?? pixelSize;\n const controlMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n const resolvedMaxFontSizeMultiplier =\n inheritFontScaling && maxFontSizeMultiplier === undefined\n ? undefined\n : controlMaxFontSizeMultiplier;\n const fontScaleFactor = useComponentFontScale(\n allowFontScaling ? resolvedMaxFontSizeMultiplier : 1,\n baseSize,\n );\n const renderedSize = Math.round(baseSize * fontScaleFactor);\n const svgKey = `${name}-${colorScheme}-${pixelSize}` as SvgGlyphKey;\n const svgContent = svgMap[svgKey];\n\n if (!svgContent) {\n console.warn(`Multicolor icon \"${svgKey}\" not found`);\n return null;\n }\n\n styles.useVariants({\n flexShrink,\n backgroundColor,\n });\n\n return (\n <View\n accessible={accessible}\n accessibilityElementsHidden={accessibilityElementsHidden}\n accessibilityHint={accessibilityHint}\n accessibilityLabel={accessibilityLabel}\n accessibilityRole={accessibilityRole}\n accessibilityState={accessibilityState}\n accessibilityValue={accessibilityValue}\n importantForAccessibility={importantForAccessibility}\n testID={testID}\n style={styles.foundation as ViewProps['style']}\n >\n <SvgXml\n xml={svgContent}\n width={renderedSize}\n height={renderedSize}\n viewBox={`0 0 ${pixelSize} ${pixelSize}`}\n />\n </View>\n );\n});\n\nconst OutlineOrFillIcon = memo(function OutlineOrFillIcon({\n name,\n size = DEFAULT_PROPS.size,\n color = DEFAULT_PROPS.color,\n variant = DEFAULT_PROPS.variant,\n // Background\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Flex\n flexShrink = '0',\n // Spacing\n spacingStart,\n spacingEnd,\n spacingTop,\n spacingBottom,\n spacingHorizontal,\n spacingVertical,\n spacing,\n // Offset\n offsetStart,\n offsetEnd,\n offsetTop,\n offsetBottom,\n offsetHorizontal,\n offsetVertical,\n offset,\n // Dangerously set props\n dangerouslySetColor,\n dangerouslySetSize,\n maxFontSizeMultiplier,\n inheritFontScaling = false,\n style,\n ref,\n ...props\n}: Omit<IconProps, 'variant'> & { variant?: 'outline' | 'fill' }) {\n const pixelSize = ICON_SIZE_MAP[size];\n // Native scales fontSize and lineHeight together under the cap, so the\n // glyph cell grows proportionally; glyph selection stays at pixelSize.\n const controlMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n const resolvedMaxFontSizeMultiplier =\n inheritFontScaling && maxFontSizeMultiplier === undefined\n ? undefined\n : controlMaxFontSizeMultiplier;\n // Glyph-based icons - no useUnistyles needed, styles.useVariants is reactive\n styles.useVariants({\n color,\n backgroundColor,\n // Border\n borderRadius,\n borderTopStartRadius,\n borderTopEndRadius,\n borderBottomStartRadius,\n borderBottomEndRadius,\n borderColor,\n borderStartColor,\n borderEndColor,\n borderTopColor,\n borderBottomColor,\n borderWidth,\n borderVerticalWidth,\n borderHorizontalWidth,\n borderStartWidth,\n borderEndWidth,\n borderTopWidth,\n borderBottomWidth,\n // Flex\n flexShrink,\n // Spacing\n spacingStart,\n spacingEnd,\n spacingTop,\n spacingBottom,\n spacingHorizontal,\n spacingVertical,\n spacing,\n // Offset\n offsetStart,\n offsetEnd,\n offsetTop,\n offsetBottom,\n offsetHorizontal,\n offsetVertical,\n offset,\n });\n const glyphName = `${name}-${variant}-${pixelSize}`;\n const glyph = (glyphMap as Record<string, string>)[glyphName];\n const textStyles: StyleProp<TextStyle> = useMemo(\n () => [\n {\n fontFamily: 'uds-icons',\n textAlign: 'center',\n textAlignVertical: 'center',\n fontSize: pixelSize,\n lineHeight: getSafeIconCell(pixelSize),\n },\n styles.foundation,\n dangerouslySetColor ? { color: dangerouslySetColor } : undefined,\n dangerouslySetSize\n ? {\n fontSize: dangerouslySetSize,\n lineHeight: getSafeIconCell(dangerouslySetSize),\n }\n : undefined,\n style,\n ],\n [dangerouslySetColor, dangerouslySetSize, style, styles.foundation, pixelSize],\n );\n\n return (\n <Text\n ref={ref}\n accessibilityRole=\"image\"\n accessibilityLabel={name}\n style={textStyles}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n {...props}\n >\n {glyph}\n </Text>\n );\n});\n\n/**\n * **🎨 An icon component using UDS icon fonts and multicolor SVGs**\n *\n * @description\n * Renders icons from the UDS icon library. Supports multiple variants\n * (outline, fill, multicolor) and sizes.\n *\n * @category Display\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Icon } from '@yahoo/uds-mobile/Icon';\n *\n * <Icon name=\"ChevronRight\" size=\"md\" color=\"primary\" />\n * <Icon name=\"Star\" variant=\"fill\" color=\"accent\" />\n * <Icon name=\"Yahoo\" variant=\"multicolor\" />\n * ```\n *\n * @usage\n * - Use name prop to specify the icon\n * - Use variant prop for outline/fill/multicolor\n * - Use size prop for icon size (xs, sm, md, lg, xl)\n *\n * @accessibility\n * - Sets `accessibilityRole=\"image\"` automatically\n * - Icon name is used as accessibility label\n * - For decorative icons, set `accessibilityElementsHidden`\n *\n * @see {@link IconButton} for clickable icons\n * @see {@link IconSlot} for flexible icon rendering in components\n */\nconst Icon = memo(function Icon({ variant, ...props }: IconProps) {\n // Delegate to MulticolorIcon for SVG-based icons (has its own useUnistyles)\n if (variant === 'multicolor') {\n return <MulticolorIcon {...props} />;\n }\n\n return <OutlineOrFillIcon variant={variant} {...props} />;\n});\n\nIcon.displayName = 'Icon';\n\nexport { Icon };\nexport type { IconName, IconProps };\nexport const iconNames = glyphNames;\nexport const multicolorIconNames = svgGlyphNames;\n"],"mappings":"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"}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
4
4
|
const require_index = require("../motion-tokens/dist/index.cjs");
|
|
5
5
|
const require_motion = require("../motion.cjs");
|
|
6
|
+
const require_fontScaling_useFontScale = require("../fontScaling/useFontScale.cjs");
|
|
7
|
+
const require_fontScaling_useMaxFontSizeMultiplier = require("../fontScaling/useMaxFontSizeMultiplier.cjs");
|
|
6
8
|
const require_components_Button_buttonTheme = require("./Button/buttonTheme.cjs");
|
|
7
9
|
const require_components_Icon = require("./Icon.cjs");
|
|
8
10
|
const require_components_Pressable = require("./Pressable.cjs");
|
|
@@ -56,12 +58,22 @@ function interpolateShadowAlpha(shadow, alpha) {
|
|
|
56
58
|
* @see {@link Button} for buttons with text labels
|
|
57
59
|
* @see {@link Icon} for non-interactive icons
|
|
58
60
|
*/
|
|
59
|
-
const IconButton = (0, react.memo)(function IconButton({ name, variant = "primary", size = "md", iconVariant = "outline", iconColor, loading, disabled, style, accessibilityLabel, accessibilityHint, disableEffects = false, onPressIn, onPressOut, ref, ...props }) {
|
|
61
|
+
const IconButton = (0, react.memo)(function IconButton({ name, variant = "primary", size = "md", iconVariant = "outline", iconColor, loading, disabled, style, accessibilityLabel, accessibilityHint, disableEffects = false, maxFontSizeMultiplier, onPressIn, onPressOut, ref, ...props }) {
|
|
60
62
|
const isDisabled = disabled || loading;
|
|
61
63
|
const shouldAnimate = !disableEffects && !isDisabled;
|
|
62
64
|
const shouldAnimateVariantColors = react_native.Platform.OS !== "web";
|
|
63
65
|
const { theme } = (0, react_native_unistyles.useUnistyles)();
|
|
64
|
-
const
|
|
66
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
67
|
+
const [pressed, setPressed] = (0, react.useState)(false);
|
|
68
|
+
const resolvedIconButtonStyles = generated_styles.iconButtonStyles.useVariants({ size }) ?? generated_styles.iconButtonStyles;
|
|
69
|
+
const iconBaseSize = (0, react.useMemo)(() => require_components_Button_buttonTheme.getIconButtonIconSize(theme, size), [theme, size]);
|
|
70
|
+
const iconScaleFactor = require_fontScaling_useFontScale.useComponentFontScale(resolvedMaxFontSizeMultiplier, iconBaseSize);
|
|
71
|
+
const { minHeight, iconCellHeight, paddingVertical, hasExplicitHeight } = (0, react.useMemo)(() => require_components_Button_buttonTheme.getIconButtonControlMetrics(theme, size, iconScaleFactor), [
|
|
72
|
+
theme,
|
|
73
|
+
size,
|
|
74
|
+
iconScaleFactor
|
|
75
|
+
]);
|
|
76
|
+
const scaledIconSize = Math.round(iconBaseSize * iconScaleFactor);
|
|
65
77
|
const controlDimensions = hasExplicitHeight ? {
|
|
66
78
|
height: "auto",
|
|
67
79
|
width: "auto",
|
|
@@ -72,8 +84,6 @@ const IconButton = (0, react.memo)(function IconButton({ name, variant = "primar
|
|
|
72
84
|
minHeight,
|
|
73
85
|
paddingVertical
|
|
74
86
|
};
|
|
75
|
-
const [pressed, setPressed] = (0, react.useState)(false);
|
|
76
|
-
const resolvedIconButtonStyles = generated_styles.iconButtonStyles.useVariants({ size }) ?? generated_styles.iconButtonStyles;
|
|
77
87
|
const resolvedButtonStyles = generated_styles.buttonStyles.useVariants({
|
|
78
88
|
variant,
|
|
79
89
|
disabled: isDisabled,
|
|
@@ -151,7 +161,7 @@ const IconButton = (0, react.memo)(function IconButton({ name, variant = "primar
|
|
|
151
161
|
],
|
|
152
162
|
...props,
|
|
153
163
|
children: loading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.ActivityIndicator, {
|
|
154
|
-
size:
|
|
164
|
+
size: scaledIconSize,
|
|
155
165
|
color: resolvedIconColor ?? resolvedButtonStyles.icon.color
|
|
156
166
|
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Icon.Icon, {
|
|
157
167
|
name,
|
|
@@ -161,7 +171,8 @@ const IconButton = (0, react.memo)(function IconButton({ name, variant = "primar
|
|
|
161
171
|
resolvedButtonStyles.icon,
|
|
162
172
|
{ lineHeight: iconCellHeight }
|
|
163
173
|
],
|
|
164
|
-
dangerouslySetColor: resolvedIconColor
|
|
174
|
+
dangerouslySetColor: resolvedIconColor,
|
|
175
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier
|
|
165
176
|
})
|
|
166
177
|
});
|
|
167
178
|
});
|
|
@@ -26,6 +26,12 @@ interface IconButtonProps extends Omit<PressableProps$1, 'children'> {
|
|
|
26
26
|
* @default false
|
|
27
27
|
*/
|
|
28
28
|
disableEffects?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Caps how far the icon and control grow with the OS text-size setting.
|
|
31
|
+
* Set null to remove the cap; override app-wide via UDSFontScalingProvider.
|
|
32
|
+
* @default 2
|
|
33
|
+
*/
|
|
34
|
+
maxFontSizeMultiplier?: number | null;
|
|
29
35
|
/** Ref to the underlying View */
|
|
30
36
|
ref?: Ref<View>;
|
|
31
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.d.cts","names":[],"sources":["../../src/components/IconButton.tsx"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"IconButton.d.cts","names":[],"sources":["../../src/components/IconButton.tsx"],"mappings":";;;;;;;;;;UAsDU,eAAA,SAAwB,IAAA,CAAK,gBAAA;;EAErC,IAAA,EAAM,QAAA;EAFE;EAIR,OAAA,GAAU,iBAAA;;EAEV,IAAA,GAAO,cAAA;EAJD;EAMN,WAAA,GAAc,WAAA;EAFP;EAIP,SAAA,GAAY,UAAA;EAAA;EAEZ,OAAA;EAaM;;;;EARN,cAAA;EAjBqC;;;;;EAuBrC,qBAAA;EAjBO;EAmBP,GAAA,GAAM,GAAA,CAAI,IAAA;AAAA;;;;;;;;;;;AAAI;;;;;;;;;;;;;;;;;;;;;;;cAwCV,UAAA,EAAU,OAAA,CAAA,oBAAA,CAAA,eAAA"}
|
|
@@ -26,6 +26,12 @@ interface IconButtonProps extends Omit<PressableProps$1, 'children'> {
|
|
|
26
26
|
* @default false
|
|
27
27
|
*/
|
|
28
28
|
disableEffects?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Caps how far the icon and control grow with the OS text-size setting.
|
|
31
|
+
* Set null to remove the cap; override app-wide via UDSFontScalingProvider.
|
|
32
|
+
* @default 2
|
|
33
|
+
*/
|
|
34
|
+
maxFontSizeMultiplier?: number | null;
|
|
29
35
|
/** Ref to the underlying View */
|
|
30
36
|
ref?: Ref<View>;
|
|
31
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.d.ts","names":[],"sources":["../../src/components/IconButton.tsx"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"IconButton.d.ts","names":[],"sources":["../../src/components/IconButton.tsx"],"mappings":";;;;;;;;;;UAsDU,eAAA,SAAwB,IAAA,CAAK,gBAAA;;EAErC,IAAA,EAAM,QAAA;EAFE;EAIR,OAAA,GAAU,iBAAA;;EAEV,IAAA,GAAO,cAAA;EAJD;EAMN,WAAA,GAAc,WAAA;EAFP;EAIP,SAAA,GAAY,UAAA;EAAA;EAEZ,OAAA;EAaM;;;;EARN,cAAA;EAjBqC;;;;;EAuBrC,qBAAA;EAjBO;EAmBP,GAAA,GAAM,GAAA,CAAI,IAAA;AAAA;;;;;;;;;;;AAAI;;;;;;;;;;;;;;;;;;;;;;;cAwCV,UAAA,EAAU,OAAA,CAAA,oBAAA,CAAA,eAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/*! © 2026 Yahoo, Inc. UDS Mobile v0.0.0-development */
|
|
2
2
|
import { SCALE_EFFECTS } from "../motion-tokens/dist/index.js";
|
|
3
3
|
import { BUTTON_SPRING_CONFIG } from "../motion.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useComponentFontScale } from "../fontScaling/useFontScale.js";
|
|
5
|
+
import { useMaxFontSizeMultiplier } from "../fontScaling/useMaxFontSizeMultiplier.js";
|
|
6
|
+
import { getIconButtonControlMetrics, getIconButtonIconSize } from "./Button/buttonTheme.js";
|
|
5
7
|
import { Icon } from "./Icon.js";
|
|
6
8
|
import { AnimatedPressable } from "./Pressable.js";
|
|
7
9
|
import { memo, useCallback, useMemo, useState } from "react";
|
|
@@ -54,12 +56,22 @@ function interpolateShadowAlpha(shadow, alpha) {
|
|
|
54
56
|
* @see {@link Button} for buttons with text labels
|
|
55
57
|
* @see {@link Icon} for non-interactive icons
|
|
56
58
|
*/
|
|
57
|
-
const IconButton = memo(function IconButton({ name, variant = "primary", size = "md", iconVariant = "outline", iconColor, loading, disabled, style, accessibilityLabel, accessibilityHint, disableEffects = false, onPressIn, onPressOut, ref, ...props }) {
|
|
59
|
+
const IconButton = memo(function IconButton({ name, variant = "primary", size = "md", iconVariant = "outline", iconColor, loading, disabled, style, accessibilityLabel, accessibilityHint, disableEffects = false, maxFontSizeMultiplier, onPressIn, onPressOut, ref, ...props }) {
|
|
58
60
|
const isDisabled = disabled || loading;
|
|
59
61
|
const shouldAnimate = !disableEffects && !isDisabled;
|
|
60
62
|
const shouldAnimateVariantColors = Platform.OS !== "web";
|
|
61
63
|
const { theme } = useUnistyles();
|
|
62
|
-
const
|
|
64
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
65
|
+
const [pressed, setPressed] = useState(false);
|
|
66
|
+
const resolvedIconButtonStyles = iconButtonStyles.useVariants({ size }) ?? iconButtonStyles;
|
|
67
|
+
const iconBaseSize = useMemo(() => getIconButtonIconSize(theme, size), [theme, size]);
|
|
68
|
+
const iconScaleFactor = useComponentFontScale(resolvedMaxFontSizeMultiplier, iconBaseSize);
|
|
69
|
+
const { minHeight, iconCellHeight, paddingVertical, hasExplicitHeight } = useMemo(() => getIconButtonControlMetrics(theme, size, iconScaleFactor), [
|
|
70
|
+
theme,
|
|
71
|
+
size,
|
|
72
|
+
iconScaleFactor
|
|
73
|
+
]);
|
|
74
|
+
const scaledIconSize = Math.round(iconBaseSize * iconScaleFactor);
|
|
63
75
|
const controlDimensions = hasExplicitHeight ? {
|
|
64
76
|
height: "auto",
|
|
65
77
|
width: "auto",
|
|
@@ -70,8 +82,6 @@ const IconButton = memo(function IconButton({ name, variant = "primary", size =
|
|
|
70
82
|
minHeight,
|
|
71
83
|
paddingVertical
|
|
72
84
|
};
|
|
73
|
-
const [pressed, setPressed] = useState(false);
|
|
74
|
-
const resolvedIconButtonStyles = iconButtonStyles.useVariants({ size }) ?? iconButtonStyles;
|
|
75
85
|
const resolvedButtonStyles = buttonStyles.useVariants({
|
|
76
86
|
variant,
|
|
77
87
|
disabled: isDisabled,
|
|
@@ -149,7 +159,7 @@ const IconButton = memo(function IconButton({ name, variant = "primary", size =
|
|
|
149
159
|
],
|
|
150
160
|
...props,
|
|
151
161
|
children: loading ? /* @__PURE__ */ jsx(ActivityIndicator, {
|
|
152
|
-
size:
|
|
162
|
+
size: scaledIconSize,
|
|
153
163
|
color: resolvedIconColor ?? resolvedButtonStyles.icon.color
|
|
154
164
|
}) : /* @__PURE__ */ jsx(Icon, {
|
|
155
165
|
name,
|
|
@@ -159,7 +169,8 @@ const IconButton = memo(function IconButton({ name, variant = "primary", size =
|
|
|
159
169
|
resolvedButtonStyles.icon,
|
|
160
170
|
{ lineHeight: iconCellHeight }
|
|
161
171
|
],
|
|
162
|
-
dangerouslySetColor: resolvedIconColor
|
|
172
|
+
dangerouslySetColor: resolvedIconColor,
|
|
173
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier
|
|
163
174
|
})
|
|
164
175
|
});
|
|
165
176
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.js","names":["foundationStyles"],"sources":["../../src/components/IconButton.tsx"],"sourcesContent":["import type { ButtonVariantFlat, IconButtonSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useCallback, useMemo, useState } from 'react';\nimport type { View } from 'react-native';\nimport { ActivityIndicator, Platform } from 'react-native';\nimport {\n Easing,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n withTiming,\n} from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- iconbutton control height from theme size layers\nimport { useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedTheme, useAnimatedVariantColor } from 'react-native-unistyles/reanimated';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { buttonStyles, iconButtonStyles, styles as foundationStyles } from '../../generated/styles';\nimport { BUTTON_SPRING_CONFIG, SCALE_EFFECTS } from '../motion';\nimport { getIconButtonControlMetrics } from './Button/buttonTheme';\nimport type { IconName } from './Icon';\nimport { Icon } from './Icon';\nimport type { PressableProps } from './Pressable';\nimport { AnimatedPressable } from './Pressable';\n\n/* -------------------------------------------------------------------------- */\n/* Animation Helpers */\n/* -------------------------------------------------------------------------- */\n\nfunction interpolateShadowAlpha(shadow: string | undefined, alpha: number): string {\n 'worklet';\n if (!shadow) {\n return '';\n }\n if (alpha >= 1) {\n return shadow;\n }\n if (alpha <= 0) {\n return '';\n }\n\n return shadow.replace(/rgba\\(([^,]+),\\s*([^,]+),\\s*([^,]+),\\s*([^)]+)\\)/g, (_, r, g, b, a) => {\n const newAlpha = parseFloat(a) * alpha;\n return `rgba(${r}, ${g}, ${b}, ${newAlpha.toFixed(3)})`;\n });\n}\n\n/* -------------------------------------------------------------------------- */\n/* IconButton Props */\n/* -------------------------------------------------------------------------- */\n\ninterface IconButtonProps extends Omit<PressableProps, 'children'> {\n /** Icon to render from the icons package */\n name: IconName;\n /** The visual style variant @default 'primary' */\n variant?: ButtonVariantFlat;\n /** The size of the button @default 'md' */\n size?: IconButtonSize;\n /** The icon style variant @default 'outline' */\n iconVariant?: IconVariant;\n /** Override the icon color token without changing the button variant tokens */\n iconColor?: StyleProps['color'];\n /** Shows a loading spinner and disables the button */\n loading?: boolean;\n /**\n * Disable motion effects (scale on press, icon animations)\n * @default false\n */\n disableEffects?: boolean;\n /** Ref to the underlying View */\n ref?: Ref<View>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* IconButton Component */\n/* -------------------------------------------------------------------------- */\n\n/**\n * **An icon button element that can be used to trigger an action**\n *\n * @description\n * An icon-only button for actions where space is limited. Features animated\n * scale effect on press and smooth color transitions matching the web UDS\n * IconButton behavior.\n *\n * @category Interactive\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { IconButton } from '@yahoo/uds-mobile/IconButton';\n *\n * <IconButton name=\"Add\" onPress={() => console.log('pressed')} />\n * <IconButton name=\"Close\" variant=\"secondary\" size=\"sm\" />\n * <IconButton name=\"Settings\" loading />\n * ```\n *\n * @usage\n * - Use for toolbar actions\n * - Use for closing modals/dialogs\n * - Always provide accessibilityLabel for screen readers\n *\n * @accessibility\n * - Sets `accessibilityRole=\"button\"` automatically\n * - Announces loading state to screen readers\n * - **Always** provide `accessibilityLabel` since there's no visible text\n *\n * @see {@link Button} for buttons with text labels\n * @see {@link Icon} for non-interactive icons\n */\nconst IconButton = memo(function IconButton({\n name,\n variant = 'primary',\n size = 'md',\n iconVariant = 'outline',\n iconColor,\n loading,\n disabled,\n style,\n accessibilityLabel,\n accessibilityHint,\n disableEffects = false,\n onPressIn,\n onPressOut,\n ref,\n ...props\n}: IconButtonProps) {\n const isDisabled = disabled || loading;\n const shouldAnimate = !disableEffects && !isDisabled;\n const shouldAnimateVariantColors = Platform.OS !== 'web';\n\n const { theme } = useUnistyles();\n const { minHeight, iconCellHeight, paddingVertical, hasExplicitHeight } = useMemo(\n () => getIconButtonControlMetrics(theme, size),\n [theme, size],\n );\n // Explicit token height (match-button-height) becomes a minimum with redistributed\n // padding so the safe icon cell fits and font scaling can grow the control.\n const controlDimensions = hasExplicitHeight\n ? ({\n height: 'auto',\n width: 'auto',\n minHeight,\n minWidth: minHeight,\n paddingVertical,\n } as const)\n : ({ minHeight, paddingVertical } as const);\n\n /* --------------------------------- State ---------------------------------- */\n const [pressed, setPressed] = useState(false);\n\n // On web, useVariants returns the resolved style object instead of mutating\n // the generated styles in place.\n const variantIconButtonStyles = iconButtonStyles.useVariants({ size }) as unknown as\n typeof iconButtonStyles | undefined;\n const resolvedIconButtonStyles = variantIconButtonStyles ?? iconButtonStyles;\n\n const variantButtonStyles = buttonStyles.useVariants({\n variant,\n disabled: isDisabled,\n pressed,\n }) as unknown as typeof buttonStyles | undefined;\n const resolvedButtonStyles = variantButtonStyles ?? buttonStyles;\n\n const variantFoundationStyles = foundationStyles.useVariants({ color: iconColor }) as unknown as\n typeof foundationStyles | undefined;\n const resolvedFoundationStyles = variantFoundationStyles ?? foundationStyles;\n\n const resolvedIconColor = iconColor\n ? (resolvedFoundationStyles.foundation.color as string | undefined)\n : undefined;\n\n // Animate colors using Unistyles' useAnimatedVariantColor\n const backgroundColor = useAnimatedVariantColor(resolvedButtonStyles.root, 'backgroundColor');\n const borderColor = useAnimatedVariantColor(resolvedButtonStyles.root, 'borderColor');\n\n // Get animated theme for boxShadow\n const animatedTheme = useAnimatedTheme();\n\n /* ------------------------------- Animation -------------------------------- */\n const scale = useSharedValue<number>(SCALE_EFFECTS.none);\n\n const handlePressIn = useCallback<NonNullable<PressableProps['onPressIn']>>(\n (event) => {\n setPressed(true);\n if (shouldAnimate) {\n scale.value = withSpring(SCALE_EFFECTS.down, BUTTON_SPRING_CONFIG);\n }\n onPressIn?.(event);\n },\n [shouldAnimate, scale, onPressIn],\n );\n\n const handlePressOut = useCallback<NonNullable<PressableProps['onPressOut']>>(\n (event) => {\n setPressed(false);\n if (shouldAnimate) {\n scale.value = withSpring(SCALE_EFFECTS.none, BUTTON_SPRING_CONFIG);\n }\n onPressOut?.(event);\n },\n [shouldAnimate, scale, onPressOut],\n );\n\n const a11yState = useMemo(() => ({ disabled: isDisabled, busy: loading }), [isDisabled, loading]);\n\n /* --------------------------------- Styles --------------------------------- */\n // Animate pressed state for shadow\n const pressProgress = useDerivedValue(\n () => withTiming(pressed ? 1 : 0, { duration: 220, easing: Easing.bezier(0, 0, 0.2, 1) }),\n [pressed],\n );\n\n // Animate using Unistyles' variant color system + boxShadow from theme\n const animatedRootStyle = useAnimatedStyle(() => {\n // Get boxShadow from theme using flattened path (no camelCase conversion needed!)\n const components = animatedTheme.value.components as unknown as Record<\n string,\n Record<string, unknown>\n >;\n const shadowPressed = components[`button/variant/${variant}/root/pressed`]?.boxShadow as\n string | undefined;\n\n return {\n transform: [{ scale: scale.value }],\n // On web, Unistyles already emits the resolved variant color class. The\n // animated variant color hook can resolve to the black fallback there.\n ...(shouldAnimateVariantColors && {\n backgroundColor: withTiming(backgroundColor.value, {\n duration: 220,\n easing: Easing.bezier(0, 0, 0.2, 1),\n }),\n borderColor: withTiming(borderColor.value, {\n duration: 220,\n easing: Easing.bezier(0, 0, 0.2, 1),\n }),\n }),\n // Only animate shadow if the theme defines one for this variant\n ...(shadowPressed && {\n boxShadow: interpolateShadowAlpha(shadowPressed, pressProgress.value),\n }),\n };\n });\n\n /* --------------------------------- Render --------------------------------- */\n return (\n <AnimatedPressable\n ref={ref}\n disabled={isDisabled}\n onPressIn={handlePressIn}\n onPressOut={handlePressOut}\n flexDirection=\"row\"\n alignItems=\"center\"\n justifyContent=\"center\"\n overflow=\"hidden\"\n accessibilityLabel={loading ? `${accessibilityLabel ?? ''}, loading` : accessibilityLabel}\n accessibilityHint={accessibilityHint}\n accessibilityRole=\"button\"\n accessibilityState={a11yState}\n style={[\n resolvedIconButtonStyles.root,\n resolvedButtonStyles.root,\n controlDimensions,\n resolvedFoundationStyles.foundation,\n animatedRootStyle,\n typeof style === 'function' ? style({ pressed }) : style,\n ]}\n {...props}\n >\n {loading ? (\n <ActivityIndicator\n size={resolvedIconButtonStyles.icon.fontSize}\n color={resolvedIconColor ?? resolvedButtonStyles.icon.color}\n />\n ) : (\n <Icon\n name={name}\n variant={iconVariant}\n style={[\n resolvedIconButtonStyles.icon,\n resolvedButtonStyles.icon,\n { lineHeight: iconCellHeight },\n ]}\n dangerouslySetColor={resolvedIconColor}\n />\n )}\n </AnimatedPressable>\n );\n});\n\nIconButton.displayName = 'IconButton';\n\nexport { IconButton, type IconButtonProps };\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"IconButton.js","names":["foundationStyles"],"sources":["../../src/components/IconButton.tsx"],"sourcesContent":["import type { ButtonVariantFlat, IconButtonSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { memo, useCallback, useMemo, useState } from 'react';\nimport type { View } from 'react-native';\nimport { ActivityIndicator, Platform } from 'react-native';\nimport {\n Easing,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n withTiming,\n} from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- iconbutton control height from theme size layers\nimport { useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedTheme, useAnimatedVariantColor } from 'react-native-unistyles/reanimated';\n\nimport type { StyleProps } from '../../generated/styles';\nimport { buttonStyles, iconButtonStyles, styles as foundationStyles } from '../../generated/styles';\nimport { useComponentFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { BUTTON_SPRING_CONFIG, SCALE_EFFECTS } from '../motion';\nimport { getIconButtonControlMetrics, getIconButtonIconSize } from './Button/buttonTheme';\nimport type { IconName } from './Icon';\nimport { Icon } from './Icon';\nimport type { PressableProps } from './Pressable';\nimport { AnimatedPressable } from './Pressable';\n\n/* -------------------------------------------------------------------------- */\n/* Animation Helpers */\n/* -------------------------------------------------------------------------- */\n\nfunction interpolateShadowAlpha(shadow: string | undefined, alpha: number): string {\n 'worklet';\n if (!shadow) {\n return '';\n }\n if (alpha >= 1) {\n return shadow;\n }\n if (alpha <= 0) {\n return '';\n }\n\n return shadow.replace(/rgba\\(([^,]+),\\s*([^,]+),\\s*([^,]+),\\s*([^)]+)\\)/g, (_, r, g, b, a) => {\n const newAlpha = parseFloat(a) * alpha;\n return `rgba(${r}, ${g}, ${b}, ${newAlpha.toFixed(3)})`;\n });\n}\n\n/* -------------------------------------------------------------------------- */\n/* IconButton Props */\n/* -------------------------------------------------------------------------- */\n\ninterface IconButtonProps extends Omit<PressableProps, 'children'> {\n /** Icon to render from the icons package */\n name: IconName;\n /** The visual style variant @default 'primary' */\n variant?: ButtonVariantFlat;\n /** The size of the button @default 'md' */\n size?: IconButtonSize;\n /** The icon style variant @default 'outline' */\n iconVariant?: IconVariant;\n /** Override the icon color token without changing the button variant tokens */\n iconColor?: StyleProps['color'];\n /** Shows a loading spinner and disables the button */\n loading?: boolean;\n /**\n * Disable motion effects (scale on press, icon animations)\n * @default false\n */\n disableEffects?: boolean;\n /**\n * Caps how far the icon and control grow with the OS text-size setting.\n * Set null to remove the cap; override app-wide via UDSFontScalingProvider.\n * @default 2\n */\n maxFontSizeMultiplier?: number | null;\n /** Ref to the underlying View */\n ref?: Ref<View>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* IconButton Component */\n/* -------------------------------------------------------------------------- */\n\n/**\n * **An icon button element that can be used to trigger an action**\n *\n * @description\n * An icon-only button for actions where space is limited. Features animated\n * scale effect on press and smooth color transitions matching the web UDS\n * IconButton behavior.\n *\n * @category Interactive\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { IconButton } from '@yahoo/uds-mobile/IconButton';\n *\n * <IconButton name=\"Add\" onPress={() => console.log('pressed')} />\n * <IconButton name=\"Close\" variant=\"secondary\" size=\"sm\" />\n * <IconButton name=\"Settings\" loading />\n * ```\n *\n * @usage\n * - Use for toolbar actions\n * - Use for closing modals/dialogs\n * - Always provide accessibilityLabel for screen readers\n *\n * @accessibility\n * - Sets `accessibilityRole=\"button\"` automatically\n * - Announces loading state to screen readers\n * - **Always** provide `accessibilityLabel` since there's no visible text\n *\n * @see {@link Button} for buttons with text labels\n * @see {@link Icon} for non-interactive icons\n */\nconst IconButton = memo(function IconButton({\n name,\n variant = 'primary',\n size = 'md',\n iconVariant = 'outline',\n iconColor,\n loading,\n disabled,\n style,\n accessibilityLabel,\n accessibilityHint,\n disableEffects = false,\n maxFontSizeMultiplier,\n onPressIn,\n onPressOut,\n ref,\n ...props\n}: IconButtonProps) {\n const isDisabled = disabled || loading;\n const shouldAnimate = !disableEffects && !isDisabled;\n const shouldAnimateVariantColors = Platform.OS !== 'web';\n\n const { theme } = useUnistyles();\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n\n /* --------------------------------- State ---------------------------------- */\n const [pressed, setPressed] = useState(false);\n\n // On web, useVariants returns the resolved style object instead of mutating\n // the generated styles in place.\n const variantIconButtonStyles = iconButtonStyles.useVariants({ size }) as unknown as\n typeof iconButtonStyles | undefined;\n const resolvedIconButtonStyles = variantIconButtonStyles ?? iconButtonStyles;\n\n const iconBaseSize = useMemo(() => getIconButtonIconSize(theme, size), [theme, size]);\n const iconScaleFactor = useComponentFontScale(resolvedMaxFontSizeMultiplier, iconBaseSize);\n const { minHeight, iconCellHeight, paddingVertical, hasExplicitHeight } = useMemo(\n () => getIconButtonControlMetrics(theme, size, iconScaleFactor),\n [theme, size, iconScaleFactor],\n );\n const scaledIconSize = Math.round(iconBaseSize * iconScaleFactor);\n // Explicit token height (match-button-height) becomes a minimum with redistributed\n // padding so the safe icon cell fits and font scaling can grow the control.\n const controlDimensions = hasExplicitHeight\n ? ({\n height: 'auto',\n width: 'auto',\n minHeight,\n minWidth: minHeight,\n paddingVertical,\n } as const)\n : ({ minHeight, paddingVertical } as const);\n\n const variantButtonStyles = buttonStyles.useVariants({\n variant,\n disabled: isDisabled,\n pressed,\n }) as unknown as typeof buttonStyles | undefined;\n const resolvedButtonStyles = variantButtonStyles ?? buttonStyles;\n\n const variantFoundationStyles = foundationStyles.useVariants({ color: iconColor }) as unknown as\n typeof foundationStyles | undefined;\n const resolvedFoundationStyles = variantFoundationStyles ?? foundationStyles;\n\n const resolvedIconColor = iconColor\n ? (resolvedFoundationStyles.foundation.color as string | undefined)\n : undefined;\n\n // Animate colors using Unistyles' useAnimatedVariantColor\n const backgroundColor = useAnimatedVariantColor(resolvedButtonStyles.root, 'backgroundColor');\n const borderColor = useAnimatedVariantColor(resolvedButtonStyles.root, 'borderColor');\n\n // Get animated theme for boxShadow\n const animatedTheme = useAnimatedTheme();\n\n /* ------------------------------- Animation -------------------------------- */\n const scale = useSharedValue<number>(SCALE_EFFECTS.none);\n\n const handlePressIn = useCallback<NonNullable<PressableProps['onPressIn']>>(\n (event) => {\n setPressed(true);\n if (shouldAnimate) {\n scale.value = withSpring(SCALE_EFFECTS.down, BUTTON_SPRING_CONFIG);\n }\n onPressIn?.(event);\n },\n [shouldAnimate, scale, onPressIn],\n );\n\n const handlePressOut = useCallback<NonNullable<PressableProps['onPressOut']>>(\n (event) => {\n setPressed(false);\n if (shouldAnimate) {\n scale.value = withSpring(SCALE_EFFECTS.none, BUTTON_SPRING_CONFIG);\n }\n onPressOut?.(event);\n },\n [shouldAnimate, scale, onPressOut],\n );\n\n const a11yState = useMemo(() => ({ disabled: isDisabled, busy: loading }), [isDisabled, loading]);\n\n /* --------------------------------- Styles --------------------------------- */\n // Animate pressed state for shadow\n const pressProgress = useDerivedValue(\n () => withTiming(pressed ? 1 : 0, { duration: 220, easing: Easing.bezier(0, 0, 0.2, 1) }),\n [pressed],\n );\n\n // Animate using Unistyles' variant color system + boxShadow from theme\n const animatedRootStyle = useAnimatedStyle(() => {\n // Get boxShadow from theme using flattened path (no camelCase conversion needed!)\n const components = animatedTheme.value.components as unknown as Record<\n string,\n Record<string, unknown>\n >;\n const shadowPressed = components[`button/variant/${variant}/root/pressed`]?.boxShadow as\n string | undefined;\n\n return {\n transform: [{ scale: scale.value }],\n // On web, Unistyles already emits the resolved variant color class. The\n // animated variant color hook can resolve to the black fallback there.\n ...(shouldAnimateVariantColors && {\n backgroundColor: withTiming(backgroundColor.value, {\n duration: 220,\n easing: Easing.bezier(0, 0, 0.2, 1),\n }),\n borderColor: withTiming(borderColor.value, {\n duration: 220,\n easing: Easing.bezier(0, 0, 0.2, 1),\n }),\n }),\n // Only animate shadow if the theme defines one for this variant\n ...(shadowPressed && {\n boxShadow: interpolateShadowAlpha(shadowPressed, pressProgress.value),\n }),\n };\n });\n\n /* --------------------------------- Render --------------------------------- */\n return (\n <AnimatedPressable\n ref={ref}\n disabled={isDisabled}\n onPressIn={handlePressIn}\n onPressOut={handlePressOut}\n flexDirection=\"row\"\n alignItems=\"center\"\n justifyContent=\"center\"\n overflow=\"hidden\"\n accessibilityLabel={loading ? `${accessibilityLabel ?? ''}, loading` : accessibilityLabel}\n accessibilityHint={accessibilityHint}\n accessibilityRole=\"button\"\n accessibilityState={a11yState}\n style={[\n resolvedIconButtonStyles.root,\n resolvedButtonStyles.root,\n controlDimensions,\n resolvedFoundationStyles.foundation,\n animatedRootStyle,\n typeof style === 'function' ? style({ pressed }) : style,\n ]}\n {...props}\n >\n {loading ? (\n <ActivityIndicator\n size={scaledIconSize}\n color={resolvedIconColor ?? resolvedButtonStyles.icon.color}\n />\n ) : (\n <Icon\n name={name}\n variant={iconVariant}\n style={[\n resolvedIconButtonStyles.icon,\n resolvedButtonStyles.icon,\n { lineHeight: iconCellHeight },\n ]}\n dangerouslySetColor={resolvedIconColor}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n />\n )}\n </AnimatedPressable>\n );\n});\n\nIconButton.displayName = 'IconButton';\n\nexport { IconButton, type IconButtonProps };\n"],"mappings":"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"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
4
4
|
const require_components_HStack = require("./HStack.cjs");
|
|
5
|
+
const require_fontScaling_useFontScale = require("../fontScaling/useFontScale.cjs");
|
|
6
|
+
const require_fontScaling_useMaxFontSizeMultiplier = require("../fontScaling/useMaxFontSizeMultiplier.cjs");
|
|
5
7
|
const require_components_IconSlot = require("./IconSlot.cjs");
|
|
6
8
|
const require_components_Text = require("./Text.cjs");
|
|
7
9
|
const require_components_InputHelpText = require("./InputHelpText.cjs");
|
|
@@ -47,8 +49,9 @@ let lodash_es = require("lodash-es");
|
|
|
47
49
|
* @see {@link Checkbox} for boolean selections
|
|
48
50
|
* @see {@link Radio} for single-select options
|
|
49
51
|
*/
|
|
50
|
-
const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, endIcon, helpText, helperTextIcon, hasError, disabled, readOnly, required, width = "100%", defaultValue, value: controlledValue, onChangeText, onFocus, onBlur, placeholder, placeholderTextColor, ref, ...textInputProps }) {
|
|
52
|
+
const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, endIcon, helpText, helperTextIcon, hasError, disabled, readOnly, required, width = "100%", defaultValue, value: controlledValue, onChangeText, onFocus, onBlur, placeholder, placeholderTextColor, maxFontSizeMultiplier, ref, ...textInputProps }) {
|
|
51
53
|
const uid = `uds-input-${(0, react.useId)()}`;
|
|
54
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
52
55
|
const [internalValue, setInternalValue] = (0, react.useState)(defaultValue ?? "");
|
|
53
56
|
const [isFocused, setIsFocused] = (0, react.useState)(false);
|
|
54
57
|
const isControlled = controlledValue !== void 0;
|
|
@@ -73,30 +76,47 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
73
76
|
readonly: readOnly,
|
|
74
77
|
invalid: hasError
|
|
75
78
|
});
|
|
79
|
+
const fontScaleFactor = require_fontScaling_useFontScale.useComponentFontScale(resolvedMaxFontSizeMultiplier, (typeof generated_styles.inputStyles.inputWrapperStatic.lineHeight === "number" ? generated_styles.inputStyles.inputWrapperStatic.lineHeight : void 0) ?? (typeof generated_styles.inputStyles.inputWrapperStatic.fontSize === "number" ? generated_styles.inputStyles.inputWrapperStatic.fontSize : void 0));
|
|
76
80
|
const computedPlaceholderColor = placeholderTextColor ?? generated_styles.inputStyles.inputPlaceholder.color;
|
|
77
81
|
const rootStyle = (0, react.useMemo)(() => [{
|
|
78
82
|
width,
|
|
79
83
|
opacity: disabled ? .5 : 1
|
|
80
84
|
}], [width, disabled]);
|
|
81
|
-
const inputWrapperStyle = (0, react.useMemo)(() =>
|
|
82
|
-
generated_styles.inputStyles.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const inputWrapperStyle = (0, react.useMemo)(() => {
|
|
86
|
+
const { gap, paddingVertical } = generated_styles.inputStyles.inputWrapperStatic;
|
|
87
|
+
const scaledMetrics = fontScaleFactor === 1 ? void 0 : {
|
|
88
|
+
...typeof gap === "number" && { gap: Math.round(gap * fontScaleFactor) },
|
|
89
|
+
...typeof paddingVertical === "number" && { paddingVertical: Math.round(paddingVertical * fontScaleFactor) }
|
|
90
|
+
};
|
|
91
|
+
return [
|
|
92
|
+
generated_styles.inputStyles.inputWrapper,
|
|
93
|
+
generated_styles.inputStyles.inputWrapperStatic,
|
|
94
|
+
generated_styles.inputStyles.inputWrapperDynamic,
|
|
95
|
+
scaledMetrics,
|
|
96
|
+
{
|
|
97
|
+
flexDirection: "row",
|
|
98
|
+
alignItems: "center"
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
}, [
|
|
102
|
+
fontScaleFactor,
|
|
90
103
|
generated_styles.inputStyles.inputWrapper,
|
|
91
104
|
generated_styles.inputStyles.inputWrapperStatic,
|
|
92
105
|
generated_styles.inputStyles.inputWrapperDynamic
|
|
93
106
|
]);
|
|
94
|
-
const textInputStyle = (0, react.useMemo)(() =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
const textInputStyle = (0, react.useMemo)(() => {
|
|
108
|
+
const inputHeight = generated_styles.inputStyles.input.height;
|
|
109
|
+
return [
|
|
110
|
+
generated_styles.inputStyles.input,
|
|
111
|
+
typeof inputHeight === "number" ? { height: Math.round(inputHeight * fontScaleFactor) } : void 0,
|
|
112
|
+
{
|
|
113
|
+
flex: 1,
|
|
114
|
+
includeFontPadding: false,
|
|
115
|
+
textAlignVertical: "center",
|
|
116
|
+
paddingVertical: 0
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
}, [fontScaleFactor, generated_styles.inputStyles.input]);
|
|
100
120
|
const labelContent = (0, react.useMemo)(() => {
|
|
101
121
|
if (!label) return null;
|
|
102
122
|
const content = (0, lodash_es.isFunction)(label) ? label() : label;
|
|
@@ -105,9 +125,13 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
105
125
|
alignItems: "flex-end",
|
|
106
126
|
spacingBottom: "2",
|
|
107
127
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Text.Text, {
|
|
128
|
+
variant: "inherit",
|
|
129
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
108
130
|
style: generated_styles.inputStyles.label,
|
|
109
131
|
children: content
|
|
110
132
|
}), required && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Text.Text, {
|
|
133
|
+
variant: "inherit",
|
|
134
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
111
135
|
style: generated_styles.inputStyles.labelRequired,
|
|
112
136
|
children: "*"
|
|
113
137
|
})]
|
|
@@ -115,6 +139,7 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
115
139
|
}, [
|
|
116
140
|
label,
|
|
117
141
|
required,
|
|
142
|
+
resolvedMaxFontSizeMultiplier,
|
|
118
143
|
generated_styles.inputStyles.label,
|
|
119
144
|
generated_styles.inputStyles.labelRequired
|
|
120
145
|
]);
|
|
@@ -123,17 +148,27 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
123
148
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
|
|
124
149
|
icon: startIcon,
|
|
125
150
|
variant: "outline",
|
|
151
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
126
152
|
style: generated_styles.inputStyles.startIcon
|
|
127
153
|
});
|
|
128
|
-
}, [
|
|
154
|
+
}, [
|
|
155
|
+
startIcon,
|
|
156
|
+
resolvedMaxFontSizeMultiplier,
|
|
157
|
+
generated_styles.inputStyles.startIcon
|
|
158
|
+
]);
|
|
129
159
|
const endIconContent = (0, react.useMemo)(() => {
|
|
130
160
|
if (!endIcon) return null;
|
|
131
161
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
|
|
132
162
|
icon: endIcon,
|
|
133
163
|
variant: "outline",
|
|
164
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
134
165
|
style: generated_styles.inputStyles.endIcon
|
|
135
166
|
});
|
|
136
|
-
}, [
|
|
167
|
+
}, [
|
|
168
|
+
endIcon,
|
|
169
|
+
resolvedMaxFontSizeMultiplier,
|
|
170
|
+
generated_styles.inputStyles.endIcon
|
|
171
|
+
]);
|
|
137
172
|
const helpTextContent = (0, react.useMemo)(() => {
|
|
138
173
|
if (!helpText) return null;
|
|
139
174
|
const content = (0, lodash_es.isFunction)(helpText) ? helpText() : helpText;
|
|
@@ -145,6 +180,7 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
145
180
|
readOnly,
|
|
146
181
|
hasError,
|
|
147
182
|
pressed: isFocused,
|
|
183
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
148
184
|
children: content
|
|
149
185
|
});
|
|
150
186
|
}, [
|
|
@@ -154,6 +190,7 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
154
190
|
helperTextIcon,
|
|
155
191
|
isFocused,
|
|
156
192
|
readOnly,
|
|
193
|
+
resolvedMaxFontSizeMultiplier,
|
|
157
194
|
size,
|
|
158
195
|
valueState
|
|
159
196
|
]);
|
|
@@ -178,6 +215,7 @@ const Input = (0, react.memo)(function Input({ label, size = "md", startIcon, en
|
|
|
178
215
|
placeholder,
|
|
179
216
|
placeholderTextColor: computedPlaceholderColor,
|
|
180
217
|
editable: !disabled && !readOnly,
|
|
218
|
+
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
181
219
|
style: textInputStyle,
|
|
182
220
|
accessibilityLabel: typeof label === "string" ? label : void 0,
|
|
183
221
|
accessibilityHint: typeof helpText === "string" ? helpText : void 0,
|
|
@@ -10,6 +10,11 @@ import { TextInput, TextInputProps } from "react-native";
|
|
|
10
10
|
interface InputProps extends Omit<UniversalInputProps<IconSlotType>, 'width'>, Omit<TextInputProps, 'style' | 'editable'>, Pick<SizeProps, 'width'> {
|
|
11
11
|
/** Ref to the underlying TextInput element */
|
|
12
12
|
ref?: Ref<TextInput>;
|
|
13
|
+
/**
|
|
14
|
+
* Caps the field text, labels, icons, and geometry at the control scale.
|
|
15
|
+
* Set null to remove the cap. @default 2
|
|
16
|
+
*/
|
|
17
|
+
maxFontSizeMultiplier?: number | null;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* **📦 An input that allows users to enter text and collect data.**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.cts","names":[],"sources":["../../src/components/Input.tsx"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Input.d.cts","names":[],"sources":["../../src/components/Input.tsx"],"mappings":";;;;;;;;;UAsBU,UAAA,SAEN,IAAA,CAAK,mBAAA,CAAoB,YAAA,aACzB,IAAA,CAAK,cAAA,yBACL,IAAA,CAAK,SAAA;;EAEP,GAAA,GAAM,GAAA,CAAI,SAAA;EALV;;;;EAUA,qBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;AAAqB;;;;;;;;;;;;;;;cA0CjB,KAAA,EAAK,OAAA,CAAA,oBAAA,CAAA,UAAA"}
|
|
@@ -10,6 +10,11 @@ import { TextInput, TextInputProps } from "react-native";
|
|
|
10
10
|
interface InputProps extends Omit<UniversalInputProps<IconSlotType>, 'width'>, Omit<TextInputProps, 'style' | 'editable'>, Pick<SizeProps, 'width'> {
|
|
11
11
|
/** Ref to the underlying TextInput element */
|
|
12
12
|
ref?: Ref<TextInput>;
|
|
13
|
+
/**
|
|
14
|
+
* Caps the field text, labels, icons, and geometry at the control scale.
|
|
15
|
+
* Set null to remove the cap. @default 2
|
|
16
|
+
*/
|
|
17
|
+
maxFontSizeMultiplier?: number | null;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* **📦 An input that allows users to enter text and collect data.**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","names":[],"sources":["../../src/components/Input.tsx"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Input.d.ts","names":[],"sources":["../../src/components/Input.tsx"],"mappings":";;;;;;;;;UAsBU,UAAA,SAEN,IAAA,CAAK,mBAAA,CAAoB,YAAA,aACzB,IAAA,CAAK,cAAA,yBACL,IAAA,CAAK,SAAA;;EAEP,GAAA,GAAM,GAAA,CAAI,SAAA;EALV;;;;EAUA,qBAAA;AAAA;;;;;;;;;;;;;;;;;;;;;AAAqB;;;;;;;;;;;;;;;cA0CjB,KAAA,EAAK,OAAA,CAAA,oBAAA,CAAA,UAAA"}
|