@vvedantb/native-ui 0.37.1 → 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/AmbientBackground.jsx +16 -28
- package/dist/Avatar.jsx +2 -2
- package/dist/BottomSheetContainer.jsx +1 -1
- package/dist/BulkActionBar.jsx +1 -1
- package/dist/Card.jsx +4 -4
- package/dist/Chip.jsx +2 -2
- package/dist/DateTimeField.jsx +1 -1
- package/dist/Dialog.jsx +3 -3
- package/dist/DropdownMenu.jsx +3 -3
- package/dist/EmptyState.jsx +4 -4
- package/dist/FloatingTabBar.jsx +2 -2
- package/dist/LabeledSwitchRow.jsx +2 -2
- package/dist/ListRow.jsx +2 -2
- package/dist/PinnedBotTile.jsx +2 -2
- package/dist/StatGrid.jsx +1 -1
- package/dist/Stepper.jsx +2 -2
- package/dist/Toast.jsx +1 -1
- package/dist/ai/activity-question.jsx +2 -2
- package/dist/ai/card-button.jsx +2 -2
- package/dist/ai/choice-question.jsx +8 -8
- package/dist/ai/message-action-sheet.jsx +2 -2
- package/dist/ai/message-quote.jsx +2 -2
- package/dist/ai/message.jsx +2 -2
- package/dist/ai/reply-quote-chip.jsx +2 -2
- package/dist/ai/subagent-cards.jsx +6 -6
- package/dist/ai/tool-approval-card.jsx +1 -1
- 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/examples/ParityGallery.jsx +2 -2
- package/dist/generative-ui/components.jsx +2 -2
- package/dist/index.js +3 -0
- package/dist/marketing/UpgradeToProCard.jsx +2 -2
- package/dist/media/ImageGallery.jsx +2 -2
- package/dist/motion.js +3 -2
- package/dist/neutralTheme.js +163 -0
- package/dist/primitives/card.jsx +2 -2
- package/dist/primitives/icon.jsx +0 -4
- package/dist/primitives/select.jsx +0 -2
- package/dist/primitives/text.jsx +13 -13
- package/dist/primitives/toast-drag-gesture.jsx +3 -2
- package/dist/settings/MoreFromProjectV.jsx +2 -2
- package/dist/settings/SettingsSection.jsx +1 -1
- package/dist/settings/ThemeModePicker.jsx +8 -11
- package/dist/themeModeStore.js +67 -0
- package/dist/themeModes.js +9 -0
- package/package.json +47 -19
- package/src/AmbientBackground.tsx +8 -26
- package/src/Avatar.tsx +2 -2
- package/src/BottomSheetContainer.tsx +1 -1
- package/src/BulkActionBar.tsx +2 -2
- package/src/Card.tsx +5 -5
- package/src/Chip.tsx +2 -2
- package/src/DateTimeField.tsx +2 -2
- package/src/Dialog.tsx +3 -3
- package/src/DropdownMenu.tsx +3 -3
- package/src/EmptyState.tsx +4 -4
- package/src/FloatingTabBar.tsx +2 -2
- package/src/LabeledSwitchRow.tsx +2 -2
- package/src/ListRow.tsx +2 -2
- package/src/PinnedBotTile.tsx +2 -2
- package/src/StatGrid.tsx +2 -2
- package/src/Stepper.tsx +2 -2
- package/src/Toast.tsx +2 -2
- package/src/ai/activity-question.tsx +1 -1
- package/src/ai/card-button.tsx +1 -1
- package/src/ai/choice-question.tsx +10 -10
- package/src/ai/message-action-sheet.tsx +2 -2
- package/src/ai/message-quote.tsx +2 -2
- package/src/ai/message.tsx +2 -2
- package/src/ai/reply-quote-chip.tsx +2 -2
- package/src/ai/subagent-cards.tsx +5 -5
- package/src/ai/tool-approval-card.tsx +4 -4
- 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 +104 -3
- 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/examples/ParityGallery.tsx +2 -2
- package/src/generative-ui/components.tsx +3 -3
- package/src/highlight.ts +1 -1
- package/src/index.ts +5 -0
- package/src/marketing/UpgradeToProCard.tsx +2 -2
- package/src/media/ImageGallery.tsx +1 -1
- package/src/motion.ts +3 -2
- package/src/neutralTheme.ts +130 -0
- package/src/primitives/card.tsx +3 -3
- package/src/primitives/icon.tsx +0 -2
- package/src/primitives/select.tsx +0 -2
- package/src/primitives/text.tsx +13 -13
- package/src/primitives/toast-drag-gesture.tsx +2 -2
- package/src/settings/MoreFromProjectV.tsx +2 -2
- package/src/settings/SettingsSection.tsx +3 -3
- package/src/settings/ThemeModePicker.tsx +11 -19
- package/src/themeModeStore.ts +94 -0
- package/src/themeModes.ts +10 -0
- package/types/prism-react-renderer.d.ts +22 -0
|
@@ -93,8 +93,8 @@ export function UpgradeToProCard({
|
|
|
93
93
|
>
|
|
94
94
|
<Text
|
|
95
95
|
numberOfLines={1}
|
|
96
|
-
className={cn("min-w-0 flex-1 font-instrument-sans-
|
|
97
|
-
style={[textStyle("foreground", scheme), sizeStyle(titleSize), typeStyle("
|
|
96
|
+
className={cn("min-w-0 flex-1 font-instrument-sans-medium", titleSize)}
|
|
97
|
+
style={[textStyle("foreground", scheme), sizeStyle(titleSize), typeStyle("medium")]}
|
|
98
98
|
>
|
|
99
99
|
{title}
|
|
100
100
|
</Text>
|
|
@@ -119,7 +119,7 @@ function ImageGrid({ images, onOpen }: { images: GalleryImage[]; onOpen: (index:
|
|
|
119
119
|
<Image source={{ uri: image.url }} resizeMode="cover" style={{ width: "100%", height: "100%" }} />
|
|
120
120
|
{tile.overflow > 0 ? (
|
|
121
121
|
<View className="absolute inset-0 items-center justify-center" style={{ backgroundColor: withAlpha(tokens.color.black, 0.6) }}>
|
|
122
|
-
<Text className="font-instrument-sans-
|
|
122
|
+
<Text className="font-instrument-sans-medium text-xl" style={[{ color: tokens.color.white }, typeStyle("medium")]}>
|
|
123
123
|
{`+${tile.overflow}`}
|
|
124
124
|
</Text>
|
|
125
125
|
</View>
|
package/src/motion.ts
CHANGED
|
@@ -15,10 +15,11 @@ export const SHEET_SPRING = {
|
|
|
15
15
|
reduceMotion: ReduceMotion.System,
|
|
16
16
|
} as const;
|
|
17
17
|
|
|
18
|
-
/** A dragged sheet that springs home:
|
|
18
|
+
/** A dragged sheet that springs home: critically damped, no bounce. Add the release `velocity`. */
|
|
19
19
|
export const SHEET_SNAP_SPRING = {
|
|
20
20
|
duration: 300,
|
|
21
|
-
dampingRatio:
|
|
21
|
+
dampingRatio: 1,
|
|
22
|
+
overshootClamping: true,
|
|
22
23
|
reduceMotion: ReduceMotion.System,
|
|
23
24
|
} as const;
|
|
24
25
|
|
|
@@ -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/card.tsx
CHANGED
|
@@ -42,14 +42,14 @@ const CardTitle = React.forwardRef<
|
|
|
42
42
|
React.ElementRef<typeof Text>,
|
|
43
43
|
React.ComponentPropsWithoutRef<typeof Text> & { className?: string }
|
|
44
44
|
>(({ className, style, ...props }, ref) => {
|
|
45
|
-
// The web `font-
|
|
45
|
+
// The web `font-medium`: the semibold face, with its weight as a style.
|
|
46
46
|
return (
|
|
47
47
|
<Text
|
|
48
48
|
ref={ref}
|
|
49
49
|
role="heading"
|
|
50
50
|
aria-level={3}
|
|
51
|
-
className={cn("font-instrument-sans-
|
|
52
|
-
style={[typeStyle("
|
|
51
|
+
className={cn("font-instrument-sans-medium leading-none", className)}
|
|
52
|
+
style={[typeStyle("medium"), style]}
|
|
53
53
|
{...props}
|
|
54
54
|
/>
|
|
55
55
|
);
|
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";
|
package/src/primitives/text.tsx
CHANGED
|
@@ -17,26 +17,26 @@ const textVariants = cva(
|
|
|
17
17
|
variant: {
|
|
18
18
|
default: "",
|
|
19
19
|
h1: cn(
|
|
20
|
-
"text-4xl font-instrument-sans-
|
|
20
|
+
"text-4xl font-instrument-sans-medium tracking-tight",
|
|
21
21
|
Platform.select({ web: "scroll-m-20" }),
|
|
22
22
|
),
|
|
23
23
|
h2: cn(
|
|
24
|
-
"text-3xl font-instrument-sans-
|
|
24
|
+
"text-3xl font-instrument-sans-medium tracking-tight border-border border-b pb-2",
|
|
25
25
|
Platform.select({ web: "scroll-m-20" }),
|
|
26
26
|
),
|
|
27
27
|
h3: cn(
|
|
28
|
-
"text-2xl font-instrument-sans-
|
|
28
|
+
"text-2xl font-instrument-sans-medium tracking-tight",
|
|
29
29
|
Platform.select({ web: "scroll-m-20" }),
|
|
30
30
|
),
|
|
31
31
|
h4: cn(
|
|
32
|
-
"text-xl font-instrument-sans-
|
|
32
|
+
"text-xl font-instrument-sans-medium tracking-tight",
|
|
33
33
|
Platform.select({ web: "scroll-m-20" }),
|
|
34
34
|
),
|
|
35
35
|
p: "leading-7",
|
|
36
36
|
blockquote: "border-l-2 border-border pl-4 italic",
|
|
37
|
-
code: "bg-muted rounded px-[0.3rem] py-[0.2rem] text-sm font-instrument-sans-
|
|
37
|
+
code: "bg-muted rounded px-[0.3rem] py-[0.2rem] text-sm font-instrument-sans-medium",
|
|
38
38
|
lead: "text-xl text-muted-foreground",
|
|
39
|
-
large: "text-lg font-instrument-sans-
|
|
39
|
+
large: "text-lg font-instrument-sans-medium",
|
|
40
40
|
small: "text-sm font-instrument-sans-medium",
|
|
41
41
|
muted: "text-sm text-muted-foreground",
|
|
42
42
|
},
|
|
@@ -69,14 +69,14 @@ const ARIA_LEVEL: Partial<Record<TextVariant, string>> = {
|
|
|
69
69
|
// The weight of each variant's `font-instrument-sans-*` class, set as a style
|
|
70
70
|
// beside it (`typeStyle`): where an app maps every one of those classes to one
|
|
71
71
|
// family, the class alone draws Regular. Headings are semibold, as the web
|
|
72
|
-
// titles; `h1` was `font-
|
|
72
|
+
// titles; `h1` was `font-medium` before 0.3.13.
|
|
73
73
|
const WEIGHT: Partial<Record<TextVariant, ReturnType<typeof typeStyle>>> = {
|
|
74
|
-
h1: typeStyle("
|
|
75
|
-
h2: typeStyle("
|
|
76
|
-
h3: typeStyle("
|
|
77
|
-
h4: typeStyle("
|
|
78
|
-
code: typeStyle("
|
|
79
|
-
large: typeStyle("
|
|
74
|
+
h1: typeStyle("medium"),
|
|
75
|
+
h2: typeStyle("medium"),
|
|
76
|
+
h3: typeStyle("medium"),
|
|
77
|
+
h4: typeStyle("medium"),
|
|
78
|
+
code: typeStyle("medium"),
|
|
79
|
+
large: typeStyle("medium"),
|
|
80
80
|
small: typeStyle("medium"),
|
|
81
81
|
};
|
|
82
82
|
|
|
@@ -21,8 +21,8 @@ import { useWebClickGuard } from "./web-click-guard";
|
|
|
21
21
|
// The toast drag on Gesture Handler: the track phase and the release run as
|
|
22
22
|
// worklets on the UI thread. The rules are plain worklets in `toastDrag`.
|
|
23
23
|
|
|
24
|
-
/** Back home after a short drag:
|
|
25
|
-
const HOME_SPRING = { duration: 250, dampingRatio:
|
|
24
|
+
/** Back home after a short drag: critically damped, no bounce. */
|
|
25
|
+
const HOME_SPRING = { duration: 250, dampingRatio: 1, overshootClamping: true, reduceMotion: ReduceMotion.System } as const;
|
|
26
26
|
/** Away up the screen: no overshoot back into view. */
|
|
27
27
|
const AWAY_SPRING = { duration: 250, dampingRatio: 1, overshootClamping: true, reduceMotion: ReduceMotion.System } as const;
|
|
28
28
|
|
|
@@ -49,8 +49,8 @@ export function FromProjectV({ className, testID }: FromProjectVProps) {
|
|
|
49
49
|
</Text>
|
|
50
50
|
<ProjectVMark size={14} color={muted} />
|
|
51
51
|
<Text
|
|
52
|
-
className="text-sm font-instrument-sans-
|
|
53
|
-
style={[textStyle("muted", scheme), typeStyle("
|
|
52
|
+
className="text-sm font-instrument-sans-medium"
|
|
53
|
+
style={[textStyle("muted", scheme), typeStyle("medium")]}
|
|
54
54
|
>
|
|
55
55
|
Project V
|
|
56
56
|
</Text>
|
|
@@ -33,11 +33,11 @@ export function SettingsSection({
|
|
|
33
33
|
<View className="flex-row items-start justify-between gap-4 px-4">
|
|
34
34
|
<View className="min-w-0 flex-1">
|
|
35
35
|
{typeof title === "string" ? (
|
|
36
|
-
// Web `text-sm font-
|
|
36
|
+
// Web `text-sm font-medium`: 14 / 20, 600.
|
|
37
37
|
<Text
|
|
38
38
|
accessibilityRole="header"
|
|
39
|
-
className="text-sm font-instrument-sans-
|
|
40
|
-
style={[textStyle("foreground", scheme), sizeStyle("text-sm"), typeStyle("
|
|
39
|
+
className="text-sm font-instrument-sans-medium"
|
|
40
|
+
style={[textStyle("foreground", scheme), sizeStyle("text-sm"), typeStyle("medium")]}
|
|
41
41
|
>
|
|
42
42
|
{title}
|
|
43
43
|
</Text>
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { IconCheck, IconCircleHalf, IconDeviceDesktop, IconMoon, IconSun } from "@tabler/icons-react-native";
|
|
2
2
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
3
|
-
import Svg, {
|
|
3
|
+
import Svg, { Path, Rect } from "react-native-svg";
|
|
4
4
|
import { cn } from "../cn";
|
|
5
5
|
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
6
6
|
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 };
|
|
19
16
|
/** Web `bg-zinc-900`. */
|
|
20
17
|
const ZINC_900 = "#18181b";
|
|
21
18
|
// Swatches and icons show the theme itself, so they use the web's fixed colours, not tokens.
|
|
22
|
-
// System has no swatch colour (it is a
|
|
19
|
+
// System has no swatch colour (it is a hard split) and a muted icon.
|
|
23
20
|
const SWATCHES: Record<ThemeMode, string | null> = {
|
|
24
21
|
light: "#ffffff",
|
|
25
22
|
neutral: "#3f3f46",
|
|
@@ -44,18 +41,13 @@ export type ThemeModePickerProps = {
|
|
|
44
41
|
testID?: string;
|
|
45
42
|
};
|
|
46
43
|
|
|
47
|
-
/** The
|
|
48
|
-
function
|
|
44
|
+
/** The System swatch: white with a hard diagonal half in zinc-900, no gradient. */
|
|
45
|
+
function SplitSwatch() {
|
|
49
46
|
return (
|
|
50
47
|
// Sized by props: an unsized Svg is 300 wide and widens the tile.
|
|
51
|
-
<Svg width="100%" height="100%" style={StyleSheet.absoluteFill}>
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
<Stop offset="0" stopColor="#ffffff" />
|
|
55
|
-
<Stop offset="1" stopColor={ZINC_900} />
|
|
56
|
-
</LinearGradient>
|
|
57
|
-
</Defs>
|
|
58
|
-
<Rect width="100%" height="100%" fill="url(#theme-mode-system)" />
|
|
48
|
+
<Svg width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none" style={StyleSheet.absoluteFill}>
|
|
49
|
+
<Rect width="1" height="1" fill="#ffffff" />
|
|
50
|
+
<Path d="M1 0 L1 1 L0 1 Z" fill={ZINC_900} />
|
|
59
51
|
</Svg>
|
|
60
52
|
);
|
|
61
53
|
}
|
|
@@ -96,8 +88,8 @@ export function ThemeModePicker({ value, onChange, modes = THEME_MODES, classNam
|
|
|
96
88
|
className="mx-2 h-12 items-center justify-center self-stretch overflow-hidden rounded-2xl"
|
|
97
89
|
style={swatch ? { backgroundColor: swatch } : undefined}
|
|
98
90
|
>
|
|
99
|
-
{swatch ? null : <
|
|
100
|
-
{/* Positioned, so the web build paints it over the positioned
|
|
91
|
+
{swatch ? null : <SplitSwatch />}
|
|
92
|
+
{/* Positioned, so the web build paints it over the positioned swatch. */}
|
|
101
93
|
<View className="absolute inset-0 items-center justify-center">
|
|
102
94
|
<Icon size={22} color={ICON_COLOURS[mode] ?? tokens.color.muted[scheme]} />
|
|
103
95
|
</View>
|
|
@@ -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>;
|