@vvedantb/native-ui 0.4.0 → 0.5.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/src/StatusDot.tsx CHANGED
@@ -4,7 +4,10 @@ import { palette, withAlpha } from "./palette";
4
4
  import { tokens } from "./tokens";
5
5
  import { useScheme } from "./useScheme";
6
6
 
7
- /** The web `StatusTone`s. */
7
+ /**
8
+ * The web `StatusTone`s, and `info` (native only, from 0.5.0): neutral news
9
+ * such as "synced" or "new", in blue.
10
+ */
8
11
  export type StatusTone =
9
12
  | "progress"
10
13
  | "business-review"
@@ -13,6 +16,7 @@ export type StatusTone =
13
16
  | "cancelled"
14
17
  | "active"
15
18
  | "critical"
19
+ | "info"
16
20
  | "neutral";
17
21
 
18
22
  export type StatusDotProps = ViewProps & {
@@ -22,6 +26,13 @@ export type StatusDotProps = ViewProps & {
22
26
  className?: string;
23
27
  };
24
28
 
29
+ /**
30
+ * The `info` blue: Tailwind `blue-500` in light and the lighter `blue-400` in
31
+ * dark. Local to the dot: `tokens.css` has no `--info`, so it is not a
32
+ * `palette` key.
33
+ */
34
+ const INFO = { light: "#3b82f6", dark: "#60a5fa" } as const;
35
+
25
36
  function toneColor(tone: StatusTone, scheme: "light" | "dark") {
26
37
  switch (tone) {
27
38
  case "progress":
@@ -37,6 +48,8 @@ function toneColor(tone: StatusTone, scheme: "light" | "dark") {
37
48
  return withAlpha(tokens.color.muted[scheme], 0.4);
38
49
  case "critical":
39
50
  return palette.danger[scheme];
51
+ case "info":
52
+ return INFO[scheme];
40
53
  default:
41
54
  return withAlpha(tokens.color.muted[scheme], 0.6);
42
55
  }
@@ -9,6 +9,10 @@ export type ThemeToggleProps = {
9
9
  testID?: string;
10
10
  };
11
11
 
12
+ /** Logged when NativeWind's `setColorScheme` throws. */
13
+ const DARK_MODE_CLASS_HINT =
14
+ 'ThemeToggle could not set the colour scheme. NativeWind throws while Tailwind darkMode is "media" (the default): set darkMode: "class" in tailwind.config.js. See the @vvedantb/native-ui README, Theme.';
15
+
12
16
  /**
13
17
  * A `HeaderIconButton` that switches between light and dark with NativeWind's
14
18
  * `setColorScheme`, the scheme `useScheme` reads. It shows and names the
@@ -16,6 +20,10 @@ export type ThemeToggleProps = {
16
20
  * "Switch to light mode" in dark. The choice lasts only as long as NativeWind
17
21
  * keeps it; an app that restores it on the next launch stores
18
22
  * `useColorScheme().colorScheme` itself.
23
+ *
24
+ * `setColorScheme` throws unless the app sets Tailwind `darkMode: "class"`.
25
+ * The press then logs that fix with `console.error` and leaves the scheme as
26
+ * it is, instead of throwing from the press handler.
19
27
  */
20
28
  export function ThemeToggle({ testID }: ThemeToggleProps) {
21
29
  const { setColorScheme } = useColorScheme();
@@ -24,12 +32,16 @@ export function ThemeToggle({ testID }: ThemeToggleProps) {
24
32
  const next = scheme === "dark" ? "light" : "dark";
25
33
  const Icon = next === "dark" ? IconMoon : IconSun;
26
34
 
35
+ const toggle = () => {
36
+ try {
37
+ setColorScheme(next);
38
+ } catch (error) {
39
+ console.error(DARK_MODE_CLASS_HINT, error);
40
+ }
41
+ };
42
+
27
43
  return (
28
- <HeaderIconButton
29
- label={`Switch to ${next} mode`}
30
- testID={testID}
31
- onPress={() => setColorScheme(next)}
32
- >
44
+ <HeaderIconButton label={`Switch to ${next} mode`} testID={testID} onPress={toggle}>
33
45
  <Icon size={largerText ? 26 : 22} color={tokens.color.foreground[scheme]} />
34
46
  </HeaderIconButton>
35
47
  );
@@ -1,3 +1,4 @@
1
1
  // `@vvedantb/native-ui/date-time`. Imports
2
2
  // `@react-native-community/datetimepicker` and `dayjs`.
3
3
  export { DateTimeField } from "../DateTimeField";
4
+ export type { DateTimeFieldProps } from "../DateTimeField";
@@ -1,9 +1,13 @@
1
- // `@vvedantb/native-ui/layout`: screen containers, page headers and settings
2
- // chrome.
1
+ // `@vvedantb/native-ui/layout`: screen containers, page headers, section
2
+ // labels and settings chrome.
3
3
  export { SafeAreaContainer } from "../SafeAreaContainer";
4
4
  export { ScreenContainer } from "../ScreenContainer";
5
5
  export { PageTitle, PageHeader } from "../PageTitle";
6
6
  export type { PageTitleProps, PageHeaderProps } from "../PageTitle";
7
+ export { StackPageHeader } from "../StackPageHeader";
8
+ export type { StackPageHeaderProps } from "../StackPageHeader";
9
+ export { SectionLabel } from "../SectionLabel";
10
+ export type { SectionLabelProps } from "../SectionLabel";
7
11
  export { SettingsSection } from "../settings/SettingsSection";
8
12
  export { SettingsField } from "../settings/SettingsField";
9
13
  export { SettingsToggleRow } from "../settings/SettingsToggleRow";
@@ -1,4 +1,9 @@
1
- // `@vvedantb/native-ui/page-title`: `PageTitle` and `PageHeader` on their own.
2
- // Reaches no optional peer, not even a loader.
1
+ // `@vvedantb/native-ui/page-title`: `PageTitle`, `PageHeader` and (from 0.5.0)
2
+ // `StackPageHeader`. Reaches no optional peer, not even a loader.
3
+ // `StackPageHeader` imports one Tabler icon (a required peer) for its back
4
+ // button; Metro does not tree-shake by default, so that bundles the Tabler
5
+ // package with this entry.
3
6
  export { PageTitle, PageHeader } from "../PageTitle";
4
7
  export type { PageTitleProps, PageHeaderProps } from "../PageTitle";
8
+ export { StackPageHeader } from "../StackPageHeader";
9
+ export type { StackPageHeaderProps } from "../StackPageHeader";
@@ -1,6 +1,8 @@
1
1
  // `@vvedantb/native-ui/primitives`: fields, display, tabs, overlays and
2
2
  // toasts. `BottomSheetContainer`, `DateTimeField` and `AmbientBackground` are
3
- // not here; they have their own entries.
3
+ // not here; they have their own entries. `Text` and `TextClassContext` are the
4
+ // `primitives/text` variants (from 0.5.0); they are not on the root entry.
5
+ export { Text, TextClassContext } from "../primitives/text";
4
6
  export { Button } from "../Button";
5
7
  export type { ButtonProps, ButtonSize, ButtonVariant } from "../Button";
6
8
  export { Input } from "../Input";
@@ -23,6 +25,20 @@ export { Badge } from "../Badge";
23
25
  export type { BadgeProps, BadgeVariant } from "../Badge";
24
26
  export { StatusDot } from "../StatusDot";
25
27
  export type { StatusDotProps, StatusTone } from "../StatusDot";
28
+ export { ColorSwatches } from "../ColorSwatches";
29
+ export type { ColorSwatchesProps, ColorSwatchesSize } from "../ColorSwatches";
30
+ export { StatGrid } from "../StatGrid";
31
+ export type { StatGridItem, StatGridProps } from "../StatGrid";
32
+ export { SectionLabel } from "../SectionLabel";
33
+ export type { SectionLabelProps } from "../SectionLabel";
34
+ export { SheetRow } from "../SheetRow";
35
+ export type { SheetRowProps } from "../SheetRow";
36
+ export { PageIndicator } from "../PageIndicator";
37
+ export type { PageIndicatorProps } from "../PageIndicator";
38
+ export { IconButton } from "../IconButton";
39
+ export type { IconButtonProps, IconButtonSize, IconButtonVariant } from "../IconButton";
40
+ export { CaptureButton } from "../CaptureButton";
41
+ export type { CaptureButtonProps } from "../CaptureButton";
26
42
  export { Separator } from "../Separator";
27
43
  export type { SeparatorProps } from "../Separator";
28
44
  export { Progress } from "../Progress";
@@ -43,6 +59,7 @@ export type {
43
59
  TabsContentProps,
44
60
  } from "../Tabs";
45
61
  export { ListRow } from "../ListRow";
62
+ export type { ListRowProps } from "../ListRow";
46
63
  export { HeaderIconButton } from "../HeaderIconButton";
47
64
  export { ThemeToggle } from "../ThemeToggle";
48
65
  export type { ThemeToggleProps } from "../ThemeToggle";
@@ -54,6 +71,7 @@ export {
54
71
  CardContent,
55
72
  CardFooter,
56
73
  } from "../Card";
74
+ export type { CardProps } from "../Card";
57
75
  export { Skeleton, CardSkeleton } from "../Skeleton";
58
76
  export { EmptyState } from "../EmptyState";
59
77
  export type { EmptyStateVariant } from "../EmptyState";
@@ -1,11 +1,18 @@
1
1
  // Reference screen for the components that mirror `@vvedantb/ui`. Render it in
2
2
  // an Expo route to compare against the web: it needs the same NativeWind setup
3
3
  // as the rest of the package and a `SafeAreaProvider` above it. It always
4
- // renders the default sizes (larger text off), as the web does. Prices below
5
- // are placeholders, not real plan prices.
4
+ // renders the default sizes (larger text off), as the web does. Prices, names
5
+ // and figures below are placeholders, not real data.
6
6
  import { useState, type ReactNode } from "react";
7
7
  import { ScrollView, Text, View, type TextProps } from "react-native";
8
- import { IconInbox } from "@tabler/icons-react-native";
8
+ import {
9
+ IconCopy,
10
+ IconInbox,
11
+ IconPhoto,
12
+ IconRefresh,
13
+ IconTrash,
14
+ IconX,
15
+ } from "@tabler/icons-react-native";
9
16
  import {
10
17
  APP_ICONS,
11
18
  APP_NAMES,
@@ -18,12 +25,14 @@ import {
18
25
  AlertDialogHeader,
19
26
  AlertDialogTitle,
20
27
  AlertDialogTrigger,
28
+ AmbientBackground,
21
29
  AppMark,
22
30
  AppWordmark,
23
31
  Avatar,
24
32
  AvatarFallback,
25
33
  Badge,
26
34
  Button,
35
+ CaptureButton,
27
36
  Card,
28
37
  CardContent,
29
38
  CardDescription,
@@ -32,7 +41,9 @@ import {
32
41
  CardTitle,
33
42
  CenteredSpinner,
34
43
  Checkbox,
44
+ ColorSwatches,
35
45
  ConfirmDialog,
46
+ DateTimeField,
36
47
  Dialog,
37
48
  DialogBody,
38
49
  DialogClose,
@@ -44,15 +55,20 @@ import {
44
55
  DialogTrigger,
45
56
  EmptyState,
46
57
  GoogleMark,
58
+ IconButton,
47
59
  Input,
48
60
  Label,
49
61
  LabeledSwitchRow,
62
+ ListRow,
63
+ NEUTRAL_900,
50
64
  NativeUiProvider,
51
65
  PageHeader,
66
+ PageIndicator,
52
67
  PageTitle,
53
68
  PricingModal,
54
69
  Progress,
55
70
  SearchInput,
71
+ SectionLabel,
56
72
  Select,
57
73
  Separator,
58
74
  Sheet,
@@ -60,10 +76,13 @@ import {
60
76
  SheetDescription,
61
77
  SheetFooter,
62
78
  SheetHeader,
79
+ SheetRow,
63
80
  SheetTitle,
64
81
  SheetTrigger,
65
82
  Skeleton,
66
83
  Spinner,
84
+ StackPageHeader,
85
+ StatGrid,
67
86
  StatusDot,
68
87
  Switch,
69
88
  Tabs,
@@ -75,6 +94,7 @@ import {
75
94
  Toaster,
76
95
  UpgradeToProCard,
77
96
  initials,
97
+ palette,
78
98
  toast,
79
99
  tokens,
80
100
  useNativeUi,
@@ -125,9 +145,13 @@ const STATUS_TONES: StatusTone[] = [
125
145
  "cancelled",
126
146
  "active",
127
147
  "critical",
148
+ "info",
128
149
  "neutral",
129
150
  ];
130
151
 
152
+ const SWATCHES = ["#db2777", "#2563eb", "#16a34a", "#f59e0b", "#181818", "#ffffff"];
153
+ const SWATCH_LABELS = ["Pink", "Blue", "Green", "Amber", "Black", "White"];
154
+
131
155
  // Space after the last section, so Card, Upgrade and Overlays can scroll to the
132
156
  // top of an 844-tall phone for screenshot crops.
133
157
  const GALLERY_END_SPACE = 720;
@@ -194,6 +218,13 @@ function GalleryScreen() {
194
218
  const [progress, setProgress] = useState(40);
195
219
  const [pricingOpen, setPricingOpen] = useState(false);
196
220
  const [confirmOpen, setConfirmOpen] = useState(false);
221
+ const [swatch, setSwatch] = useState(SWATCHES[0]!);
222
+ const [due, setDue] = useState<Date | null>(null);
223
+ const [when, setWhen] = useState(() => new Date());
224
+ const [muted, setMuted] = useState(false);
225
+ const [sort, setSort] = useState<"newest" | "name">("newest");
226
+ const [page, setPage] = useState(0);
227
+ const scheme = useScheme();
197
228
 
198
229
  return (
199
230
  <View className="flex-1">
@@ -367,6 +398,9 @@ function GalleryScreen() {
367
398
  <Card title="Today" description="Card props, as before.">
368
399
  <GalleryText>Body</GalleryText>
369
400
  </Card>
401
+ <Card title="Pressable" description="onPress makes the whole card a button." onPress={() => toast("Card pressed")}>
402
+ <GalleryText>Tap anywhere on the card.</GalleryText>
403
+ </Card>
370
404
  <Card>
371
405
  <CardHeader>
372
406
  <CardTitle>Composed</CardTitle>
@@ -515,6 +549,139 @@ function GalleryScreen() {
515
549
  </EmptyState.Root>
516
550
  </Section>
517
551
 
552
+ {/* 0.5.0: the Verve, vibot and Velth pieces. */}
553
+ <Section title="ColorSwatches">
554
+ <ColorSwatches
555
+ value={swatch}
556
+ onChange={setSwatch}
557
+ colors={SWATCHES}
558
+ labels={SWATCH_LABELS}
559
+ accessibilityLabel="Accent colour"
560
+ />
561
+ <ColorSwatches
562
+ value={swatch}
563
+ onChange={setSwatch}
564
+ colors={SWATCHES}
565
+ labels={SWATCH_LABELS}
566
+ accessibilityLabel="Accent colour"
567
+ size="sm"
568
+ disabled
569
+ />
570
+ </Section>
571
+
572
+ <Section title="DateTimeField">
573
+ {/* Date only, empty until picked, with a clear button once set. */}
574
+ <DateTimeField
575
+ mode="date"
576
+ value={due}
577
+ onChange={setDue}
578
+ placeholder="No due date"
579
+ onClear={() => setDue(null)}
580
+ />
581
+ <DateTimeField value={when} onChange={setWhen} />
582
+ </Section>
583
+
584
+ <Section title="ListRow">
585
+ {/* Long-press the first row for its second action. */}
586
+ <ListRow
587
+ title="Ada Lovelace"
588
+ meta="See you at nine"
589
+ leading={
590
+ <View>
591
+ <Avatar>
592
+ <AvatarFallback>{initials("Ada Lovelace")}</AvatarFallback>
593
+ </Avatar>
594
+ <StatusDot tone="info" size="md" className="absolute right-0 top-0" />
595
+ </View>
596
+ }
597
+ titleEnd={<Badge variant="secondary">09:41</Badge>}
598
+ accessibilityLabel="Ada Lovelace, unread, 09:41"
599
+ onPress={() => toast("Open thread")}
600
+ onLongPress={() => toast("Thread actions")}
601
+ />
602
+ {/* The switch sits outside the pressable area: it toggles without opening the row. */}
603
+ <ListRow
604
+ title="Mute thread"
605
+ meta="Tap the row or the switch"
606
+ onPress={() => toast("Row pressed")}
607
+ control={<Switch checked={muted} onCheckedChange={setMuted} accessibilityLabel="Mute thread" />}
608
+ />
609
+ </Section>
610
+
611
+ <Section title="SectionLabel and StatGrid">
612
+ <SectionLabel>Today</SectionLabel>
613
+ <StatGrid
614
+ items={[
615
+ { label: "Done", value: "6" },
616
+ { label: "This week", value: "31" },
617
+ { label: "Streak", value: "12 days" },
618
+ ]}
619
+ />
620
+ <SectionLabel uppercase>Library</SectionLabel>
621
+ <StatGrid
622
+ columns={3}
623
+ items={[
624
+ { label: "Books", value: "24" },
625
+ { label: "Notes", value: "130" },
626
+ { label: "Clips", value: "8" },
627
+ ]}
628
+ />
629
+ </Section>
630
+
631
+ <Section title="SheetRow">
632
+ {/* Static rows on the sheet surface; in an app they sit in a `SheetContent`. */}
633
+ <View className="py-2" style={{ backgroundColor: palette.overlay[scheme], borderRadius: tokens.radius.lg }}>
634
+ <SheetRow icon={IconCopy} title="Copy link" onPress={() => toast("Copied")} />
635
+ <SheetRow icon={IconPhoto} title="Save image" detail="To your photo library" onPress={() => toast("Saved")} />
636
+ <SheetRow title="Newest first" active={sort === "newest"} onPress={() => setSort("newest")} />
637
+ <SheetRow title="By name" active={sort === "name"} onPress={() => setSort("name")} />
638
+ <SheetRow icon={IconPhoto} title="Export" detail="Needs V Pro" disabled />
639
+ <SheetRow icon={IconTrash} title="Delete" danger onPress={() => toast.error("Deleted")} />
640
+ </View>
641
+ </Section>
642
+
643
+ <Section title="PageIndicator">
644
+ <PageIndicator count={4} index={page} />
645
+ <PageIndicator count={4} index={page} onChange={setPage} />
646
+ </Section>
647
+
648
+ <Section title="StackPageHeader">
649
+ {/* `safeTop={false}`: the strip is not at the top of the screen. */}
650
+ <AmbientBackground className="flex-none overflow-hidden rounded-lg">
651
+ <StackPageHeader
652
+ title="Details"
653
+ description="Edited 2 min ago"
654
+ safeTop={false}
655
+ onBack={() => toast("Back")}
656
+ headerRight={<ThemeToggle />}
657
+ />
658
+ </AmbientBackground>
659
+ <AmbientBackground className="flex-none overflow-hidden rounded-lg">
660
+ <StackPageHeader title="A much longer page title that is cut off" safeTop={false} onBack={() => toast("Back")} />
661
+ </AmbientBackground>
662
+ </Section>
663
+
664
+ <Section title="Camera chrome">
665
+ {/* A dark stand-in for the live preview. */}
666
+ <View className="h-72 justify-between overflow-hidden rounded-lg p-4" style={{ backgroundColor: NEUTRAL_900 }}>
667
+ <View className="flex-row justify-between">
668
+ <IconButton variant="overlay" icon={IconX} label="Close camera" onPress={() => toast("Close")} />
669
+ <IconButton variant="overlay" icon={IconRefresh} label="Flip camera" onPress={() => toast("Flip")} />
670
+ </View>
671
+ <View className="flex-row items-center justify-between">
672
+ <IconButton variant="overlay" size="lg" icon={IconPhoto} label="Open library" onPress={() => toast("Library")} />
673
+ <CaptureButton onPress={() => toast.success("Captured")} />
674
+ <View style={{ width: 48 }} />
675
+ </View>
676
+ </View>
677
+ <View className="flex-row items-center gap-3">
678
+ <IconButton icon={IconCopy} label="Copy" size="sm" onPress={() => toast("Copied")} />
679
+ <IconButton icon={IconCopy} label="Copy" onPress={() => toast("Copied")} />
680
+ <IconButton icon={IconCopy} label="Copy" size="lg" onPress={() => toast("Copied")} />
681
+ <IconButton icon={IconTrash} label="Delete" disabled />
682
+ </View>
683
+ </Section>
684
+
518
685
  {/* The full chat screen, with the composer and keyboard, is `AiChatGallery` (`@vvedantb/native-ui/ai-gallery`). */}
519
686
  <Section title="AI chat">
520
687
  <AiChatSamples />
package/src/index.ts CHANGED
@@ -59,6 +59,20 @@ export { Badge } from "./Badge";
59
59
  export type { BadgeProps, BadgeVariant } from "./Badge";
60
60
  export { StatusDot } from "./StatusDot";
61
61
  export type { StatusDotProps, StatusTone } from "./StatusDot";
62
+ export { ColorSwatches } from "./ColorSwatches";
63
+ export type { ColorSwatchesProps, ColorSwatchesSize } from "./ColorSwatches";
64
+ export { StatGrid } from "./StatGrid";
65
+ export type { StatGridItem, StatGridProps } from "./StatGrid";
66
+ export { SectionLabel } from "./SectionLabel";
67
+ export type { SectionLabelProps } from "./SectionLabel";
68
+ export { SheetRow } from "./SheetRow";
69
+ export type { SheetRowProps } from "./SheetRow";
70
+ export { PageIndicator } from "./PageIndicator";
71
+ export type { PageIndicatorProps } from "./PageIndicator";
72
+ export { IconButton } from "./IconButton";
73
+ export type { IconButtonProps, IconButtonSize, IconButtonVariant } from "./IconButton";
74
+ export { CaptureButton } from "./CaptureButton";
75
+ export type { CaptureButtonProps } from "./CaptureButton";
62
76
  export { Separator } from "./Separator";
63
77
  export type { SeparatorProps } from "./Separator";
64
78
  export { Progress } from "./Progress";
@@ -79,6 +93,7 @@ export type {
79
93
  TabsContentProps,
80
94
  } from "./Tabs";
81
95
  export { ListRow } from "./ListRow";
96
+ export type { ListRowProps } from "./ListRow";
82
97
  export { HeaderIconButton } from "./HeaderIconButton";
83
98
  export { ThemeToggle } from "./ThemeToggle";
84
99
  export type { ThemeToggleProps } from "./ThemeToggle";
@@ -90,6 +105,7 @@ export {
90
105
  CardContent,
91
106
  CardFooter,
92
107
  } from "./Card";
108
+ export type { CardProps } from "./Card";
93
109
  export { Skeleton, CardSkeleton } from "./Skeleton";
94
110
  export { EmptyState } from "./EmptyState";
95
111
  export type { EmptyStateVariant } from "./EmptyState";
@@ -136,11 +152,14 @@ export { Toaster } from "./Toast";
136
152
  export { toast } from "./toastStore";
137
153
  export type { ToastOptions, ToastVariant } from "./toastStore";
138
154
  export { DateTimeField } from "./DateTimeField";
155
+ export type { DateTimeFieldProps } from "./DateTimeField";
139
156
  export { BottomSheetContainer } from "./BottomSheetContainer";
140
157
  export { SafeAreaContainer } from "./SafeAreaContainer";
141
158
  export { ScreenContainer } from "./ScreenContainer";
142
159
  export { PageTitle, PageHeader } from "./PageTitle";
143
160
  export type { PageTitleProps, PageHeaderProps } from "./PageTitle";
161
+ export { StackPageHeader } from "./StackPageHeader";
162
+ export type { StackPageHeaderProps } from "./StackPageHeader";
144
163
  export { SettingsSection } from "./settings/SettingsSection";
145
164
  export { SettingsField } from "./settings/SettingsField";
146
165
  export { SettingsToggleRow } from "./settings/SettingsToggleRow";