@coinbase/cds-mobile 9.7.2 → 9.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,18 @@ All notable changes to this project will be documented in this file.
8
8
 
9
9
  <!-- template-start -->
10
10
 
11
+ ## 9.9.0 (7/27/2026 PST)
12
+
13
+ #### 🚀 Updates
14
+
15
+ - Feat: support disabling icon scaling. [[#811](https://github.com/coinbase/cds/pull/811)]
16
+
17
+ ## 9.8.0 (7/23/2026 PST)
18
+
19
+ #### 🚀 Updates
20
+
21
+ - Feat: add createIcon factory to decouple Icon from a single icon set. [[#786](https://github.com/coinbase/cds/pull/786)]
22
+
11
23
  ## 9.7.2 (7/23/2026 PST)
12
24
 
13
25
  #### 🐞 Fixes
@@ -1,7 +1,7 @@
1
1
  export declare const useAppState: () =>
2
2
  | 'background'
3
- | 'unknown'
4
3
  | 'active'
5
4
  | 'inactive'
5
+ | 'unknown'
6
6
  | 'extension';
7
7
  //# sourceMappingURL=useAppState.d.ts.map
@@ -1,70 +1,53 @@
1
- import React from 'react';
2
- import { Animated, type StyleProp, type TextStyle, type ViewStyle } from 'react-native';
3
- import type { ThemeVars } from '@coinbase/cds-common/core/theme';
4
1
  import type { IconName } from '@coinbase/cds-common/types/IconName';
5
- import type { IconSize, IconSourcePixelSize } from '@coinbase/cds-common/types/IconSize';
6
- import type { SharedAccessibilityProps } from '@coinbase/cds-common/types/SharedAccessibilityProps';
7
- import type { SharedProps } from '@coinbase/cds-common/types/SharedProps';
8
- import type { PaddingProps } from '@coinbase/cds-common/types/SpacingProps';
9
- export type IconBaseProps = SharedProps &
10
- PaddingProps &
11
- Pick<SharedAccessibilityProps, 'accessibilityLabel' | 'accessibilityHint'> & {
12
- /**
13
- * Size for a given icon.
14
- * @default m
15
- */
16
- size?: IconSize;
17
- /** Name of the icon, as defined in Figma. */
18
- name: IconName;
19
- /**
20
- * Fallback element to render if unable to find an icon with matching name
21
- * @default null
22
- * */
23
- fallback?: null | React.ReactNode;
24
- /**
25
- * Toggles the active and inactive state of the navigation icon
26
- * @default false
27
- */
28
- active?: boolean;
29
- /** Color of the icon when used as a foreground.
30
- * @default primary
31
- */
32
- color?: ThemeVars.Color;
33
- /**
34
- * @deprecated Use `style`, `styles.icon`, or the `color` prop to customize icon color. This will be removed in a future major release.
35
- * @deprecationExpectedRemoval v10
36
- */
37
- dangerouslySetColor?: string | Animated.AnimatedInterpolation<string>;
38
- animated?: boolean;
39
- style?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
40
- };
41
- export type IconProps = IconBaseProps & {
42
- /** Custom styles for individual elements of the Icon component */
43
- styles?: {
44
- /** Outer Box wrapper element */
45
- root?: StyleProp<ViewStyle>;
46
- /** Inner icon glyph Text element */
47
- icon?: StyleProp<TextStyle>;
48
- };
49
- };
50
- declare const getIconSourceSize: (iconSize: number) => IconSourcePixelSize;
51
- export declare const Icon: React.MemoExoticComponent<
52
- (
53
- _props: IconProps,
54
- ) =>
2
+ import {
3
+ getIconSourceSize,
4
+ type IconBaseProps as IconBasePropsGeneric,
5
+ type IconProps as IconPropsGeneric,
6
+ } from './createIcon';
7
+ export type IconBaseProps = IconBasePropsGeneric<IconName>;
8
+ export type IconProps = IconPropsGeneric<IconName>;
9
+ export declare const Icon: import('react').MemoExoticComponent<
10
+ ({
11
+ ref,
12
+ ..._props
13
+ }: import('@coinbase/cds-common').SharedProps &
14
+ import('@coinbase/cds-common').PaddingProps &
15
+ Pick<
16
+ import('@coinbase/cds-common').SharedAccessibilityProps,
17
+ 'accessibilityLabel' | 'accessibilityHint'
18
+ > &
19
+ Pick<import('react-native').TextProps, 'allowFontScaling'> & {
20
+ size?: import('@coinbase/cds-common').IconSize;
21
+ name: IconName;
22
+ fallback?: null | React.ReactNode;
23
+ active?: boolean;
24
+ color?: import('@coinbase/cds-common').ThemeVars.Color;
25
+ dangerouslySetColor?: string | import('react-native').Animated.AnimatedInterpolation<string>;
26
+ animated?: boolean;
27
+ } & {
28
+ style?: import('react-native').Animated.WithAnimatedValue<
29
+ import('react-native').StyleProp<import('react-native').TextStyle>
30
+ >;
31
+ styles?: {
32
+ root?: import('react-native').StyleProp<import('react-native').ViewStyle>;
33
+ icon?: import('react-native').StyleProp<import('react-native').TextStyle>;
34
+ };
35
+ } & {
36
+ ref?: React.Ref<import('react-native').Text>;
37
+ }) =>
55
38
  | string
56
39
  | number
57
40
  | bigint
58
41
  | boolean
59
- | Iterable<React.ReactNode>
42
+ | Iterable<import('react').ReactNode>
60
43
  | Promise<
61
44
  | string
62
45
  | number
63
46
  | bigint
64
47
  | boolean
65
- | React.ReactPortal
66
- | React.ReactElement<unknown, string | React.JSXElementConstructor<any>>
67
- | Iterable<React.ReactNode>
48
+ | import('react').ReactPortal
49
+ | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>>
50
+ | Iterable<import('react').ReactNode>
68
51
  | null
69
52
  | undefined
70
53
  >
@@ -1 +1 @@
1
- {"version":3,"file":"Icon.d.ts","sourceRoot":"","sources":["../../src/icons/Icon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,QAAQ,EACR,KAAK,SAAS,EAEd,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AACzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AACpG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAQ5E,MAAM,MAAM,aAAa,GAAG,WAAW,GACrC,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,cAAc,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;AAC3D,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAEnD,eAAO,MAAM,IAAI;;;;;;;;;;;YAMitG,CAAC;YAAyE,CAAC;;;;kWAH3yG,CAAC;AAEH,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,138 @@
1
+ import React from 'react';
2
+ import {
3
+ Animated,
4
+ type StyleProp,
5
+ Text,
6
+ type TextProps as NativeTextProps,
7
+ type TextStyle,
8
+ type ViewStyle,
9
+ } from 'react-native';
10
+ import type { ThemeVars } from '@coinbase/cds-common/core/theme';
11
+ import type { IconSize, IconSourcePixelSize } from '@coinbase/cds-common/types/IconSize';
12
+ import type { SharedAccessibilityProps } from '@coinbase/cds-common/types/SharedAccessibilityProps';
13
+ import type { SharedProps } from '@coinbase/cds-common/types/SharedProps';
14
+ import type { PaddingProps } from '@coinbase/cds-common/types/SpacingProps';
15
+ /** Default font family for the CDS icon glyph font. */
16
+ export declare const DEFAULT_ICON_FONT_FAMILY = 'CoinbaseIcons';
17
+ /**
18
+ * Shape of the glyph map an icon set must provide. Keys are
19
+ * `${name}-${sourcePixelSize}-${'active' | 'inactive'}` and values are the
20
+ * single Unicode character rendered in the icon font.
21
+ */
22
+ export type GlyphMap<Name extends string> = Record<
23
+ `${Name}-${IconSourcePixelSize}-${'active' | 'inactive'}`,
24
+ string
25
+ >;
26
+ /** Arguments passed to a glyph resolver to look up an icon's glyph. */
27
+ export type IconGlyphResolverArgs<Name extends string> = {
28
+ /** Glyph map bound to this icon set. */
29
+ glyphMap: GlyphMap<Name>;
30
+ /** Icon name requested via the `name` prop. */
31
+ name: Name;
32
+ /** Size token requested via the `size` prop. */
33
+ size: IconSize;
34
+ /** Resolved pixel size from the theme (includes device font scaling). */
35
+ pixelSize: number;
36
+ /** Whether the active variant was requested. */
37
+ active: boolean;
38
+ };
39
+ /** Configuration used to bind an icon set to a typed `Icon` component. */
40
+ export type CreateIconConfig<Name extends string> = {
41
+ /** Generated glyph map for this icon set. */
42
+ glyphMap: GlyphMap<Name>;
43
+ /**
44
+ * Font family registered by the icon set's font (loaded via `expo-font`).
45
+ * @default 'CoinbaseIcons'
46
+ */
47
+ fontFamily?: string;
48
+ /**
49
+ * Resolves the glyph to render for an icon from the glyph map. Override to
50
+ * support a custom key format or size model. Defaults to the CDS scheme:
51
+ * `${name}-${sourceSize}-${'active' | 'inactive'}`, where `sourceSize` is
52
+ * `12`, `16`, or `24`.
53
+ */
54
+ getGlyph?: (args: IconGlyphResolverArgs<Name>) => string | undefined;
55
+ };
56
+ export type IconBaseProps<Name extends string = string> = SharedProps &
57
+ PaddingProps &
58
+ Pick<SharedAccessibilityProps, 'accessibilityLabel' | 'accessibilityHint'> &
59
+ Pick<NativeTextProps, 'allowFontScaling'> & {
60
+ /**
61
+ * Size for a given icon.
62
+ * @default m
63
+ */
64
+ size?: IconSize;
65
+ /** Name of the icon, as defined in Figma. */
66
+ name: Name;
67
+ /**
68
+ * Fallback element to render if unable to find an icon with matching name
69
+ * @default null
70
+ * */
71
+ fallback?: null | React.ReactNode;
72
+ /**
73
+ * Toggles the active and inactive state of the navigation icon
74
+ * @default false
75
+ */
76
+ active?: boolean;
77
+ /** Color of the icon when used as a foreground.
78
+ * @default primary
79
+ */
80
+ color?: ThemeVars.Color;
81
+ /**
82
+ * @deprecated Use `style`, `styles.icon`, or the `color` prop to customize icon color. This will be removed in a future major release.
83
+ * @deprecationExpectedRemoval v10
84
+ */
85
+ dangerouslySetColor?: string | Animated.AnimatedInterpolation<string>;
86
+ animated?: boolean;
87
+ };
88
+ export type IconProps<Name extends string = string> = IconBaseProps<Name> & {
89
+ /** Custom style applied to the outer container. */
90
+ style?: Animated.WithAnimatedValue<StyleProp<TextStyle>>;
91
+ /** Custom styles for individual elements of the Icon component */
92
+ styles?: {
93
+ /** Outer Box wrapper element */
94
+ root?: StyleProp<ViewStyle>;
95
+ /** Inner icon glyph Text element */
96
+ icon?: StyleProp<TextStyle>;
97
+ };
98
+ };
99
+ declare const getIconSourceSize: (iconSize: number) => IconSourcePixelSize;
100
+ /**
101
+ * Creates a typed `Icon` component bound to a specific icon set (glyph map,
102
+ * font family, and name union). The default CDS `Icon` is created from this
103
+ * factory; consumers with their own icon package can create their own typed
104
+ * icon component that reuses all of the CDS rendering, accessibility, and
105
+ * theming behavior.
106
+ */
107
+ export declare function createIcon<Name extends string>({
108
+ glyphMap,
109
+ fontFamily,
110
+ getGlyph,
111
+ }: CreateIconConfig<Name>): React.MemoExoticComponent<
112
+ ({
113
+ ref,
114
+ ..._props
115
+ }: IconProps<Name> & {
116
+ ref?: React.Ref<Text>;
117
+ }) =>
118
+ | string
119
+ | number
120
+ | bigint
121
+ | boolean
122
+ | Iterable<React.ReactNode>
123
+ | Promise<
124
+ | string
125
+ | number
126
+ | bigint
127
+ | boolean
128
+ | React.ReactPortal
129
+ | React.ReactElement<unknown, string | React.JSXElementConstructor<any>>
130
+ | Iterable<React.ReactNode>
131
+ | null
132
+ | undefined
133
+ >
134
+ | import('react/jsx-runtime').JSX.Element
135
+ | null
136
+ >;
137
+ export { getIconSourceSize };
138
+ //# sourceMappingURL=createIcon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIcon.d.ts","sourceRoot":"","sources":["../../src/icons/createIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,EACL,QAAQ,EACR,KAAK,SAAS,EACd,IAAI,EACJ,KAAK,SAAS,IAAI,eAAe,EACjC,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AACzF,OAAO,KAAK,EAAE,wBAAwB,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FAMILY } from './createIcon';
3
+ export type { CreateIconConfig, GlyphMap, IconGlyphResolverArgs } from './createIcon';
2
4
  export * from './LogoMark';
3
5
  export * from './LogoWordmark';
4
6
  export * from './SubBrandLogoMark';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/icons/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/icons/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACpE,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtF,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,YAAY,CAAC"}
package/esm/icons/Icon.js CHANGED
@@ -1,90 +1,7 @@
1
- import React, { memo, useMemo } from 'react';
2
- import { Animated, Text, useWindowDimensions } from 'react-native';
3
1
  import { glyphMap } from '@coinbase/cds-icons/glyphMap';
4
- import { isDevelopment } from '@coinbase/cds-utils';
5
- import { useComponentConfig } from '../hooks/useComponentConfig';
6
- import { useTheme } from '../hooks/useTheme';
7
- import { Box } from '../layout/Box';
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- const getIconSourceSize = iconSize => {
10
- if (iconSize <= 12) return 12;
11
- if (iconSize <= 16) return 16;
12
- return 24;
13
- };
14
- export const Icon = /*#__PURE__*/memo(_props => {
15
- const mergedProps = useComponentConfig('Icon', _props);
16
- const {
17
- accessibilityLabel,
18
- accessibilityHint,
19
- animated = false,
20
- color = 'fgPrimary',
21
- dangerouslySetColor,
22
- style,
23
- styles,
24
- fallback = null,
25
- name,
26
- size = 'm',
27
- testID,
28
- padding,
29
- paddingX,
30
- paddingY,
31
- paddingTop,
32
- paddingEnd,
33
- paddingBottom,
34
- paddingStart,
35
- active
36
- } = mergedProps;
37
- const TextComponent = animated ? Animated.Text : Text;
38
- const theme = useTheme();
39
- const {
40
- fontScale
41
- } = useWindowDimensions();
42
-
43
- // Scale according to device a11y font size settings
44
- const iconSize = theme.iconSize[size] * fontScale;
45
- const sourceSize = getIconSourceSize(iconSize);
46
- const iconColor = theme.color[color];
47
- const finalColor = dangerouslySetColor != null ? dangerouslySetColor : iconColor;
48
- const rootStyle = useMemo(() => {
49
- var _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8;
50
- return [{
51
- paddingTop: theme.space[(_ref = (_ref2 = paddingTop != null ? paddingTop : paddingY) != null ? _ref2 : padding) != null ? _ref : 0],
52
- paddingEnd: theme.space[(_ref3 = (_ref4 = paddingEnd != null ? paddingEnd : paddingX) != null ? _ref4 : padding) != null ? _ref3 : 0],
53
- paddingBottom: theme.space[(_ref5 = (_ref6 = paddingBottom != null ? paddingBottom : paddingY) != null ? _ref6 : padding) != null ? _ref5 : 0],
54
- paddingStart: theme.space[(_ref7 = (_ref8 = paddingStart != null ? paddingStart : paddingX) != null ? _ref8 : padding) != null ? _ref7 : 0]
55
- }, style, styles == null ? void 0 : styles.root];
56
- }, [style, theme.space, padding, paddingX, paddingY, paddingTop, paddingEnd, paddingBottom, paddingStart, styles == null ? void 0 : styles.root]);
57
- const iconStyle = useMemo(() => [{
58
- fontFamily: 'CoinbaseIcons',
59
- fontSize: iconSize,
60
- height: iconSize,
61
- width: iconSize,
62
- lineHeight: iconSize,
63
- color: finalColor
64
- }, styles == null ? void 0 : styles.icon], [finalColor, iconSize, styles == null ? void 0 : styles.icon]);
65
- const iconName = name + "-" + sourceSize + "-" + (active ? 'active' : 'inactive');
66
- const glyph = glyphMap[iconName];
67
- if (glyph === undefined) {
68
- if (isDevelopment()) {
69
- console.error("Unable to find glyph for icon name \"" + name + "\" with glyph key \"" + iconName + "\"");
70
- }
71
- return fallback;
72
- }
73
- return /*#__PURE__*/_jsx(Box, {
74
- animated: animated,
75
- style: rootStyle,
76
- testID: testID,
77
- children: /*#__PURE__*/_jsx(TextComponent, {
78
- accessibilityHint: accessibilityHint,
79
- accessibilityLabel: accessibilityLabel,
80
- accessibilityRole: "image",
81
- accessible: !!accessibilityLabel,
82
- allowFontScaling: false
83
- // TODO https://linear.app/coinbase/issue/CDS-1518/audit-potentially-harmful-reactnative-animated-pattern
84
- ,
85
- style: iconStyle,
86
- children: glyph
87
- })
88
- });
2
+ import { createIcon, DEFAULT_ICON_FONT_FAMILY, getIconSourceSize } from './createIcon';
3
+ export const Icon = createIcon({
4
+ glyphMap,
5
+ fontFamily: DEFAULT_ICON_FONT_FAMILY
89
6
  });
90
7
  export { getIconSourceSize };
@@ -0,0 +1,145 @@
1
+ const _excluded = ["ref"];
2
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
3
+ import React, { memo, useMemo } from 'react';
4
+ import { Animated, Text, useWindowDimensions } from 'react-native';
5
+ import { isDevelopment } from '@coinbase/cds-utils';
6
+ import { useComponentConfig } from '../hooks/useComponentConfig';
7
+ import { useTheme } from '../hooks/useTheme';
8
+ import { Box } from '../layout/Box';
9
+
10
+ /** Default font family for the CDS icon glyph font. */
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ export const DEFAULT_ICON_FONT_FAMILY = 'CoinbaseIcons';
13
+
14
+ /**
15
+ * Shape of the glyph map an icon set must provide. Keys are
16
+ * `${name}-${sourcePixelSize}-${'active' | 'inactive'}` and values are the
17
+ * single Unicode character rendered in the icon font.
18
+ */
19
+
20
+ /** Arguments passed to a glyph resolver to look up an icon's glyph. */
21
+
22
+ /** Configuration used to bind an icon set to a typed `Icon` component. */
23
+
24
+ const getIconSourceSize = iconSize => {
25
+ if (iconSize <= 12) return 12;
26
+ if (iconSize <= 16) return 16;
27
+ return 24;
28
+ };
29
+
30
+ /** Default glyph resolver using the CDS `${name}-${sourceSize}-${state}` key scheme. */
31
+ const defaultGetGlyph = _ref => {
32
+ let {
33
+ glyphMap,
34
+ name,
35
+ pixelSize,
36
+ active
37
+ } = _ref;
38
+ const sourceSize = getIconSourceSize(pixelSize);
39
+ const key = name + "-" + sourceSize + "-" + (active ? 'active' : 'inactive');
40
+ return glyphMap[key];
41
+ };
42
+
43
+ /**
44
+ * Creates a typed `Icon` component bound to a specific icon set (glyph map,
45
+ * font family, and name union). The default CDS `Icon` is created from this
46
+ * factory; consumers with their own icon package can create their own typed
47
+ * icon component that reuses all of the CDS rendering, accessibility, and
48
+ * theming behavior.
49
+ */
50
+ export function createIcon(_ref2) {
51
+ let {
52
+ glyphMap,
53
+ fontFamily = DEFAULT_ICON_FONT_FAMILY,
54
+ getGlyph = defaultGetGlyph
55
+ } = _ref2;
56
+ const Icon = /*#__PURE__*/memo(_ref3 => {
57
+ let {
58
+ ref
59
+ } = _ref3,
60
+ _props = _objectWithoutPropertiesLoose(_ref3, _excluded);
61
+ const mergedProps = useComponentConfig('Icon', _props);
62
+ const {
63
+ accessibilityLabel,
64
+ accessibilityHint,
65
+ animated = false,
66
+ color = 'fgPrimary',
67
+ dangerouslySetColor,
68
+ style,
69
+ styles,
70
+ fallback = null,
71
+ name,
72
+ size = 'm',
73
+ testID,
74
+ padding,
75
+ paddingX,
76
+ paddingY,
77
+ paddingTop,
78
+ paddingEnd,
79
+ paddingBottom,
80
+ paddingStart,
81
+ active,
82
+ allowFontScaling = true
83
+ } = mergedProps;
84
+ const TextComponent = animated ? Animated.Text : Text;
85
+ const theme = useTheme();
86
+ const {
87
+ fontScale
88
+ } = useWindowDimensions();
89
+ const iconSize = allowFontScaling ? theme.iconSize[size] * fontScale : theme.iconSize[size];
90
+ const iconColor = theme.color[color];
91
+ const finalColor = dangerouslySetColor != null ? dangerouslySetColor : iconColor;
92
+ const rootStyle = useMemo(() => {
93
+ var _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref0, _ref1;
94
+ return [{
95
+ paddingTop: theme.space[(_ref4 = (_ref5 = paddingTop != null ? paddingTop : paddingY) != null ? _ref5 : padding) != null ? _ref4 : 0],
96
+ paddingEnd: theme.space[(_ref6 = (_ref7 = paddingEnd != null ? paddingEnd : paddingX) != null ? _ref7 : padding) != null ? _ref6 : 0],
97
+ paddingBottom: theme.space[(_ref8 = (_ref9 = paddingBottom != null ? paddingBottom : paddingY) != null ? _ref9 : padding) != null ? _ref8 : 0],
98
+ paddingStart: theme.space[(_ref0 = (_ref1 = paddingStart != null ? paddingStart : paddingX) != null ? _ref1 : padding) != null ? _ref0 : 0]
99
+ }, style, styles == null ? void 0 : styles.root];
100
+ }, [style, theme.space, padding, paddingX, paddingY, paddingTop, paddingEnd, paddingBottom, paddingStart, styles == null ? void 0 : styles.root]);
101
+ const iconStyle = useMemo(() => [{
102
+ fontFamily,
103
+ fontSize: iconSize,
104
+ height: iconSize,
105
+ width: iconSize,
106
+ lineHeight: iconSize,
107
+ color: finalColor
108
+ }, styles == null ? void 0 : styles.icon], [finalColor, iconSize, styles == null ? void 0 : styles.icon]);
109
+ const glyph = getGlyph({
110
+ glyphMap,
111
+ name,
112
+ size,
113
+ pixelSize: iconSize,
114
+ active: Boolean(active)
115
+ });
116
+ if (glyph === undefined) {
117
+ if (isDevelopment()) {
118
+ console.error("Unable to find glyph for icon \"" + name + "\" at size \"" + size + "\"");
119
+ }
120
+ return fallback;
121
+ }
122
+ return /*#__PURE__*/_jsx(Box, {
123
+ animated: animated,
124
+ style: rootStyle,
125
+ testID: testID,
126
+ children: /*#__PURE__*/_jsx(TextComponent, {
127
+ ref: ref,
128
+ accessibilityHint: accessibilityHint,
129
+ accessibilityLabel: accessibilityLabel,
130
+ accessibilityRole: "image",
131
+ accessible: !!accessibilityLabel
132
+ // We do not use the built in scaling because it changes the icon thickness
133
+ ,
134
+ allowFontScaling: false
135
+ // TODO https://linear.app/coinbase/issue/CDS-1518/audit-potentially-harmful-reactnative-animated-pattern
136
+ ,
137
+ style: iconStyle,
138
+ children: glyph
139
+ })
140
+ });
141
+ });
142
+ Icon.displayName = 'Icon';
143
+ return Icon;
144
+ }
145
+ export { getIconSourceSize };
@@ -1,4 +1,5 @@
1
1
  export * from './Icon';
2
+ export { createIcon, DEFAULT_ICON_FONT_FAMILY } from './createIcon';
2
3
  export * from './LogoMark';
3
4
  export * from './LogoWordmark';
4
5
  export * from './SubBrandLogoMark';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coinbase/cds-mobile",
3
- "version": "9.7.2",
3
+ "version": "9.9.0",
4
4
  "description": "Coinbase Design System - Mobile",
5
5
  "repository": {
6
6
  "type": "git",
@@ -218,9 +218,9 @@
218
218
  "react-native-worklets": "0.5.2"
219
219
  },
220
220
  "dependencies": {
221
- "@coinbase/cds-common": "^9.7.2",
221
+ "@coinbase/cds-common": "^9.9.0",
222
222
  "@coinbase/cds-icons": "^5.21.0",
223
- "@coinbase/cds-illustrations": "^4.44.0",
223
+ "@coinbase/cds-illustrations": "^4.45.0",
224
224
  "@coinbase/cds-lottie-files": "^3.3.4",
225
225
  "@coinbase/cds-utils": "^2.3.5",
226
226
  "@floating-ui/react-native": "^0.10.5",