@yahoo/uds-mobile 2.24.0-beta.7 → 2.24.0-beta.8
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 +2 -1
- package/dist/components/Avatar/AvatarIcon.cjs +1 -1
- package/dist/components/Avatar/AvatarIcon.js +1 -1
- package/dist/components/Avatar/AvatarIcon.js.map +1 -1
- package/dist/components/Avatar/AvatarImage.cjs +1 -1
- package/dist/components/Avatar/AvatarImage.js +1 -1
- package/dist/components/Avatar/AvatarImage.js.map +1 -1
- package/dist/components/Avatar/AvatarText.cjs +1 -1
- package/dist/components/Avatar/AvatarText.js +1 -1
- package/dist/components/Avatar/AvatarText.js.map +1 -1
- package/dist/components/Avatar/useAvatarFontScale.d.cts +1 -1
- package/dist/components/Avatar/useAvatarFontScale.d.ts +1 -1
- package/dist/components/Avatar/useAvatarFontScale.js.map +1 -1
- package/dist/components/Button/buttonTheme.cjs +6 -1
- package/dist/components/Button/buttonTheme.d.cts +3 -1
- package/dist/components/Button/buttonTheme.d.cts.map +1 -1
- package/dist/components/Button/buttonTheme.d.ts +3 -1
- package/dist/components/Button/buttonTheme.d.ts.map +1 -1
- package/dist/components/Button/buttonTheme.js +6 -2
- package/dist/components/Button/buttonTheme.js.map +1 -1
- package/dist/components/Button.cjs +1 -1
- package/dist/components/Button.js +1 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Checkbox.cjs +11 -5
- package/dist/components/Checkbox.d.cts.map +1 -1
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/Checkbox.js +11 -5
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/Chip/ChipBase.cjs +1 -1
- package/dist/components/Chip/ChipBase.js +1 -1
- package/dist/components/Chip/ChipBase.js.map +1 -1
- package/dist/components/Icon.cjs +2 -2
- package/dist/components/Icon.js +2 -2
- 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 +1 -1
- package/dist/components/Input.js +1 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/InputHelpText.cjs +1 -1
- package/dist/components/InputHelpText.js +1 -1
- package/dist/components/InputHelpText.js.map +1 -1
- package/dist/components/Link.cjs +3 -1
- package/dist/components/Link.d.cts.map +1 -1
- package/dist/components/Link.d.ts.map +1 -1
- package/dist/components/Link.js +3 -1
- package/dist/components/Link.js.map +1 -1
- package/dist/components/Pagination/Pagination.cjs +1 -1
- package/dist/components/Pagination/Pagination.js +1 -1
- package/dist/components/Pagination/Pagination.js.map +1 -1
- package/dist/components/Pagination/paginationContext.d.cts +2 -2
- package/dist/components/Pagination/paginationContext.d.ts +2 -2
- package/dist/components/Pagination/paginationContext.js.map +1 -1
- package/dist/components/Radio/Radio.cjs +1 -1
- package/dist/components/Radio/Radio.js +1 -1
- package/dist/components/Radio/Radio.js.map +1 -1
- package/dist/components/Select/Select.cjs +1 -1
- package/dist/components/Select/Select.js +1 -1
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/SelectItem.cjs +3 -1
- 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 +3 -1
- package/dist/components/Select/SelectItem.js.map +1 -1
- package/dist/components/Select/SelectTrigger.cjs +3 -1
- 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 +3 -1
- package/dist/components/Select/SelectTrigger.js.map +1 -1
- package/dist/components/Select/types.d.cts +1 -1
- package/dist/components/Select/types.d.ts +1 -1
- package/dist/components/Switch.cjs +18 -3
- package/dist/components/Switch.d.cts.map +1 -1
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +18 -3
- package/dist/components/Switch.js.map +1 -1
- package/dist/components/Tabs/Tab.cjs +1 -1
- package/dist/components/Tabs/Tab.js +1 -1
- package/dist/components/Tabs/Tab.js.map +1 -1
- package/dist/components/Text.cjs +2 -1
- package/dist/components/Text.d.cts.map +1 -1
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js +2 -1
- package/dist/components/Text.js.map +1 -1
- package/dist/fontScaling/FontScalingContext.cjs +8 -2
- package/dist/fontScaling/FontScalingContext.d.cts +4 -2
- package/dist/fontScaling/FontScalingContext.d.cts.map +1 -1
- package/dist/fontScaling/FontScalingContext.d.ts +4 -2
- package/dist/fontScaling/FontScalingContext.d.ts.map +1 -1
- package/dist/fontScaling/FontScalingContext.js +9 -4
- package/dist/fontScaling/FontScalingContext.js.map +1 -1
- package/dist/fontScaling/types.d.cts +8 -7
- package/dist/fontScaling/types.d.cts.map +1 -1
- package/dist/fontScaling/types.d.ts +8 -7
- package/dist/fontScaling/types.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.cjs +4 -0
- package/dist/fontScaling/useFontScale.d.cts +1 -0
- package/dist/fontScaling/useFontScale.d.cts.map +1 -1
- package/dist/fontScaling/useFontScale.d.ts +1 -0
- package/dist/fontScaling/useFontScale.d.ts.map +1 -1
- package/dist/fontScaling/useFontScale.js +4 -0
- package/dist/fontScaling/useFontScale.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -508,7 +508,8 @@ matrix.
|
|
|
508
508
|
When upgrading from manual scaling workarounds, remove app-level geometry multiplication only after
|
|
509
509
|
comparing the screen with UDS defaults; applying both can make controls oversized. App-owned
|
|
510
510
|
composite controls should use `useFontScale(cap, baseSize)`. As a temporary rollback,
|
|
511
|
-
`fontScaling={{ enabled: false }}` restores
|
|
511
|
+
`fontScaling={{ enabled: false }}` restores the pre-feature behavior: native text scaling remains,
|
|
512
|
+
while UDS-added caps, ramps, multicolor-icon scaling, and control geometry growth are disabled.
|
|
512
513
|
|
|
513
514
|
## Fonts
|
|
514
515
|
|
|
@@ -12,7 +12,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
12
12
|
let generated_styles = require("../../../generated/styles");
|
|
13
13
|
//#region src/components/Avatar/AvatarIcon.tsx
|
|
14
14
|
const AvatarIcon = (0, react.memo)(function AvatarIcon({ size = "md", variant = require_components_Avatar_utils.DEFAULT_AVATAR_VARIANT, icon, customSize, maxFontSizeMultiplier, style, accessibilityLabel, alt, ref, ...viewProps }) {
|
|
15
|
-
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
15
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
16
16
|
generated_styles.avatarStyles.useVariants({
|
|
17
17
|
size,
|
|
18
18
|
icon: variant
|
|
@@ -10,7 +10,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
10
10
|
import { avatarStyles } from "../../../generated/styles";
|
|
11
11
|
//#region src/components/Avatar/AvatarIcon.tsx
|
|
12
12
|
const AvatarIcon = memo(function AvatarIcon({ size = "md", variant = DEFAULT_AVATAR_VARIANT, icon, customSize, maxFontSizeMultiplier, style, accessibilityLabel, alt, ref, ...viewProps }) {
|
|
13
|
-
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
13
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
14
14
|
avatarStyles.useVariants({
|
|
15
15
|
size,
|
|
16
16
|
icon: variant
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarIcon.js","names":[],"sources":["../../../src/components/Avatar/AvatarIcon.tsx"],"sourcesContent":["import { memo, useMemo } from 'react';\nimport { StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { IconSlot } from '../IconSlot';\nimport type { AvatarIconProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport {\n DEFAULT_AVATAR_SIZE,\n DEFAULT_AVATAR_VARIANT,\n getAvatarSizeStyle,\n getDefaultAvatarIcon,\n} from './utils';\n\nconst AvatarIcon = memo(function AvatarIcon({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n icon,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n alt,\n ref,\n ...viewProps\n}: AvatarIconProps) {\n const resolvedMaxFontSizeMultiplier
|
|
1
|
+
{"version":3,"file":"AvatarIcon.js","names":[],"sources":["../../../src/components/Avatar/AvatarIcon.tsx"],"sourcesContent":["import { memo, useMemo } from 'react';\nimport { StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { IconSlot } from '../IconSlot';\nimport type { AvatarIconProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport {\n DEFAULT_AVATAR_SIZE,\n DEFAULT_AVATAR_VARIANT,\n getAvatarSizeStyle,\n getDefaultAvatarIcon,\n} from './utils';\n\nconst AvatarIcon = memo(function AvatarIcon({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n icon,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n alt,\n ref,\n ...viewProps\n}: AvatarIconProps) {\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n avatarStyles.useVariants({ size, icon: variant });\n const fontScaleFactor = useAvatarFontScale(resolvedMaxFontSizeMultiplier);\n\n const rootStyle = useMemo(\n () => [\n avatarStyles.root,\n avatarStaticStyles.root,\n getAvatarSizeStyle(avatarStyles.root, customSize, fontScaleFactor),\n style,\n ],\n [avatarStyles.root, customSize, fontScaleFactor, style],\n );\n\n return (\n <Box\n ref={ref}\n accessibilityRole=\"image\"\n accessibilityLabel={accessibilityLabel ?? alt}\n {...viewProps}\n style={rootStyle}\n >\n <IconSlot\n icon={icon ?? getDefaultAvatarIcon(variant)}\n variant=\"fill\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={avatarStyles.icon}\n />\n </Box>\n );\n});\n\nAvatarIcon.displayName = 'AvatarIcon';\n\nconst avatarStaticStyles = StyleSheet.create({\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n overflow: 'hidden',\n },\n});\n\nexport { AvatarIcon };\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,aAAa,KAAK,SAAS,WAAW,EAC1C,OAAA,MACA,UAAU,wBACV,MACA,YACA,uBACA,OACA,oBACA,KACA,KACA,GAAG,aACe;CAClB,MAAM,gCAAgC,yBAAyB,WAAW,sBAAsB;CAChG,aAAa,YAAY;EAAE;EAAM,MAAM;EAAS,CAAC;CACjD,MAAM,kBAAkB,mBAAmB,8BAA8B;CAEzE,MAAM,YAAY,cACV;EACJ,aAAa;EACb,mBAAmB;EACnB,mBAAmB,aAAa,MAAM,YAAY,gBAAgB;EAClE;EACD,EACD;EAAC,aAAa;EAAM;EAAY;EAAiB;EAAM,CACxD;CAED,OACE,oBAAC,KAAD;EACO;EACL,mBAAkB;EAClB,oBAAoB,sBAAsB;EAC1C,GAAI;EACJ,OAAO;YAEP,oBAAC,UAAD;GACE,MAAM,QAAQ,qBAAqB,QAAQ;GAC3C,SAAQ;GACR,uBAAuB;GACvB,OAAO,aAAa;GACpB,CAAA;EACE,CAAA;EAER;AAEF,WAAW,cAAc;AAEzB,MAAM,qBAAqB,WAAW,OAAO,EAC3C,MAAM;CACJ,YAAY;CACZ,gBAAgB;CAChB,UAAU;CACX,EACF,CAAC"}
|
|
@@ -13,7 +13,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
13
13
|
let generated_styles = require("../../../generated/styles");
|
|
14
14
|
//#region src/components/Avatar/AvatarImage.tsx
|
|
15
15
|
const AvatarImage = (0, react.memo)(function AvatarImage({ size = "md", variant = require_components_Avatar_utils.DEFAULT_AVATAR_VARIANT, src, alt, fallback, icon, abbreviationStrategy, customSize, maxFontSizeMultiplier, style, accessibilityLabel, ref, ...viewProps }) {
|
|
16
|
-
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
16
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
17
17
|
const [imageError, setImageError] = (0, react.useState)(false);
|
|
18
18
|
const shouldShowImage = Boolean(src) && !imageError;
|
|
19
19
|
generated_styles.avatarStyles.useVariants({
|
|
@@ -11,7 +11,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
11
11
|
import { avatarStyles } from "../../../generated/styles";
|
|
12
12
|
//#region src/components/Avatar/AvatarImage.tsx
|
|
13
13
|
const AvatarImage = memo(function AvatarImage({ size = "md", variant = DEFAULT_AVATAR_VARIANT, src, alt, fallback, icon, abbreviationStrategy, customSize, maxFontSizeMultiplier, style, accessibilityLabel, ref, ...viewProps }) {
|
|
14
|
-
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
14
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
15
15
|
const [imageError, setImageError] = useState(false);
|
|
16
16
|
const shouldShowImage = Boolean(src) && !imageError;
|
|
17
17
|
avatarStyles.useVariants({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarImage.js","names":["RNImage"],"sources":["../../../src/components/Avatar/AvatarImage.tsx"],"sourcesContent":["import { memo, useMemo, useState } from 'react';\nimport { Image as RNImage, StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { AvatarIcon } from './AvatarIcon';\nimport { AvatarText } from './AvatarText';\nimport type { AvatarImageProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport { DEFAULT_AVATAR_SIZE, DEFAULT_AVATAR_VARIANT, getAvatarSizeStyle } from './utils';\n\nconst AvatarImage = memo(function AvatarImage({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n src,\n alt,\n fallback,\n icon,\n abbreviationStrategy,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n ref,\n ...viewProps\n}: AvatarImageProps) {\n const resolvedMaxFontSizeMultiplier
|
|
1
|
+
{"version":3,"file":"AvatarImage.js","names":["RNImage"],"sources":["../../../src/components/Avatar/AvatarImage.tsx"],"sourcesContent":["import { memo, useMemo, useState } from 'react';\nimport { Image as RNImage, StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { AvatarIcon } from './AvatarIcon';\nimport { AvatarText } from './AvatarText';\nimport type { AvatarImageProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport { DEFAULT_AVATAR_SIZE, DEFAULT_AVATAR_VARIANT, getAvatarSizeStyle } from './utils';\n\nconst AvatarImage = memo(function AvatarImage({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n src,\n alt,\n fallback,\n icon,\n abbreviationStrategy,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n ref,\n ...viewProps\n}: AvatarImageProps) {\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n const [imageError, setImageError] = useState(false);\n const shouldShowImage = Boolean(src) && !imageError;\n\n avatarStyles.useVariants({ size, image: variant });\n const fontScaleFactor = useAvatarFontScale(resolvedMaxFontSizeMultiplier);\n\n const rootStyle = useMemo(\n () => [\n avatarStyles.root,\n avatarStaticStyles.root,\n getAvatarSizeStyle(avatarStyles.root, customSize, fontScaleFactor),\n style,\n ],\n [avatarStyles.root, customSize, fontScaleFactor, style],\n );\n\n if (!shouldShowImage) {\n if (fallback || alt) {\n return (\n <AvatarText\n ref={ref}\n size={size}\n variant={variant}\n name={alt}\n initials={fallback}\n abbreviationStrategy={abbreviationStrategy}\n customSize={customSize}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n accessibilityLabel={accessibilityLabel ?? alt ?? fallback}\n style={style}\n {...viewProps}\n />\n );\n }\n\n return (\n <AvatarIcon\n ref={ref}\n size={size}\n variant={variant}\n icon={icon}\n customSize={customSize}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n accessibilityLabel={accessibilityLabel ?? alt}\n style={style}\n {...viewProps}\n />\n );\n }\n\n return (\n <Box\n ref={ref}\n accessibilityRole=\"image\"\n accessibilityLabel={accessibilityLabel ?? alt}\n {...viewProps}\n style={rootStyle}\n >\n <RNImage\n source={{ uri: src }}\n accessibilityLabel={alt}\n onError={() => setImageError(true)}\n style={avatarStaticStyles.image}\n />\n </Box>\n );\n});\n\nAvatarImage.displayName = 'AvatarImage';\n\nconst avatarStaticStyles = StyleSheet.create({\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n overflow: 'hidden',\n },\n image: {\n height: '100%',\n width: '100%',\n },\n});\n\nexport { AvatarImage };\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,cAAc,KAAK,SAAS,YAAY,EAC5C,OAAA,MACA,UAAU,wBACV,KACA,KACA,UACA,MACA,sBACA,YACA,uBACA,OACA,oBACA,KACA,GAAG,aACgB;CACnB,MAAM,gCAAgC,yBAAyB,WAAW,sBAAsB;CAChG,MAAM,CAAC,YAAY,iBAAiB,SAAS,MAAM;CACnD,MAAM,kBAAkB,QAAQ,IAAI,IAAI,CAAC;CAEzC,aAAa,YAAY;EAAE;EAAM,OAAO;EAAS,CAAC;CAClD,MAAM,kBAAkB,mBAAmB,8BAA8B;CAEzE,MAAM,YAAY,cACV;EACJ,aAAa;EACb,mBAAmB;EACnB,mBAAmB,aAAa,MAAM,YAAY,gBAAgB;EAClE;EACD,EACD;EAAC,aAAa;EAAM;EAAY;EAAiB;EAAM,CACxD;CAED,IAAI,CAAC,iBAAiB;EACpB,IAAI,YAAY,KACd,OACE,oBAAC,YAAD;GACO;GACC;GACG;GACT,MAAM;GACN,UAAU;GACY;GACV;GACZ,uBAAuB;GACvB,oBAAoB,sBAAsB,OAAO;GAC1C;GACP,GAAI;GACJ,CAAA;EAIN,OACE,oBAAC,YAAD;GACO;GACC;GACG;GACH;GACM;GACZ,uBAAuB;GACvB,oBAAoB,sBAAsB;GACnC;GACP,GAAI;GACJ,CAAA;;CAIN,OACE,oBAAC,KAAD;EACO;EACL,mBAAkB;EAClB,oBAAoB,sBAAsB;EAC1C,GAAI;EACJ,OAAO;YAEP,oBAACA,OAAD;GACE,QAAQ,EAAE,KAAK,KAAK;GACpB,oBAAoB;GACpB,eAAe,cAAc,KAAK;GAClC,OAAO,mBAAmB;GAC1B,CAAA;EACE,CAAA;EAER;AAEF,YAAY,cAAc;AAE1B,MAAM,qBAAqB,WAAW,OAAO;CAC3C,MAAM;EACJ,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACX;CACD,OAAO;EACL,QAAQ;EACR,OAAO;EACR;CACF,CAAC"}
|
|
@@ -12,7 +12,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
12
12
|
let generated_styles = require("../../../generated/styles");
|
|
13
13
|
//#region src/components/Avatar/AvatarText.tsx
|
|
14
14
|
const AvatarText = (0, react.memo)(function AvatarText({ size = "md", variant = require_components_Avatar_utils.DEFAULT_AVATAR_VARIANT, name, initials, abbreviationStrategy, customSize, maxFontSizeMultiplier, style, accessibilityLabel, ref, ...viewProps }) {
|
|
15
|
-
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
15
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
16
16
|
generated_styles.avatarStyles.useVariants({
|
|
17
17
|
size,
|
|
18
18
|
text: variant
|
|
@@ -10,7 +10,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
10
10
|
import { avatarStyles } from "../../../generated/styles";
|
|
11
11
|
//#region src/components/Avatar/AvatarText.tsx
|
|
12
12
|
const AvatarText = memo(function AvatarText({ size = "md", variant = DEFAULT_AVATAR_VARIANT, name, initials, abbreviationStrategy, customSize, maxFontSizeMultiplier, style, accessibilityLabel, ref, ...viewProps }) {
|
|
13
|
-
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
13
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
14
14
|
avatarStyles.useVariants({
|
|
15
15
|
size,
|
|
16
16
|
text: variant
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvatarText.js","names":["Text"],"sources":["../../../src/components/Avatar/AvatarText.tsx"],"sourcesContent":["import { memo, useMemo } from 'react';\nimport { StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { Text } from '../Text';\nimport type { AvatarTextProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport {\n DEFAULT_AVATAR_SIZE,\n DEFAULT_AVATAR_VARIANT,\n generateAvatarAbbreviation,\n getAvatarSizeStyle,\n} from './utils';\n\nconst AvatarText = memo(function AvatarText({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n name,\n initials,\n abbreviationStrategy,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n ref,\n ...viewProps\n}: AvatarTextProps) {\n const resolvedMaxFontSizeMultiplier
|
|
1
|
+
{"version":3,"file":"AvatarText.js","names":["Text"],"sources":["../../../src/components/Avatar/AvatarText.tsx"],"sourcesContent":["import { memo, useMemo } from 'react';\nimport { StyleSheet } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useMaxFontSizeMultiplier } from '../../fontScaling/useMaxFontSizeMultiplier';\nimport { Box } from '../Box';\nimport { Text } from '../Text';\nimport type { AvatarTextProps } from './types';\nimport { useAvatarFontScale } from './useAvatarFontScale';\nimport {\n DEFAULT_AVATAR_SIZE,\n DEFAULT_AVATAR_VARIANT,\n generateAvatarAbbreviation,\n getAvatarSizeStyle,\n} from './utils';\n\nconst AvatarText = memo(function AvatarText({\n size = DEFAULT_AVATAR_SIZE,\n variant = DEFAULT_AVATAR_VARIANT,\n name,\n initials,\n abbreviationStrategy,\n customSize,\n maxFontSizeMultiplier,\n style,\n accessibilityLabel,\n ref,\n ...viewProps\n}: AvatarTextProps) {\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n avatarStyles.useVariants({ size, text: variant });\n const fontScaleFactor = useAvatarFontScale(resolvedMaxFontSizeMultiplier);\n\n const rootStyle = useMemo(\n () => [\n avatarStyles.root,\n avatarStaticStyles.root,\n getAvatarSizeStyle(avatarStyles.root, customSize, fontScaleFactor),\n style,\n ],\n [avatarStyles.root, customSize, fontScaleFactor, style],\n );\n\n return (\n <Box\n ref={ref}\n accessibilityRole=\"image\"\n accessibilityLabel={accessibilityLabel ?? name ?? initials}\n {...viewProps}\n style={rootStyle}\n >\n <Text\n color=\"inherit\"\n variant=\"inherit\"\n numberOfLines={1}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={avatarStyles.text}\n >\n {initials || generateAvatarAbbreviation(name, abbreviationStrategy)}\n </Text>\n </Box>\n );\n});\n\nAvatarText.displayName = 'AvatarText';\n\nconst avatarStaticStyles = StyleSheet.create({\n root: {\n alignItems: 'center',\n justifyContent: 'center',\n overflow: 'hidden',\n },\n});\n\nexport { AvatarText };\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,aAAa,KAAK,SAAS,WAAW,EAC1C,OAAA,MACA,UAAU,wBACV,MACA,UACA,sBACA,YACA,uBACA,OACA,oBACA,KACA,GAAG,aACe;CAClB,MAAM,gCAAgC,yBAAyB,WAAW,sBAAsB;CAChG,aAAa,YAAY;EAAE;EAAM,MAAM;EAAS,CAAC;CACjD,MAAM,kBAAkB,mBAAmB,8BAA8B;CAEzE,MAAM,YAAY,cACV;EACJ,aAAa;EACb,mBAAmB;EACnB,mBAAmB,aAAa,MAAM,YAAY,gBAAgB;EAClE;EACD,EACD;EAAC,aAAa;EAAM;EAAY;EAAiB;EAAM,CACxD;CAED,OACE,oBAAC,KAAD;EACO;EACL,mBAAkB;EAClB,oBAAoB,sBAAsB,QAAQ;EAClD,GAAI;EACJ,OAAO;YAEP,oBAACA,QAAD;GACE,OAAM;GACN,SAAQ;GACR,eAAe;GACf,uBAAuB;GACvB,OAAO,aAAa;aAEnB,YAAY,2BAA2B,MAAM,qBAAqB;GAC9D,CAAA;EACH,CAAA;EAER;AAEF,WAAW,cAAc;AAEzB,MAAM,qBAAqB,WAAW,OAAO,EAC3C,MAAM;CACJ,YAAY;CACZ,gBAAgB;CAChB,UAAU;CACX,EACF,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/components/Avatar/useAvatarFontScale.d.ts
|
|
3
3
|
/** Keep every avatar content type on one size-aware scale that contains text and icons. */
|
|
4
|
-
declare function useAvatarFontScale(maxFontSizeMultiplier
|
|
4
|
+
declare function useAvatarFontScale(maxFontSizeMultiplier?: number): number;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { useAvatarFontScale };
|
|
7
7
|
//# sourceMappingURL=useAvatarFontScale.d.cts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/components/Avatar/useAvatarFontScale.d.ts
|
|
3
3
|
/** Keep every avatar content type on one size-aware scale that contains text and icons. */
|
|
4
|
-
declare function useAvatarFontScale(maxFontSizeMultiplier
|
|
4
|
+
declare function useAvatarFontScale(maxFontSizeMultiplier?: number): number;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { useAvatarFontScale };
|
|
7
7
|
//# sourceMappingURL=useAvatarFontScale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAvatarFontScale.js","names":[],"sources":["../../../src/components/Avatar/useAvatarFontScale.ts"],"sourcesContent":["import type { TextStyle } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useFontScale } from '../../fontScaling/useFontScale';\n\n/** Keep every avatar content type on one size-aware scale that contains text and icons. */\nfunction useAvatarFontScale(maxFontSizeMultiplier
|
|
1
|
+
{"version":3,"file":"useAvatarFontScale.js","names":[],"sources":["../../../src/components/Avatar/useAvatarFontScale.ts"],"sourcesContent":["import type { TextStyle } from 'react-native';\n\nimport { avatarStyles } from '../../../generated/styles';\nimport { useFontScale } from '../../fontScaling/useFontScale';\n\n/** Keep every avatar content type on one size-aware scale that contains text and icons. */\nfunction useAvatarFontScale(maxFontSizeMultiplier?: number): number {\n const textStyle = avatarStyles.text as TextStyle;\n const iconStyle = avatarStyles.icon as TextStyle;\n const textScaleFactor = useFontScale(\n maxFontSizeMultiplier,\n (typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : undefined) ??\n (typeof textStyle.fontSize === 'number' ? textStyle.fontSize : undefined),\n );\n const iconScaleFactor = useFontScale(\n maxFontSizeMultiplier,\n (typeof iconStyle.fontSize === 'number' ? iconStyle.fontSize : undefined) ??\n (typeof iconStyle.lineHeight === 'number' ? iconStyle.lineHeight : undefined),\n );\n\n return Math.max(textScaleFactor, iconScaleFactor);\n}\n\nexport { useAvatarFontScale };\n"],"mappings":";;;;;AAMA,SAAS,mBAAmB,uBAAwC;CAClE,MAAM,YAAY,aAAa;CAC/B,MAAM,YAAY,aAAa;CAC/B,MAAM,kBAAkB,aACtB,wBACC,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa,KAAA,OAChE,OAAO,UAAU,aAAa,WAAW,UAAU,WAAW,KAAA,GAClE;CACD,MAAM,kBAAkB,aACtB,wBACC,OAAO,UAAU,aAAa,WAAW,UAAU,WAAW,KAAA,OAC5D,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa,KAAA,GACtE;CAED,OAAO,KAAK,IAAI,iBAAiB,gBAAgB"}
|
|
@@ -22,6 +22,10 @@ function getLayerStyle(theme, path) {
|
|
|
22
22
|
function getIconSize(iconStyle) {
|
|
23
23
|
return (typeof iconStyle.fontSize === "number" ? iconStyle.fontSize : void 0) ?? (typeof iconStyle.lineHeight === "number" ? iconStyle.lineHeight : void 0) ?? 16;
|
|
24
24
|
}
|
|
25
|
+
/** Base icon size for an IconButton size layer. */
|
|
26
|
+
function getIconButtonIconSize(theme, size) {
|
|
27
|
+
return getIconSize(getLayerStyle(theme, iconButtonSizePath(size, "icon")));
|
|
28
|
+
}
|
|
25
29
|
function getVerticalPadding(rootStyle) {
|
|
26
30
|
return (typeof rootStyle.paddingVertical === "number" ? rootStyle.paddingVertical : void 0) ?? (typeof rootStyle.padding === "number" ? rootStyle.padding : void 0) ?? 0;
|
|
27
31
|
}
|
|
@@ -85,7 +89,7 @@ function getButtonControlMetrics(theme, size, fontScaleFactor = 1) {
|
|
|
85
89
|
function getIconButtonControlMetrics(theme, size, fontScaleFactor = 1) {
|
|
86
90
|
const rootStyle = getLayerStyle(theme, iconButtonSizePath(size, "root"));
|
|
87
91
|
const iconStyle = getLayerStyle(theme, iconButtonSizePath(size, "icon"));
|
|
88
|
-
const iconSize =
|
|
92
|
+
const iconSize = getIconButtonIconSize(theme, size);
|
|
89
93
|
const tokenLineHeight = typeof iconStyle.lineHeight === "number" ? iconStyle.lineHeight : iconSize;
|
|
90
94
|
const paddingVertical = getVerticalPadding(rootStyle);
|
|
91
95
|
const explicitHeight = typeof rootStyle.height === "number" ? rootStyle.height : void 0;
|
|
@@ -110,4 +114,5 @@ function getButtonTextStyle(textStyle, labelLineHeight) {
|
|
|
110
114
|
exports.getButtonControlMetrics = getButtonControlMetrics;
|
|
111
115
|
exports.getButtonTextStyle = getButtonTextStyle;
|
|
112
116
|
exports.getIconButtonControlMetrics = getIconButtonControlMetrics;
|
|
117
|
+
exports.getIconButtonIconSize = getIconButtonIconSize;
|
|
113
118
|
exports.getSafeIconCell = getSafeIconCell;
|
|
@@ -6,6 +6,8 @@ import { TextStyle } from "react-native";
|
|
|
6
6
|
type ButtonTheme = {
|
|
7
7
|
components: Record<string, any>;
|
|
8
8
|
};
|
|
9
|
+
/** Base icon size for an IconButton size layer. */
|
|
10
|
+
declare function getIconButtonIconSize(theme: ButtonTheme, size: IconButtonSize): number;
|
|
9
11
|
/** Safe line box for the icon font's em square plus any bbox overflow. */
|
|
10
12
|
declare function getSafeIconCell(fontSize: number): number;
|
|
11
13
|
/**
|
|
@@ -42,5 +44,5 @@ declare function getIconButtonControlMetrics(theme: ButtonTheme, size: IconButto
|
|
|
42
44
|
/** Apply the metric-safe line height after the token typography styles. */
|
|
43
45
|
declare function getButtonTextStyle(textStyle: TextStyle, labelLineHeight: number): TextStyle;
|
|
44
46
|
//#endregion
|
|
45
|
-
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getSafeIconCell };
|
|
47
|
+
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getIconButtonIconSize, getSafeIconCell };
|
|
46
48
|
//# sourceMappingURL=buttonTheme.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttonTheme.d.cts","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"mappings":";;;;;KAKK,WAAA;EAEH,UAAA,EAAY,MAAA;AAAA;;
|
|
1
|
+
{"version":3,"file":"buttonTheme.d.cts","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"mappings":";;;;;KAKK,WAAA;EAEH,UAAA,EAAY,MAAA;AAAA;;iBA6BL,qBAAA,CAAsB,KAAA,EAAO,WAAA,EAAa,IAAA,EAAM,cAAA;;iBAoCzC,eAAA,CAAgB,QAAA;AAjEZ;;;;;;;;;AAAA,iBA0FJ,uBAAA,CACd,KAAA,EAAO,WAAA,EACP,IAAA,EAAM,UAAA,EACN,eAAA;EAA4B,KAAA;EAAe,IAAA;EAAc,QAAA;AAAA;EAEzD,SAAA;EACA,eAAA;EACA,cAAA;EACA,eAAA;AAAA;;;;;;;iBA4Cc,2BAAA,CACd,KAAA,EAAO,WAAA,EACP,IAAA,EAAM,cAAA,EACN,eAAA;EAEA,SAAA;EACA,cAAA;EACA,eAAA;EACA,iBAAA;AAAA;;iBA4Bc,kBAAA,CAAmB,SAAA,EAAW,SAAA,EAAW,eAAA,WAA0B,SAAA"}
|
|
@@ -6,6 +6,8 @@ import { TextStyle } from "react-native";
|
|
|
6
6
|
type ButtonTheme = {
|
|
7
7
|
components: Record<string, any>;
|
|
8
8
|
};
|
|
9
|
+
/** Base icon size for an IconButton size layer. */
|
|
10
|
+
declare function getIconButtonIconSize(theme: ButtonTheme, size: IconButtonSize): number;
|
|
9
11
|
/** Safe line box for the icon font's em square plus any bbox overflow. */
|
|
10
12
|
declare function getSafeIconCell(fontSize: number): number;
|
|
11
13
|
/**
|
|
@@ -42,5 +44,5 @@ declare function getIconButtonControlMetrics(theme: ButtonTheme, size: IconButto
|
|
|
42
44
|
/** Apply the metric-safe line height after the token typography styles. */
|
|
43
45
|
declare function getButtonTextStyle(textStyle: TextStyle, labelLineHeight: number): TextStyle;
|
|
44
46
|
//#endregion
|
|
45
|
-
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getSafeIconCell };
|
|
47
|
+
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getIconButtonIconSize, getSafeIconCell };
|
|
46
48
|
//# sourceMappingURL=buttonTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttonTheme.d.ts","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"mappings":";;;;;KAKK,WAAA;EAEH,UAAA,EAAY,MAAA;AAAA;;
|
|
1
|
+
{"version":3,"file":"buttonTheme.d.ts","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"mappings":";;;;;KAKK,WAAA;EAEH,UAAA,EAAY,MAAA;AAAA;;iBA6BL,qBAAA,CAAsB,KAAA,EAAO,WAAA,EAAa,IAAA,EAAM,cAAA;;iBAoCzC,eAAA,CAAgB,QAAA;AAjEZ;;;;;;;;;AAAA,iBA0FJ,uBAAA,CACd,KAAA,EAAO,WAAA,EACP,IAAA,EAAM,UAAA,EACN,eAAA;EAA4B,KAAA;EAAe,IAAA;EAAc,QAAA;AAAA;EAEzD,SAAA;EACA,eAAA;EACA,cAAA;EACA,eAAA;AAAA;;;;;;;iBA4Cc,2BAAA,CACd,KAAA,EAAO,WAAA,EACP,IAAA,EAAM,cAAA,EACN,eAAA;EAEA,SAAA;EACA,cAAA;EACA,eAAA;EACA,iBAAA;AAAA;;iBA4Bc,kBAAA,CAAmB,SAAA,EAAW,SAAA,EAAW,eAAA,WAA0B,SAAA"}
|
|
@@ -21,6 +21,10 @@ function getLayerStyle(theme, path) {
|
|
|
21
21
|
function getIconSize(iconStyle) {
|
|
22
22
|
return (typeof iconStyle.fontSize === "number" ? iconStyle.fontSize : void 0) ?? (typeof iconStyle.lineHeight === "number" ? iconStyle.lineHeight : void 0) ?? 16;
|
|
23
23
|
}
|
|
24
|
+
/** Base icon size for an IconButton size layer. */
|
|
25
|
+
function getIconButtonIconSize(theme, size) {
|
|
26
|
+
return getIconSize(getLayerStyle(theme, iconButtonSizePath(size, "icon")));
|
|
27
|
+
}
|
|
24
28
|
function getVerticalPadding(rootStyle) {
|
|
25
29
|
return (typeof rootStyle.paddingVertical === "number" ? rootStyle.paddingVertical : void 0) ?? (typeof rootStyle.padding === "number" ? rootStyle.padding : void 0) ?? 0;
|
|
26
30
|
}
|
|
@@ -84,7 +88,7 @@ function getButtonControlMetrics(theme, size, fontScaleFactor = 1) {
|
|
|
84
88
|
function getIconButtonControlMetrics(theme, size, fontScaleFactor = 1) {
|
|
85
89
|
const rootStyle = getLayerStyle(theme, iconButtonSizePath(size, "root"));
|
|
86
90
|
const iconStyle = getLayerStyle(theme, iconButtonSizePath(size, "icon"));
|
|
87
|
-
const iconSize =
|
|
91
|
+
const iconSize = getIconButtonIconSize(theme, size);
|
|
88
92
|
const tokenLineHeight = typeof iconStyle.lineHeight === "number" ? iconStyle.lineHeight : iconSize;
|
|
89
93
|
const paddingVertical = getVerticalPadding(rootStyle);
|
|
90
94
|
const explicitHeight = typeof rootStyle.height === "number" ? rootStyle.height : void 0;
|
|
@@ -106,6 +110,6 @@ function getButtonTextStyle(textStyle, labelLineHeight) {
|
|
|
106
110
|
};
|
|
107
111
|
}
|
|
108
112
|
//#endregion
|
|
109
|
-
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getSafeIconCell };
|
|
113
|
+
export { getButtonControlMetrics, getButtonTextStyle, getIconButtonControlMetrics, getIconButtonIconSize, getSafeIconCell };
|
|
110
114
|
|
|
111
115
|
//# sourceMappingURL=buttonTheme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttonTheme.js","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"sourcesContent":["import type { ButtonSize, IconButtonSize } from '@yahoo/uds-types';\nimport type { TextStyle, ViewStyle } from 'react-native';\n\nimport { fontMetrics } from '../../../generated/fontMetrics';\n\ntype ButtonTheme = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n components: Record<string, any>;\n};\n\nconst SHARED_BUTTON_ICONBUTTON_SIZES = new Set<IconButtonSize>(['xs', 'sm', 'md', 'lg']);\n// Covers common native font boxes (roughly 1.2em) plus pixel-rounding headroom.\nconst UNKNOWN_FONT_LINE_HEIGHT_RATIO = 1.3;\n\nfunction buttonSizePath(size: ButtonSize, layer: 'root' | 'icon' | 'rootText'): string {\n return `button/size/${size}/${layer}/rest`;\n}\n\nfunction iconButtonSizePath(size: IconButtonSize, layer: 'root' | 'icon'): string {\n return `iconButton/size/${size}/${layer}/rest`;\n}\n\nfunction getLayerStyle(theme: ButtonTheme, path: string): ViewStyle | TextStyle {\n const style = theme.components[path];\n return style && typeof style === 'object' ? style : {};\n}\n\nfunction getIconSize(iconStyle: TextStyle): number {\n return (\n (typeof iconStyle.fontSize === 'number' ? iconStyle.fontSize : undefined) ??\n (typeof iconStyle.lineHeight === 'number' ? iconStyle.lineHeight : undefined) ??\n 16\n );\n}\n\nfunction getVerticalPadding(rootStyle: ViewStyle): number {\n return (\n (typeof rootStyle.paddingVertical === 'number' ? rootStyle.paddingVertical : undefined) ??\n (typeof rootStyle.padding === 'number' ? rootStyle.padding : undefined) ??\n 0\n );\n}\n\nfunction getMetricHeight(value: number, unitsPerEm: number, fontSize: number): number {\n return Math.ceil((Math.max(0, value) / unitsPerEm) * fontSize);\n}\n\nfunction getSafeLabelLineHeight(textStyle: TextStyle, fallbackFontSize: number): number {\n const fontSize = typeof textStyle.fontSize === 'number' ? textStyle.fontSize : fallbackFontSize;\n const tokenLineHeight =\n typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : fontSize;\n const metrics =\n typeof textStyle.fontFamily === 'string' ? fontMetrics[textStyle.fontFamily] : undefined;\n\n if (!metrics || metrics.unitsPerEm <= 0) {\n return Math.max(tokenLineHeight, Math.ceil(fontSize * UNKNOWN_FONT_LINE_HEIGHT_RATIO));\n }\n\n const metricsLineHeight =\n getMetricHeight(metrics.ascent, metrics.unitsPerEm, fontSize) +\n getMetricHeight(-metrics.descent, metrics.unitsPerEm, fontSize) +\n getMetricHeight(metrics.lineGap, metrics.unitsPerEm, fontSize);\n\n return Math.max(tokenLineHeight, metricsLineHeight);\n}\n\n/** Safe line box for the icon font's em square plus any bbox overflow. */\nexport function getSafeIconCell(fontSize: number): number {\n const metrics = fontMetrics['uds-icons'];\n if (!metrics || metrics.unitsPerEm <= 0) {\n return Math.ceil(fontSize * UNKNOWN_FONT_LINE_HEIGHT_RATIO);\n }\n\n const overflowAboveEm = Math.max(0, metrics.bbox.maxY - metrics.unitsPerEm);\n const overflowBelowEm = Math.max(0, -metrics.bbox.minY);\n\n return (\n Math.ceil(fontSize) +\n getMetricHeight(overflowAboveEm, metrics.unitsPerEm, fontSize) +\n getMetricHeight(overflowBelowEm, metrics.unitsPerEm, fontSize)\n );\n}\n\n/**\n * Safe native content metrics while retaining the token-derived target control height.\n *\n * `fontScaleFactor` pre-scales container metrics only. A single number keeps\n * the legacy linear behavior; distinct label/icon factors let Android 14+\n * geometry follow its size-dependent nonlinear font curve. The returned\n * `labelLineHeight`/`iconCellHeight` stay unscaled because native Text applies\n * the same cap.\n */\nexport function getButtonControlMetrics(\n theme: ButtonTheme,\n size: ButtonSize,\n fontScaleFactor: number | { label: number; icon: number; iconCell?: number } = 1,\n): {\n minHeight: number;\n labelLineHeight: number;\n iconCellHeight: number;\n paddingVertical: number;\n} {\n const rootStyle = getLayerStyle(theme, buttonSizePath(size, 'root')) as ViewStyle;\n const iconStyle = getLayerStyle(theme, buttonSizePath(size, 'icon')) as TextStyle;\n const textStyle = getLayerStyle(theme, buttonSizePath(size, 'rootText')) as TextStyle;\n const paddingVertical = getVerticalPadding(rootStyle);\n const iconSize = getIconSize(iconStyle);\n const fontSize = typeof textStyle.fontSize === 'number' ? textStyle.fontSize : iconSize;\n const tokenLineHeight =\n typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : fontSize;\n const labelScaleFactor =\n typeof fontScaleFactor === 'number' ? fontScaleFactor : fontScaleFactor.label;\n const iconScaleFactor =\n typeof fontScaleFactor === 'number' ? fontScaleFactor : fontScaleFactor.icon;\n const iconCellScaleFactor =\n typeof fontScaleFactor === 'number'\n ? fontScaleFactor\n : (fontScaleFactor.iconCell ?? fontScaleFactor.icon);\n const targetContentHeight = Math.max(\n iconSize * iconScaleFactor,\n tokenLineHeight * labelScaleFactor,\n );\n const minHeight = Math.ceil(paddingVertical * 2 + targetContentHeight);\n const labelLineHeight = getSafeLabelLineHeight(textStyle, iconSize);\n const iconCellHeight = getSafeIconCell(iconSize);\n const safeContentHeight = Math.max(\n labelLineHeight * labelScaleFactor,\n iconCellHeight * iconCellScaleFactor,\n );\n\n return {\n minHeight,\n labelLineHeight,\n iconCellHeight,\n paddingVertical: Math.max(0, (minHeight - safeContentHeight) / 2),\n };\n}\n\n/**\n * Safe icon cell within the token-derived control size; explicit token height (match-button-height opt-in) wins as the target.\n *\n * `fontScaleFactor` behaves as in {@link getButtonControlMetrics}; an explicit\n * token height stays fixed, with padding absorbing the scaled content.\n */\nexport function getIconButtonControlMetrics(\n theme: ButtonTheme,\n size: IconButtonSize,\n fontScaleFactor = 1,\n): {\n minHeight: number;\n iconCellHeight: number;\n paddingVertical: number;\n hasExplicitHeight: boolean;\n} {\n const rootStyle = getLayerStyle(theme, iconButtonSizePath(size, 'root')) as ViewStyle;\n const iconStyle = getLayerStyle(theme, iconButtonSizePath(size, 'icon')) as TextStyle;\n const iconSize = getIconSize(iconStyle);\n const tokenLineHeight =\n typeof iconStyle.lineHeight === 'number' ? iconStyle.lineHeight : iconSize;\n const paddingVertical = getVerticalPadding(rootStyle);\n const explicitHeight = typeof rootStyle.height === 'number' ? rootStyle.height : undefined;\n const hasExplicitHeight =\n SHARED_BUTTON_ICONBUTTON_SIZES.has(size) && explicitHeight !== undefined;\n const minHeight = hasExplicitHeight\n ? (explicitHeight as number)\n : Math.ceil(paddingVertical * 2 + Math.max(iconSize, tokenLineHeight) * fontScaleFactor);\n const iconCellHeight = getSafeIconCell(iconSize);\n\n return {\n minHeight,\n iconCellHeight,\n paddingVertical: Math.max(\n 0,\n (minHeight - Math.max(iconSize, iconCellHeight) * fontScaleFactor) / 2,\n ),\n hasExplicitHeight,\n };\n}\n\n/** Apply the metric-safe line height after the token typography styles. */\nexport function getButtonTextStyle(textStyle: TextStyle, labelLineHeight: number): TextStyle {\n return {\n ...textStyle,\n lineHeight: labelLineHeight,\n };\n}\n"],"mappings":";;;AAUA,MAAM,iCAAiC,IAAI,IAAoB;CAAC;CAAM;CAAM;CAAM;CAAK,CAAC;AAExF,MAAM,iCAAiC;AAEvC,SAAS,eAAe,MAAkB,OAA6C;CACrF,OAAO,eAAe,KAAK,GAAG,MAAM;;AAGtC,SAAS,mBAAmB,MAAsB,OAAgC;CAChF,OAAO,mBAAmB,KAAK,GAAG,MAAM;;AAG1C,SAAS,cAAc,OAAoB,MAAqC;CAC9E,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,EAAE;;AAGxD,SAAS,YAAY,WAA8B;CACjD,QACG,OAAO,UAAU,aAAa,WAAW,UAAU,WAAW,KAAA,OAC9D,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa,KAAA,MACnE;;AAIJ,SAAS,mBAAmB,WAA8B;CACxD,QACG,OAAO,UAAU,oBAAoB,WAAW,UAAU,kBAAkB,KAAA,OAC5E,OAAO,UAAU,YAAY,WAAW,UAAU,UAAU,KAAA,MAC7D;;AAIJ,SAAS,gBAAgB,OAAe,YAAoB,UAA0B;CACpF,OAAO,KAAK,KAAM,KAAK,IAAI,GAAG,MAAM,GAAG,aAAc,SAAS;;AAGhE,SAAS,uBAAuB,WAAsB,kBAAkC;CACtF,MAAM,WAAW,OAAO,UAAU,aAAa,WAAW,UAAU,WAAW;CAC/E,MAAM,kBACJ,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa;CACpE,MAAM,UACJ,OAAO,UAAU,eAAe,WAAW,YAAY,UAAU,cAAc,KAAA;CAEjF,IAAI,CAAC,WAAW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gB,YAAY,gBAAgB;CACnD,MAAM,sBAAsB,KAAK,IAC/B,WAAW,iBACX,kBAAkB,iBACnB;CACD,MAAM,YAAY,KAAK,KAAK,kBAAkB,IAAI,oBAAoB;CACtE,MAAM,kBAAkB,uBAAuB,WAAW,SAAS;CACnE,MAAM,iBAAiB,gBAAgB,SAAS;CAChD,MAAM,oBAAoB,KAAK,IAC7B,kBAAkB,kBAClB,iBAAiB,oBAClB;CAED,OAAO;EACL;EACA;EACA;EACA,iBAAiB,KAAK,IAAI,IAAI,YAAY,qBAAqB,EAAE;EAClE;;;;;;;;AASH,SAAgB,4BACd,OACA,MACA,kBAAkB,GAMlB;CACA,MAAM,YAAY,cAAc,OAAO,mBAAmB,MAAM,OAAO,CAAC;CACxE,MAAM,YAAY,cAAc,OAAO,mBAAmB,MAAM,OAAO,CAAC;CACxE,MAAM,WAAW,YAAY,UAAU;CACvC,MAAM,kBACJ,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa;CACpE,MAAM,kBAAkB,mBAAmB,UAAU;CACrD,MAAM,iBAAiB,OAAO,UAAU,WAAW,WAAW,UAAU,SAAS,KAAA;CACjF,MAAM,oBACJ,+BAA+B,IAAI,KAAK,IAAI,mBAAmB,KAAA;CACjE,MAAM,YAAY,oBACb,iBACD,KAAK,KAAK,kBAAkB,IAAI,KAAK,IAAI,UAAU,gBAAgB,GAAG,gBAAgB;CAC1F,MAAM,iBAAiB,gBAAgB,SAAS;CAEhD,OAAO;EACL;EACA;EACA,iBAAiB,KAAK,IACpB,IACC,YAAY,KAAK,IAAI,UAAU,eAAe,GAAG,mBAAmB,EACtE;EACD;EACD;;;AAIH,SAAgB,mBAAmB,WAAsB,iBAAoC;CAC3F,OAAO;EACL,GAAG;EACH,YAAY;EACb"}
|
|
1
|
+
{"version":3,"file":"buttonTheme.js","names":[],"sources":["../../../src/components/Button/buttonTheme.ts"],"sourcesContent":["import type { ButtonSize, IconButtonSize } from '@yahoo/uds-types';\nimport type { TextStyle, ViewStyle } from 'react-native';\n\nimport { fontMetrics } from '../../../generated/fontMetrics';\n\ntype ButtonTheme = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n components: Record<string, any>;\n};\n\nconst SHARED_BUTTON_ICONBUTTON_SIZES = new Set<IconButtonSize>(['xs', 'sm', 'md', 'lg']);\n// Covers common native font boxes (roughly 1.2em) plus pixel-rounding headroom.\nconst UNKNOWN_FONT_LINE_HEIGHT_RATIO = 1.3;\n\nfunction buttonSizePath(size: ButtonSize, layer: 'root' | 'icon' | 'rootText'): string {\n return `button/size/${size}/${layer}/rest`;\n}\n\nfunction iconButtonSizePath(size: IconButtonSize, layer: 'root' | 'icon'): string {\n return `iconButton/size/${size}/${layer}/rest`;\n}\n\nfunction getLayerStyle(theme: ButtonTheme, path: string): ViewStyle | TextStyle {\n const style = theme.components[path];\n return style && typeof style === 'object' ? style : {};\n}\n\nfunction getIconSize(iconStyle: TextStyle): number {\n return (\n (typeof iconStyle.fontSize === 'number' ? iconStyle.fontSize : undefined) ??\n (typeof iconStyle.lineHeight === 'number' ? iconStyle.lineHeight : undefined) ??\n 16\n );\n}\n\n/** Base icon size for an IconButton size layer. */\nfunction getIconButtonIconSize(theme: ButtonTheme, size: IconButtonSize): number {\n return getIconSize(getLayerStyle(theme, iconButtonSizePath(size, 'icon')) as TextStyle);\n}\n\nfunction getVerticalPadding(rootStyle: ViewStyle): number {\n return (\n (typeof rootStyle.paddingVertical === 'number' ? rootStyle.paddingVertical : undefined) ??\n (typeof rootStyle.padding === 'number' ? rootStyle.padding : undefined) ??\n 0\n );\n}\n\nfunction getMetricHeight(value: number, unitsPerEm: number, fontSize: number): number {\n return Math.ceil((Math.max(0, value) / unitsPerEm) * fontSize);\n}\n\nfunction getSafeLabelLineHeight(textStyle: TextStyle, fallbackFontSize: number): number {\n const fontSize = typeof textStyle.fontSize === 'number' ? textStyle.fontSize : fallbackFontSize;\n const tokenLineHeight =\n typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : fontSize;\n const metrics =\n typeof textStyle.fontFamily === 'string' ? fontMetrics[textStyle.fontFamily] : undefined;\n\n if (!metrics || metrics.unitsPerEm <= 0) {\n return Math.max(tokenLineHeight, Math.ceil(fontSize * UNKNOWN_FONT_LINE_HEIGHT_RATIO));\n }\n\n const metricsLineHeight =\n getMetricHeight(metrics.ascent, metrics.unitsPerEm, fontSize) +\n getMetricHeight(-metrics.descent, metrics.unitsPerEm, fontSize) +\n getMetricHeight(metrics.lineGap, metrics.unitsPerEm, fontSize);\n\n return Math.max(tokenLineHeight, metricsLineHeight);\n}\n\n/** Safe line box for the icon font's em square plus any bbox overflow. */\nexport function getSafeIconCell(fontSize: number): number {\n const metrics = fontMetrics['uds-icons'];\n if (!metrics || metrics.unitsPerEm <= 0) {\n return Math.ceil(fontSize * UNKNOWN_FONT_LINE_HEIGHT_RATIO);\n }\n\n const overflowAboveEm = Math.max(0, metrics.bbox.maxY - metrics.unitsPerEm);\n const overflowBelowEm = Math.max(0, -metrics.bbox.minY);\n\n return (\n Math.ceil(fontSize) +\n getMetricHeight(overflowAboveEm, metrics.unitsPerEm, fontSize) +\n getMetricHeight(overflowBelowEm, metrics.unitsPerEm, fontSize)\n );\n}\n\n/**\n * Safe native content metrics while retaining the token-derived target control height.\n *\n * `fontScaleFactor` pre-scales container metrics only. A single number keeps\n * the legacy linear behavior; distinct label/icon factors let Android 14+\n * geometry follow its size-dependent nonlinear font curve. The returned\n * `labelLineHeight`/`iconCellHeight` stay unscaled because native Text applies\n * the same cap.\n */\nexport function getButtonControlMetrics(\n theme: ButtonTheme,\n size: ButtonSize,\n fontScaleFactor: number | { label: number; icon: number; iconCell?: number } = 1,\n): {\n minHeight: number;\n labelLineHeight: number;\n iconCellHeight: number;\n paddingVertical: number;\n} {\n const rootStyle = getLayerStyle(theme, buttonSizePath(size, 'root')) as ViewStyle;\n const iconStyle = getLayerStyle(theme, buttonSizePath(size, 'icon')) as TextStyle;\n const textStyle = getLayerStyle(theme, buttonSizePath(size, 'rootText')) as TextStyle;\n const paddingVertical = getVerticalPadding(rootStyle);\n const iconSize = getIconSize(iconStyle);\n const fontSize = typeof textStyle.fontSize === 'number' ? textStyle.fontSize : iconSize;\n const tokenLineHeight =\n typeof textStyle.lineHeight === 'number' ? textStyle.lineHeight : fontSize;\n const labelScaleFactor =\n typeof fontScaleFactor === 'number' ? fontScaleFactor : fontScaleFactor.label;\n const iconScaleFactor =\n typeof fontScaleFactor === 'number' ? fontScaleFactor : fontScaleFactor.icon;\n const iconCellScaleFactor =\n typeof fontScaleFactor === 'number'\n ? fontScaleFactor\n : (fontScaleFactor.iconCell ?? fontScaleFactor.icon);\n const targetContentHeight = Math.max(\n iconSize * iconScaleFactor,\n tokenLineHeight * labelScaleFactor,\n );\n const minHeight = Math.ceil(paddingVertical * 2 + targetContentHeight);\n const labelLineHeight = getSafeLabelLineHeight(textStyle, iconSize);\n const iconCellHeight = getSafeIconCell(iconSize);\n const safeContentHeight = Math.max(\n labelLineHeight * labelScaleFactor,\n iconCellHeight * iconCellScaleFactor,\n );\n\n return {\n minHeight,\n labelLineHeight,\n iconCellHeight,\n paddingVertical: Math.max(0, (minHeight - safeContentHeight) / 2),\n };\n}\n\n/**\n * Safe icon cell within the token-derived control size; explicit token height (match-button-height opt-in) wins as the target.\n *\n * `fontScaleFactor` behaves as in {@link getButtonControlMetrics}; an explicit\n * token height stays fixed, with padding absorbing the scaled content.\n */\nexport function getIconButtonControlMetrics(\n theme: ButtonTheme,\n size: IconButtonSize,\n fontScaleFactor = 1,\n): {\n minHeight: number;\n iconCellHeight: number;\n paddingVertical: number;\n hasExplicitHeight: boolean;\n} {\n const rootStyle = getLayerStyle(theme, iconButtonSizePath(size, 'root')) as ViewStyle;\n const iconStyle = getLayerStyle(theme, iconButtonSizePath(size, 'icon')) as TextStyle;\n const iconSize = getIconButtonIconSize(theme, size);\n const tokenLineHeight =\n typeof iconStyle.lineHeight === 'number' ? iconStyle.lineHeight : iconSize;\n const paddingVertical = getVerticalPadding(rootStyle);\n const explicitHeight = typeof rootStyle.height === 'number' ? rootStyle.height : undefined;\n const hasExplicitHeight =\n SHARED_BUTTON_ICONBUTTON_SIZES.has(size) && explicitHeight !== undefined;\n const minHeight = hasExplicitHeight\n ? (explicitHeight as number)\n : Math.ceil(paddingVertical * 2 + Math.max(iconSize, tokenLineHeight) * fontScaleFactor);\n const iconCellHeight = getSafeIconCell(iconSize);\n\n return {\n minHeight,\n iconCellHeight,\n paddingVertical: Math.max(\n 0,\n (minHeight - Math.max(iconSize, iconCellHeight) * fontScaleFactor) / 2,\n ),\n hasExplicitHeight,\n };\n}\n\n/** Apply the metric-safe line height after the token typography styles. */\nexport function getButtonTextStyle(textStyle: TextStyle, labelLineHeight: number): TextStyle {\n return {\n ...textStyle,\n lineHeight: labelLineHeight,\n };\n}\n\nexport { getIconButtonIconSize };\n"],"mappings":";;;AAUA,MAAM,iCAAiC,IAAI,IAAoB;CAAC;CAAM;CAAM;CAAM;CAAK,CAAC;AAExF,MAAM,iCAAiC;AAEvC,SAAS,eAAe,MAAkB,OAA6C;CACrF,OAAO,eAAe,KAAK,GAAG,MAAM;;AAGtC,SAAS,mBAAmB,MAAsB,OAAgC;CAChF,OAAO,mBAAmB,KAAK,GAAG,MAAM;;AAG1C,SAAS,cAAc,OAAoB,MAAqC;CAC9E,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,SAAS,OAAO,UAAU,WAAW,QAAQ,EAAE;;AAGxD,SAAS,YAAY,WAA8B;CACjD,QACG,OAAO,UAAU,aAAa,WAAW,UAAU,WAAW,KAAA,OAC9D,OAAO,UAAU,eAAe,WAAW,UAAU,aAAa,KAAA,MACnE;;;AAKJ,SAAS,sBAAsB,OAAoB,MAA8B;CAC/E,OAAO,YAAY,cAAc,OAAO,mBAAmB,MAAM,OAAO,CAAC,CAAc;;AAGzF,SAAS,mBAAmB,WAA8B;CACxD,QACG,OAAO,UAAU,oBAAoB,WAAW,UAAU,kBAAkB,KAAA,OAC5E,OAAO,UAAU,YAAY,W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GAAG,gBAAgB;CAC1F,MAAM,iBAAiB,gBAAgB,SAAS;CAEhD,OAAO;EACL;EACA;EACA,iBAAiB,KAAK,IACpB,IACC,YAAY,KAAK,IAAI,UAAU,eAAe,GAAG,mBAAmB,EACtE;EACD;EACD;;;AAIH,SAAgB,mBAAmB,WAAsB,iBAAoC;CAC3F,OAAO;EACL,GAAG;EACH,YAAY;EACb"}
|
|
@@ -89,7 +89,7 @@ function AnimatedIconSlot({ children, visible, iconSize, iconCellHeight, gap })
|
|
|
89
89
|
*/
|
|
90
90
|
const Button = (0, react.memo)(function Button({ variant = "primary", size = "md", iconVariant = "outline", startIcon, endIcon, loading, disabled, width: _width, children, style, accessibilityLabel, accessibilityHint, disableEffects = false, maxFontSizeMultiplier, onPressIn, onPressOut, ref, ...props }) {
|
|
91
91
|
const shouldAnimate = !disableEffects;
|
|
92
|
-
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
92
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
93
93
|
const { theme } = (0, react_native_unistyles.useUnistyles)();
|
|
94
94
|
const baseMetrics = (0, react.useMemo)(() => require_components_Button_buttonTheme.getButtonControlMetrics(theme, size), [theme, size]);
|
|
95
95
|
const labelScaleFactor = require_fontScaling_useFontScale.useFontScale(resolvedMaxFontSizeMultiplier, baseMetrics.labelLineHeight);
|
|
@@ -86,7 +86,7 @@ function AnimatedIconSlot({ children, visible, iconSize, iconCellHeight, gap })
|
|
|
86
86
|
*/
|
|
87
87
|
const Button = memo(function Button({ variant = "primary", size = "md", iconVariant = "outline", startIcon, endIcon, loading, disabled, width: _width, children, style, accessibilityLabel, accessibilityHint, disableEffects = false, maxFontSizeMultiplier, onPressIn, onPressOut, ref, ...props }) {
|
|
88
88
|
const shouldAnimate = !disableEffects;
|
|
89
|
-
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
89
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
90
90
|
const { theme } = useUnistyles();
|
|
91
91
|
const baseMetrics = useMemo(() => getButtonControlMetrics(theme, size), [theme, size]);
|
|
92
92
|
const labelScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, baseMetrics.labelLineHeight);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","names":["Text"],"sources":["../../src/components/Button.tsx"],"sourcesContent":["import type { ButtonSize, ButtonVariantFlat, IconSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { isValidElement, memo, useCallback, useMemo, useState } from 'react';\nimport type { View } from 'react-native';\nimport { ActivityIndicator } from 'react-native';\nimport Animated, {\n Easing,\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n withTiming,\n} from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- button control height from theme size layers\nimport { useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedTheme } from 'react-native-unistyles/reanimated';\n\nimport { buttonStyles } from '../../generated/styles';\nimport { ResolvedControlFontScalingProvider } from '../fontScaling/FontScalingContext';\nimport { useFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { BUTTON_SPRING_CONFIG, SCALE_EFFECTS } from '../motion';\nimport { getButtonControlMetrics, getButtonTextStyle } from './Button/buttonTheme';\nimport type { IconSlotType } from './IconSlot';\nimport { IconSlot } from './IconSlot';\nimport type { PressableProps } from './Pressable';\nimport { AnimatedPressable } from './Pressable';\nimport { Text } from './Text';\n\n/* -------------------------------------------------------------------------- */\n/* Animation Helpers */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Interpolates a boxShadow string by scaling the alpha of all colors.\n * This allows smooth fade-in/out of shadows.\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/* Animated Icon Slot */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Animated wrapper for icon/loading content.\n * Matches web Button icon animation: scale 0.7→1, opacity 0→1, width 0→auto\n * Uses staggered animation: opacity waits until halfway through width animation.\n */\nfunction AnimatedIconSlot({\n children,\n visible,\n iconSize,\n iconCellHeight,\n gap,\n}: {\n children: React.ReactNode;\n visible: boolean;\n iconSize: number;\n iconCellHeight: number;\n gap: number;\n}) {\n // Use useDerivedValue instead of useEffect + useSharedValue\n // This is the idiomatic Reanimated pattern for deriving animated values from React state\n const progress = useDerivedValue(\n () => withSpring(visible ? 1 : 0, BUTTON_SPRING_CONFIG),\n [visible],\n );\n\n const animatedStyle = useAnimatedStyle(() => {\n // Total width includes icon + gap when visible\n const totalWidth = iconSize + gap;\n const width = interpolate(progress.value, [0, 1], [0, totalWidth]);\n\n // Staggered animation: opacity starts at 50% of width animation\n // On enter: width expands first, then icon fades in\n // On exit: icon fades out first, then width collapses\n const opacity = interpolate(progress.value, [0.5, 1], [0, 1], 'clamp');\n const scale = interpolate(progress.value, [0.5, 1], [0.7, 1], 'clamp');\n\n return {\n width,\n opacity,\n transform: [{ scale }],\n overflow: 'hidden' as const,\n minHeight: iconCellHeight,\n justifyContent: 'center' as const,\n };\n });\n\n return <Animated.View style={animatedStyle}>{children}</Animated.View>;\n}\n\n// function LoadingIcon({ size, variant }: { size: ButtonSize, variant: ButtonVariantFlat }) {\n// const { theme } = useUnistyles();\n// const themeKey = `buttonVariant${variantToCapitalMap[variant]}IconRest` as const;\n// const iconSize = theme.components.buttonSizeLgIconRest.fontSize;\n// return <ActivityIndicator size={iconSize} color={theme.colors.text.primary} />;\n// }\n\n/* -------------------------------------------------------------------------- */\n/* Button Props */\n/* -------------------------------------------------------------------------- */\n\ninterface ButtonProps extends Omit<PressableProps, 'children' | 'disabled'> {\n /** The visual style variant of the button @default 'primary' */\n variant?: ButtonVariantFlat;\n /** The size of the button @default 'md' */\n size?: ButtonSize;\n /** The icon style variant @default 'outline' */\n iconVariant?: IconVariant;\n /** Icon displayed before the button label */\n startIcon?: IconSlotType;\n /** Icon displayed after the button label */\n endIcon?: IconSlotType;\n /** Shows a loading spinner and disables the button */\n loading?: boolean;\n /** Whether the button is disabled */\n disabled?: boolean;\n /** Button label content */\n children?: React.ReactNode;\n /**\n * Disable motion effects (scale on press, icon animations)\n * @default false\n */\n disableEffects?: boolean;\n /**\n * Caps how far the label and icons grow with the OS text-size setting; the\n * button grows to fit the scaled content. Set null to remove the cap;\n * 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/* Button Component */\n/* -------------------------------------------------------------------------- */\n\n/**\n * **🖲️ A button element that can be used to trigger an action**\n *\n * @description\n * A button is a fundamental component used to trigger an action or event.\n * Buttons are interactive elements that users can click, tap, or otherwise\n * engage with to submit forms, open dialogues, or perform any other interaction.\n *\n * Features animated scale effect on press and smooth icon transitions matching\n * the web UDS Button behavior.\n *\n * @category Interactive\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Button } from '@yahoo/uds-mobile/Button';\n *\n * <Button onPress={() => console.log('pressed')}>Save</Button>\n * <Button variant=\"secondary\">Cancel</Button>\n * <Button startIcon=\"Add\" variant=\"brand\">Add Item</Button>\n * <Button loading>Saving...</Button>\n * ```\n *\n * @accessibility\n * - Sets `accessibilityRole=\"button\"` automatically\n * - Announces loading state to screen readers\n * - Use `accessibilityLabel` for icon-only buttons\n *\n * @see {@link IconButton} for icon-only buttons\n * @see {@link Link} for navigation actions\n */\nconst Button = memo(function Button({\n variant = 'primary',\n size = 'md',\n iconVariant = 'outline',\n startIcon,\n endIcon,\n loading,\n disabled,\n width: _width,\n children,\n style,\n accessibilityLabel,\n accessibilityHint,\n disableEffects = false,\n maxFontSizeMultiplier,\n onPressIn,\n onPressOut,\n ref,\n ...props\n}: ButtonProps) {\n const shouldAnimate = !disableEffects;\n\n // Inside a control, \"no cap resolved\" must force-uncap (0) rather than let\n // the label's own variant default or an inherited cap apply.\n const resolvedMaxFontSizeMultiplier =\n useMaxFontSizeMultiplier('control', maxFontSizeMultiplier) ?? 0;\n\n const { theme } = useUnistyles();\n const baseMetrics = useMemo(() => getButtonControlMetrics(theme, size), [theme, size]);\n const labelScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, baseMetrics.labelLineHeight);\n\n /* --------------------------------- State ---------------------------------- */\n const [pressed, setPressed] = useState(false);\n\n buttonStyles.useVariants({ size, variant, disabled, pressed });\n\n // Get gap and icon size from current variant styles\n const buttonGap = buttonStyles.root.gap;\n const iconSize = buttonStyles.icon.fontSize;\n const iconScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, iconSize);\n const iconCellScaleFactor = useFontScale(\n resolvedMaxFontSizeMultiplier,\n baseMetrics.iconCellHeight,\n );\n const { minHeight, labelLineHeight, iconCellHeight, paddingVertical } = useMemo(\n () =>\n getButtonControlMetrics(theme, size, {\n label: labelScaleFactor,\n icon: iconScaleFactor,\n iconCell: iconCellScaleFactor,\n }),\n [theme, size, labelScaleFactor, iconScaleFactor, iconCellScaleFactor],\n );\n\n // Get animated theme for boxShadow (useAnimatedVariantColor doesn't support non-color props)\n const animatedTheme = useAnimatedTheme();\n\n /* ------------------------------- Animation -------------------------------- */\n const scale = useSharedValue<number>(SCALE_EFFECTS.none);\n\n const handlePressIn = useCallback(\n (event: Parameters<NonNullable<PressableProps['onPressIn']>>[0]) => {\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(\n (event: Parameters<NonNullable<PressableProps['onPressOut']>>[0]) => {\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 /* -------------------------------- Content --------------------------------- */\n const childrenNode =\n children &&\n (isValidElement(children) ? (\n <ResolvedControlFontScalingProvider maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}>\n {children}\n </ResolvedControlFontScalingProvider>\n ) : (\n <Text\n numberOfLines={1}\n textAlign=\"center\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={getButtonTextStyle(buttonStyles.text, labelLineHeight)}\n >\n {children}\n </Text>\n ));\n\n const a11yState = useMemo(() => ({ disabled, busy: loading }), [disabled, loading]);\n\n /* --------------------------------- Styles --------------------------------- */\n // Animate pressed state for shadow (0 = rest, 1 = pressed)\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 animatedStyles = useAnimatedStyle(() => {\n // Get boxShadow from theme using flattened path (no camelCase conversion needed!)\n const components = animatedTheme.value.components;\n const buttonVariantPath = `button/variant/${variant}/root/pressed` as const;\n const shadowPressed = components[buttonVariantPath]?.boxShadow;\n\n return {\n transform: [{ scale: scale.value }],\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 // Determine what should be visible in start slot\n const showLoading = !!loading;\n const showStartIcon = !!startIcon && !loading;\n const showEndIcon = !!endIcon && !loading;\n\n const iconSizeToken = (buttonStyles.icon.iconSizeToken as IconSize) ?? 'sm';\n\n // Containers pre-scale by the capped factor; icon styles stay unscaled and\n // native grows them by the same capped multiplier.\n const scaledIconSize = Math.round(iconSize * iconScaleFactor);\n const scaledIconCellHeight = Math.ceil(iconCellHeight * iconCellScaleFactor);\n\n // Start slot: either loading spinner or start icon\n const startContent = (\n <AnimatedIconSlot\n visible={showLoading || showStartIcon}\n iconSize={scaledIconSize}\n iconCellHeight={scaledIconCellHeight}\n gap={buttonGap}\n >\n {showLoading ? (\n <ActivityIndicator size={scaledIconSize} color={buttonStyles.icon.color} />\n ) : (\n <IconSlot\n icon={startIcon}\n size={iconSizeToken}\n variant={iconVariant}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[buttonStyles.icon, { lineHeight: iconCellHeight }]}\n />\n )}\n </AnimatedIconSlot>\n );\n\n // End slot: only end icon (no loading here)\n const endContent = (\n <AnimatedIconSlot\n visible={showEndIcon}\n iconSize={scaledIconSize}\n iconCellHeight={scaledIconCellHeight}\n gap={buttonGap}\n >\n <IconSlot\n icon={endIcon}\n size={iconSizeToken}\n variant={iconVariant}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[buttonStyles.icon, { lineHeight: iconCellHeight }]}\n />\n </AnimatedIconSlot>\n );\n\n const rootStyles = useMemo(\n () => [\n buttonStyles.root,\n { minHeight, paddingVertical },\n animatedStyles,\n typeof style === 'function' ? style({ pressed }) : style,\n ],\n [buttonStyles.root, minHeight, paddingVertical, animatedStyles, style, pressed],\n );\n\n /* --------------------------------- Render --------------------------------- */\n return (\n <AnimatedPressable\n ref={ref}\n disabled={disabled}\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 alignContent=\"center\"\n style={rootStyles}\n {...props}\n >\n {startContent}\n {childrenNode}\n {endContent}\n </AnimatedPressable>\n );\n});\n\nButton.displayName = 'Button';\n\nexport { Button, type ButtonProps };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAS,uBAAuB,QAA4B,OAAuB;AACjF;CACA,IAAI,CAAC,QACH,OAAO;CAET,IAAI,SAAS,GACX,OAAO;CAET,IAAI,SAAS,GACX,OAAO;CAGT,OAAO,OAAO,QAAQ,sDAAsD,GAAG,GAAG,GAAG,GAAG,MAAM;EAE5F,OAAO,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KADZ,WAAW,EAAE,GAAG,OACS,QAAQ,EAAE,CAAC;GACrD;;;;;;;AAYJ,SAAS,iBAAiB,EACxB,UACA,SACA,UACA,gBACA,OAOC;CAGD,MAAM,WAAW,sBACT,WAAW,UAAU,IAAI,GAAG,qBAAqB,EACvD,CAAC,QAAQ,CACV;CAED,MAAM,gBAAgB,uBAAuB;EAE3C,MAAM,aAAa,WAAW;EAS9B,OAAO;GACL,OATY,YAAY,SAAS,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,WAAW,CAS1D;GACL,SALc,YAAY,SAAS,OAAO,CAAC,IAAK,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,QAKrD;GACP,WAAW,CAAC,EAAE,OALF,YAAY,SAAS,OAAO,CAAC,IAAK,EAAE,EAAE,CAAC,IAAK,EAAE,EAAE,QAKzC,EAAE,CAAC;GACtB,UAAU;GACV,WAAW;GACX,gBAAgB;GACjB;GACD;CAEF,OAAO,oBAAC,SAAS,MAAV;EAAe,OAAO;EAAgB;EAAyB,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFxE,MAAM,SAAS,KAAK,SAAS,OAAO,EAClC,UAAU,WACV,OAAO,MACP,cAAc,WACd,WACA,SACA,SACA,UACA,OAAO,QACP,UACA,OACA,o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B;GACvB,OAAO,CAAC,aAAa,MAAM,EAAE,YAAY,gBAAgB,CAAC;GAC1D,CAAA;EACe,CAAA;CAGrB,MAAM,aAAa,cACX;EACJ,aAAa;EACb;GAAE;GAAW;GAAiB;EAC9B;EACA,OAAO,UAAU,aAAa,MAAM,EAAE,SAAS,CAAC,GAAG;EACpD,EACD;EAAC,aAAa;EAAM;EAAW;EAAiB;EAAgB;EAAO;EAAQ,CAChF;CAGD,OACE,qBAAC,mBAAD;EACO;EACK;EACV,WAAW;EACX,YAAY;EACZ,eAAc;EACd,YAAW;EACX,gBAAe;EACf,UAAS;EACT,oBAAoB,UAAU,GAAG,sBAAsB,GAAG,aAAa;EACpD;EACnB,mBAAkB;EAClB,oBAAoB;EACpB,cAAa;EACb,OAAO;EACP,GAAI;YAfN;GAiBG;GACA;GACA;GACiB;;EAEtB;AAEF,OAAO,cAAc"}
|
|
1
|
+
{"version":3,"file":"Button.js","names":["Text"],"sources":["../../src/components/Button.tsx"],"sourcesContent":["import type { ButtonSize, ButtonVariantFlat, IconSize, IconVariant } from '@yahoo/uds-types';\nimport type { Ref } from 'react';\nimport { isValidElement, memo, useCallback, useMemo, useState } from 'react';\nimport type { View } from 'react-native';\nimport { ActivityIndicator } from 'react-native';\nimport Animated, {\n Easing,\n interpolate,\n useAnimatedStyle,\n useDerivedValue,\n useSharedValue,\n withSpring,\n withTiming,\n} from 'react-native-reanimated';\n// eslint-disable-next-line uds/no-use-unistyles -- button control height from theme size layers\nimport { useUnistyles } from 'react-native-unistyles';\nimport { useAnimatedTheme } from 'react-native-unistyles/reanimated';\n\nimport { buttonStyles } from '../../generated/styles';\nimport { ResolvedControlFontScalingProvider } from '../fontScaling/FontScalingContext';\nimport { useFontScale } from '../fontScaling/useFontScale';\nimport { useMaxFontSizeMultiplier } from '../fontScaling/useMaxFontSizeMultiplier';\nimport { BUTTON_SPRING_CONFIG, SCALE_EFFECTS } from '../motion';\nimport { getButtonControlMetrics, getButtonTextStyle } from './Button/buttonTheme';\nimport type { IconSlotType } from './IconSlot';\nimport { IconSlot } from './IconSlot';\nimport type { PressableProps } from './Pressable';\nimport { AnimatedPressable } from './Pressable';\nimport { Text } from './Text';\n\n/* -------------------------------------------------------------------------- */\n/* Animation Helpers */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Interpolates a boxShadow string by scaling the alpha of all colors.\n * This allows smooth fade-in/out of shadows.\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/* Animated Icon Slot */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Animated wrapper for icon/loading content.\n * Matches web Button icon animation: scale 0.7→1, opacity 0→1, width 0→auto\n * Uses staggered animation: opacity waits until halfway through width animation.\n */\nfunction AnimatedIconSlot({\n children,\n visible,\n iconSize,\n iconCellHeight,\n gap,\n}: {\n children: React.ReactNode;\n visible: boolean;\n iconSize: number;\n iconCellHeight: number;\n gap: number;\n}) {\n // Use useDerivedValue instead of useEffect + useSharedValue\n // This is the idiomatic Reanimated pattern for deriving animated values from React state\n const progress = useDerivedValue(\n () => withSpring(visible ? 1 : 0, BUTTON_SPRING_CONFIG),\n [visible],\n );\n\n const animatedStyle = useAnimatedStyle(() => {\n // Total width includes icon + gap when visible\n const totalWidth = iconSize + gap;\n const width = interpolate(progress.value, [0, 1], [0, totalWidth]);\n\n // Staggered animation: opacity starts at 50% of width animation\n // On enter: width expands first, then icon fades in\n // On exit: icon fades out first, then width collapses\n const opacity = interpolate(progress.value, [0.5, 1], [0, 1], 'clamp');\n const scale = interpolate(progress.value, [0.5, 1], [0.7, 1], 'clamp');\n\n return {\n width,\n opacity,\n transform: [{ scale }],\n overflow: 'hidden' as const,\n minHeight: iconCellHeight,\n justifyContent: 'center' as const,\n };\n });\n\n return <Animated.View style={animatedStyle}>{children}</Animated.View>;\n}\n\n// function LoadingIcon({ size, variant }: { size: ButtonSize, variant: ButtonVariantFlat }) {\n// const { theme } = useUnistyles();\n// const themeKey = `buttonVariant${variantToCapitalMap[variant]}IconRest` as const;\n// const iconSize = theme.components.buttonSizeLgIconRest.fontSize;\n// return <ActivityIndicator size={iconSize} color={theme.colors.text.primary} />;\n// }\n\n/* -------------------------------------------------------------------------- */\n/* Button Props */\n/* -------------------------------------------------------------------------- */\n\ninterface ButtonProps extends Omit<PressableProps, 'children' | 'disabled'> {\n /** The visual style variant of the button @default 'primary' */\n variant?: ButtonVariantFlat;\n /** The size of the button @default 'md' */\n size?: ButtonSize;\n /** The icon style variant @default 'outline' */\n iconVariant?: IconVariant;\n /** Icon displayed before the button label */\n startIcon?: IconSlotType;\n /** Icon displayed after the button label */\n endIcon?: IconSlotType;\n /** Shows a loading spinner and disables the button */\n loading?: boolean;\n /** Whether the button is disabled */\n disabled?: boolean;\n /** Button label content */\n children?: React.ReactNode;\n /**\n * Disable motion effects (scale on press, icon animations)\n * @default false\n */\n disableEffects?: boolean;\n /**\n * Caps how far the label and icons grow with the OS text-size setting; the\n * button grows to fit the scaled content. Set null to remove the cap;\n * 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/* Button Component */\n/* -------------------------------------------------------------------------- */\n\n/**\n * **🖲️ A button element that can be used to trigger an action**\n *\n * @description\n * A button is a fundamental component used to trigger an action or event.\n * Buttons are interactive elements that users can click, tap, or otherwise\n * engage with to submit forms, open dialogues, or perform any other interaction.\n *\n * Features animated scale effect on press and smooth icon transitions matching\n * the web UDS Button behavior.\n *\n * @category Interactive\n * @platform mobile\n *\n * @example\n * ```tsx\n * import { Button } from '@yahoo/uds-mobile/Button';\n *\n * <Button onPress={() => console.log('pressed')}>Save</Button>\n * <Button variant=\"secondary\">Cancel</Button>\n * <Button startIcon=\"Add\" variant=\"brand\">Add Item</Button>\n * <Button loading>Saving...</Button>\n * ```\n *\n * @accessibility\n * - Sets `accessibilityRole=\"button\"` automatically\n * - Announces loading state to screen readers\n * - Use `accessibilityLabel` for icon-only buttons\n *\n * @see {@link IconButton} for icon-only buttons\n * @see {@link Link} for navigation actions\n */\nconst Button = memo(function Button({\n variant = 'primary',\n size = 'md',\n iconVariant = 'outline',\n startIcon,\n endIcon,\n loading,\n disabled,\n width: _width,\n children,\n style,\n accessibilityLabel,\n accessibilityHint,\n disableEffects = false,\n maxFontSizeMultiplier,\n onPressIn,\n onPressOut,\n ref,\n ...props\n}: ButtonProps) {\n const shouldAnimate = !disableEffects;\n\n // Inside a control, \"no cap resolved\" must force-uncap (0) rather than let\n // the label's own variant default or an inherited cap apply.\n const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier('control', maxFontSizeMultiplier);\n\n const { theme } = useUnistyles();\n const baseMetrics = useMemo(() => getButtonControlMetrics(theme, size), [theme, size]);\n const labelScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, baseMetrics.labelLineHeight);\n\n /* --------------------------------- State ---------------------------------- */\n const [pressed, setPressed] = useState(false);\n\n buttonStyles.useVariants({ size, variant, disabled, pressed });\n\n // Get gap and icon size from current variant styles\n const buttonGap = buttonStyles.root.gap;\n const iconSize = buttonStyles.icon.fontSize;\n const iconScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, iconSize);\n const iconCellScaleFactor = useFontScale(\n resolvedMaxFontSizeMultiplier,\n baseMetrics.iconCellHeight,\n );\n const { minHeight, labelLineHeight, iconCellHeight, paddingVertical } = useMemo(\n () =>\n getButtonControlMetrics(theme, size, {\n label: labelScaleFactor,\n icon: iconScaleFactor,\n iconCell: iconCellScaleFactor,\n }),\n [theme, size, labelScaleFactor, iconScaleFactor, iconCellScaleFactor],\n );\n\n // Get animated theme for boxShadow (useAnimatedVariantColor doesn't support non-color props)\n const animatedTheme = useAnimatedTheme();\n\n /* ------------------------------- Animation -------------------------------- */\n const scale = useSharedValue<number>(SCALE_EFFECTS.none);\n\n const handlePressIn = useCallback(\n (event: Parameters<NonNullable<PressableProps['onPressIn']>>[0]) => {\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(\n (event: Parameters<NonNullable<PressableProps['onPressOut']>>[0]) => {\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 /* -------------------------------- Content --------------------------------- */\n const childrenNode =\n children &&\n (isValidElement(children) ? (\n <ResolvedControlFontScalingProvider maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}>\n {children}\n </ResolvedControlFontScalingProvider>\n ) : (\n <Text\n numberOfLines={1}\n textAlign=\"center\"\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={getButtonTextStyle(buttonStyles.text, labelLineHeight)}\n >\n {children}\n </Text>\n ));\n\n const a11yState = useMemo(() => ({ disabled, busy: loading }), [disabled, loading]);\n\n /* --------------------------------- Styles --------------------------------- */\n // Animate pressed state for shadow (0 = rest, 1 = pressed)\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 animatedStyles = useAnimatedStyle(() => {\n // Get boxShadow from theme using flattened path (no camelCase conversion needed!)\n const components = animatedTheme.value.components;\n const buttonVariantPath = `button/variant/${variant}/root/pressed` as const;\n const shadowPressed = components[buttonVariantPath]?.boxShadow;\n\n return {\n transform: [{ scale: scale.value }],\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 // Determine what should be visible in start slot\n const showLoading = !!loading;\n const showStartIcon = !!startIcon && !loading;\n const showEndIcon = !!endIcon && !loading;\n\n const iconSizeToken = (buttonStyles.icon.iconSizeToken as IconSize) ?? 'sm';\n\n // Containers pre-scale by the capped factor; icon styles stay unscaled and\n // native grows them by the same capped multiplier.\n const scaledIconSize = Math.round(iconSize * iconScaleFactor);\n const scaledIconCellHeight = Math.ceil(iconCellHeight * iconCellScaleFactor);\n\n // Start slot: either loading spinner or start icon\n const startContent = (\n <AnimatedIconSlot\n visible={showLoading || showStartIcon}\n iconSize={scaledIconSize}\n iconCellHeight={scaledIconCellHeight}\n gap={buttonGap}\n >\n {showLoading ? (\n <ActivityIndicator size={scaledIconSize} color={buttonStyles.icon.color} />\n ) : (\n <IconSlot\n icon={startIcon}\n size={iconSizeToken}\n variant={iconVariant}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[buttonStyles.icon, { lineHeight: iconCellHeight }]}\n />\n )}\n </AnimatedIconSlot>\n );\n\n // End slot: only end icon (no loading here)\n const endContent = (\n <AnimatedIconSlot\n visible={showEndIcon}\n iconSize={scaledIconSize}\n iconCellHeight={scaledIconCellHeight}\n gap={buttonGap}\n >\n <IconSlot\n icon={endIcon}\n size={iconSizeToken}\n variant={iconVariant}\n maxFontSizeMultiplier={resolvedMaxFontSizeMultiplier}\n style={[buttonStyles.icon, { lineHeight: iconCellHeight }]}\n />\n </AnimatedIconSlot>\n );\n\n const rootStyles = useMemo(\n () => [\n buttonStyles.root,\n { minHeight, paddingVertical },\n animatedStyles,\n typeof style === 'function' ? style({ pressed }) : style,\n ],\n [buttonStyles.root, minHeight, paddingVertical, animatedStyles, style, pressed],\n );\n\n /* --------------------------------- Render --------------------------------- */\n return (\n <AnimatedPressable\n ref={ref}\n disabled={disabled}\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 alignContent=\"center\"\n style={rootStyles}\n {...props}\n >\n {startContent}\n {childrenNode}\n {endContent}\n </AnimatedPressable>\n );\n});\n\nButton.displayName = 'Button';\n\nexport { Button, type ButtonProps };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAS,uBAAuB,QAA4B,OAAuB;AACjF;CACA,IAAI,CAAC,QACH,OAAO;CAET,IAAI,SAAS,GACX,OAAO;CAET,IAAI,SAAS,GACX,OAAO;CAGT,OAAO,OAAO,QAAQ,sDAAsD,GAAG,GAAG,GAAG,GAAG,MAAM;EAE5F,OAAO,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KADZ,WAAW,EAAE,GAAG,OACS,QAAQ,EAAE,CAAC;GACrD;;;;;;;AAYJ,SAAS,iBAAiB,EACxB,UACA,SACA,UACA,gBACA,OAOC;CAGD,MAAM,WAAW,sBACT,WAAW,UAAU,IAAI,GAAG,qBAAqB,EACvD,CAAC,QAAQ,CACV;CAED,MAAM,gBAAgB,uBAAuB;EAE3C,MAAM,aAAa,WAAW;EAS9B,OAAO;GACL,OATY,YAAY,SAAS,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,WAAW,CAS1D;GACL,SALc,YAAY,SAAS,OAAO,CAAC,IAAK,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,QAKrD;GACP,WAAW,CAAC,EAAE,OALF,YAAY,SAAS,OAAO,CAAC,IAAK,EAAE,EAAE,CAAC,IAAK,EAAE,EAAE,QAKzC,EAAE,CAAC;GACtB,UAAU;GACV,WAAW;GACX,gBAAgB;GACjB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vB,OAAO,CAAC,aAAa,MAAM,EAAE,YAAY,gBAAgB,CAAC;GAC1D,CAAA;EAEa,CAAA;CAIrB,MAAM,aACJ,oBAAC,kBAAD;EACE,SAAS;EACT,UAAU;EACV,gBAAgB;EAChB,KAAK;YAEL,oBAAC,UAAD;GACE,MAAM;GACN,MAAM;GACN,SAAS;GACT,uBAAuB;GACvB,OAAO,CAAC,aAAa,MAAM,EAAE,YAAY,gBAAgB,CAAC;GAC1D,CAAA;EACe,CAAA;CAGrB,MAAM,aAAa,cACX;EACJ,aAAa;EACb;GAAE;GAAW;GAAiB;EAC9B;EACA,OAAO,UAAU,aAAa,MAAM,EAAE,SAAS,CAAC,GAAG;EACpD,EACD;EAAC,aAAa;EAAM;EAAW;EAAiB;EAAgB;EAAO;EAAQ,CAChF;CAGD,OACE,qBAAC,mBAAD;EACO;EACK;EACV,WAAW;EACX,YAAY;EACZ,eAAc;EACd,YAAW;EACX,gBAAe;EACf,UAAS;EACT,oBAAoB,UAAU,GAAG,sBAAsB,GAAG,aAAa;EACpD;EACnB,mBAAkB;EAClB,oBAAoB;EACpB,cAAa;EACb,OAAO;EACP,GAAI;YAfN;GAiBG;GACA;GACA;GACiB;;EAEtB;AAEF,OAAO,cAAc"}
|
|
@@ -5,6 +5,7 @@ const require_index = require("../motion-tokens/dist/index.cjs");
|
|
|
5
5
|
const require_motion = require("../motion.cjs");
|
|
6
6
|
const require_fontScaling_useFontScale = require("../fontScaling/useFontScale.cjs");
|
|
7
7
|
const require_fontScaling_useMaxFontSizeMultiplier = require("../fontScaling/useMaxFontSizeMultiplier.cjs");
|
|
8
|
+
const require_components_Button_buttonTheme = require("./Button/buttonTheme.cjs");
|
|
8
9
|
const require_components_Icon = require("./Icon.cjs");
|
|
9
10
|
const require_components_Pressable = require("./Pressable.cjs");
|
|
10
11
|
const require_components_FormLabel = require("./FormLabel.cjs");
|
|
@@ -55,7 +56,7 @@ const VARIANT_ERROR_MAP = {
|
|
|
55
56
|
*/
|
|
56
57
|
const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "start", variant: variantProp = "primary", size = "md", checked: checkedProp, hasError, reduceMotion, defaultChecked, disabled, required, maxFontSizeMultiplier, onChange, ref, ...viewProps }) {
|
|
57
58
|
const uid = `uds-checkbox-${(0, react.useId)()}`;
|
|
58
|
-
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
59
|
+
const resolvedMaxFontSizeMultiplier = require_fontScaling_useMaxFontSizeMultiplier.useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
59
60
|
const isControlled = checkedProp !== void 0;
|
|
60
61
|
const [internalChecked, setInternalChecked] = (0, react.useState)(isControlled ? checkedProp : defaultChecked ?? false);
|
|
61
62
|
const [pressed, setPressed] = (0, react.useState)(false);
|
|
@@ -98,6 +99,7 @@ const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "sta
|
|
|
98
99
|
const fontScaleFactor = require_fontScaling_useFontScale.useFontScale(resolvedMaxFontSizeMultiplier, typeof boxBaseSize === "number" ? boxBaseSize : void 0);
|
|
99
100
|
const markScaleFactor = require_fontScaling_useFontScale.useFontScale(resolvedMaxFontSizeMultiplier, _yahoo_uds_icons_tokens.ICON_SIZE_MAP.sm);
|
|
100
101
|
const scaledMarkSize = Math.round(_yahoo_uds_icons_tokens.ICON_SIZE_MAP.sm * markScaleFactor);
|
|
102
|
+
const hasScaledLayout = fontScaleFactor !== 1;
|
|
101
103
|
const rootStyle = (0, react.useMemo)(() => [generated_styles.checkboxStyles.root, { opacity: disabled ? .5 : 1 }], [generated_styles.checkboxStyles.root, disabled]);
|
|
102
104
|
const checkboxBoxStyle = (0, react.useMemo)(() => {
|
|
103
105
|
const { width, height, borderRadius } = generated_styles.checkboxStyles.checkbox;
|
|
@@ -129,7 +131,7 @@ const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "sta
|
|
|
129
131
|
required,
|
|
130
132
|
showRequiredAsterisk: required,
|
|
131
133
|
hasError,
|
|
132
|
-
flexShrink: "1",
|
|
134
|
+
flexShrink: hasScaledLayout ? "1" : void 0,
|
|
133
135
|
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
134
136
|
style: generated_styles.checkboxStyles.text
|
|
135
137
|
});
|
|
@@ -137,6 +139,7 @@ const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "sta
|
|
|
137
139
|
label,
|
|
138
140
|
required,
|
|
139
141
|
hasError,
|
|
142
|
+
hasScaledLayout,
|
|
140
143
|
resolvedMaxFontSizeMultiplier,
|
|
141
144
|
generated_styles.checkboxStyles.text
|
|
142
145
|
]);
|
|
@@ -153,8 +156,8 @@ const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "sta
|
|
|
153
156
|
disabled,
|
|
154
157
|
flexDirection: labelPosition === "start" ? "row" : "row-reverse",
|
|
155
158
|
alignItems: "center",
|
|
156
|
-
alignSelf: "stretch",
|
|
157
|
-
minHeight: 52,
|
|
159
|
+
alignSelf: hasScaledLayout ? "stretch" : "flex-start",
|
|
160
|
+
minHeight: hasScaledLayout ? 52 : void 0,
|
|
158
161
|
accessibilityRole: "checkbox",
|
|
159
162
|
accessibilityState: a11yState,
|
|
160
163
|
accessibilityLabel: typeof label === "string" ? label : void 0,
|
|
@@ -167,7 +170,10 @@ const Checkbox = (0, react.memo)(function Checkbox({ label, labelPosition = "sta
|
|
|
167
170
|
size: "sm",
|
|
168
171
|
dangerouslySetSize: scaledMarkSize,
|
|
169
172
|
allowFontScaling: false,
|
|
170
|
-
style: generated_styles.checkboxStyles.checkboxIcon
|
|
173
|
+
style: [generated_styles.checkboxStyles.checkboxIcon, markScaleFactor !== 1 ? {
|
|
174
|
+
fontSize: scaledMarkSize,
|
|
175
|
+
lineHeight: require_components_Button_buttonTheme.getSafeIconCell(scaledMarkSize)
|
|
176
|
+
} : void 0]
|
|
171
177
|
})
|
|
172
178
|
}), labelContent]
|
|
173
179
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.cts","names":[],"sources":["../../src/components/Checkbox.tsx"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"Checkbox.d.cts","names":[],"sources":["../../src/components/Checkbox.tsx"],"mappings":";;;;;;;UAuBU,aAAA,SAAsB,IAAA,CAAK,SAAA,YAAqB,sBAAA;;EAExD,GAAA,GAAM,GAAA,CAAI,IAAA;EAFF;EAIR,cAAA;;EAEA,QAAA;EAJU;EAMV,QAAA;EAR8B;;;;;;EAe9B,qBAAA;EAbA;EAeA,QAAA,IAAY,OAAA;AAAA;;;;;;;;;AAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;cAqDxB,QAAA,EAAQ,OAAA,CAAA,oBAAA,CAAA,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.d.ts","names":[],"sources":["../../src/components/Checkbox.tsx"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"Checkbox.d.ts","names":[],"sources":["../../src/components/Checkbox.tsx"],"mappings":";;;;;;;UAuBU,aAAA,SAAsB,IAAA,CAAK,SAAA,YAAqB,sBAAA;;EAExD,GAAA,GAAM,GAAA,CAAI,IAAA;EAFF;EAIR,cAAA;;EAEA,QAAA;EAJU;EAMV,QAAA;EAR8B;;;;;;EAe9B,qBAAA;EAbA;EAeA,QAAA,IAAY,OAAA;AAAA;;;;;;;;;AAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;cAqDxB,QAAA,EAAQ,OAAA,CAAA,oBAAA,CAAA,aAAA"}
|
|
@@ -3,6 +3,7 @@ import { SCALE_EFFECTS } from "../motion-tokens/dist/index.js";
|
|
|
3
3
|
import { BUTTON_SPRING_CONFIG } from "../motion.js";
|
|
4
4
|
import { useFontScale } from "../fontScaling/useFontScale.js";
|
|
5
5
|
import { useMaxFontSizeMultiplier } from "../fontScaling/useMaxFontSizeMultiplier.js";
|
|
6
|
+
import { getSafeIconCell } from "./Button/buttonTheme.js";
|
|
6
7
|
import { Icon } from "./Icon.js";
|
|
7
8
|
import { Pressable } from "./Pressable.js";
|
|
8
9
|
import { FormLabel } from "./FormLabel.js";
|
|
@@ -52,7 +53,7 @@ const VARIANT_ERROR_MAP = {
|
|
|
52
53
|
*/
|
|
53
54
|
const Checkbox = memo(function Checkbox({ label, labelPosition = "start", variant: variantProp = "primary", size = "md", checked: checkedProp, hasError, reduceMotion, defaultChecked, disabled, required, maxFontSizeMultiplier, onChange, ref, ...viewProps }) {
|
|
54
55
|
const uid = `uds-checkbox-${useId()}`;
|
|
55
|
-
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier)
|
|
56
|
+
const resolvedMaxFontSizeMultiplier = useMaxFontSizeMultiplier("control", maxFontSizeMultiplier);
|
|
56
57
|
const isControlled = checkedProp !== void 0;
|
|
57
58
|
const [internalChecked, setInternalChecked] = useState(isControlled ? checkedProp : defaultChecked ?? false);
|
|
58
59
|
const [pressed, setPressed] = useState(false);
|
|
@@ -95,6 +96,7 @@ const Checkbox = memo(function Checkbox({ label, labelPosition = "start", varian
|
|
|
95
96
|
const fontScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, typeof boxBaseSize === "number" ? boxBaseSize : void 0);
|
|
96
97
|
const markScaleFactor = useFontScale(resolvedMaxFontSizeMultiplier, ICON_SIZE_MAP.sm);
|
|
97
98
|
const scaledMarkSize = Math.round(ICON_SIZE_MAP.sm * markScaleFactor);
|
|
99
|
+
const hasScaledLayout = fontScaleFactor !== 1;
|
|
98
100
|
const rootStyle = useMemo(() => [checkboxStyles.root, { opacity: disabled ? .5 : 1 }], [checkboxStyles.root, disabled]);
|
|
99
101
|
const checkboxBoxStyle = useMemo(() => {
|
|
100
102
|
const { width, height, borderRadius } = checkboxStyles.checkbox;
|
|
@@ -126,7 +128,7 @@ const Checkbox = memo(function Checkbox({ label, labelPosition = "start", varian
|
|
|
126
128
|
required,
|
|
127
129
|
showRequiredAsterisk: required,
|
|
128
130
|
hasError,
|
|
129
|
-
flexShrink: "1",
|
|
131
|
+
flexShrink: hasScaledLayout ? "1" : void 0,
|
|
130
132
|
maxFontSizeMultiplier: resolvedMaxFontSizeMultiplier,
|
|
131
133
|
style: checkboxStyles.text
|
|
132
134
|
});
|
|
@@ -134,6 +136,7 @@ const Checkbox = memo(function Checkbox({ label, labelPosition = "start", varian
|
|
|
134
136
|
label,
|
|
135
137
|
required,
|
|
136
138
|
hasError,
|
|
139
|
+
hasScaledLayout,
|
|
137
140
|
resolvedMaxFontSizeMultiplier,
|
|
138
141
|
checkboxStyles.text
|
|
139
142
|
]);
|
|
@@ -150,8 +153,8 @@ const Checkbox = memo(function Checkbox({ label, labelPosition = "start", varian
|
|
|
150
153
|
disabled,
|
|
151
154
|
flexDirection: labelPosition === "start" ? "row" : "row-reverse",
|
|
152
155
|
alignItems: "center",
|
|
153
|
-
alignSelf: "stretch",
|
|
154
|
-
minHeight: 52,
|
|
156
|
+
alignSelf: hasScaledLayout ? "stretch" : "flex-start",
|
|
157
|
+
minHeight: hasScaledLayout ? 52 : void 0,
|
|
155
158
|
accessibilityRole: "checkbox",
|
|
156
159
|
accessibilityState: a11yState,
|
|
157
160
|
accessibilityLabel: typeof label === "string" ? label : void 0,
|
|
@@ -164,7 +167,10 @@ const Checkbox = memo(function Checkbox({ label, labelPosition = "start", varian
|
|
|
164
167
|
size: "sm",
|
|
165
168
|
dangerouslySetSize: scaledMarkSize,
|
|
166
169
|
allowFontScaling: false,
|
|
167
|
-
style: checkboxStyles.checkboxIcon
|
|
170
|
+
style: [checkboxStyles.checkboxIcon, markScaleFactor !== 1 ? {
|
|
171
|
+
fontSize: scaledMarkSize,
|
|
172
|
+
lineHeight: getSafeIconCell(scaledMarkSize)
|
|
173
|
+
} : void 0]
|
|
168
174
|
})
|
|
169
175
|
}), labelContent]
|
|
170
176
|
});
|