@terreno/ui 0.0.17 → 0.1.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.
Files changed (48) hide show
  1. package/dist/Button.js +1 -1
  2. package/dist/Button.js.map +1 -1
  3. package/dist/Common.d.ts +1 -1
  4. package/dist/Hyperlink.js +2 -2
  5. package/dist/Hyperlink.js.map +1 -1
  6. package/dist/Page.js +2 -1
  7. package/dist/Page.js.map +1 -1
  8. package/dist/TerrenoProvider.js +1 -1
  9. package/dist/TerrenoProvider.js.map +1 -1
  10. package/dist/Text.js +3 -0
  11. package/dist/Text.js.map +1 -1
  12. package/dist/Theme.js +27 -27
  13. package/dist/Theme.js.map +1 -1
  14. package/dist/Toast.js +7 -5
  15. package/dist/Toast.js.map +1 -1
  16. package/dist/ToastNotifications.d.ts +144 -0
  17. package/dist/ToastNotifications.js +387 -0
  18. package/dist/ToastNotifications.js.map +1 -0
  19. package/dist/UserInactivity.js +2 -2
  20. package/dist/UserInactivity.js.map +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js.map +1 -1
  23. package/package.json +8 -7
  24. package/src/Button.tsx +1 -1
  25. package/src/Common.ts +1 -2
  26. package/src/Hyperlink.tsx +2 -10
  27. package/src/Page.tsx +3 -2
  28. package/src/TerrenoProvider.tsx +1 -1
  29. package/src/Text.tsx +3 -0
  30. package/src/Theme.tsx +33 -27
  31. package/src/Toast.tsx +7 -5
  32. package/src/ToastNotifications.test.tsx +645 -0
  33. package/src/ToastNotifications.tsx +746 -0
  34. package/src/UserInactivity.tsx +2 -2
  35. package/src/__snapshots__/Button.test.tsx.snap +12 -12
  36. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +2 -2
  37. package/src/__snapshots__/ErrorPage.test.tsx.snap +1 -1
  38. package/src/__snapshots__/Field.test.tsx.snap +138 -138
  39. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +2 -2
  40. package/src/__snapshots__/InfoModalIcon.test.tsx.snap +4 -4
  41. package/src/__snapshots__/Modal.test.tsx.snap +3 -3
  42. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +2 -2
  43. package/src/__snapshots__/Page.test.tsx.snap +1 -1
  44. package/src/__snapshots__/PhoneNumberField.test.tsx.snap +17 -17
  45. package/src/bunSetup.ts +23 -0
  46. package/src/index.tsx +2 -0
  47. package/src/table/__snapshots__/TableDate.test.tsx.snap +4 -4
  48. package/src/table/__snapshots__/TableRow.test.tsx.snap +64 -64
package/src/Theme.tsx CHANGED
@@ -163,11 +163,39 @@ type DeepPartial<T> = {
163
163
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
164
164
  };
165
165
 
166
+ const computeTheme = (
167
+ themeConfig: DeepPartial<TerrenoThemeConfig>,
168
+ primitives: ThemePrimitives
169
+ ): TerrenoTheme => {
170
+ const theme = Object.keys(themeConfig).reduce((acc, key) => {
171
+ if (key === "primitives") {
172
+ return acc;
173
+ }
174
+ const value = themeConfig[key as keyof TerrenoThemeConfig] ?? {};
175
+ acc[key as keyof TerrenoTheme] = Object.keys(value).reduce((accKey, valueKey) => {
176
+ const primitiveKey = value[valueKey as keyof typeof value] as keyof ThemePrimitives;
177
+ if (key === "font") {
178
+ accKey[valueKey] = primitiveKey;
179
+ } else {
180
+ if (primitives[primitiveKey] === undefined) {
181
+ console.error(`Primitive ${primitiveKey} not found in theme.`);
182
+ }
183
+ accKey[valueKey as keyof typeof accKey] = primitives[primitiveKey];
184
+ }
185
+ return accKey;
186
+ }, {} as any);
187
+ return acc;
188
+ }, {} as TerrenoTheme);
189
+ return {...theme, primitives};
190
+ };
191
+
192
+ const defaultComputedTheme = computeTheme(defaultTheme, defaultPrimitives);
193
+
166
194
  export const ThemeContext = createContext({
167
195
  resetTheme: () => {},
168
196
  setPrimitives: (_primitives: DeepPartial<typeof defaultPrimitives>) => {},
169
197
  setTheme: (_theme: DeepPartial<TerrenoThemeConfig>) => {},
170
- theme: {} as TerrenoTheme,
198
+ theme: defaultComputedTheme,
171
199
  });
172
200
 
173
201
  interface ThemeProviderProps {
@@ -178,32 +206,10 @@ export const ThemeProvider = ({children}: ThemeProviderProps) => {
178
206
  const [providerTheme, setProviderTheme] = useState<DeepPartial<TerrenoThemeConfig>>(defaultTheme);
179
207
  const [providerPrimitives, setProviderPrimitives] = useState<ThemePrimitives>(defaultPrimitives);
180
208
 
181
- const computedTheme = useMemo(() => {
182
- // Map the providerTheme and transform the strings into the actual values from the primitives.
183
- // Do this for each sub-object in the theme. E.g. theme.text, theme.surface, etc.
184
- const theme = Object.keys(providerTheme).reduce((acc, key) => {
185
- if (key === "primitives") return acc;
186
- const value = providerTheme[key as keyof TerrenoThemeConfig] ?? {};
187
- // for each key, map the value to the primitive value.
188
- acc[key as keyof TerrenoTheme] = Object.keys(value).reduce((accKey, valueKey) => {
189
- const primitiveKey = value[valueKey as keyof typeof value] as keyof ThemePrimitives;
190
- if (key === "font") {
191
- accKey[valueKey] = primitiveKey;
192
- } else {
193
- if (providerPrimitives[primitiveKey] === undefined) {
194
- console.error(`Primitive ${primitiveKey} not found in theme.`);
195
- }
196
- accKey[valueKey as keyof typeof accKey] = providerPrimitives[primitiveKey];
197
- }
198
- return accKey;
199
- }, {} as any);
200
- return acc;
201
- }, {} as TerrenoTheme);
202
- return {
203
- ...theme,
204
- primitives: providerPrimitives,
205
- };
206
- }, [providerTheme, providerPrimitives]);
209
+ const computedTheme = useMemo(
210
+ () => computeTheme(providerTheme, providerPrimitives),
211
+ [providerTheme, providerPrimitives]
212
+ );
207
213
 
208
214
  const setPrimitives = (newPrimitives: Partial<ThemePrimitives>) => {
209
215
  setProviderPrimitives((prev) => ({...prev, ...newPrimitives}));
package/src/Toast.tsx CHANGED
@@ -1,12 +1,12 @@
1
1
  import type React from "react";
2
2
  import {Platform, Pressable, View} from "react-native";
3
- import {useToast as useRNToast} from "react-native-toast-notifications";
4
3
 
5
4
  import type {IconName, SurfaceColor, TextColor, ToastProps} from "./Common";
6
5
  import {Heading} from "./Heading";
7
6
  import {Icon} from "./Icon";
8
7
  import {Text} from "./Text";
9
8
  import {useTheme} from "./Theme";
9
+ import {useToastNotifications} from "./ToastNotifications";
10
10
  import {isAPIError, printAPIError} from "./Utilities";
11
11
 
12
12
  const TOAST_DURATION_MS = 3 * 1000;
@@ -30,8 +30,12 @@ export function useToast(): {
30
30
  show: (title: string, options?: UseToastOptions) => string;
31
31
  catch: (error: any, message?: string, options?: UseToastVariantOptions) => void;
32
32
  } {
33
- const toast = useRNToast();
33
+ const toast = useToastNotifications();
34
34
  const show = (title: string, options?: UseToastOptions): string => {
35
+ if (!toast?.show) {
36
+ console.warn("Toast not ready yet — provider ref may not be initialized");
37
+ return "";
38
+ }
35
39
  const toastData = {
36
40
  variant: "info",
37
41
  ...options,
@@ -39,7 +43,6 @@ export function useToast(): {
39
43
  };
40
44
  return toast.show(title, {
41
45
  data: toastData,
42
- // a duration of 0 keeps the toast up infinitely until hidden
43
46
  duration: options?.persistent ? 0 : TOAST_DURATION_MS,
44
47
  });
45
48
  };
@@ -60,7 +63,7 @@ export function useToast(): {
60
63
  console.error(title);
61
64
  return show(title, {...options, variant: "error"});
62
65
  },
63
- hide: (id: string) => toast.hide(id),
66
+ hide: (id: string) => toast?.hide?.(id),
64
67
  info: (title: string, options?: UseToastVariantOptions): string => {
65
68
  console.info(title);
66
69
  return show(title, {...options, variant: "info"});
@@ -79,7 +82,6 @@ export function useToast(): {
79
82
 
80
83
  // TODO: Support secondary version of Toast.
81
84
  // TODO: Support dismissible version of Toast. Currently only persistent are dismissible.
82
- // This may require a different library from react-native-toast-notifications.
83
85
  export const Toast = ({
84
86
  title,
85
87
  variant = "info",