@terreno/ui 0.20.0 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Badge.js +5 -6
- package/dist/Badge.js.map +1 -1
- 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/PickerSelect.js +14 -10
- package/dist/PickerSelect.js.map +1 -1
- 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/Badge.tsx +5 -6
- 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/PickerSelect.tsx +27 -27
- package/src/TerrenoProvider.tsx +32 -22
- package/src/__snapshots__/AddressField.test.tsx.snap +7 -3
- package/src/__snapshots__/Badge.test.tsx.snap +2 -2
- package/src/__snapshots__/Button.test.tsx.snap +0 -71
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +51 -24
- package/src/__snapshots__/DataTable.test.tsx.snap +0 -366
- package/src/__snapshots__/Field.test.tsx.snap +49 -21
- package/src/__snapshots__/PickerSelect.test.tsx.snap +51 -24
- package/src/__snapshots__/SegmentedControl.test.tsx.snap +6 -9
- package/src/__snapshots__/SelectField.test.tsx.snap +44 -21
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +42 -18
- package/src/index.tsx +1 -0
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +19 -15
- package/src/test-utils.tsx +32 -0
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/PickerSelect.tsx
CHANGED
|
@@ -38,7 +38,6 @@ import {
|
|
|
38
38
|
Text,
|
|
39
39
|
TextInput,
|
|
40
40
|
type TextInputProps,
|
|
41
|
-
type TextProps,
|
|
42
41
|
TouchableOpacity,
|
|
43
42
|
View,
|
|
44
43
|
} from "react-native";
|
|
@@ -389,37 +388,32 @@ export const RNPickerSelect = ({
|
|
|
389
388
|
return <View style={{pointerEvents: "box-only"}}>{children}</View>;
|
|
390
389
|
}
|
|
391
390
|
|
|
392
|
-
const
|
|
391
|
+
const selectedLabel = selectedItem?.inputLabel ?? selectedItem?.label ?? "";
|
|
392
|
+
const baseTextInputStyle = {
|
|
393
|
+
color: disabled ? theme.text.secondaryLight : theme.text.primary,
|
|
394
|
+
flex: 1,
|
|
395
|
+
};
|
|
393
396
|
return (
|
|
394
397
|
<View
|
|
395
398
|
style={{
|
|
399
|
+
alignItems: "center",
|
|
396
400
|
flexDirection: "row",
|
|
397
|
-
justifyContent: "space-between",
|
|
398
401
|
pointerEvents: "box-only",
|
|
399
402
|
width: "100%",
|
|
400
403
|
}}
|
|
401
404
|
>
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
) : (
|
|
415
|
-
<TextInput
|
|
416
|
-
readOnly
|
|
417
|
-
style={{color: theme.text.primary}}
|
|
418
|
-
testID="text_input"
|
|
419
|
-
value={selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
420
|
-
{...textInputProps}
|
|
421
|
-
/>
|
|
422
|
-
)}
|
|
405
|
+
<TextInput
|
|
406
|
+
editable={false}
|
|
407
|
+
multiline
|
|
408
|
+
{...textInputProps}
|
|
409
|
+
style={
|
|
410
|
+
textInputProps?.style
|
|
411
|
+
? [baseTextInputStyle, textInputProps.style]
|
|
412
|
+
: baseTextInputStyle
|
|
413
|
+
}
|
|
414
|
+
testID={textInputProps?.testID ?? "text_input"}
|
|
415
|
+
value={selectedLabel}
|
|
416
|
+
/>
|
|
423
417
|
{renderIcon()}
|
|
424
418
|
</View>
|
|
425
419
|
);
|
|
@@ -440,6 +434,7 @@ export const RNPickerSelect = ({
|
|
|
440
434
|
]}
|
|
441
435
|
>
|
|
442
436
|
<Pressable
|
|
437
|
+
disabled={disabled}
|
|
443
438
|
onPress={() => {
|
|
444
439
|
togglePicker(true);
|
|
445
440
|
}}
|
|
@@ -448,7 +443,8 @@ export const RNPickerSelect = ({
|
|
|
448
443
|
flexDirection: "row",
|
|
449
444
|
justifyContent: "center",
|
|
450
445
|
minHeight: 40,
|
|
451
|
-
|
|
446
|
+
paddingHorizontal: 8,
|
|
447
|
+
width: "100%",
|
|
452
448
|
}}
|
|
453
449
|
testID="ios_touchable_wrapper"
|
|
454
450
|
{...touchableWrapperProps}
|
|
@@ -507,7 +503,12 @@ export const RNPickerSelect = ({
|
|
|
507
503
|
children?: ReactNode;
|
|
508
504
|
}>;
|
|
509
505
|
return (
|
|
510
|
-
<Component
|
|
506
|
+
<Component
|
|
507
|
+
{...(!fixAndroidTouchableBug ? {disabled} : {})}
|
|
508
|
+
onPress={onOpen}
|
|
509
|
+
testID="android_touchable_wrapper"
|
|
510
|
+
{...touchableWrapperProps}
|
|
511
|
+
>
|
|
511
512
|
<View>
|
|
512
513
|
{renderTextInputOrChildren()}
|
|
513
514
|
<Picker
|
|
@@ -636,7 +637,6 @@ export const RNPickerSelect = ({
|
|
|
636
637
|
style={{
|
|
637
638
|
alignItems: "center",
|
|
638
639
|
flexDirection: "row",
|
|
639
|
-
justifyContent: "space-between",
|
|
640
640
|
minHeight: 40,
|
|
641
641
|
paddingHorizontal: 8,
|
|
642
642
|
width: "100%",
|
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
|
};
|
|
@@ -387,9 +387,11 @@ exports[`AddressField renders correctly with default props 1`] = `
|
|
|
387
387
|
"$$typeof": Symbol(react.test.json),
|
|
388
388
|
"children": null,
|
|
389
389
|
"props": {
|
|
390
|
-
"
|
|
390
|
+
"editable": false,
|
|
391
|
+
"multiline": true,
|
|
391
392
|
"style": {
|
|
392
393
|
"color": "#1C1C1C",
|
|
394
|
+
"flex": 1,
|
|
393
395
|
},
|
|
394
396
|
"testID": "text_input",
|
|
395
397
|
"value": "Please select an option.",
|
|
@@ -410,8 +412,8 @@ exports[`AddressField renders correctly with default props 1`] = `
|
|
|
410
412
|
],
|
|
411
413
|
"props": {
|
|
412
414
|
"style": {
|
|
415
|
+
"alignItems": "center",
|
|
413
416
|
"flexDirection": "row",
|
|
414
|
-
"justifyContent": "space-between",
|
|
415
417
|
"pointerEvents": "box-only",
|
|
416
418
|
"width": "100%",
|
|
417
419
|
},
|
|
@@ -421,13 +423,15 @@ exports[`AddressField renders correctly with default props 1`] = `
|
|
|
421
423
|
},
|
|
422
424
|
],
|
|
423
425
|
"props": {
|
|
426
|
+
"disabled": false,
|
|
424
427
|
"onPress": [Function],
|
|
425
428
|
"style": {
|
|
426
429
|
"alignItems": "center",
|
|
427
430
|
"flexDirection": "row",
|
|
428
431
|
"justifyContent": "center",
|
|
429
432
|
"minHeight": 40,
|
|
430
|
-
"
|
|
433
|
+
"paddingHorizontal": 8,
|
|
434
|
+
"width": "100%",
|
|
431
435
|
},
|
|
432
436
|
"testID": "ios_touchable_wrapper",
|
|
433
437
|
},
|
|
@@ -30,10 +30,10 @@ exports[`Badge renders correctly with default props 1`] = `
|
|
|
30
30
|
"backgroundColor": "#2B6072",
|
|
31
31
|
"borderRadius": 4,
|
|
32
32
|
"flexDirection": "row",
|
|
33
|
-
"height":
|
|
33
|
+
"height": 20,
|
|
34
34
|
"justifyContent": "center",
|
|
35
35
|
"paddingHorizontal": 8,
|
|
36
|
-
"paddingVertical":
|
|
36
|
+
"paddingVertical": 0,
|
|
37
37
|
"width": "auto",
|
|
38
38
|
},
|
|
39
39
|
false,
|
|
@@ -1043,77 +1043,6 @@ exports[`Button renders with tooltip on desktop (wrapped in Tooltip) 1`] = `
|
|
|
1043
1043
|
}
|
|
1044
1044
|
`;
|
|
1045
1045
|
|
|
1046
|
-
exports[`Button renders with tooltipIncludeArrow and tooltipIdealPosition 1`] = `
|
|
1047
|
-
{
|
|
1048
|
-
"$$typeof": Symbol(react.test.json),
|
|
1049
|
-
"children": [
|
|
1050
|
-
{
|
|
1051
|
-
"$$typeof": Symbol(react.test.json),
|
|
1052
|
-
"children": [
|
|
1053
|
-
{
|
|
1054
|
-
"$$typeof": Symbol(react.test.json),
|
|
1055
|
-
"children": [
|
|
1056
|
-
{
|
|
1057
|
-
"$$typeof": Symbol(react.test.json),
|
|
1058
|
-
"children": [
|
|
1059
|
-
"Arrow Tip",
|
|
1060
|
-
],
|
|
1061
|
-
"props": {
|
|
1062
|
-
"style": {
|
|
1063
|
-
"color": "#FFFFFF",
|
|
1064
|
-
"fontSize": 16,
|
|
1065
|
-
"fontWeight": "700",
|
|
1066
|
-
},
|
|
1067
|
-
},
|
|
1068
|
-
"type": "Text",
|
|
1069
|
-
},
|
|
1070
|
-
],
|
|
1071
|
-
"props": {
|
|
1072
|
-
"style": {
|
|
1073
|
-
"flexDirection": "row",
|
|
1074
|
-
},
|
|
1075
|
-
"testID": undefined,
|
|
1076
|
-
},
|
|
1077
|
-
"type": "View",
|
|
1078
|
-
},
|
|
1079
|
-
],
|
|
1080
|
-
"props": {
|
|
1081
|
-
"style": {
|
|
1082
|
-
"flexDirection": "row",
|
|
1083
|
-
},
|
|
1084
|
-
"testID": undefined,
|
|
1085
|
-
},
|
|
1086
|
-
"type": "View",
|
|
1087
|
-
},
|
|
1088
|
-
],
|
|
1089
|
-
"props": {
|
|
1090
|
-
"accessibilityHint": "Press to perform action",
|
|
1091
|
-
"accessibilityLabel": "Arrow Tip",
|
|
1092
|
-
"accessibilityRole": "button",
|
|
1093
|
-
"accessibilityState": {
|
|
1094
|
-
"disabled": false,
|
|
1095
|
-
},
|
|
1096
|
-
"disabled": false,
|
|
1097
|
-
"onPress": [Function: debounced],
|
|
1098
|
-
"style": {
|
|
1099
|
-
"alignItems": "center",
|
|
1100
|
-
"alignSelf": "flex-start",
|
|
1101
|
-
"backgroundColor": "#0E9DCD",
|
|
1102
|
-
"borderColor": undefined,
|
|
1103
|
-
"borderRadius": 360,
|
|
1104
|
-
"borderWidth": undefined,
|
|
1105
|
-
"flexDirection": "column",
|
|
1106
|
-
"justifyContent": "center",
|
|
1107
|
-
"paddingHorizontal": 20,
|
|
1108
|
-
"paddingVertical": 8,
|
|
1109
|
-
"width": "auto",
|
|
1110
|
-
},
|
|
1111
|
-
"testID": undefined,
|
|
1112
|
-
},
|
|
1113
|
-
"type": "PressableScale",
|
|
1114
|
-
}
|
|
1115
|
-
`;
|
|
1116
|
-
|
|
1117
1046
|
exports[`Button renders with custom confirmationText and modalSubTitle 1`] = `
|
|
1118
1047
|
{
|
|
1119
1048
|
"$$typeof": Symbol(react.test.json),
|