@vvedantb/native-ui 0.37.2 → 0.38.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/README.md +8 -7
- package/dist/app-root/AuthGroupGate.jsx +65 -0
- package/dist/app-root/SsoCallbackScreen.jsx +97 -0
- package/dist/app-root/fonts.js +88 -0
- package/dist/app-root/index.js +3 -0
- package/dist/auth/AuthScreen.jsx +252 -74
- package/dist/auth/SecondFactorScreen.jsx +18 -12
- package/dist/auth/SignInScreen.jsx +40 -17
- package/dist/crash/LastCrashDialog.jsx +56 -0
- package/dist/crash/lastCrash.js +213 -0
- package/dist/entries/app-root.js +6 -0
- package/dist/entries/crash.js +5 -0
- package/dist/entries/theme.js +3 -0
- package/dist/index.js +3 -0
- package/dist/neutralTheme.js +163 -0
- package/dist/primitives/icon.jsx +0 -4
- package/dist/primitives/select.jsx +0 -2
- package/dist/settings/ThemeModePicker.jsx +2 -5
- package/dist/themeModeStore.js +67 -0
- package/dist/themeModes.js +9 -0
- package/package.json +47 -19
- package/src/app-root/AuthGroupGate.tsx +46 -0
- package/src/app-root/SsoCallbackScreen.tsx +62 -0
- package/src/app-root/fonts.ts +55 -0
- package/src/app-root/index.ts +6 -0
- package/src/auth/AuthScreen.tsx +102 -1
- package/src/auth/SecondFactorScreen.tsx +20 -2
- package/src/auth/SignInScreen.tsx +119 -53
- package/src/crash/LastCrashDialog.tsx +42 -0
- package/src/crash/lastCrash.ts +239 -0
- package/src/entries/app-root.ts +6 -0
- package/src/entries/crash.ts +16 -0
- package/src/entries/theme.ts +6 -0
- package/src/highlight.ts +1 -1
- package/src/index.ts +5 -0
- package/src/neutralTheme.ts +130 -0
- package/src/primitives/icon.tsx +0 -2
- package/src/primitives/select.tsx +0 -2
- package/src/settings/ThemeModePicker.tsx +2 -5
- package/src/themeModeStore.ts +94 -0
- package/src/themeModes.ts +10 -0
- package/types/prism-react-renderer.d.ts +22 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { configureTheme } from "./configureTheme";
|
|
2
|
+
import { palette, withAlpha } from "./palette";
|
|
3
|
+
import { tokens } from "./tokens";
|
|
4
|
+
|
|
5
|
+
/** The web Neutral theme (`.dark.neutral` in `@vvedantb/ui` tokens.css), as hex. */
|
|
6
|
+
export const NEUTRAL_PALETTE = {
|
|
7
|
+
background: "#222325",
|
|
8
|
+
surface: "#303134",
|
|
9
|
+
surfaceSecondary: "#3a3b3e",
|
|
10
|
+
surfaceTertiary: "#444548",
|
|
11
|
+
border: "#4e4f52",
|
|
12
|
+
muted: "#9fa0a2",
|
|
13
|
+
foreground: "#fafafa",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
/** The same colours as space-separated RGB channels, for NativeWind variables that take channels. */
|
|
17
|
+
export const NEUTRAL_CHANNELS = {
|
|
18
|
+
background: "34 35 37",
|
|
19
|
+
surface: "48 49 52",
|
|
20
|
+
surfaceSecondary: "58 59 62",
|
|
21
|
+
surfaceTertiary: "68 69 72",
|
|
22
|
+
border: "78 79 82",
|
|
23
|
+
muted: "159 160 162",
|
|
24
|
+
foreground: "250 250 250",
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
/** The kit dark-slot values that Neutral changes. */
|
|
28
|
+
type DarkFamily = {
|
|
29
|
+
color: Record<
|
|
30
|
+
| "background"
|
|
31
|
+
| "foreground"
|
|
32
|
+
| "muted"
|
|
33
|
+
| "border"
|
|
34
|
+
| "separator"
|
|
35
|
+
| "surface"
|
|
36
|
+
| "surfaceSecondary"
|
|
37
|
+
| "surfaceCard"
|
|
38
|
+
| "fill",
|
|
39
|
+
string
|
|
40
|
+
>;
|
|
41
|
+
palette: Record<"default" | "overlay" | "segment" | "surfaceTertiary" | "fieldPlaceholder" | "tabBarPill", string>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The package dark values, copied at import so a Neutral pick can be undone. */
|
|
45
|
+
const DARK: DarkFamily = {
|
|
46
|
+
color: {
|
|
47
|
+
background: tokens.color.background.dark,
|
|
48
|
+
foreground: tokens.color.foreground.dark,
|
|
49
|
+
muted: tokens.color.muted.dark,
|
|
50
|
+
border: tokens.color.border.dark,
|
|
51
|
+
separator: tokens.color.separator.dark,
|
|
52
|
+
surface: tokens.color.surface.dark,
|
|
53
|
+
surfaceSecondary: tokens.color.surfaceSecondary.dark,
|
|
54
|
+
surfaceCard: tokens.color.surfaceCard.dark,
|
|
55
|
+
fill: tokens.color.fill.dark,
|
|
56
|
+
},
|
|
57
|
+
palette: {
|
|
58
|
+
default: palette.default.dark,
|
|
59
|
+
overlay: palette.overlay.dark,
|
|
60
|
+
segment: palette.segment.dark,
|
|
61
|
+
surfaceTertiary: palette.surfaceTertiary.dark,
|
|
62
|
+
fieldPlaceholder: palette.fieldPlaceholder.dark,
|
|
63
|
+
tabBarPill: palette.tabBarPill.dark,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const NEUTRAL: DarkFamily = {
|
|
68
|
+
color: {
|
|
69
|
+
background: NEUTRAL_PALETTE.background,
|
|
70
|
+
foreground: NEUTRAL_PALETTE.foreground,
|
|
71
|
+
muted: NEUTRAL_PALETTE.muted,
|
|
72
|
+
border: NEUTRAL_PALETTE.border,
|
|
73
|
+
separator: NEUTRAL_PALETTE.surfaceSecondary,
|
|
74
|
+
surface: NEUTRAL_PALETTE.surface,
|
|
75
|
+
surfaceSecondary: NEUTRAL_PALETTE.surfaceSecondary,
|
|
76
|
+
surfaceCard: NEUTRAL_PALETTE.surface,
|
|
77
|
+
// The package glass is its dark surface at 88%; Neutral's surface the same.
|
|
78
|
+
fill: withAlpha(NEUTRAL_PALETTE.surface, 0.88),
|
|
79
|
+
},
|
|
80
|
+
palette: {
|
|
81
|
+
default: NEUTRAL_PALETTE.surfaceTertiary,
|
|
82
|
+
overlay: NEUTRAL_PALETTE.surface,
|
|
83
|
+
segment: NEUTRAL_PALETTE.surfaceTertiary,
|
|
84
|
+
surfaceTertiary: NEUTRAL_PALETTE.surfaceTertiary,
|
|
85
|
+
fieldPlaceholder: NEUTRAL_PALETTE.muted,
|
|
86
|
+
tabBarPill: NEUTRAL_PALETTE.surfaceTertiary,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Dark-slot colours that replace the ones `paintDarkFamily` would paint. */
|
|
91
|
+
export type PaintDarkFamilyOverrides = {
|
|
92
|
+
color?: Partial<DarkFamily["color"]>;
|
|
93
|
+
palette?: Partial<DarkFamily["palette"]>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Puts the Dark or Neutral colours in the kit's dark slot (`configureTheme`).
|
|
98
|
+
* Light is not changed. Kit parts under `NativeUiProvider` redraw at once.
|
|
99
|
+
* Status and accent colours stay Dark's. `overrides` replaces any painted
|
|
100
|
+
* dark-slot colour, for an app that keeps its own value.
|
|
101
|
+
*/
|
|
102
|
+
export function paintDarkFamily(family: "dark" | "neutral", overrides?: PaintDarkFamilyOverrides): void {
|
|
103
|
+
const base = family === "neutral" ? NEUTRAL : DARK;
|
|
104
|
+
const next: DarkFamily = {
|
|
105
|
+
color: { ...base.color, ...overrides?.color },
|
|
106
|
+
palette: { ...base.palette, ...overrides?.palette },
|
|
107
|
+
};
|
|
108
|
+
const { color } = tokens;
|
|
109
|
+
configureTheme({
|
|
110
|
+
color: {
|
|
111
|
+
background: { light: color.background.light, dark: next.color.background },
|
|
112
|
+
foreground: { light: color.foreground.light, dark: next.color.foreground },
|
|
113
|
+
muted: { light: color.muted.light, dark: next.color.muted },
|
|
114
|
+
border: { light: color.border.light, dark: next.color.border },
|
|
115
|
+
separator: { light: color.separator.light, dark: next.color.separator },
|
|
116
|
+
surface: { light: color.surface.light, dark: next.color.surface },
|
|
117
|
+
surfaceSecondary: { light: color.surfaceSecondary.light, dark: next.color.surfaceSecondary },
|
|
118
|
+
surfaceCard: { light: color.surfaceCard.light, dark: next.color.surfaceCard },
|
|
119
|
+
fill: { light: color.fill.light, dark: next.color.fill },
|
|
120
|
+
},
|
|
121
|
+
palette: {
|
|
122
|
+
default: { light: palette.default.light, dark: next.palette.default },
|
|
123
|
+
overlay: { light: palette.overlay.light, dark: next.palette.overlay },
|
|
124
|
+
segment: { light: palette.segment.light, dark: next.palette.segment },
|
|
125
|
+
surfaceTertiary: { light: palette.surfaceTertiary.light, dark: next.palette.surfaceTertiary },
|
|
126
|
+
fieldPlaceholder: { light: palette.fieldPlaceholder.light, dark: next.palette.fieldPlaceholder },
|
|
127
|
+
tabBarPill: { light: palette.tabBarPill.light, dark: next.palette.tabBarPill },
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
package/src/primitives/icon.tsx
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { IconProps as TablerIconProps } from "@tabler/icons-react-native";
|
|
3
3
|
|
|
4
|
-
// Tabler, not Lucide: a Lucide icon always sets `testID` on its `Svg`, which
|
|
5
|
-
// on web is a DOM `<svg>`, so React logs it as an unknown DOM prop.
|
|
6
4
|
type IconProps = TablerIconProps & {
|
|
7
5
|
as: React.ComponentType<TablerIconProps>;
|
|
8
6
|
className?: string;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import * as SelectPrimitive from "@rn-primitives/select";
|
|
2
|
-
// Tabler, not Lucide: a Lucide icon always sets `testID` on its `Svg`, which
|
|
3
|
-
// on web is a DOM `<svg>`, so React logs it as an unknown DOM prop.
|
|
4
2
|
import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react-native";
|
|
5
3
|
import * as React from "react";
|
|
6
4
|
import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
@@ -7,12 +7,9 @@ import { palette, withAlpha } from "../palette";
|
|
|
7
7
|
import { useLargerText } from "../theme";
|
|
8
8
|
import { tokens } from "../tokens";
|
|
9
9
|
import { useScheme } from "../useScheme";
|
|
10
|
+
import { THEME_MODES, type ThemeMode } from "../themeModes";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
export type ThemeMode = "light" | "neutral" | "dark" | "system";
|
|
13
|
-
|
|
14
|
-
/** Default order: light to dark, then system. */
|
|
15
|
-
export const THEME_MODES = ["light", "neutral", "dark", "system"] as const satisfies readonly ThemeMode[];
|
|
12
|
+
export { THEME_MODES, type ThemeMode };
|
|
16
13
|
|
|
17
14
|
const LABELS: Record<ThemeMode, string> = { light: "Light", neutral: "Neutral", dark: "Dark", system: "System" };
|
|
18
15
|
const ICONS = { light: IconSun, neutral: IconCircleHalf, dark: IconMoon, system: IconDeviceDesktop };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { colorScheme } from "nativewind";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { paintDarkFamily } from "./neutralTheme";
|
|
4
|
+
import { parseThemeMode, type ThemeMode } from "./themeModes";
|
|
5
|
+
|
|
6
|
+
/** Where the mode is kept: SecureStore, AsyncStorage or the app's own store. Sync or async. */
|
|
7
|
+
export type ThemeModeStorage = {
|
|
8
|
+
getItem: (key: string) => Promise<string | null> | string | null;
|
|
9
|
+
setItem: (key: string, value: string) => Promise<void> | void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ThemeModeStoreOptions = {
|
|
13
|
+
/** The storage key. Keep the app's existing key so a saved pick survives the update. */
|
|
14
|
+
key: string;
|
|
15
|
+
storage: ThemeModeStorage;
|
|
16
|
+
/** Called when a read or write of `storage` fails. Without it the failure is ignored. */
|
|
17
|
+
onError?: (error: Error) => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ThemeModeStore = {
|
|
21
|
+
/** The current mode, "system" included (NativeWind reports only the resolved scheme). */
|
|
22
|
+
getMode: () => ThemeMode;
|
|
23
|
+
subscribe: (listener: () => void) => () => void;
|
|
24
|
+
/** Reads the saved mode and paints it. A pick made before the read ends wins. Never rejects. */
|
|
25
|
+
restore: () => Promise<void>;
|
|
26
|
+
/** Paints `mode` at once and saves it. */
|
|
27
|
+
set: (mode: ThemeMode) => void;
|
|
28
|
+
/** React hook for the current mode. */
|
|
29
|
+
useMode: () => ThemeMode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function toError(error: Error | string | number | boolean | object | null | undefined): Error {
|
|
33
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The appearance mode of this phone: light, neutral, dark or system, starting
|
|
38
|
+
* at "system". Neutral is the NativeWind dark scheme with the Neutral palette
|
|
39
|
+
* in the kit's dark slot (`paintDarkFamily`).
|
|
40
|
+
*/
|
|
41
|
+
export function createThemeModeStore({ key, storage, onError }: ThemeModeStoreOptions): ThemeModeStore {
|
|
42
|
+
let current: ThemeMode = "system";
|
|
43
|
+
/** True once the user picked a mode: a slow restore must not undo it. */
|
|
44
|
+
let chosen = false;
|
|
45
|
+
const listeners = new Set<() => void>();
|
|
46
|
+
const report = (error: Error | string | number | boolean | object | null | undefined) => onError?.(toError(error));
|
|
47
|
+
|
|
48
|
+
/** Paints `mode`. The dark slot goes first, so the scheme change redraws with it. */
|
|
49
|
+
function apply(mode: ThemeMode) {
|
|
50
|
+
current = mode;
|
|
51
|
+
paintDarkFamily(mode === "neutral" ? "neutral" : "dark");
|
|
52
|
+
colorScheme.set(mode === "neutral" ? "dark" : mode);
|
|
53
|
+
for (const listener of listeners) listener();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function subscribe(listener: () => void) {
|
|
57
|
+
listeners.add(listener);
|
|
58
|
+
return () => {
|
|
59
|
+
listeners.delete(listener);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const getMode = () => current;
|
|
64
|
+
|
|
65
|
+
async function restore() {
|
|
66
|
+
let saved: string | null = null;
|
|
67
|
+
try {
|
|
68
|
+
saved = await storage.getItem(key);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
report(error instanceof Error ? error : String(error));
|
|
71
|
+
}
|
|
72
|
+
if (chosen) return;
|
|
73
|
+
apply(parseThemeMode(saved) ?? "system");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function set(mode: ThemeMode) {
|
|
77
|
+
chosen = true;
|
|
78
|
+
if (mode !== current) apply(mode);
|
|
79
|
+
Promise.resolve()
|
|
80
|
+
.then(() => storage.setItem(key, mode))
|
|
81
|
+
.catch(report);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Server render and hydration: the mode is always "system" until `restore` runs on the client. */
|
|
85
|
+
const getServerSnapshot = (): ThemeMode => "system";
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
getMode,
|
|
89
|
+
subscribe,
|
|
90
|
+
restore,
|
|
91
|
+
set,
|
|
92
|
+
useMode: () => useSyncExternalStore(subscribe, getMode, getServerSnapshot),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A theme the picker can show, as the web `ThemeModePicker`. Neutral is the dark scheme with a grey palette. */
|
|
2
|
+
export type ThemeMode = "light" | "neutral" | "dark" | "system";
|
|
3
|
+
|
|
4
|
+
/** Default order: light to dark, then system. */
|
|
5
|
+
export const THEME_MODES = ["light", "neutral", "dark", "system"] as const satisfies readonly ThemeMode[];
|
|
6
|
+
|
|
7
|
+
/** The mode that `value` names, or `undefined` for anything else (a missing or stale stored value). */
|
|
8
|
+
export function parseThemeMode(value: string | null | undefined): ThemeMode | undefined {
|
|
9
|
+
return THEME_MODES.find((mode) => mode === value);
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The part of the optional peer `prism-react-renderer` that `CodeBlock` uses.
|
|
3
|
+
* `src/highlight.ts` imports these types by relative path, so a consuming app
|
|
4
|
+
* type-checks without the peer installed and without a global
|
|
5
|
+
* `declare module`, which would replace the real types in the app. Published
|
|
6
|
+
* with the package (`files`). The peer itself is loaded at run time only.
|
|
7
|
+
*/
|
|
8
|
+
import type { ReactElement, ReactNode } from "react";
|
|
9
|
+
|
|
10
|
+
export type Token = { types: string[]; content: string; empty?: boolean };
|
|
11
|
+
export type PrismTheme = {
|
|
12
|
+
plain: { color?: string; backgroundColor?: string };
|
|
13
|
+
styles: Array<{ types: string[]; style: { color?: string; fontStyle?: string } }>;
|
|
14
|
+
};
|
|
15
|
+
export type RenderProps = { tokens: Token[][] };
|
|
16
|
+
export function Highlight(props: {
|
|
17
|
+
code: string;
|
|
18
|
+
language: string;
|
|
19
|
+
theme?: PrismTheme;
|
|
20
|
+
children: (props: RenderProps) => ReactElement;
|
|
21
|
+
}): ReactNode;
|
|
22
|
+
export const themes: Record<string, PrismTheme>;
|