@vvedantb/native-ui 0.35.0 → 0.36.1

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 (42) hide show
  1. package/README.md +16 -1
  2. package/dist/Button.jsx +29 -18
  3. package/dist/DropdownMenu.jsx +89 -39
  4. package/dist/ExpoWebRoot.jsx +42 -21
  5. package/dist/Field.jsx +309 -0
  6. package/dist/FloatingTabBar.jsx +98 -94
  7. package/dist/IconButton.jsx +74 -51
  8. package/dist/ai/conversation.jsx +1 -1
  9. package/dist/ai/icon-button.jsx +67 -60
  10. package/dist/ai/prompt-input.jsx +9 -8
  11. package/dist/blur.js +6 -0
  12. package/dist/controlStyles.js +24 -2
  13. package/dist/entries/primitives.js +1 -0
  14. package/dist/examples/ParityGallery.jsx +488 -475
  15. package/dist/glassBlur.jsx +1 -1
  16. package/dist/index.js +1 -0
  17. package/dist/primitives/window-layer.jsx +35 -28
  18. package/package.json +27 -3
  19. package/src/Button.tsx +18 -7
  20. package/src/DropdownMenu.tsx +53 -7
  21. package/src/ExpoWebRoot.tsx +18 -3
  22. package/src/Field.tsx +105 -0
  23. package/src/FloatingTabBar.tsx +17 -12
  24. package/src/IconButton.tsx +7 -4
  25. package/src/Spinner.tsx +2 -2
  26. package/src/ai/conversation.tsx +1 -1
  27. package/src/ai/icon-button.tsx +5 -4
  28. package/src/ai/message.tsx +2 -2
  29. package/src/ai/prompt-input.tsx +6 -4
  30. package/src/auth/AccountScreens.tsx +4 -4
  31. package/src/auth/SignInScreen.tsx +4 -4
  32. package/src/blur.ts +8 -0
  33. package/src/controlStyles.ts +29 -2
  34. package/src/entries/primitives.ts +2 -0
  35. package/src/examples/ParityGallery.tsx +22 -1
  36. package/src/glassBlur.tsx +5 -7
  37. package/src/index.ts +2 -0
  38. package/src/primitives/sheet-gesture.tsx +1 -2
  39. package/src/primitives/web-click-guard.ts +3 -3
  40. package/src/primitives/window-layer.tsx +8 -6
  41. package/src/tabBarRoutes.ts +4 -3
  42. package/src/webview/HtmlView.tsx +5 -2
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
1
+ import { createContext, useContext, useEffect, useRef, useState, type ComponentRef, type ComponentType, type ReactNode } from "react";
2
2
  import { Pressable, StyleSheet, Text, View, type ViewProps } from "react-native";
3
3
  import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
4
4
  import {
@@ -143,7 +143,7 @@ export function Message({
143
143
  // The open context menu: where the message was and what it offers, read at the hold.
144
144
  const [held, setHeld] = useState<{ anchor: MessageMenuRect; menu: MessageMenu } | null>(null);
145
145
  // Measured at the hold: the menu draws the message again where it is on screen.
146
- const pressable = useRef<View>(null);
146
+ const pressable = useRef<ComponentRef<typeof View>>(null);
147
147
  const hasActions = actions != null && actions.length > 0;
148
148
  const longPressable = onLongPress != null || hasActions || menu != null;
149
149
  // In a thread, the menu freezes the list's keyboard handling until its close settles (see `overlay`).
@@ -1,4 +1,4 @@
1
- import { useContext, useState, type ReactNode } from "react";
1
+ import { forwardRef, useContext, useState, type ElementRef, type ReactNode } from "react";
2
2
  import { Platform, Pressable, Text, View, useWindowDimensions } from "react-native";
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context";
4
4
  import { IconArrowUp, IconChevronDown, IconPlayerStopFilled } from "@tabler/icons-react-native";
@@ -83,9 +83,11 @@ export function PromptInputSubmit({
83
83
  export type PromptInputButtonProps = ChatIconButtonProps;
84
84
 
85
85
  /** A ghost tool button for the composer `toolbar`, such as attach (web `PromptInputButton`). Give it `icon` and `label`. */
86
- export function PromptInputButton(props: PromptInputButtonProps) {
87
- return <ChatIconButton variant="ghost" {...props} />;
88
- }
86
+ export const PromptInputButton = forwardRef<ElementRef<typeof ChatIconButton>, PromptInputButtonProps>(
87
+ function PromptInputButton(props, ref) {
88
+ return <ChatIconButton ref={ref} variant="ghost" {...props} />;
89
+ },
90
+ );
89
91
 
90
92
  /**
91
93
  * The web `ModelPicker` trigger (`model-picker.tsx` `TRIGGER_CLASS`), the
@@ -1,5 +1,5 @@
1
- import { useRef, useState, type ReactNode } from "react";
2
- import type { TextInput } from "react-native";
1
+ import { useRef, useState, type ComponentRef, type ReactNode } from "react";
2
+ import { TextInput } from "react-native";
3
3
  import { useUser } from "@clerk/expo";
4
4
  import { useRouter, type Href } from "expo-router";
5
5
  import { Button } from "../Button";
@@ -86,8 +86,8 @@ export function ChangePasswordScreen({
86
86
  const [confirm, setConfirm] = useState("");
87
87
  const [error, setError] = useState("");
88
88
  const [submitting, setSubmitting] = useState(false);
89
- const nextField = useRef<TextInput>(null);
90
- const confirmField = useRef<TextInput>(null);
89
+ const nextField = useRef<ComponentRef<typeof TextInput>>(null);
90
+ const confirmField = useRef<ComponentRef<typeof TextInput>>(null);
91
91
  const id = (name: string) => `${testIDPrefix}-${name}`;
92
92
  // Until the user loads, show the current-password field: most accounts have one.
93
93
  const hasPassword = user ? user.passwordEnabled : true;
@@ -1,5 +1,5 @@
1
- import { useRef, useState, type ReactNode } from "react";
2
- import { Text, View, type TextInput } from "react-native";
1
+ import { useRef, useState, type ComponentRef, type ReactNode } from "react";
2
+ import { Text, TextInput, View } from "react-native";
3
3
  import { useSignIn, useSignUp } from "@clerk/expo";
4
4
  import { useRouter, type Href } from "expo-router";
5
5
  import { Button } from "../Button";
@@ -237,8 +237,8 @@ export function SignInScreen({
237
237
  const [error, setError] = useState("");
238
238
  const [submitting, setSubmitting] = useState(false);
239
239
  // The field each "next" key moves to.
240
- const passwordField = useRef<TextInput>(null);
241
- const confirmField = useRef<TextInput>(null);
240
+ const passwordField = useRef<ComponentRef<typeof TextInput>>(null);
241
+ const confirmField = useRef<ComponentRef<typeof TextInput>>(null);
242
242
  const signUp = mode === "sign-up";
243
243
  const reset = mode === "reset-password";
244
244
  const id = (name: string) => `${testIDPrefix ?? mode}-${name}`;
package/src/blur.ts CHANGED
@@ -2,6 +2,14 @@ import type * as ExpoBlur from "expo-blur";
2
2
 
3
3
  export type ExpoBlurModule = typeof ExpoBlur;
4
4
 
5
+ /**
6
+ * The ref an expo-blur `BlurView` blurs (its `blurTarget` prop, and the ref a
7
+ * `BlurTargetView` takes). Derived from expo-blur's own type so the two match
8
+ * under any React Native version.
9
+ */
10
+ export type BlurTargetRef = NonNullable<ExpoBlur.BlurViewProps["blurTarget"]>;
11
+ export type BlurTargetElement = NonNullable<BlurTargetRef["current"]>;
12
+
5
13
  let expoBlur: ExpoBlurModule | null | undefined;
6
14
 
7
15
  /**
@@ -14,17 +14,29 @@ type Scheme = "light" | "dark";
14
14
 
15
15
  /**
16
16
  * `primary` and `default` are the same (`default` is the web name). `outline`
17
- * is the web bordered neutral button. `tinted` is the pink tint that `outline`
18
- * drew before 0.3.0.
17
+ * is the web bordered neutral button. `tertiary` is the web name for `ghost`
18
+ * and `danger` for `destructive`. `success`, `warning` and `flat` match the web
19
+ * variants. `tinted` is a legacy alias: the pink tint that `outline` drew
20
+ * before 0.3.0 (it keeps its NativeWind classes).
21
+ *
22
+ * Hierarchy: `primary`/`default` is the one main action, `secondary` an
23
+ * alternative, `tertiary`/`ghost` a dismissive action, `destructive`/`danger`
24
+ * a destructive action, `success` and `warning` show status, and `outline`,
25
+ * `link` and `flat` are visual.
19
26
  */
20
27
  export type ButtonVariant =
21
28
  | "primary"
22
29
  | "default"
23
30
  | "secondary"
31
+ | "tertiary"
24
32
  | "outline"
25
33
  | "destructive"
34
+ | "danger"
26
35
  | "ghost"
27
36
  | "link"
37
+ | "success"
38
+ | "warning"
39
+ | "flat"
28
40
  | "tinted";
29
41
 
30
42
  export type ButtonColors = {
@@ -54,9 +66,24 @@ export function buttonColors(variant: ButtonVariant, scheme: Scheme): ButtonColo
54
66
  color: tokens.color.foreground[scheme],
55
67
  };
56
68
  case "destructive":
69
+ case "danger":
57
70
  return { backgroundColor: palette.destructive, borderColor: none, color: tokens.color.white };
58
71
  case "ghost":
72
+ case "tertiary":
73
+ case "flat":
59
74
  return { backgroundColor: none, borderColor: none, color: tokens.color.muted[scheme] };
75
+ case "success":
76
+ return {
77
+ backgroundColor: palette.success[scheme],
78
+ borderColor: none,
79
+ color: palette.successForeground[scheme],
80
+ };
81
+ case "warning":
82
+ return {
83
+ backgroundColor: palette.warning[scheme],
84
+ borderColor: none,
85
+ color: palette.warningForeground[scheme],
86
+ };
60
87
  case "link":
61
88
  return { backgroundColor: none, borderColor: none, color: palette.primary[scheme] };
62
89
  case "tinted":
@@ -15,6 +15,8 @@ export { Textarea } from "../Textarea";
15
15
  export type { TextareaProps } from "../Textarea";
16
16
  export { Label } from "../Label";
17
17
  export type { LabelProps } from "../Label";
18
+ export { Field, FieldControl, FieldDescription, FieldError, FieldLabel } from "../Field";
19
+ export type { FieldProps } from "../Field";
18
20
  export { Select } from "../Select";
19
21
  export type { SelectOption, SelectProps } from "../Select";
20
22
  export { Switch } from "../Switch";
@@ -68,6 +68,11 @@ import {
68
68
  GoogleMark,
69
69
  IconButton,
70
70
  Input,
71
+ Field,
72
+ FieldControl,
73
+ FieldDescription,
74
+ FieldError,
75
+ FieldLabel,
71
76
  Label,
72
77
  LabeledSwitchRow,
73
78
  ListRow,
@@ -131,12 +136,19 @@ import {
131
136
  } from "../ai";
132
137
  import { AiChatSamples } from "./AiChatGallery";
133
138
 
139
+ // Every shared variant; the aliases (`primary`, `tertiary`, `danger`) draw as the name they alias.
134
140
  const BUTTON_VARIANTS: ButtonVariant[] = [
135
141
  "default",
142
+ "primary",
136
143
  "secondary",
137
144
  "outline",
138
145
  "destructive",
146
+ "danger",
139
147
  "ghost",
148
+ "tertiary",
149
+ "flat",
150
+ "success",
151
+ "warning",
140
152
  "link",
141
153
  ];
142
154
 
@@ -289,7 +301,7 @@ function GalleryScreen() {
289
301
  {/* The web gallery: a full-width column of variants, then the sm row. */}
290
302
  <View className="gap-2">
291
303
  {BUTTON_VARIANTS.map((variant) => (
292
- <Button key={variant} variant={variant} onPress={() => toast(variant)}>
304
+ <Button key={variant} testID={`button-variant-${variant}`} variant={variant} onPress={() => toast(variant)}>
293
305
  {variant}
294
306
  </Button>
295
307
  ))}
@@ -307,6 +319,9 @@ function GalleryScreen() {
307
319
  Small
308
320
  </Button>
309
321
  <Button fullWidth={false}>Default</Button>
322
+ <Button size="md" fullWidth={false}>
323
+ Medium
324
+ </Button>
310
325
  <Button size="lg" fullWidth={false}>
311
326
  Large
312
327
  </Button>
@@ -357,6 +372,12 @@ function GalleryScreen() {
357
372
  <Label nativeID="gallery-name">Name</Label>
358
373
  <Input placeholder="Your name" accessibilityLabel="Name" />
359
374
  </View>
375
+ <Field testID="field-parity">
376
+ <FieldLabel testID="field-parity-label">Email</FieldLabel>
377
+ <FieldControl testID="field-parity-input" placeholder="you@example.com" />
378
+ <FieldDescription testID="field-parity-description">We never share it.</FieldDescription>
379
+ <FieldError testID="field-parity-error">Enter a valid email.</FieldError>
380
+ </Field>
360
381
  {/* Empty (`sm`: icon and placeholder) and filled (`md`: the clear button). */}
361
382
  <SearchInput value={emptySearch} onChange={setEmptySearch} />
362
383
  <SearchInput value={search} onChange={setSearch} size="md" label="Search colours" />
package/src/glassBlur.tsx CHANGED
@@ -5,14 +5,10 @@ import {
5
5
  useRef,
6
6
  useState,
7
7
  useSyncExternalStore,
8
- type ComponentRef,
9
8
  type ReactNode,
10
- type RefObject,
11
9
  } from "react";
12
10
  import { StyleSheet, View, type ViewProps } from "react-native";
13
- import { loadBlur } from "./blur";
14
-
15
- type BlurTargetRef = RefObject<ComponentRef<typeof View> | null>;
11
+ import { loadBlur, type BlurTargetElement, type BlurTargetRef } from "./blur";
16
12
 
17
13
  /**
18
14
  * The current blur target, outside React state. A target change (each tab
@@ -84,7 +80,7 @@ export function GlassBlurTarget({
84
80
  ...props
85
81
  }: GlassBlurTargetProps) {
86
82
  const store = useContext(BlurTargetStoreContext);
87
- const ref = useRef<ComponentRef<typeof View>>(null);
83
+ const ref = useRef<BlurTargetElement>(null);
88
84
  const BlurTargetView = loadBlur()?.BlurTargetView;
89
85
 
90
86
  // Publish the ref only once it is attached: expo-blur compares
@@ -102,12 +98,14 @@ export function GlassBlurTarget({
102
98
  // Surfaces in here get no target: a blur view must not sit inside its own.
103
99
  const content = <BlurTargetStoreContext.Provider value={null}>{children}</BlurTargetStoreContext.Provider>;
104
100
 
101
+ // The plain `View` is the fallback when expo-blur is absent: no `BlurView`
102
+ // then reads the store, so this branch needs no target ref.
105
103
  return BlurTargetView ? (
106
104
  <BlurTargetView ref={ref} style={[styles.fill, style]} {...props}>
107
105
  {content}
108
106
  </BlurTargetView>
109
107
  ) : (
110
- <View ref={ref} style={[styles.fill, style]} {...props}>
108
+ <View style={[styles.fill, style]} {...props}>
111
109
  {content}
112
110
  </View>
113
111
  );
package/src/index.ts CHANGED
@@ -52,6 +52,8 @@ export { Textarea } from "./Textarea";
52
52
  export type { TextareaProps } from "./Textarea";
53
53
  export { Label } from "./Label";
54
54
  export type { LabelProps } from "./Label";
55
+ export { Field, FieldControl, FieldDescription, FieldError, FieldLabel } from "./Field";
56
+ export type { FieldProps } from "./Field";
55
57
  export { Select } from "./Select";
56
58
  export type { SelectOption, SelectProps } from "./Select";
57
59
  export { Switch } from "./Switch";
@@ -4,7 +4,6 @@ import {
4
4
  Gesture,
5
5
  GestureDetector,
6
6
  GestureHandlerRootView,
7
- type NativeGesture,
8
7
  } from "react-native-gesture-handler";
9
8
  import Animated, {
10
9
  cancelAnimation,
@@ -46,7 +45,7 @@ import { GestureToastDrag } from "./toast-drag-gesture";
46
45
  /** What a body inside the sheet needs from the drag around it. */
47
46
  type SheetScrollLink = {
48
47
  /** The body's native scroll, run together with the sheet's pan. */
49
- native: NativeGesture;
48
+ native: ReturnType<typeof Gesture.Native>;
50
49
  /** While the sheet follows the finger: the scroll offset the body holds; else `null`. */
51
50
  heldTop: SharedValue<number | null>;
52
51
  };
@@ -1,5 +1,5 @@
1
- import { useRef } from "react";
2
- import { Platform, type View } from "react-native";
1
+ import { useRef, type ComponentRef } from "react";
2
+ import { Platform, View } from "react-native";
3
3
 
4
4
  /** The part of a DOM element the web click guard uses: on the web a `View` is a DOM element. */
5
5
  type DomNode = {
@@ -27,7 +27,7 @@ export function useWebClickGuard(swallowOnDown: () => boolean = () => false) {
27
27
  swallowNext: () => {
28
28
  swallow.current = true;
29
29
  },
30
- ref: (node: View | null) => {
30
+ ref: (node: ComponentRef<typeof View> | null) => {
31
31
  if (Platform.OS !== "web" || !node || !isDomNode(node)) return;
32
32
  const onClick = (event: DomEvent) => {
33
33
  if (!swallow.current) return;
@@ -1,6 +1,6 @@
1
- import { useId, useLayoutEffect, useSyncExternalStore, type ReactNode } from "react";
1
+ import { useId, useLayoutEffect, useSyncExternalStore, type ComponentRef, type ReactNode } from "react";
2
2
  import { BackHandler, Modal, StyleSheet, View } from "react-native";
3
- import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
3
+ import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
4
4
  import { useReduceMotion } from "../useReduceMotion";
5
5
 
6
6
  // Overlays drawn in the app's own window. A React Native `Modal` is a window
@@ -59,7 +59,7 @@ const onBack = () => {
59
59
  };
60
60
 
61
61
  /** Mounted: the host is there, and it answers Android back for its layers. */
62
- const hostRef = (view: View | null) => {
62
+ const hostRef = (view: ComponentRef<typeof View> | null) => {
63
63
  if (view === null) return undefined;
64
64
  hosts += 1;
65
65
  const back = BackHandler.addEventListener("hardwareBackPress", onBack);
@@ -79,9 +79,11 @@ const hostRef = (view: View | null) => {
79
79
  export function WindowLayerHost({ children }: { children: ReactNode }) {
80
80
  const shown = useSyncExternalStore(subscribe, () => layers, () => EMPTY);
81
81
  // The layers fade in and out as a Modal's `fade`, unless they move on their
82
- // own (`fade={false}`); with Reduce Motion they appear at once.
83
- const enter = FadeIn.duration(200).reduceMotion(ReduceMotion.System);
84
- const exit = FadeOut.duration(150).reduceMotion(ReduceMotion.System);
82
+ // own (`fade={false}`). With Reduce Motion they get no layout animation at
83
+ // all, as the fallback Modal gets `animationType="none"`.
84
+ const reduceMotion = useReduceMotion();
85
+ const enter = reduceMotion ? undefined : FadeIn.duration(200);
86
+ const exit = reduceMotion ? undefined : FadeOut.duration(150);
85
87
  return (
86
88
  <View ref={hostRef} style={styles.fill}>
87
89
  <View
@@ -27,10 +27,11 @@ export type FloatingTabOptions = {
27
27
  * Only `display: "none"` is read: on the focused route it hides the whole
28
28
  * bar, as in React Navigation's own bar (for example while a screen is in
29
29
  * select mode and shows its `BulkActionBar` in the bar's place). Typed
30
- * loosely: React Navigation's own type allows animated styles, any of
31
- * which is an object or a falsy value.
30
+ * loosely: Expo Router's own type is an animated style, each member of
31
+ * which is an object, a falsy value or `void` (a mapped animated field).
32
+ * `displayOf` reads only `display`.
32
33
  */
33
- tabBarStyle?: object | false | "" | null;
34
+ tabBarStyle?: object | false | "" | null | void;
34
35
  };
35
36
 
36
37
  /** The `display` a style resolves to: in an array the last one set wins, as in `StyleSheet.flatten`. */
@@ -60,7 +60,10 @@ export function HtmlView({
60
60
  ref: handle,
61
61
  testID,
62
62
  }: HtmlViewProps) {
63
- const ref = useRef<WebView>(null);
63
+ // `WebView<object>`: react-native-webview 14 types the class as
64
+ // `WebView<P = undefined>`, and its props as `WebViewProps & P`, which is
65
+ // `never` without a type argument.
66
+ const ref = useRef<WebView<object>>(null);
64
67
  useImperativeHandle(handle, () => ({
65
68
  postMessage: (message: string) => ref.current?.injectJavaScript(htmlViewPostScript(message)),
66
69
  }));
@@ -77,7 +80,7 @@ export function HtmlView({
77
80
 
78
81
  return (
79
82
  <View testID={testID} style={{ height }}>
80
- <WebView
83
+ <WebView<object>
81
84
  ref={ref}
82
85
  source={{ html }}
83
86
  accessibilityLabel={title}