@terreno/ui 0.19.0 → 0.20.1
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/dist/Button.js +3 -1
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +36 -2
- package/dist/Common.js.map +1 -1
- package/dist/Icon.js +6 -0
- package/dist/Icon.js.map +1 -1
- package/dist/IconButton.js +3 -1
- package/dist/IconButton.js.map +1 -1
- package/dist/IconRegistry.d.ts +17 -0
- package/dist/IconRegistry.js +26 -0
- package/dist/IconRegistry.js.map +1 -0
- package/dist/TerrenoProvider.d.ts +7 -0
- package/dist/TerrenoProvider.js +12 -11
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Button.test.tsx +18 -1
- package/src/Button.tsx +7 -1
- package/src/Common.ts +45 -2
- package/src/Icon.test.tsx +23 -1
- package/src/Icon.tsx +8 -0
- package/src/IconButton.test.tsx +23 -1
- package/src/IconButton.tsx +4 -0
- package/src/IconRegistry.test.tsx +104 -0
- package/src/IconRegistry.tsx +41 -0
- package/src/TerrenoProvider.tsx +32 -22
- package/src/index.tsx +1 -0
- package/src/test-utils.tsx +32 -0
package/dist/Button.js
CHANGED
|
@@ -5,6 +5,7 @@ import { PressableOpacity, PressableScale, PressableWithoutFeedback, } from "pre
|
|
|
5
5
|
import { lazy, Suspense, useCallback, useMemo, useState } from "react";
|
|
6
6
|
import { ActivityIndicator, Pressable, Text, View } from "react-native";
|
|
7
7
|
import { Box } from "./Box";
|
|
8
|
+
import { useCustomIcon } from "./IconRegistry";
|
|
8
9
|
import { isMobileDevice } from "./MediaQuery";
|
|
9
10
|
import { useTheme } from "./Theme";
|
|
10
11
|
import { Tooltip } from "./Tooltip";
|
|
@@ -22,6 +23,7 @@ const ButtonComponent = ({ confirmationText = "Are you sure you want to continue
|
|
|
22
23
|
const [loading, setLoading] = useState(propsLoading);
|
|
23
24
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
24
25
|
const { theme } = useTheme();
|
|
26
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
25
27
|
const { backgroundColor, borderColor, borderWidth, color } = useMemo(() => {
|
|
26
28
|
if (!theme) {
|
|
27
29
|
return {};
|
|
@@ -99,7 +101,7 @@ const ButtonComponent = ({ confirmationText = "Are you sure you want to continue
|
|
|
99
101
|
alignSelf: "center",
|
|
100
102
|
marginLeft: iconPosition === "right" ? 8 : 0,
|
|
101
103
|
marginRight: iconPosition === "left" ? 8 : 0,
|
|
102
|
-
}, children: _jsx(FontAwesome6, { color: color, name: iconName, size: 16, solid: true }) })), _jsx(Text, { style: { color, fontSize: 16, fontWeight: "700" }, children: text })] }), Boolean(loading) && (_jsx(Box, { marginLeft: 2, children: _jsx(ActivityIndicator, { color: color, size: "small" }) }))] }), withConfirmation && showConfirmation && (_jsx(Suspense, { fallback: null, children: _jsx(LazyModal, { onDismiss: () => setShowConfirmation(false), primaryButtonOnClick: async () => {
|
|
104
|
+
}, children: CustomIcon ? (_jsx(CustomIcon, { color: color !== null && color !== void 0 ? color : theme.text.inverted, size: 16 })) : (_jsx(FontAwesome6, { color: color, name: iconName, size: 16, solid: true })) })), _jsx(Text, { style: { color, fontSize: 16, fontWeight: "700" }, children: text })] }), Boolean(loading) && (_jsx(Box, { marginLeft: 2, children: _jsx(ActivityIndicator, { color: color, size: "small" }) }))] }), withConfirmation && showConfirmation && (_jsx(Suspense, { fallback: null, children: _jsx(LazyModal, { onDismiss: () => setShowConfirmation(false), primaryButtonOnClick: async () => {
|
|
103
105
|
await onClick();
|
|
104
106
|
setShowConfirmation(false);
|
|
105
107
|
}, primaryButtonText: "Confirm", secondaryButtonOnClick: () => setShowConfirmation(false), secondaryButtonText: "Cancel", subtitle: modalSubTitle, text: confirmationText, title: modalTitle, visible: showConfirmation }) }))] })));
|
package/dist/Button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
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K,KAAK,EAAI,CAAC;AACxC,CAAC,CAAC"}
|
package/dist/Common.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CountryCode } from "libphonenumber-js";
|
|
2
2
|
import type React from "react";
|
|
3
|
-
import type { ReactElement, ReactNode } from "react";
|
|
3
|
+
import type { FC, ReactElement, ReactNode } from "react";
|
|
4
4
|
import type { ImageStyle, ListRenderItemInfo, ScrollView, StyleProp, TextInput, TextStyle, ViewStyle } from "react-native";
|
|
5
5
|
import type { DimensionValue } from "react-native/Libraries/StyleSheet/StyleSheetTypes";
|
|
6
6
|
import type { Styles } from "react-native-google-places-autocomplete";
|
|
@@ -293,7 +293,41 @@ export interface TerrenoThemeConfig {
|
|
|
293
293
|
}
|
|
294
294
|
export type Direction = "up" | "right" | "down" | "left";
|
|
295
295
|
export type OnChangeCallback = (result: string) => void;
|
|
296
|
-
|
|
296
|
+
/**
|
|
297
|
+
* Augmentable registry of custom icon names. Downstream consumers extend this
|
|
298
|
+
* interface via TypeScript declaration merging to register their own icons and
|
|
299
|
+
* get type-safe, autocompleted names everywhere an `iconName` is accepted.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* declare module "@terreno/ui" {
|
|
304
|
+
* interface CustomIconRegistry {
|
|
305
|
+
* brandLogo: true;
|
|
306
|
+
* sparkle: true;
|
|
307
|
+
* }
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
export interface CustomIconRegistry {
|
|
312
|
+
}
|
|
313
|
+
/** The set of custom icon names registered via {@link CustomIconRegistry}. */
|
|
314
|
+
export type CustomIconName = keyof CustomIconRegistry & string;
|
|
315
|
+
export type IconName = FontAwesome6SolidNames | FontAwesome6BrandNames | FontAwesome6RegularNames | CustomIconName;
|
|
316
|
+
/** Props passed to a custom icon component when it is rendered. */
|
|
317
|
+
export interface CustomIconProps {
|
|
318
|
+
/** Resolved color string, already mapped from the active theme. */
|
|
319
|
+
color: string;
|
|
320
|
+
/** Resolved icon size in pixels. */
|
|
321
|
+
size: number;
|
|
322
|
+
testID?: string;
|
|
323
|
+
}
|
|
324
|
+
/** A component that renders a custom (non-FontAwesome) icon. */
|
|
325
|
+
export type CustomIconComponent = FC<CustomIconProps>;
|
|
326
|
+
/**
|
|
327
|
+
* Map of custom icon name to the component that renders it. Provided to
|
|
328
|
+
* `TerrenoProvider` via the `icons` prop to register custom icons.
|
|
329
|
+
*/
|
|
330
|
+
export type IconRegistryMap = Record<string, CustomIconComponent>;
|
|
297
331
|
export type AlignContent = "start" | "end" | "center" | "between" | "around" | "stretch";
|
|
298
332
|
export type AlignSelf = "auto" | "start" | "end" | "center" | "baseline" | "stretch";
|
|
299
333
|
export type AlignItems = "start" | "end" | "center" | "baseline" | "stretch";
|
package/dist/Common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../src/Common.ts"],"names":[],"mappings":"AAwaA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,CAAC,EAAE,EAAE;IACL,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAqB,EAAE,EAAE;IAClD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,WAAW,CAAC,OAAyB,CAAC,CAAC;AAChD,CAAC,CAAC;AAqBF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAe,EAAE,EAAE;IAClD,OAAO;QACL,KAAK,EAAE,EAAE;QACT,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,EAAE;QACN,EAAE,EAAE,CAAC;KACN,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;AAClB,CAAC,CAAC;AAsTF,MAAM,YAAY,GAAG;IACnB,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;IACV,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,EAAE;IACR,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,CAAC;IACL,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,GAAG;IACZ,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,EAAE;CACP,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAkB,EAAE,EAAE;IAChD,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC,CAAC;AA4pEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;CACV,CAAC"}
|
package/dist/Icon.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import FontAwesome6 from "@expo/vector-icons/FontAwesome6";
|
|
3
3
|
import { iconSizeToNumber } from "./Common";
|
|
4
|
+
import { useCustomIcon } from "./IconRegistry";
|
|
4
5
|
import { useTheme } from "./Theme";
|
|
5
6
|
export const Icon = ({ color = "primary", size = "md", iconName, type = "solid", testID, }) => {
|
|
6
7
|
var _a;
|
|
7
8
|
const { theme } = useTheme();
|
|
9
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
8
10
|
const iconColor = (_a = theme.text[color]) !== null && _a !== void 0 ? _a : color;
|
|
9
11
|
const iconSize = iconSizeToNumber(size);
|
|
12
|
+
// A registered custom icon takes precedence over the FontAwesome glyph set.
|
|
13
|
+
if (CustomIcon) {
|
|
14
|
+
return _jsx(CustomIcon, { color: iconColor, size: iconSize, testID: testID });
|
|
15
|
+
}
|
|
10
16
|
return (_jsx(FontAwesome6, { brand: type === "brand", color: iconColor, duotone: type === "duotone", light: type === "light" || type === "sharpLight", name: iconName, regular: type === "regular", selectable: undefined, sharp: type === "sharp", size: iconSize, solid: type === "solid" || type === "sharpSolid", testID: testID, thin: type === "thin" }));
|
|
11
17
|
};
|
|
12
18
|
//# sourceMappingURL=Icon.js.map
|
package/dist/Icon.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","sourceRoot":"","sources":["../src/Icon.tsx"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,iCAAiC,CAAC;AAG3D,OAAO,EAAiB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAEjC,MAAM,CAAC,MAAM,IAAI,GAAkB,CAAC,EAClC,KAAK,GAAG,SAAS,EACjB,IAAI,GAAG,IAAI,EACX,QAAQ,EACR,IAAI,GAAG,OAAO,EACd,MAAM,GACP,EAAE,EAAE;;IACH,MAAM,EAAC,KAAK,EAAC,GAAG,QAAQ,EAAE,CAAC;IAC3B,MAAM,SAAS,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,mCAAI,KAAK,CAAC;IAC7C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Icon.js","sourceRoot":"","sources":["../src/Icon.tsx"],"names":[],"mappings":";AAAA,OAAO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,CAAC,CAAC"}
|
package/dist/IconButton.js
CHANGED
|
@@ -3,6 +3,7 @@ import FontAwesome6 from "@expo/vector-icons/FontAwesome6";
|
|
|
3
3
|
import debounce from "lodash/debounce";
|
|
4
4
|
import { useState } from "react";
|
|
5
5
|
import { ActivityIndicator, Text as NativeText, Pressable, View } from "react-native";
|
|
6
|
+
import { useCustomIcon } from "./IconRegistry";
|
|
6
7
|
import { isMobileDevice } from "./MediaQuery";
|
|
7
8
|
import { Modal } from "./Modal";
|
|
8
9
|
import { Text } from "./Text";
|
|
@@ -17,6 +18,7 @@ const IconButtonComponent = ({ accessibilityHint, accessibilityLabel, confirmati
|
|
|
17
18
|
const [loading, setLoading] = useState(propsLoading);
|
|
18
19
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
19
20
|
const { theme } = useTheme();
|
|
21
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
20
22
|
let accessLabel = accessibilityLabel;
|
|
21
23
|
if (tooltipText && accessibilityLabel === "") {
|
|
22
24
|
accessLabel = tooltipText;
|
|
@@ -77,7 +79,7 @@ const IconButtonComponent = ({ accessibilityHint, accessibilityLabel, confirmati
|
|
|
77
79
|
height: 32,
|
|
78
80
|
justifyContent: "center",
|
|
79
81
|
width: 32,
|
|
80
|
-
}, testID: testID, children: [loading ? (_jsx(ActivityIndicator, { color: color, size: "small" })) : (_jsx(FontAwesome6, { color: color, name: iconName, selectable: undefined, size: variant === "navigation" ? 20 : 16, solid: true })), Boolean(indicator) && (_jsx(View, { style: {
|
|
82
|
+
}, testID: testID, children: [loading ? (_jsx(ActivityIndicator, { color: color, size: "small" })) : CustomIcon ? (_jsx(CustomIcon, { color: color, size: variant === "navigation" ? 20 : 16 })) : (_jsx(FontAwesome6, { color: color, name: iconName, selectable: undefined, size: variant === "navigation" ? 20 : 16, solid: true })), Boolean(indicator) && (_jsx(View, { style: {
|
|
81
83
|
alignItems: "center",
|
|
82
84
|
backgroundColor: indicatorColor,
|
|
83
85
|
borderRadius: 10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C,iBAAiB,IAChB,QAAQ,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAC1C,SAAS,EAAE,KAAK,IAAI,EAAE;oBACpB,MAAM,OAAO,EAAE,CAAC;oBAChB,mBAAmB,CAAC,KAAK,CAAC,CAAC;gBAC7B,CAAC,EACD,QAAQ,EAAE,SAAS,EACnB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,gBAAgB,GACzB,CACH,IACS,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAwB,CAAC,KAAK,EAAE,EAAE;IACvD,MAAM,EAAC,WAAW,EAAE,oBAAoB,EAAE,mBAAmB,GAAG,KAAK,EAAC,GAAG,KAAK,CAAC;IAC/E,MAAM,gBAAgB,GAAG,cAAc,EAAE,IAAI,QAAQ,EAAE,CAAC;IAExD,IAAI,WAAW,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,OAAO,CACL,KAAC,OAAO,IACN,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,mBAAmB,EACjC,IAAI,EAAE,WAAW,YAEjB,KAAC,mBAAmB,oBAAK,KAAK,EAAI,GAC1B,CACX,CAAC;IACJ,CAAC;IAED,OAAO,KAAC,mBAAmB,oBAAK,KAAK,EAAI,CAAC;AAC5C,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type FC, type ReactNode } from "react";
|
|
2
|
+
import type { CustomIconComponent, IconName, IconRegistryMap } from "./Common";
|
|
3
|
+
interface IconRegistryProviderProps {
|
|
4
|
+
/** Map of custom icon name to the component that renders it. */
|
|
5
|
+
icons?: IconRegistryMap;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare const IconRegistryProvider: FC<IconRegistryProviderProps>;
|
|
9
|
+
/** Returns the full map of registered custom icons. */
|
|
10
|
+
export declare const useIconRegistry: () => IconRegistryMap;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the registered custom icon component for the given name, or undefined
|
|
13
|
+
* when the name is not a registered custom icon (in which case callers should
|
|
14
|
+
* fall through to rendering a FontAwesome icon).
|
|
15
|
+
*/
|
|
16
|
+
export declare const useCustomIcon: (iconName?: IconName) => CustomIconComponent | undefined;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
// Stable empty registry so consumers that don't register icons don't trigger
|
|
4
|
+
// unnecessary context re-renders.
|
|
5
|
+
const EMPTY_REGISTRY = {};
|
|
6
|
+
const IconRegistryContext = createContext(EMPTY_REGISTRY);
|
|
7
|
+
export const IconRegistryProvider = ({ icons, children }) => {
|
|
8
|
+
return (_jsx(IconRegistryContext.Provider, { value: icons !== null && icons !== void 0 ? icons : EMPTY_REGISTRY, children: children }));
|
|
9
|
+
};
|
|
10
|
+
/** Returns the full map of registered custom icons. */
|
|
11
|
+
export const useIconRegistry = () => {
|
|
12
|
+
return useContext(IconRegistryContext);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns the registered custom icon component for the given name, or undefined
|
|
16
|
+
* when the name is not a registered custom icon (in which case callers should
|
|
17
|
+
* fall through to rendering a FontAwesome icon).
|
|
18
|
+
*/
|
|
19
|
+
export const useCustomIcon = (iconName) => {
|
|
20
|
+
const registry = useContext(IconRegistryContext);
|
|
21
|
+
if (!iconName) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return registry[iconName];
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=IconRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IconRegistry.js","sourceRoot":"","sources":["../src/IconRegistry.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAA2B,UAAU,EAAC,MAAM,OAAO,CAAC;AAIzE,6EAA6E;AAC7E,kCAAkC;AAClC,MAAM,cAAc,GAAoB,EAAE,CAAC;AAE3C,MAAM,mBAAmB,GAAG,aAAa,CAAkB,cAAc,CAAC,CAAC;AAQ3E,MAAM,CAAC,MAAM,oBAAoB,GAAkC,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAC,EAAE,EAAE;IACvF,OAAO,CACL,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,cAAc,YACzD,QAAQ,GACoB,CAChC,CAAC;AACJ,CAAC,CAAC;AAEF,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,GAAoB,EAAE;IACnD,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAmB,EAAmC,EAAE;IACpF,MAAM,QAAQ,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACjD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5B,CAAC,CAAC"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
import type { FC } from "react";
|
|
3
|
+
import type { IconRegistryMap } from "./Common";
|
|
3
4
|
export declare const TerrenoProvider: FC<{
|
|
4
5
|
children: React.ReactNode;
|
|
5
6
|
openAPISpecUrl?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Custom icons to register, keyed by icon name. Registered names take
|
|
9
|
+
* precedence over FontAwesome glyphs and are usable anywhere an `iconName`
|
|
10
|
+
* is accepted (Icon, Button, IconButton, fields, etc.).
|
|
11
|
+
*/
|
|
12
|
+
icons?: IconRegistryMap;
|
|
6
13
|
}>;
|
package/dist/TerrenoProvider.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Host } from "react-native-portalize";
|
|
3
|
+
import { IconRegistryProvider } from "./IconRegistry";
|
|
3
4
|
import { OpenAPIProvider } from "./OpenAPIContext";
|
|
4
5
|
import { ThemeProvider } from "./Theme";
|
|
5
6
|
import { Toast } from "./Toast";
|
|
6
7
|
import { ToastProvider } from "./ToastNotifications";
|
|
7
|
-
export const TerrenoProvider = ({ children, openAPISpecUrl }) => {
|
|
8
|
-
return (_jsx(ThemeProvider, { children: _jsx(ToastProvider, { animationDuration: 250, animationType: "slide-in", duration: 50000, offset: 50, placement: "bottom", renderToast: (toastOptions) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
export const TerrenoProvider = ({ children, openAPISpecUrl, icons }) => {
|
|
9
|
+
return (_jsx(ThemeProvider, { children: _jsx(IconRegistryProvider, { icons: icons, children: _jsx(ToastProvider, { animationDuration: 250, animationType: "slide-in", duration: 50000, offset: 50, placement: "bottom", renderToast: (toastOptions) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const dataOnDismiss = (_a = toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.data) === null || _a === void 0 ? void 0 : _a.onDismiss;
|
|
12
|
+
const providerOnHide = toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.onHide;
|
|
13
|
+
const handleDismiss = () => {
|
|
14
|
+
dataOnDismiss === null || dataOnDismiss === void 0 ? void 0 : dataOnDismiss();
|
|
15
|
+
providerOnHide === null || providerOnHide === void 0 ? void 0 : providerOnHide();
|
|
16
|
+
};
|
|
17
|
+
return _jsx(Toast, Object.assign({}, toastOptions === null || toastOptions === void 0 ? void 0 : toastOptions.data, { onDismiss: handleDismiss }));
|
|
18
|
+
}, swipeEnabled: true, children: _jsx(OpenAPIProvider, { specUrl: openAPISpecUrl, children: _jsx(Host, { children: children }) }) }) }) }));
|
|
18
19
|
};
|
|
19
20
|
//# sourceMappingURL=TerrenoProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TerrenoProvider.js","sourceRoot":"","sources":["../src/TerrenoProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"TerrenoProvider.js","sourceRoot":"","sources":["../src/TerrenoProvider.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAG5C,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAEnD,MAAM,CAAC,MAAM,eAAe,GASvB,CAAC,EAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAC,EAAE,EAAE;IACzC,OAAO,CACL,KAAC,aAAa,cACZ,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,YAChC,KAAC,aAAa,IACZ,iBAAiB,EAAE,GAAG,EACtB,aAAa,EAAC,UAAU,EACxB,QAAQ,EAAE,KAAK,EACf,MAAM,EAAE,EAAE,EACV,SAAS,EAAC,QAAQ,EAClB,WAAW,EAAE,CAAC,YAAY,EAAE,EAAE;;oBAC5B,MAAM,aAAa,GAAG,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,0CAAE,SAAS,CAAC;oBACpD,MAAM,cAAc,GAAG,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,CAAC;oBAC5C,MAAM,aAAa,GAAG,GAAG,EAAE;wBACzB,aAAa,aAAb,aAAa,uBAAb,aAAa,EAAI,CAAC;wBAClB,cAAc,aAAd,cAAc,uBAAd,cAAc,EAAI,CAAC;oBACrB,CAAC,CAAC;oBAEF,OAAO,KAAC,KAAK,oBAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,IAAI,IAAE,SAAS,EAAE,aAAa,IAAI,CAAC;gBACrE,CAAC,EACD,YAAY,kBAEZ,KAAC,eAAe,IAAC,OAAO,EAAE,cAAc,YACtC,KAAC,IAAI,cAAE,QAAQ,GAAQ,GACP,GACJ,GACK,GACT,CACjB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from "./HeightActionSheet";
|
|
|
41
41
|
export * from "./HeightField";
|
|
42
42
|
export * from "./Icon";
|
|
43
43
|
export * from "./IconButton";
|
|
44
|
+
export * from "./IconRegistry";
|
|
44
45
|
export * from "./Image";
|
|
45
46
|
export * from "./ImageBackground";
|
|
46
47
|
export * from "./InfoModalIcon";
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ export * from "./HeightActionSheet";
|
|
|
40
40
|
export * from "./HeightField";
|
|
41
41
|
export * from "./Icon";
|
|
42
42
|
export * from "./IconButton";
|
|
43
|
+
export * from "./IconRegistry";
|
|
43
44
|
export * from "./Image";
|
|
44
45
|
export * from "./ImageBackground";
|
|
45
46
|
export * from "./InfoModalIcon";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,cAAc,QAAQ,CAAC;A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5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|
package/package.json
CHANGED
package/src/Button.test.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import {describe, expect, it, mock} from "bun:test";
|
|
|
2
2
|
import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
|
|
3
3
|
|
|
4
4
|
import {Button} from "./Button";
|
|
5
|
-
import {renderWithTheme} from "./test-utils";
|
|
5
|
+
import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
|
|
6
6
|
|
|
7
7
|
describe("Button", () => {
|
|
8
8
|
it("renders correctly with default props", () => {
|
|
@@ -295,4 +295,21 @@ describe("Button", () => {
|
|
|
295
295
|
);
|
|
296
296
|
expect(toJSON()).toMatchSnapshot();
|
|
297
297
|
});
|
|
298
|
+
|
|
299
|
+
describe("custom icons", () => {
|
|
300
|
+
it("renders a registered custom icon by name", () => {
|
|
301
|
+
const {queryByTestId} = renderWithIcons(
|
|
302
|
+
<Button iconName="testCustomIcon" onClick={() => {}} text="Custom" />
|
|
303
|
+
);
|
|
304
|
+
expect(queryByTestId(TEST_CUSTOM_ICON_TEST_ID)).not.toBeNull();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("renders a FontAwesome icon (not the custom one) for unregistered names", () => {
|
|
308
|
+
const {queryByTestId, getByText} = renderWithIcons(
|
|
309
|
+
<Button iconName="check" onClick={() => {}} text="FontAwesome" />
|
|
310
|
+
);
|
|
311
|
+
expect(queryByTestId(TEST_CUSTOM_ICON_TEST_ID)).toBeNull();
|
|
312
|
+
expect(getByText("FontAwesome")).toBeTruthy();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
298
315
|
});
|
package/src/Button.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {ActivityIndicator, Pressable, type PressableProps, Text, View} from "rea
|
|
|
12
12
|
|
|
13
13
|
import {Box} from "./Box";
|
|
14
14
|
import type {ButtonPressAnimation, ButtonProps} from "./Common";
|
|
15
|
+
import {useCustomIcon} from "./IconRegistry";
|
|
15
16
|
import {isMobileDevice} from "./MediaQuery";
|
|
16
17
|
import {useTheme} from "./Theme";
|
|
17
18
|
import {Tooltip} from "./Tooltip";
|
|
@@ -53,6 +54,7 @@ const ButtonComponent: React.FC<ButtonProps> = ({
|
|
|
53
54
|
const [loading, setLoading] = useState(propsLoading);
|
|
54
55
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
55
56
|
const {theme} = useTheme();
|
|
57
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
56
58
|
|
|
57
59
|
const {backgroundColor, borderColor, borderWidth, color} = useMemo(() => {
|
|
58
60
|
if (!theme) {
|
|
@@ -157,7 +159,11 @@ const ButtonComponent: React.FC<ButtonProps> = ({
|
|
|
157
159
|
marginRight: iconPosition === "left" ? 8 : 0,
|
|
158
160
|
}}
|
|
159
161
|
>
|
|
160
|
-
|
|
162
|
+
{CustomIcon ? (
|
|
163
|
+
<CustomIcon color={color ?? theme.text.inverted} size={16} />
|
|
164
|
+
) : (
|
|
165
|
+
<FontAwesome6 color={color} name={iconName} size={16} solid />
|
|
166
|
+
)}
|
|
161
167
|
</View>
|
|
162
168
|
)}
|
|
163
169
|
<Text style={{color, fontSize: 16, fontWeight: "700"}}>{text}</Text>
|
package/src/Common.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {CountryCode} from "libphonenumber-js";
|
|
2
2
|
import type React from "react";
|
|
3
|
-
import type {ReactElement, ReactNode} from "react";
|
|
3
|
+
import type {FC, ReactElement, ReactNode} from "react";
|
|
4
4
|
import type {
|
|
5
5
|
ImageStyle,
|
|
6
6
|
ListRenderItemInfo,
|
|
@@ -355,8 +355,51 @@ export type Direction = "up" | "right" | "down" | "left";
|
|
|
355
355
|
|
|
356
356
|
export type OnChangeCallback = (result: string) => void;
|
|
357
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Augmentable registry of custom icon names. Downstream consumers extend this
|
|
360
|
+
* interface via TypeScript declaration merging to register their own icons and
|
|
361
|
+
* get type-safe, autocompleted names everywhere an `iconName` is accepted.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```typescript
|
|
365
|
+
* declare module "@terreno/ui" {
|
|
366
|
+
* interface CustomIconRegistry {
|
|
367
|
+
* brandLogo: true;
|
|
368
|
+
* sparkle: true;
|
|
369
|
+
* }
|
|
370
|
+
* }
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
// biome-ignore lint/suspicious/noEmptyInterface: Intentionally empty so consumers can augment it via declaration merging.
|
|
374
|
+
export interface CustomIconRegistry {}
|
|
375
|
+
|
|
376
|
+
/** The set of custom icon names registered via {@link CustomIconRegistry}. */
|
|
377
|
+
export type CustomIconName = keyof CustomIconRegistry & string;
|
|
378
|
+
|
|
358
379
|
// Update if we start supporting more icon packs from Expo Icons.
|
|
359
|
-
export type IconName =
|
|
380
|
+
export type IconName =
|
|
381
|
+
| FontAwesome6SolidNames
|
|
382
|
+
| FontAwesome6BrandNames
|
|
383
|
+
| FontAwesome6RegularNames
|
|
384
|
+
| CustomIconName;
|
|
385
|
+
|
|
386
|
+
/** Props passed to a custom icon component when it is rendered. */
|
|
387
|
+
export interface CustomIconProps {
|
|
388
|
+
/** Resolved color string, already mapped from the active theme. */
|
|
389
|
+
color: string;
|
|
390
|
+
/** Resolved icon size in pixels. */
|
|
391
|
+
size: number;
|
|
392
|
+
testID?: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** A component that renders a custom (non-FontAwesome) icon. */
|
|
396
|
+
export type CustomIconComponent = FC<CustomIconProps>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Map of custom icon name to the component that renders it. Provided to
|
|
400
|
+
* `TerrenoProvider` via the `icons` prop to register custom icons.
|
|
401
|
+
*/
|
|
402
|
+
export type IconRegistryMap = Record<string, CustomIconComponent>;
|
|
360
403
|
|
|
361
404
|
export type AlignContent = "start" | "end" | "center" | "between" | "around" | "stretch";
|
|
362
405
|
export type AlignSelf = "auto" | "start" | "end" | "center" | "baseline" | "stretch";
|
package/src/Icon.test.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
|
|
3
3
|
import {Icon} from "./Icon";
|
|
4
|
-
import {renderWithTheme} from "./test-utils";
|
|
4
|
+
import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
|
|
5
5
|
|
|
6
6
|
describe("Icon", () => {
|
|
7
7
|
it("renders correctly with default props", () => {
|
|
@@ -58,4 +58,26 @@ describe("Icon", () => {
|
|
|
58
58
|
expect(toJSON()).toMatchSnapshot();
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
describe("custom icons", () => {
|
|
63
|
+
it("renders a registered custom icon by name", () => {
|
|
64
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="testCustomIcon" />);
|
|
65
|
+
expect(queryByTestId(TEST_CUSTOM_ICON_TEST_ID)).not.toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("falls back to FontAwesome for unregistered names", () => {
|
|
69
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="check" />);
|
|
70
|
+
expect(queryByTestId(TEST_CUSTOM_ICON_TEST_ID)).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("passes the resolved pixel size to the custom icon", () => {
|
|
74
|
+
const {getByTestId} = renderWithIcons(<Icon iconName="testCustomIcon" size="lg" />);
|
|
75
|
+
expect(getByTestId(TEST_CUSTOM_ICON_TEST_ID).props.accessibilityLabel).toBe("size:20");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("forwards testID to the custom icon", () => {
|
|
79
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="testCustomIcon" testID="my-icon" />);
|
|
80
|
+
expect(queryByTestId("my-icon")).not.toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
61
83
|
});
|
package/src/Icon.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import FontAwesome6 from "@expo/vector-icons/FontAwesome6";
|
|
|
2
2
|
import type {FC} from "react";
|
|
3
3
|
|
|
4
4
|
import {type IconProps, iconSizeToNumber} from "./Common";
|
|
5
|
+
import {useCustomIcon} from "./IconRegistry";
|
|
5
6
|
import {useTheme} from "./Theme";
|
|
6
7
|
|
|
7
8
|
export const Icon: FC<IconProps> = ({
|
|
@@ -12,8 +13,15 @@ export const Icon: FC<IconProps> = ({
|
|
|
12
13
|
testID,
|
|
13
14
|
}) => {
|
|
14
15
|
const {theme} = useTheme();
|
|
16
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
15
17
|
const iconColor = theme.text[color] ?? color;
|
|
16
18
|
const iconSize = iconSizeToNumber(size);
|
|
19
|
+
|
|
20
|
+
// A registered custom icon takes precedence over the FontAwesome glyph set.
|
|
21
|
+
if (CustomIcon) {
|
|
22
|
+
return <CustomIcon color={iconColor} size={iconSize} testID={testID} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
return (
|
|
18
26
|
<FontAwesome6
|
|
19
27
|
brand={type === "brand"}
|
package/src/IconButton.test.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
2
|
|
|
3
3
|
import {IconButton} from "./IconButton";
|
|
4
|
-
import {renderWithTheme} from "./test-utils";
|
|
4
|
+
import {renderWithIcons, renderWithTheme} from "./test-utils";
|
|
5
5
|
|
|
6
6
|
describe("IconButton", () => {
|
|
7
7
|
it("renders correctly with default props", () => {
|
|
@@ -142,4 +142,26 @@ describe("IconButton", () => {
|
|
|
142
142
|
);
|
|
143
143
|
expect(toJSON()).toMatchSnapshot();
|
|
144
144
|
});
|
|
145
|
+
|
|
146
|
+
describe("custom icons", () => {
|
|
147
|
+
// IconButton renders `null` under the bun/react-test-renderer harness (all of
|
|
148
|
+
// its snapshots are null), so we verify the custom-icon code path renders
|
|
149
|
+
// without throwing rather than asserting on rendered output. The registry
|
|
150
|
+
// resolution itself is covered in IconRegistry.test.tsx via useCustomIcon.
|
|
151
|
+
it("accepts a registered custom icon name without throwing", () => {
|
|
152
|
+
expect(() =>
|
|
153
|
+
renderWithIcons(
|
|
154
|
+
<IconButton accessibilityLabel="Custom" iconName="testCustomIcon" onClick={() => {}} />
|
|
155
|
+
)
|
|
156
|
+
).not.toThrow();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("accepts an unregistered (FontAwesome) icon name without throwing", () => {
|
|
160
|
+
expect(() =>
|
|
161
|
+
renderWithIcons(
|
|
162
|
+
<IconButton accessibilityLabel="Check" iconName="check" onClick={() => {}} />
|
|
163
|
+
)
|
|
164
|
+
).not.toThrow();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
145
167
|
});
|
package/src/IconButton.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import {type FC, useState} from "react";
|
|
|
4
4
|
import {ActivityIndicator, Text as NativeText, Pressable, View} from "react-native";
|
|
5
5
|
|
|
6
6
|
import type {IconButtonProps} from "./Common";
|
|
7
|
+
import {useCustomIcon} from "./IconRegistry";
|
|
7
8
|
import {isMobileDevice} from "./MediaQuery";
|
|
8
9
|
import {Modal} from "./Modal";
|
|
9
10
|
import {Text} from "./Text";
|
|
@@ -64,6 +65,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
64
65
|
const [loading, setLoading] = useState(propsLoading);
|
|
65
66
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
66
67
|
const {theme} = useTheme();
|
|
68
|
+
const CustomIcon = useCustomIcon(iconName);
|
|
67
69
|
let accessLabel = accessibilityLabel;
|
|
68
70
|
if (tooltipText && accessibilityLabel === "") {
|
|
69
71
|
accessLabel = tooltipText;
|
|
@@ -140,6 +142,8 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
140
142
|
>
|
|
141
143
|
{loading ? (
|
|
142
144
|
<ActivityIndicator color={color} size="small" />
|
|
145
|
+
) : CustomIcon ? (
|
|
146
|
+
<CustomIcon color={color} size={variant === "navigation" ? 20 : 16} />
|
|
143
147
|
) : (
|
|
144
148
|
<FontAwesome6
|
|
145
149
|
color={color}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, it} from "bun:test";
|
|
2
|
+
import {render, renderHook} from "@testing-library/react-native";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import type {FC} from "react";
|
|
5
|
+
import {View} from "react-native";
|
|
6
|
+
|
|
7
|
+
import {Button} from "./Button";
|
|
8
|
+
import type {CustomIconProps, IconRegistryMap} from "./Common";
|
|
9
|
+
import {Icon} from "./Icon";
|
|
10
|
+
import {IconButton} from "./IconButton";
|
|
11
|
+
import {IconRegistryProvider, useCustomIcon} from "./IconRegistry";
|
|
12
|
+
import {ThemeProvider} from "./Theme";
|
|
13
|
+
|
|
14
|
+
// Register a custom icon name so it type-checks anywhere an `iconName` is accepted.
|
|
15
|
+
declare module "./Common" {
|
|
16
|
+
interface CustomIconRegistry {
|
|
17
|
+
customStar: true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let lastProps: CustomIconProps | undefined;
|
|
22
|
+
|
|
23
|
+
const CustomStar: FC<CustomIconProps> = (props) => {
|
|
24
|
+
lastProps = props;
|
|
25
|
+
return <View testID="custom-star" />;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ICONS: IconRegistryMap = {customStar: CustomStar};
|
|
29
|
+
|
|
30
|
+
const renderWithIcons = (ui: React.ReactElement, icons: IconRegistryMap = ICONS) => {
|
|
31
|
+
return render(ui, {
|
|
32
|
+
wrapper: ({children}: {children: React.ReactNode}) => (
|
|
33
|
+
<ThemeProvider>
|
|
34
|
+
<IconRegistryProvider icons={icons}>{children}</IconRegistryProvider>
|
|
35
|
+
</ThemeProvider>
|
|
36
|
+
),
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe("IconRegistry", () => {
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
lastProps = undefined;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renders a registered custom icon by name", () => {
|
|
46
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="customStar" />);
|
|
47
|
+
expect(queryByTestId("custom-star")).not.toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("falls back to FontAwesome for unregistered names", () => {
|
|
51
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="check" />);
|
|
52
|
+
expect(queryByTestId("custom-star")).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("passes resolved size and a color string to the custom icon", () => {
|
|
56
|
+
renderWithIcons(<Icon iconName="customStar" size="lg" />);
|
|
57
|
+
expect(lastProps?.size).toBe(20);
|
|
58
|
+
expect(typeof lastProps?.color).toBe("string");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("forwards testID to the custom icon", () => {
|
|
62
|
+
renderWithIcons(<Icon iconName="customStar" testID="my-icon" />);
|
|
63
|
+
expect(lastProps?.testID).toBe("my-icon");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("renders nothing custom when no icons are registered", () => {
|
|
67
|
+
const {queryByTestId} = renderWithIcons(<Icon iconName="check" />, {});
|
|
68
|
+
expect(queryByTestId("custom-star")).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("renders a custom icon inside a Button", () => {
|
|
72
|
+
const {queryByTestId} = renderWithIcons(
|
|
73
|
+
<Button iconName="customStar" onClick={() => {}} text="Starred" />
|
|
74
|
+
);
|
|
75
|
+
expect(queryByTestId("custom-star")).not.toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// IconButton renders `null` under the bun/react-test-renderer harness (all of
|
|
79
|
+
// its existing snapshots are null), so we verify its wiring via the shared
|
|
80
|
+
// `useCustomIcon` hook plus a no-throw render rather than rendered output.
|
|
81
|
+
it("renders an IconButton with a custom icon without throwing", () => {
|
|
82
|
+
expect(() =>
|
|
83
|
+
renderWithIcons(
|
|
84
|
+
<IconButton accessibilityLabel="star" iconName="customStar" onClick={() => {}} />
|
|
85
|
+
)
|
|
86
|
+
).not.toThrow();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("useCustomIcon resolves registered names and ignores everything else", () => {
|
|
90
|
+
const wrapper = ({children}: {children: React.ReactNode}) => (
|
|
91
|
+
<ThemeProvider>
|
|
92
|
+
<IconRegistryProvider icons={ICONS}>{children}</IconRegistryProvider>
|
|
93
|
+
</ThemeProvider>
|
|
94
|
+
);
|
|
95
|
+
const {result: registered} = renderHook(() => useCustomIcon("customStar"), {wrapper});
|
|
96
|
+
expect(registered.current).toBe(CustomStar);
|
|
97
|
+
|
|
98
|
+
const {result: fontAwesome} = renderHook(() => useCustomIcon("check"), {wrapper});
|
|
99
|
+
expect(fontAwesome.current).toBeUndefined();
|
|
100
|
+
|
|
101
|
+
const {result: missing} = renderHook(() => useCustomIcon(undefined), {wrapper});
|
|
102
|
+
expect(missing.current).toBeUndefined();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {createContext, type FC, type ReactNode, useContext} from "react";
|
|
2
|
+
|
|
3
|
+
import type {CustomIconComponent, IconName, IconRegistryMap} from "./Common";
|
|
4
|
+
|
|
5
|
+
// Stable empty registry so consumers that don't register icons don't trigger
|
|
6
|
+
// unnecessary context re-renders.
|
|
7
|
+
const EMPTY_REGISTRY: IconRegistryMap = {};
|
|
8
|
+
|
|
9
|
+
const IconRegistryContext = createContext<IconRegistryMap>(EMPTY_REGISTRY);
|
|
10
|
+
|
|
11
|
+
interface IconRegistryProviderProps {
|
|
12
|
+
/** Map of custom icon name to the component that renders it. */
|
|
13
|
+
icons?: IconRegistryMap;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const IconRegistryProvider: FC<IconRegistryProviderProps> = ({icons, children}) => {
|
|
18
|
+
return (
|
|
19
|
+
<IconRegistryContext.Provider value={icons ?? EMPTY_REGISTRY}>
|
|
20
|
+
{children}
|
|
21
|
+
</IconRegistryContext.Provider>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Returns the full map of registered custom icons. */
|
|
26
|
+
export const useIconRegistry = (): IconRegistryMap => {
|
|
27
|
+
return useContext(IconRegistryContext);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the registered custom icon component for the given name, or undefined
|
|
32
|
+
* when the name is not a registered custom icon (in which case callers should
|
|
33
|
+
* fall through to rendering a FontAwesome icon).
|
|
34
|
+
*/
|
|
35
|
+
export const useCustomIcon = (iconName?: IconName): CustomIconComponent | undefined => {
|
|
36
|
+
const registry = useContext(IconRegistryContext);
|
|
37
|
+
if (!iconName) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return registry[iconName];
|
|
41
|
+
};
|
package/src/TerrenoProvider.tsx
CHANGED
|
@@ -2,6 +2,8 @@ import type React from "react";
|
|
|
2
2
|
import type {FC} from "react";
|
|
3
3
|
import {Host} from "react-native-portalize";
|
|
4
4
|
|
|
5
|
+
import type {IconRegistryMap} from "./Common";
|
|
6
|
+
import {IconRegistryProvider} from "./IconRegistry";
|
|
5
7
|
import {OpenAPIProvider} from "./OpenAPIContext";
|
|
6
8
|
import {ThemeProvider} from "./Theme";
|
|
7
9
|
import {Toast} from "./Toast";
|
|
@@ -10,31 +12,39 @@ import {ToastProvider} from "./ToastNotifications";
|
|
|
10
12
|
export const TerrenoProvider: FC<{
|
|
11
13
|
children: React.ReactNode;
|
|
12
14
|
openAPISpecUrl?: string;
|
|
13
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Custom icons to register, keyed by icon name. Registered names take
|
|
17
|
+
* precedence over FontAwesome glyphs and are usable anywhere an `iconName`
|
|
18
|
+
* is accepted (Icon, Button, IconButton, fields, etc.).
|
|
19
|
+
*/
|
|
20
|
+
icons?: IconRegistryMap;
|
|
21
|
+
}> = ({children, openAPISpecUrl, icons}) => {
|
|
14
22
|
return (
|
|
15
23
|
<ThemeProvider>
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
<IconRegistryProvider icons={icons}>
|
|
25
|
+
<ToastProvider
|
|
26
|
+
animationDuration={250}
|
|
27
|
+
animationType="slide-in"
|
|
28
|
+
duration={50000}
|
|
29
|
+
offset={50}
|
|
30
|
+
placement="bottom"
|
|
31
|
+
renderToast={(toastOptions) => {
|
|
32
|
+
const dataOnDismiss = toastOptions?.data?.onDismiss;
|
|
33
|
+
const providerOnHide = toastOptions?.onHide;
|
|
34
|
+
const handleDismiss = () => {
|
|
35
|
+
dataOnDismiss?.();
|
|
36
|
+
providerOnHide?.();
|
|
37
|
+
};
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
return <Toast {...toastOptions?.data} onDismiss={handleDismiss} />;
|
|
40
|
+
}}
|
|
41
|
+
swipeEnabled
|
|
42
|
+
>
|
|
43
|
+
<OpenAPIProvider specUrl={openAPISpecUrl}>
|
|
44
|
+
<Host>{children}</Host>
|
|
45
|
+
</OpenAPIProvider>
|
|
46
|
+
</ToastProvider>
|
|
47
|
+
</IconRegistryProvider>
|
|
38
48
|
</ThemeProvider>
|
|
39
49
|
);
|
|
40
50
|
};
|
package/src/index.tsx
CHANGED
|
@@ -42,6 +42,7 @@ export * from "./HeightActionSheet";
|
|
|
42
42
|
export * from "./HeightField";
|
|
43
43
|
export * from "./Icon";
|
|
44
44
|
export * from "./IconButton";
|
|
45
|
+
export * from "./IconRegistry";
|
|
45
46
|
export * from "./Image";
|
|
46
47
|
export * from "./ImageBackground";
|
|
47
48
|
export * from "./InfoModalIcon";
|
package/src/test-utils.tsx
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
import {mock} from "bun:test";
|
|
2
2
|
import {render} from "@testing-library/react-native";
|
|
3
3
|
import type React from "react";
|
|
4
|
+
import {View} from "react-native";
|
|
4
5
|
|
|
6
|
+
import type {CustomIconProps, IconRegistryMap} from "./Common";
|
|
7
|
+
import {IconRegistryProvider} from "./IconRegistry";
|
|
5
8
|
import {ThemeProvider} from "./Theme";
|
|
6
9
|
|
|
10
|
+
// Register a custom icon name for tests. test-utils.tsx is excluded from the
|
|
11
|
+
// published build (see tsconfig), so this augmentation never leaks to consumers.
|
|
12
|
+
declare module "./Common" {
|
|
13
|
+
interface CustomIconRegistry {
|
|
14
|
+
testCustomIcon: true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const TEST_CUSTOM_ICON_TEST_ID = "test-custom-icon";
|
|
19
|
+
|
|
20
|
+
export const TestCustomIcon: React.FC<CustomIconProps> = ({size, testID}) => {
|
|
21
|
+
return <View accessibilityLabel={`size:${size}`} testID={testID ?? TEST_CUSTOM_ICON_TEST_ID} />;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const testCustomIcons: IconRegistryMap = {testCustomIcon: TestCustomIcon};
|
|
25
|
+
|
|
7
26
|
export const renderWithTheme = (ui: React.ReactElement) => {
|
|
8
27
|
return render(ui, {wrapper: ThemeProvider});
|
|
9
28
|
};
|
|
10
29
|
|
|
30
|
+
export const renderWithIcons = (
|
|
31
|
+
ui: React.ReactElement,
|
|
32
|
+
icons: IconRegistryMap = testCustomIcons
|
|
33
|
+
) => {
|
|
34
|
+
return render(ui, {
|
|
35
|
+
wrapper: ({children}: {children: React.ReactNode}) => (
|
|
36
|
+
<ThemeProvider>
|
|
37
|
+
<IconRegistryProvider icons={icons}>{children}</IconRegistryProvider>
|
|
38
|
+
</ThemeProvider>
|
|
39
|
+
),
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
11
43
|
export const createCommonMocks = () => ({
|
|
12
44
|
onBlur: mock(() => {}),
|
|
13
45
|
onChange: mock(() => {}),
|