@boostdev/design-system-react-native 0.5.1 → 0.6.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.
@@ -1,12 +1,28 @@
1
1
  import { createContext, ReactNode, useContext, useMemo } from 'react';
2
2
  import { useColorScheme } from 'react-native';
3
- import { colors } from './tokens';
3
+ import { border, colors } from './tokens';
4
4
 
5
5
  export type ThemeColorName = keyof typeof colors.light;
6
6
 
7
7
  /** Semantic theme colors, widened to `string` so brand overrides typecheck. */
8
8
  export type ThemeColors = Readonly<Record<ThemeColorName, string>>;
9
9
 
10
+ /** Corner radii of the controls, in points. */
11
+ export interface ThemeRadius {
12
+ /** Buttons with a text label. */
13
+ button: number;
14
+ /** Icon-only buttons (`isIconOnly`). */
15
+ iconButton: number;
16
+ /** Input fields: FormInput, Select, Combobox, Textarea, FileInput, NumberInput. */
17
+ field: number;
18
+ }
19
+
20
+ const defaultRadius: ThemeRadius = {
21
+ button: border.radius.m,
22
+ iconButton: border.radius.full,
23
+ field: border.radius.m,
24
+ };
25
+
10
26
  /**
11
27
  * Per-scheme token overrides, merged over the foundation colors.
12
28
  * The React Native equivalent of overriding tokens in the web
@@ -15,11 +31,18 @@ export type ThemeColors = Readonly<Record<ThemeColorName, string>>;
15
31
  export interface ThemeTokenOverrides {
16
32
  light?: Partial<Record<ThemeColorName, string>>;
17
33
  dark?: Partial<Record<ThemeColorName, string>>;
34
+ /**
35
+ * Radius overrides, the same in light and dark. The native equivalent of the
36
+ * web `--button_radius` custom property. Merged over the parent provider's
37
+ * radii, so a nested provider that only overrides colors keeps the app's radii.
38
+ */
39
+ radius?: Partial<ThemeRadius>;
18
40
  }
19
41
 
20
42
  interface ThemeContextValue {
21
43
  colors: ThemeColors;
22
44
  isDark: boolean;
45
+ radius: ThemeRadius;
23
46
  }
24
47
 
25
48
  const ThemeContext = createContext<ThemeContextValue | null>(null);
@@ -33,11 +56,17 @@ interface ThemeProviderProps {
33
56
  export function ThemeProvider({ children, colorScheme, tokens }: ThemeProviderProps) {
34
57
  const systemScheme = useColorScheme();
35
58
  const isDark = (colorScheme ?? systemScheme) === 'dark';
59
+ // Colors merge over the foundation; radii merge over the parent provider's.
60
+ const parentRadius = useContext(ThemeContext)?.radius ?? defaultRadius;
36
61
  const value = useMemo<ThemeContextValue>(() => {
37
62
  const base = isDark ? colors.dark : colors.light;
38
63
  const overrides = isDark ? tokens?.dark : tokens?.light;
39
- return { colors: { ...base, ...overrides }, isDark };
40
- }, [isDark, tokens]);
64
+ return {
65
+ colors: { ...base, ...overrides },
66
+ isDark,
67
+ radius: { ...parentRadius, ...tokens?.radius },
68
+ };
69
+ }, [isDark, tokens, parentRadius]);
41
70
  return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
42
71
  }
43
72