@terreno/ui 57.11.0 → 57.13.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/dist/AiSuggestionBox.js +9 -9
- package/dist/AiSuggestionBox.js.map +1 -1
- package/dist/Banner.js +1 -1
- package/dist/Banner.js.map +1 -1
- package/dist/Box.d.ts.map +1 -1
- package/dist/Box.js +36 -3
- package/dist/Box.js.map +1 -1
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +7 -0
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +34 -4
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DataTable.d.ts.map +1 -1
- package/dist/DataTable.js +50 -3
- package/dist/DataTable.js.map +1 -1
- package/dist/Image.d.ts.map +1 -1
- package/dist/Image.js +1 -1
- package/dist/Image.js.map +1 -1
- package/dist/MarkdownView.d.ts.map +1 -1
- package/dist/MarkdownView.js +67 -5
- package/dist/MarkdownView.js.map +1 -1
- package/dist/Modal.js +1 -1
- package/dist/SegmentedControl.d.ts.map +1 -1
- package/dist/SegmentedControl.js +15 -11
- package/dist/SegmentedControl.js.map +1 -1
- package/dist/SelectField.d.ts.map +1 -1
- package/dist/SelectField.js +4 -1
- package/dist/SelectField.js.map +1 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +145 -55
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.js +1 -1
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TerrenoProvider.d.ts +7 -3
- package/dist/TerrenoProvider.d.ts.map +1 -1
- package/dist/TerrenoProvider.js +2 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Theme.d.ts +19 -85
- package/dist/Theme.d.ts.map +1 -1
- package/dist/Theme.js +149 -33
- package/dist/Theme.js.map +1 -1
- package/dist/Toast.d.ts.map +1 -1
- package/dist/Toast.js +21 -12
- package/dist/Toast.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +5 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +1 -0
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip.js +84 -37
- package/dist/Tooltip.js.map +1 -1
- package/dist/blocks/BlocksView.d.ts.map +1 -1
- package/dist/blocks/BlocksView.js +5 -1
- package/dist/blocks/BlocksView.js.map +1 -1
- package/dist/blocks/blockRenderers.d.ts +10 -1
- package/dist/blocks/blockRenderers.d.ts.map +1 -1
- package/dist/blocks/blockRenderers.js +330 -9
- package/dist/blocks/blockRenderers.js.map +1 -1
- package/dist/blocks/useChecklistState.d.ts +18 -0
- package/dist/blocks/useChecklistState.d.ts.map +1 -0
- package/dist/blocks/useChecklistState.js +29 -0
- package/dist/blocks/useChecklistState.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -1
- package/dist/blocks/useResolvedImages.js +16 -0
- package/dist/blocks/useResolvedImages.js.map +1 -1
- package/dist/colorContrast.d.ts +9 -0
- package/dist/colorContrast.d.ts.map +1 -0
- package/dist/colorContrast.js +47 -0
- package/dist/colorContrast.js.map +1 -0
- package/dist/icons/OfflineIcon.js +1 -1
- package/dist/table/TableDate.d.ts.map +1 -1
- package/dist/table/TableDate.js +3 -1
- package/dist/table/TableDate.js.map +1 -1
- package/package.json +2 -2
- package/src/AiSuggestionBox.tsx +10 -10
- package/src/Banner.tsx +1 -1
- package/src/Box.test.tsx +80 -0
- package/src/Box.tsx +52 -0
- package/src/Button.test.tsx +39 -1
- package/src/Button.tsx +9 -0
- package/src/Common.ts +35 -4
- package/src/DataTable.test.tsx +133 -1
- package/src/DataTable.tsx +78 -3
- package/src/Image.tsx +1 -0
- package/src/MarkdownView.test.tsx +165 -2
- package/src/MarkdownView.tsx +100 -5
- package/src/Modal.tsx +1 -1
- package/src/SegmentedControl.test.tsx +7 -0
- package/src/SegmentedControl.tsx +22 -11
- package/src/SelectField.tsx +4 -1
- package/src/SplitPage.native.tsx +1 -1
- package/src/SplitPage.test.tsx +473 -5
- package/src/SplitPage.tsx +266 -132
- package/src/TerrenoProvider.tsx +15 -5
- package/src/Theme.test.tsx +212 -3
- package/src/Theme.tsx +184 -39
- package/src/Toast.test.tsx +7 -0
- package/src/Toast.tsx +22 -12
- package/src/ToastNotifications.test.tsx +36 -0
- package/src/ToastNotifications.tsx +5 -2
- package/src/Tooltip.test.tsx +232 -1
- package/src/Tooltip.tsx +128 -67
- package/src/__snapshots__/AddressField.test.tsx.snap +7 -7
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +23 -23
- package/src/__snapshots__/Banner.test.tsx.snap +3 -0
- package/src/__snapshots__/BooleanField.test.tsx.snap +3 -3
- package/src/__snapshots__/Button.test.tsx.snap +16 -16
- package/src/__snapshots__/Card.test.tsx.snap +0 -1
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +23 -23
- package/src/__snapshots__/DataTable.test.tsx.snap +30 -30
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +2 -2
- package/src/__snapshots__/DropdownPanel.test.tsx.snap +2 -2
- package/src/__snapshots__/EmailField.test.tsx.snap +2 -2
- package/src/__snapshots__/ErrorPage.test.tsx.snap +1 -1
- package/src/__snapshots__/Field.test.tsx.snap +37 -37
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +2 -1
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +2 -2
- package/src/__snapshots__/HeightField.test.tsx.snap +8 -8
- package/src/__snapshots__/HeightFieldDesktop.test.tsx.snap +6 -6
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +2 -2
- package/src/__snapshots__/MarkdownView.test.tsx.snap +2 -2
- package/src/__snapshots__/MobileAddressAutoComplete.test.tsx.snap +1 -1
- package/src/__snapshots__/Modal.test.tsx.snap +10 -10
- package/src/__snapshots__/NumberField.test.tsx.snap +1 -1
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +2 -2
- package/src/__snapshots__/Page.test.tsx.snap +1 -1
- package/src/__snapshots__/PhoneNumberField.test.tsx.snap +4 -4
- package/src/__snapshots__/PickerSelect.test.tsx.snap +8 -8
- package/src/__snapshots__/SectionDivider.test.tsx.snap +2 -2
- package/src/__snapshots__/SegmentedControl.test.tsx.snap +183 -0
- package/src/__snapshots__/SelectBadge.test.tsx.snap +9 -9
- package/src/__snapshots__/SelectField.test.tsx.snap +19 -19
- package/src/__snapshots__/Signature.test.tsx.snap +1 -1
- package/src/__snapshots__/SignatureCaptureField.test.tsx.snap +2 -2
- package/src/__snapshots__/SignatureField.test.tsx.snap +2 -2
- package/src/__snapshots__/SplitPage.test.tsx.snap +165 -67
- package/src/__snapshots__/TapToEdit.test.tsx.snap +1 -1
- package/src/__snapshots__/TerrenoProvider.test.tsx.snap +20 -4
- package/src/__snapshots__/TextArea.test.tsx.snap +4 -4
- package/src/__snapshots__/TextField.test.tsx.snap +3 -3
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +18 -18
- package/src/__snapshots__/Toast.test.tsx.snap +224 -154
- package/src/__snapshots__/TypedSignatureField.test.tsx.snap +3 -3
- package/src/__snapshots__/UnifiedAddressAutoComplete.test.tsx.snap +6 -6
- package/src/__snapshots__/WebAddressAutocomplete.test.tsx.snap +4 -4
- package/src/blocks/BlocksView.test.tsx +1101 -2
- package/src/blocks/BlocksView.tsx +5 -1
- package/src/blocks/blockRenderers.tsx +730 -22
- package/src/blocks/useChecklistState.ts +46 -0
- package/src/blocks/useResolvedImages.ts +16 -0
- package/src/bunSetup.ts +3 -0
- package/src/colorContrast.test.ts +27 -0
- package/src/colorContrast.ts +55 -0
- package/src/icons/OfflineIcon.tsx +2 -2
- package/src/icons/__snapshots__/OfflineIcon.test.tsx.snap +4 -4
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +7 -7
- package/src/signUp/__snapshots__/OAuthButtons.test.tsx.snap +3 -3
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +7 -7
- package/src/table/TableDate.tsx +3 -1
- package/src/table/__snapshots__/Table.test.tsx.snap +5 -5
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +3 -3
- package/src/table/__snapshots__/TableDate.test.tsx.snap +4 -0
- package/src/table/__snapshots__/TableHeader.test.tsx.snap +4 -4
- package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +7 -7
- package/src/table/__snapshots__/TableRow.test.tsx.snap +6 -6
package/src/Theme.test.tsx
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {act, render} from "@testing-library/react-native";
|
|
3
3
|
import {assert} from "chai";
|
|
4
|
-
import {Text, View} from "react-native";
|
|
4
|
+
import {Text, useColorScheme, View} from "react-native";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
darkThemeConfig,
|
|
8
|
+
defaultThemePrimitives,
|
|
9
|
+
lightThemeConfig,
|
|
10
|
+
resolveThemeColorScheme,
|
|
11
|
+
type ThemeColorScheme,
|
|
12
|
+
ThemeProvider,
|
|
13
|
+
themeColorSchemeOptions,
|
|
14
|
+
useTheme,
|
|
15
|
+
} from "./Theme";
|
|
7
16
|
|
|
8
17
|
type ThemeContextValue = ReturnType<typeof useTheme>;
|
|
9
18
|
type ThemeValue = ThemeContextValue["theme"];
|
|
10
19
|
|
|
11
20
|
const ThemeConsumer = () => {
|
|
12
|
-
const {theme} = useTheme();
|
|
21
|
+
const {colorScheme, colorSchemeSetting, theme} = useTheme();
|
|
13
22
|
return (
|
|
14
23
|
<View>
|
|
24
|
+
<Text testID="color-scheme">{colorScheme}</Text>
|
|
25
|
+
<Text testID="color-scheme-setting">{colorSchemeSetting}</Text>
|
|
26
|
+
<Text testID="border-ai">{theme.border.ai}</Text>
|
|
15
27
|
<Text testID="surface-base">{theme.surface?.base}</Text>
|
|
28
|
+
<Text testID="surface-ai">{theme.surface.ai}</Text>
|
|
16
29
|
<Text testID="text-primary">{theme.text?.primary}</Text>
|
|
17
30
|
</View>
|
|
18
31
|
);
|
|
@@ -39,6 +52,201 @@ describe("Theme", () => {
|
|
|
39
52
|
expect(getByTestId("surface-base").children[0]).toBe("#FFFFFF");
|
|
40
53
|
// Default text.primary is neutral900 which maps to #1C1C1C
|
|
41
54
|
expect(getByTestId("text-primary").children[0]).toBe("#1C1C1C");
|
|
55
|
+
assert.equal(getByTestId("surface-ai").children[0], "#EBFAFF");
|
|
56
|
+
assert.equal(getByTestId("border-ai").children[0], "#90D8F0");
|
|
57
|
+
assert.equal(getByTestId("color-scheme").children[0], "light");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("provides the Figma dark mode values", () => {
|
|
61
|
+
const {getByTestId} = render(
|
|
62
|
+
<ThemeProvider colorScheme="dark">
|
|
63
|
+
<ThemeConsumer />
|
|
64
|
+
</ThemeProvider>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
assert.equal(getByTestId("surface-base").children[0], "#353535");
|
|
68
|
+
assert.equal(getByTestId("surface-ai").children[0], "#035D7E");
|
|
69
|
+
assert.equal(getByTestId("border-ai").children[0], "#0086B3");
|
|
70
|
+
assert.equal(getByTestId("text-primary").children[0], "#FFFFFF");
|
|
71
|
+
assert.equal(getByTestId("color-scheme").children[0], "dark");
|
|
72
|
+
assert.equal(getByTestId("color-scheme-setting").children[0], "dark");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("follows the system scheme and accepts a later choice", () => {
|
|
76
|
+
const colorSchemeMock = useColorScheme as unknown as {
|
|
77
|
+
mockReturnValue: (value: string | null) => void;
|
|
78
|
+
};
|
|
79
|
+
let setColorScheme: ((nextColorScheme: ThemeColorScheme) => void) | undefined;
|
|
80
|
+
const Capture = (): null => {
|
|
81
|
+
setColorScheme = useTheme().setColorScheme;
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
colorSchemeMock.mockReturnValue("dark");
|
|
86
|
+
const view = render(
|
|
87
|
+
<ThemeProvider colorScheme="system">
|
|
88
|
+
<Capture />
|
|
89
|
+
<ThemeConsumer />
|
|
90
|
+
</ThemeProvider>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
assert.equal(view.getByTestId("color-scheme-setting").children[0], "system");
|
|
94
|
+
assert.equal(view.getByTestId("color-scheme").children[0], "dark");
|
|
95
|
+
assert.equal(view.getByTestId("surface-base").children[0], "#353535");
|
|
96
|
+
|
|
97
|
+
act(() => {
|
|
98
|
+
setColorScheme?.("light");
|
|
99
|
+
});
|
|
100
|
+
assert.equal(view.getByTestId("color-scheme-setting").children[0], "light");
|
|
101
|
+
assert.equal(view.getByTestId("surface-base").children[0], "#FFFFFF");
|
|
102
|
+
|
|
103
|
+
view.rerender(
|
|
104
|
+
<ThemeProvider colorScheme="dark">
|
|
105
|
+
<Capture />
|
|
106
|
+
<ThemeConsumer />
|
|
107
|
+
</ThemeProvider>
|
|
108
|
+
);
|
|
109
|
+
assert.equal(view.getByTestId("color-scheme-setting").children[0], "dark");
|
|
110
|
+
assert.equal(view.getByTestId("color-scheme").children[0], "dark");
|
|
111
|
+
colorSchemeMock.mockReturnValue("light");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("lists light, dark, and follow system", () => {
|
|
115
|
+
assert.deepEqual(
|
|
116
|
+
themeColorSchemeOptions.map((option) => option.value),
|
|
117
|
+
["light", "dark", "system"]
|
|
118
|
+
);
|
|
119
|
+
assert.equal(
|
|
120
|
+
themeColorSchemeOptions.find((option) => option.value === "system")?.label,
|
|
121
|
+
"Follow system"
|
|
122
|
+
);
|
|
123
|
+
assert.equal(resolveThemeColorScheme("system", null), "light");
|
|
124
|
+
assert.equal(resolveThemeColorScheme("system", "dark"), "dark");
|
|
125
|
+
assert.equal(resolveThemeColorScheme("light", "dark"), "light");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("maps semantic tokens to the supplied Figma modes", () => {
|
|
129
|
+
assert.deepInclude(lightThemeConfig.text, {
|
|
130
|
+
accent: "accent700",
|
|
131
|
+
error: "error200",
|
|
132
|
+
extraLight: "neutral500",
|
|
133
|
+
inverted: "neutral000",
|
|
134
|
+
link: "primary600",
|
|
135
|
+
linkLight: "primary400",
|
|
136
|
+
primary: "neutral900",
|
|
137
|
+
secondaryDark: "secondary800",
|
|
138
|
+
secondaryLight: "neutral600",
|
|
139
|
+
success: "success200",
|
|
140
|
+
warning: "warning200",
|
|
141
|
+
});
|
|
142
|
+
assert.deepInclude(lightThemeConfig.surface, {
|
|
143
|
+
ai: "primary000",
|
|
144
|
+
base: "neutral000",
|
|
145
|
+
baseAlternate: "neutral050",
|
|
146
|
+
baseHover: "secondary000",
|
|
147
|
+
disabled: "neutral500",
|
|
148
|
+
error: "error200",
|
|
149
|
+
errorLight: "error000",
|
|
150
|
+
neutral: "neutral600",
|
|
151
|
+
neutralDark: "neutral800",
|
|
152
|
+
neutralExtraLight: "neutral200",
|
|
153
|
+
neutralLight: "neutral300",
|
|
154
|
+
primary: "primary400",
|
|
155
|
+
secondaryDark: "secondary500",
|
|
156
|
+
secondaryExtraDark: "secondary800",
|
|
157
|
+
secondaryLight: "secondary100",
|
|
158
|
+
success: "success200",
|
|
159
|
+
successLight: "success000",
|
|
160
|
+
warning: "warning100",
|
|
161
|
+
warningLight: "warning000",
|
|
162
|
+
});
|
|
163
|
+
assert.deepEqual(lightThemeConfig.border, {
|
|
164
|
+
activeAccent: "accent500",
|
|
165
|
+
activeNeutral: "neutral700",
|
|
166
|
+
ai: "primary100",
|
|
167
|
+
dark: "neutral500",
|
|
168
|
+
default: "neutral300",
|
|
169
|
+
error: "error100",
|
|
170
|
+
focus: "primary200",
|
|
171
|
+
hover: "neutral200",
|
|
172
|
+
success: "success100",
|
|
173
|
+
warning: "warning100",
|
|
174
|
+
});
|
|
175
|
+
assert.deepEqual(lightThemeConfig.status, {
|
|
176
|
+
active: "success100",
|
|
177
|
+
away: "neutral500",
|
|
178
|
+
doNotDisturb: "error100",
|
|
179
|
+
});
|
|
180
|
+
assert.deepEqual(lightThemeConfig.radius, {
|
|
181
|
+
default: "radiusMd",
|
|
182
|
+
full: "radiusLg",
|
|
183
|
+
minimal: "radiusSm",
|
|
184
|
+
rounded: "radius3xl",
|
|
185
|
+
});
|
|
186
|
+
assert.deepEqual(lightThemeConfig.spacing, {
|
|
187
|
+
"2xl": "spacing8",
|
|
188
|
+
"3xl": "spacing12",
|
|
189
|
+
lg: "spacing5",
|
|
190
|
+
md: "spacing4",
|
|
191
|
+
none: "spacing0",
|
|
192
|
+
sm: "spacing2",
|
|
193
|
+
xl: "spacing6",
|
|
194
|
+
xs: "spacing1",
|
|
195
|
+
});
|
|
196
|
+
assert.deepInclude(darkThemeConfig.text, {
|
|
197
|
+
accent: "accent400",
|
|
198
|
+
error: "error000",
|
|
199
|
+
extraLight: "neutral300",
|
|
200
|
+
inverted: "neutral800",
|
|
201
|
+
link: "primary200",
|
|
202
|
+
linkLight: "primary300",
|
|
203
|
+
primary: "neutral000",
|
|
204
|
+
secondaryDark: "secondary050",
|
|
205
|
+
secondaryLight: "neutral200",
|
|
206
|
+
success: "success000",
|
|
207
|
+
warning: "warning000",
|
|
208
|
+
});
|
|
209
|
+
assert.deepInclude(darkThemeConfig.surface, {
|
|
210
|
+
ai: "primary700",
|
|
211
|
+
base: "neutral800",
|
|
212
|
+
baseAlternate: "neutral800",
|
|
213
|
+
baseHover: "secondary600",
|
|
214
|
+
disabled: "neutral300",
|
|
215
|
+
error: "error050",
|
|
216
|
+
errorLight: "error200",
|
|
217
|
+
neutral: "neutral200",
|
|
218
|
+
neutralDark: "neutral050",
|
|
219
|
+
neutralExtraLight: "neutral600",
|
|
220
|
+
neutralLight: "neutral600",
|
|
221
|
+
primary: "primary300",
|
|
222
|
+
secondaryDark: "secondary300",
|
|
223
|
+
secondaryExtraDark: "secondary050",
|
|
224
|
+
secondaryLight: "secondary600",
|
|
225
|
+
success: "success050",
|
|
226
|
+
successLight: "success200",
|
|
227
|
+
warning: "warning050",
|
|
228
|
+
warningLight: "warning200",
|
|
229
|
+
});
|
|
230
|
+
assert.deepEqual(darkThemeConfig.border, {
|
|
231
|
+
activeAccent: "accent200",
|
|
232
|
+
activeNeutral: "neutral100",
|
|
233
|
+
ai: "primary500",
|
|
234
|
+
dark: "neutral300",
|
|
235
|
+
default: "neutral400",
|
|
236
|
+
error: "error050",
|
|
237
|
+
focus: "primary200",
|
|
238
|
+
hover: "neutral600",
|
|
239
|
+
success: "success050",
|
|
240
|
+
warning: "warning050",
|
|
241
|
+
});
|
|
242
|
+
assert.deepEqual(darkThemeConfig.status, {
|
|
243
|
+
active: "success050",
|
|
244
|
+
away: "neutral300",
|
|
245
|
+
doNotDisturb: "error050",
|
|
246
|
+
});
|
|
247
|
+
assert.equal(defaultThemePrimitives.error050, "#EDA1A1");
|
|
248
|
+
assert.equal(defaultThemePrimitives.success050, "#9BE7B2");
|
|
249
|
+
assert.equal(defaultThemePrimitives.warning050, "#FAA372");
|
|
42
250
|
});
|
|
43
251
|
|
|
44
252
|
it("keeps context actions stable across parent rerenders", () => {
|
|
@@ -61,6 +269,7 @@ describe("Theme", () => {
|
|
|
61
269
|
);
|
|
62
270
|
const rerenderedValue = capturedValues.at(-1);
|
|
63
271
|
|
|
272
|
+
assert.strictEqual(rerenderedValue?.setColorScheme, initialValue?.setColorScheme);
|
|
64
273
|
assert.strictEqual(rerenderedValue?.resetTheme, initialValue?.resetTheme);
|
|
65
274
|
assert.strictEqual(rerenderedValue?.setPrimitives, initialValue?.setPrimitives);
|
|
66
275
|
assert.strictEqual(rerenderedValue?.setTheme, initialValue?.setTheme);
|
package/src/Theme.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import React, {createContext, useCallback, useMemo, useState} from "react";
|
|
1
|
+
import React, {createContext, useCallback, useContext, useEffect, useMemo, useState} from "react";
|
|
2
|
+
import {useColorScheme} from "react-native";
|
|
2
3
|
|
|
3
4
|
import type {TerrenoTheme, TerrenoThemeConfig, ThemePrimitives} from "./Common";
|
|
4
5
|
import {TerrenoFontProvider} from "./TerrenoFontProvider";
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
export const defaultThemePrimitives: ThemePrimitives = {
|
|
7
8
|
accent000: "#FFFDF7",
|
|
8
9
|
accent050: "#FCECC2",
|
|
9
10
|
accent100: "#F9E0A1",
|
|
@@ -17,6 +18,7 @@ const defaultPrimitives = {
|
|
|
17
18
|
accent900: "#332400",
|
|
18
19
|
|
|
19
20
|
error000: "#FDD7D7",
|
|
21
|
+
error050: "#EDA1A1",
|
|
20
22
|
error100: "#D33232",
|
|
21
23
|
error200: "#BD1111",
|
|
22
24
|
neutral000: "#FFFFFF",
|
|
@@ -25,7 +27,7 @@ const defaultPrimitives = {
|
|
|
25
27
|
neutral200: "#D9D9D9",
|
|
26
28
|
neutral300: "#CDCDCD",
|
|
27
29
|
neutral400: "#B3B3B3",
|
|
28
|
-
neutral500: "#
|
|
30
|
+
neutral500: "#949494",
|
|
29
31
|
neutral600: "#686868",
|
|
30
32
|
neutral700: "#4E4E4E",
|
|
31
33
|
neutral800: "#353535",
|
|
@@ -77,18 +79,21 @@ const defaultPrimitives = {
|
|
|
77
79
|
spacing12: 80,
|
|
78
80
|
|
|
79
81
|
success000: "#DCF2E2",
|
|
82
|
+
success050: "#9BE7B2",
|
|
80
83
|
success100: "#3EA45C",
|
|
81
84
|
success200: "#1A7F36",
|
|
82
85
|
|
|
83
86
|
warning000: "#FFE3C6",
|
|
87
|
+
warning050: "#FAA372",
|
|
84
88
|
warning100: "#F36719",
|
|
85
89
|
warning200: "#B14202",
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
const
|
|
92
|
+
export const lightThemeConfig: TerrenoThemeConfig = {
|
|
89
93
|
border: {
|
|
90
94
|
activeAccent: "accent500",
|
|
91
95
|
activeNeutral: "neutral700",
|
|
96
|
+
ai: "primary100",
|
|
92
97
|
dark: "neutral500",
|
|
93
98
|
default: "neutral300",
|
|
94
99
|
error: "error100",
|
|
@@ -105,7 +110,7 @@ const defaultTheme: TerrenoThemeConfig = {
|
|
|
105
110
|
primary: "Nunito",
|
|
106
111
|
title: "Titillium Web",
|
|
107
112
|
},
|
|
108
|
-
primitives:
|
|
113
|
+
primitives: defaultThemePrimitives,
|
|
109
114
|
radius: {
|
|
110
115
|
default: "radiusMd",
|
|
111
116
|
full: "radiusLg",
|
|
@@ -128,6 +133,7 @@ const defaultTheme: TerrenoThemeConfig = {
|
|
|
128
133
|
doNotDisturb: "error100",
|
|
129
134
|
},
|
|
130
135
|
surface: {
|
|
136
|
+
ai: "primary000",
|
|
131
137
|
base: "neutral000",
|
|
132
138
|
baseAlternate: "neutral050",
|
|
133
139
|
baseHover: "secondary000",
|
|
@@ -136,7 +142,8 @@ const defaultTheme: TerrenoThemeConfig = {
|
|
|
136
142
|
errorLight: "error000",
|
|
137
143
|
neutral: "neutral600",
|
|
138
144
|
neutralDark: "neutral800",
|
|
139
|
-
|
|
145
|
+
neutralExtraLight: "neutral200",
|
|
146
|
+
neutralLight: "neutral300",
|
|
140
147
|
primary: "primary400",
|
|
141
148
|
secondaryDark: "secondary500",
|
|
142
149
|
secondaryExtraDark: "secondary800",
|
|
@@ -163,10 +170,119 @@ const defaultTheme: TerrenoThemeConfig = {
|
|
|
163
170
|
},
|
|
164
171
|
};
|
|
165
172
|
|
|
166
|
-
|
|
173
|
+
export const darkThemeConfig: TerrenoThemeConfig = {
|
|
174
|
+
...lightThemeConfig,
|
|
175
|
+
border: {
|
|
176
|
+
activeAccent: "accent200",
|
|
177
|
+
activeNeutral: "neutral100",
|
|
178
|
+
ai: "primary500",
|
|
179
|
+
dark: "neutral300",
|
|
180
|
+
default: "neutral400",
|
|
181
|
+
error: "error050",
|
|
182
|
+
focus: "primary200",
|
|
183
|
+
hover: "neutral600",
|
|
184
|
+
success: "success050",
|
|
185
|
+
warning: "warning050",
|
|
186
|
+
},
|
|
187
|
+
status: {
|
|
188
|
+
active: "success050",
|
|
189
|
+
away: "neutral300",
|
|
190
|
+
doNotDisturb: "error050",
|
|
191
|
+
},
|
|
192
|
+
surface: {
|
|
193
|
+
ai: "primary700",
|
|
194
|
+
base: "neutral800",
|
|
195
|
+
baseAlternate: "neutral800",
|
|
196
|
+
baseHover: "secondary600",
|
|
197
|
+
disabled: "neutral300",
|
|
198
|
+
error: "error050",
|
|
199
|
+
errorLight: "error200",
|
|
200
|
+
neutral: "neutral200",
|
|
201
|
+
neutralDark: "neutral050",
|
|
202
|
+
neutralExtraLight: "neutral600",
|
|
203
|
+
neutralLight: "neutral600",
|
|
204
|
+
primary: "primary300",
|
|
205
|
+
secondaryDark: "secondary300",
|
|
206
|
+
secondaryExtraDark: "secondary050",
|
|
207
|
+
secondaryExtraLight: "secondary600",
|
|
208
|
+
secondaryLight: "secondary600",
|
|
209
|
+
success: "success050",
|
|
210
|
+
successLight: "success200",
|
|
211
|
+
warning: "warning050",
|
|
212
|
+
// warning200 is the darkest warning fill. warning100 (#F36719) is 2.52:1
|
|
213
|
+
// against warning text (#FFE3C6), below the 4.5:1 AA bar.
|
|
214
|
+
warningLight: "warning200",
|
|
215
|
+
},
|
|
216
|
+
text: {
|
|
217
|
+
accent: "accent400",
|
|
218
|
+
error: "error000",
|
|
219
|
+
extraLight: "neutral300",
|
|
220
|
+
inverted: "neutral800",
|
|
221
|
+
link: "primary200",
|
|
222
|
+
linkLight: "primary300",
|
|
223
|
+
primary: "neutral000",
|
|
224
|
+
secondaryDark: "secondary050",
|
|
225
|
+
secondaryLight: "neutral200",
|
|
226
|
+
success: "success000",
|
|
227
|
+
warning: "warning000",
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export type ThemeColorScheme = "light" | "dark" | "system";
|
|
232
|
+
export type ResolvedThemeColorScheme = Exclude<ThemeColorScheme, "system">;
|
|
233
|
+
|
|
234
|
+
export const themeColorSchemeOptions: {label: string; value: ThemeColorScheme}[] = [
|
|
235
|
+
{label: "Light", value: "light"},
|
|
236
|
+
{label: "Dark", value: "dark"},
|
|
237
|
+
{label: "Follow system", value: "system"},
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
export const resolveThemeColorScheme = (
|
|
241
|
+
colorScheme: ThemeColorScheme,
|
|
242
|
+
systemColorScheme: string | null | undefined
|
|
243
|
+
): ResolvedThemeColorScheme => {
|
|
244
|
+
if (colorScheme === "dark") {
|
|
245
|
+
return "dark";
|
|
246
|
+
}
|
|
247
|
+
if (colorScheme === "light") {
|
|
248
|
+
return "light";
|
|
249
|
+
}
|
|
250
|
+
if (systemColorScheme === "dark") {
|
|
251
|
+
return "dark";
|
|
252
|
+
}
|
|
253
|
+
return "light";
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type DeepPartial<T> = {
|
|
167
257
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
168
258
|
};
|
|
169
259
|
|
|
260
|
+
const mergeThemeConfig = (
|
|
261
|
+
baseTheme: DeepPartial<TerrenoThemeConfig>,
|
|
262
|
+
overrideTheme: DeepPartial<TerrenoThemeConfig>
|
|
263
|
+
): DeepPartial<TerrenoThemeConfig> => {
|
|
264
|
+
const mergedTheme = {...baseTheme};
|
|
265
|
+
|
|
266
|
+
for (const key in overrideTheme) {
|
|
267
|
+
if (!Object.hasOwn(overrideTheme, key)) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
const overrideSubTheme = overrideTheme[key as keyof TerrenoThemeConfig];
|
|
271
|
+
const baseSubTheme = baseTheme[key as keyof TerrenoThemeConfig];
|
|
272
|
+
|
|
273
|
+
if (overrideSubTheme && typeof overrideSubTheme === "object") {
|
|
274
|
+
(mergedTheme as Record<string, unknown>)[key] = {
|
|
275
|
+
...baseSubTheme,
|
|
276
|
+
...overrideSubTheme,
|
|
277
|
+
};
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
(mergedTheme as Record<string, unknown>)[key] = overrideSubTheme;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return mergedTheme;
|
|
284
|
+
};
|
|
285
|
+
|
|
170
286
|
const computeTheme = (
|
|
171
287
|
themeConfig: DeepPartial<TerrenoThemeConfig>,
|
|
172
288
|
primitives: ThemePrimitives
|
|
@@ -196,24 +312,57 @@ const computeTheme = (
|
|
|
196
312
|
return {...theme, primitives};
|
|
197
313
|
};
|
|
198
314
|
|
|
199
|
-
const defaultComputedTheme = computeTheme(
|
|
315
|
+
const defaultComputedTheme = computeTheme(lightThemeConfig, defaultThemePrimitives);
|
|
200
316
|
|
|
201
317
|
export const ThemeContext = createContext({
|
|
318
|
+
colorScheme: "light" as ResolvedThemeColorScheme,
|
|
319
|
+
colorSchemeSetting: "light" as ThemeColorScheme,
|
|
202
320
|
resetTheme: () => {},
|
|
203
|
-
|
|
321
|
+
setColorScheme: (_colorScheme: ThemeColorScheme) => {},
|
|
322
|
+
setPrimitives: (_primitives: DeepPartial<ThemePrimitives>) => {},
|
|
204
323
|
setTheme: (_theme: DeepPartial<TerrenoThemeConfig>) => {},
|
|
205
324
|
theme: defaultComputedTheme,
|
|
206
325
|
});
|
|
207
326
|
|
|
208
|
-
interface ThemeProviderProps {
|
|
327
|
+
export interface ThemeProviderProps {
|
|
209
328
|
children: React.ReactNode;
|
|
329
|
+
colorScheme?: ThemeColorScheme;
|
|
210
330
|
initialPrimitives?: DeepPartial<ThemePrimitives>;
|
|
211
331
|
}
|
|
212
332
|
|
|
213
|
-
export const ThemeProvider
|
|
214
|
-
|
|
333
|
+
export const ThemeProvider: React.FC<ThemeProviderProps> = ({
|
|
334
|
+
children,
|
|
335
|
+
colorScheme,
|
|
336
|
+
initialPrimitives,
|
|
337
|
+
}) => {
|
|
338
|
+
const systemColorScheme = useColorScheme();
|
|
339
|
+
const [colorSchemeSetting, setColorSchemeSetting] = useState<ThemeColorScheme>(
|
|
340
|
+
colorScheme ?? "light"
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
// Keep an explicit parent selection in charge when that selection changes.
|
|
344
|
+
useEffect(() => {
|
|
345
|
+
if (colorScheme === undefined) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
setColorSchemeSetting(colorScheme);
|
|
349
|
+
}, [colorScheme]);
|
|
350
|
+
|
|
351
|
+
const setColorScheme = useCallback((nextColorScheme: ThemeColorScheme): void => {
|
|
352
|
+
setColorSchemeSetting(nextColorScheme);
|
|
353
|
+
}, []);
|
|
354
|
+
|
|
355
|
+
const resolvedColorScheme = resolveThemeColorScheme(colorSchemeSetting, systemColorScheme);
|
|
356
|
+
const baseTheme = resolvedColorScheme === "dark" ? darkThemeConfig : lightThemeConfig;
|
|
357
|
+
const [providerThemeOverrides, setProviderThemeOverrides] = useState<
|
|
358
|
+
DeepPartial<TerrenoThemeConfig>
|
|
359
|
+
>({});
|
|
215
360
|
const [providerPrimitives, setProviderPrimitives] = useState<ThemePrimitives>(
|
|
216
|
-
initialPrimitives ? {...
|
|
361
|
+
initialPrimitives ? {...defaultThemePrimitives, ...initialPrimitives} : defaultThemePrimitives
|
|
362
|
+
);
|
|
363
|
+
const providerTheme = useMemo(
|
|
364
|
+
(): DeepPartial<TerrenoThemeConfig> => mergeThemeConfig(baseTheme, providerThemeOverrides),
|
|
365
|
+
[baseTheme, providerThemeOverrides]
|
|
217
366
|
);
|
|
218
367
|
|
|
219
368
|
const computedTheme = useMemo(
|
|
@@ -226,36 +375,32 @@ export const ThemeProvider = ({children, initialPrimitives}: ThemeProviderProps)
|
|
|
226
375
|
}, []);
|
|
227
376
|
|
|
228
377
|
const setTheme = useCallback((newTheme: DeepPartial<TerrenoThemeConfig>): void => {
|
|
229
|
-
|
|
230
|
-
const mergedTheme = {...prev};
|
|
231
|
-
|
|
232
|
-
for (const key in newTheme) {
|
|
233
|
-
if (Object.hasOwn(newTheme, key)) {
|
|
234
|
-
const newSubTheme = newTheme[key as keyof TerrenoThemeConfig];
|
|
235
|
-
const prevSubTheme = prev[key as keyof TerrenoThemeConfig];
|
|
236
|
-
|
|
237
|
-
if (newSubTheme && typeof newSubTheme === "object") {
|
|
238
|
-
(mergedTheme as Record<string, unknown>)[key] = {
|
|
239
|
-
...prevSubTheme,
|
|
240
|
-
...newSubTheme,
|
|
241
|
-
};
|
|
242
|
-
} else {
|
|
243
|
-
(mergedTheme as Record<string, unknown>)[key] = newSubTheme;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return mergedTheme;
|
|
249
|
-
});
|
|
378
|
+
setProviderThemeOverrides((previousTheme) => mergeThemeConfig(previousTheme, newTheme));
|
|
250
379
|
}, []);
|
|
251
380
|
|
|
252
381
|
const resetTheme = useCallback((): void => {
|
|
253
|
-
|
|
254
|
-
setProviderPrimitives(
|
|
382
|
+
setProviderThemeOverrides({});
|
|
383
|
+
setProviderPrimitives(defaultThemePrimitives);
|
|
255
384
|
}, []);
|
|
256
385
|
const contextValue = useMemo(
|
|
257
|
-
() => ({
|
|
258
|
-
|
|
386
|
+
() => ({
|
|
387
|
+
colorScheme: resolvedColorScheme,
|
|
388
|
+
colorSchemeSetting,
|
|
389
|
+
resetTheme,
|
|
390
|
+
setColorScheme,
|
|
391
|
+
setPrimitives,
|
|
392
|
+
setTheme,
|
|
393
|
+
theme: computedTheme,
|
|
394
|
+
}),
|
|
395
|
+
[
|
|
396
|
+
colorSchemeSetting,
|
|
397
|
+
computedTheme,
|
|
398
|
+
resetTheme,
|
|
399
|
+
resolvedColorScheme,
|
|
400
|
+
setColorScheme,
|
|
401
|
+
setPrimitives,
|
|
402
|
+
setTheme,
|
|
403
|
+
]
|
|
259
404
|
);
|
|
260
405
|
|
|
261
406
|
return (
|
|
@@ -265,4 +410,4 @@ export const ThemeProvider = ({children, initialPrimitives}: ThemeProviderProps)
|
|
|
265
410
|
);
|
|
266
411
|
};
|
|
267
412
|
|
|
268
|
-
export const useTheme = () =>
|
|
413
|
+
export const useTheme = (): React.ContextType<typeof ThemeContext> => useContext(ThemeContext);
|
package/src/Toast.test.tsx
CHANGED
|
@@ -22,6 +22,13 @@ beforeAll(() => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
describe("Toast", () => {
|
|
25
|
+
it("lets clicks pass through the layout wrapper beside the toast", () => {
|
|
26
|
+
const {toJSON} = renderWithTheme(<Toast title="Pass through" />);
|
|
27
|
+
const wrapper = toJSON() as {props: {style: unknown}};
|
|
28
|
+
const style = Object.assign({}, ...[wrapper.props.style].flat()) as {pointerEvents?: string};
|
|
29
|
+
expect(style.pointerEvents).toBe("box-none");
|
|
30
|
+
});
|
|
31
|
+
|
|
25
32
|
it("renders correctly with default props", () => {
|
|
26
33
|
const {toJSON} = renderWithTheme(<Toast title="Test message" />);
|
|
27
34
|
expect(toJSON()).toMatchSnapshot();
|
package/src/Toast.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
-
import {Platform, Pressable, View} from "react-native";
|
|
2
|
+
import {Platform, Pressable, StyleSheet, View} from "react-native";
|
|
3
3
|
|
|
4
4
|
import type {IconName, SurfaceColor, TextColor, ToastProps} from "./Common";
|
|
5
5
|
import {Heading} from "./Heading";
|
|
@@ -11,6 +11,13 @@ import {isAPIError, printAPIError} from "./Utilities";
|
|
|
11
11
|
|
|
12
12
|
const TOAST_DURATION_MS = 3 * 1000;
|
|
13
13
|
|
|
14
|
+
// The layout wrapper is wider than the visible toast, so it passes clicks through to the page
|
|
15
|
+
// beside the toast. pointerEvents must be registered here: react-native-web drops it from
|
|
16
|
+
// inline styles.
|
|
17
|
+
const styles = StyleSheet.create({
|
|
18
|
+
wrapper: {pointerEvents: "box-none"},
|
|
19
|
+
});
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* Base testID of the action button. Suffixed with the toast id when the caller
|
|
16
23
|
* supplied one, so stacked action toasts stay individually addressable.
|
|
@@ -148,17 +155,20 @@ export const Toast = ({
|
|
|
148
155
|
|
|
149
156
|
return (
|
|
150
157
|
<View
|
|
151
|
-
style={
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
style={[
|
|
159
|
+
styles.wrapper,
|
|
160
|
+
{
|
|
161
|
+
display: "flex",
|
|
162
|
+
flexDirection: "row",
|
|
163
|
+
flexGrow: 1,
|
|
164
|
+
justifyContent: "center",
|
|
165
|
+
marginTop: theme.spacing.sm,
|
|
166
|
+
maxWidth: Platform.OS === "web" ? 900 : "100%",
|
|
167
|
+
paddingLeft: Platform.OS === "web" ? "10%" : theme.spacing.sm,
|
|
168
|
+
paddingRight: Platform.OS === "web" ? "10%" : theme.spacing.sm,
|
|
169
|
+
width: "100%",
|
|
170
|
+
},
|
|
171
|
+
]}
|
|
162
172
|
>
|
|
163
173
|
<View
|
|
164
174
|
style={{
|
|
@@ -188,6 +188,42 @@ describe("ToastNotifications", () => {
|
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
describe("Toast functionality", () => {
|
|
191
|
+
it("lets clicks pass through the full-width safe area around toasts", async () => {
|
|
192
|
+
let toastRef: ToastType | null = null;
|
|
193
|
+
|
|
194
|
+
const TestComponent = () => {
|
|
195
|
+
const toast = useToastNotifications();
|
|
196
|
+
toastRef = toast;
|
|
197
|
+
return <Text>Test</Text>;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const {UNSAFE_root} = render(
|
|
201
|
+
<ToastProvider swipeEnabled={false}>
|
|
202
|
+
<TestComponent />
|
|
203
|
+
</ToastProvider>
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
await waitFor(() => {
|
|
207
|
+
expect(toastRef?.show).toBeDefined();
|
|
208
|
+
});
|
|
209
|
+
await act(async () => {
|
|
210
|
+
toastRef?.show("Pass through", {placement: "top"});
|
|
211
|
+
toastRef?.show("Pass through", {placement: "bottom"});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const safeAreas = UNSAFE_root.findAll(
|
|
215
|
+
(node: {type: unknown}) => node.type === "SafeAreaView",
|
|
216
|
+
{deep: true}
|
|
217
|
+
);
|
|
218
|
+
expect(safeAreas.length).toBe(2);
|
|
219
|
+
for (const safeArea of safeAreas) {
|
|
220
|
+
const style = Object.assign({}, ...[safeArea.props.style].flat()) as {
|
|
221
|
+
pointerEvents?: string;
|
|
222
|
+
};
|
|
223
|
+
expect(style.pointerEvents).toBe("box-none");
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
191
227
|
it("should show a toast and return an id", async () => {
|
|
192
228
|
let toastRef: ToastType | null = null;
|
|
193
229
|
|