@vvedantb/native-ui 0.3.13 → 0.3.14

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 CHANGED
@@ -197,6 +197,8 @@ The components keep the web sizes on screen and reach a 44 pt touch target with
197
197
 
198
198
  Text scales with the system font size. Labelled controls have minimum heights, so a large Dynamic Type size grows them instead of clipping the label (the `SearchInput` lock grows with the font scale); only the `FloatingTabBar` labels are capped (1.5×), to fit the fixed bar. With Reduce Motion on, dialogs, sheets, toasts, the `Select` popover, `PricingModal`, `Progress` and `Skeleton` do not animate. Dialogs, sheets, toasts, `FloatingTabBar` and `FloatingFAB` stay inside the safe-area insets, and dialog and sheet fields stay above the keyboard on iOS and Android.
199
199
 
200
+ The brand marks (`APP_ICONS`, the `Icon*` exports and `AppMark`) are images named by `title`, and hidden from assistive tech without one. From 0.3.14 they set the props each platform reads: `accessibilityRole="image"` and `accessibilityLabel` on iOS and Android, `role="img"` and `aria-label` on web. Without a title they set `accessibilityElementsHidden` and `importantForAccessibility="no-hide-descendants"` on native and `aria-hidden` on web. `testID` is `data-testid` on web. On web `react-native-svg` passes its props straight to the DOM `<svg>`, and React Native Web does not map `accessible`, the `accessibility*` props or `testID` there. So do not put them on an `Svg` or on a Tabler icon: put them on the parent `View` or `Pressable`. The package draws no Lucide icon, as a Lucide icon always sets `testID` on its `Svg`. On web the `Select` options are Radix DOM nodes, so from 0.3.14 they take their name and test id as `aria-label` and `data-testid` there, and as `accessibilityLabel` and `testID` on iOS and Android.
201
+
200
202
  ## Floating UI / Android shadows
201
203
 
202
204
  Do not put `elevation` or NativeWind `shadow-*` on nested or translucent chrome. `floatingShadow` is iOS `shadow*` and Android/web `boxShadow`. `FloatingSurface` clips on an inner view.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "license": "MIT",
5
5
  "description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar and the family app marks.",
6
6
  "type": "module",
package/src/Select.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { Platform } from "react-native";
2
3
  import {
3
4
  NativeSelectScrollView,
4
5
  Select as PrimitiveSelect,
@@ -17,6 +18,7 @@ import {
17
18
  typeStyle,
18
19
  } from "./controlStyles";
19
20
  import { palette } from "./palette";
21
+ import { selectItemA11yProps } from "./selectA11y";
20
22
  import { useLargerText } from "./theme";
21
23
  import { useScheme } from "./useScheme";
22
24
 
@@ -138,10 +140,11 @@ function Select<TValue = string | number | null>({
138
140
  ? `${testID}-${String(option.value ?? "null")}`
139
141
  : undefined;
140
142
  return (
143
+ // On web the item is a Radix DOM node: the name and test id
144
+ // go as `aria-label` and `data-testid` there.
141
145
  <SelectItem
142
146
  key={`${String(option.value)}-${option.label}`}
143
- testID={optionId}
144
- accessibilityLabel={option.label}
147
+ {...selectItemA11yProps({ label: option.label, testID: optionId }, Platform.OS)}
145
148
  label={option.label}
146
149
  value={String(option.value ?? NULL_SENTINEL)}
147
150
  />
@@ -1,5 +1,6 @@
1
- import type { StyleProp, ViewStyle } from "react-native";
1
+ import { Platform, type StyleProp, type ViewStyle } from "react-native";
2
2
  import Svg, { G, Path } from "react-native-svg";
3
+ import { svgA11yProps } from "../svgA11y";
3
4
  import { tokens } from "../tokens";
4
5
  import { useScheme } from "../useScheme";
5
6
  import {
@@ -19,10 +20,11 @@ export type AppIconProps = {
19
20
  color?: string;
20
21
  /** Stroke width in rendered points, for stroke glyphs. Default: the glyph's own weight. Fill glyphs ignore it. */
21
22
  stroke?: number;
22
- /** Accessible name. Without it the icon is hidden from assistive tech. */
23
+ /** Accessible name. Without it the icon is hidden from assistive tech. On web: `role="img"` and `aria-label`, or `aria-hidden`. */
23
24
  title?: string;
24
25
  /** `"center"` (default) centres the glyph in its square. `"start"` left-aligns its ink, for vertical lists. */
25
26
  align?: "center" | "start";
27
+ /** Set as `data-testid` on web, where `Svg` does not map `testID`. */
26
28
  testID?: string;
27
29
  style?: StyleProp<ViewStyle>;
28
30
  };
@@ -70,12 +72,7 @@ function createAppIcon(app: AppName, displayName: string): AppIconComponent {
70
72
  align === "start" ? APP_MARK_VIEWBOX_START[app] : APP_MARK_VIEWBOX[app]
71
73
  }
72
74
  preserveAspectRatio="xMidYMid meet"
73
- accessible={Boolean(title)}
74
- accessibilityRole={title ? "image" : undefined}
75
- accessibilityLabel={title}
76
- accessibilityElementsHidden={!title}
77
- importantForAccessibility={title ? "auto" : "no-hide-descendants"}
78
- testID={testID}
75
+ {...svgA11yProps({ title, testID }, Platform.OS)}
79
76
  style={style}
80
77
  >
81
78
  <G {...glyphProps}>
@@ -1,5 +1,6 @@
1
- import type { StyleProp, ViewStyle } from "react-native";
1
+ import { Platform, type StyleProp, type ViewStyle } from "react-native";
2
2
  import Svg, { G, Path, Rect } from "react-native-svg";
3
+ import { svgA11yProps } from "../svgA11y";
3
4
  import { APP_ICONS } from "./AppIcons";
4
5
  import {
5
6
  APP_MARKS,
@@ -18,8 +19,9 @@ export type AppMarkProps = {
18
19
  variant?: AppMarkVariant;
19
20
  /** Width and height in points. Default 24. */
20
21
  size?: number;
21
- /** Accessible name. Without it the mark is hidden from assistive tech. */
22
+ /** Accessible name. Without it the mark is hidden from assistive tech. On web: `role="img"` and `aria-label`, or `aria-hidden`. */
22
23
  title?: string;
24
+ /** Set as `data-testid` on web, where `Svg` does not map `testID`. */
23
25
  testID?: string;
24
26
  style?: StyleProp<ViewStyle>;
25
27
  };
@@ -64,12 +66,7 @@ export function AppMark({
64
66
  height={size}
65
67
  viewBox={MARK_VIEWBOX}
66
68
  preserveAspectRatio="xMidYMid meet"
67
- accessible={Boolean(title)}
68
- accessibilityRole={title ? "image" : undefined}
69
- accessibilityLabel={title}
70
- accessibilityElementsHidden={!title}
71
- importantForAccessibility={title ? "auto" : "no-hide-descendants"}
72
- testID={testID}
69
+ {...svgA11yProps({ title, testID }, Platform.OS)}
73
70
  style={style}
74
71
  >
75
72
  <Rect width={1024} height={1024} rx={TILE_RADIUS} fill={tone.bg} />
@@ -1,8 +1,10 @@
1
1
  import * as React from "react";
2
- import type { LucideIcon, LucideProps } from "lucide-react-native";
2
+ import type { IconProps as TablerIconProps } from "@tabler/icons-react-native";
3
3
 
4
- type IconProps = LucideProps & {
5
- as: LucideIcon;
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
+ type IconProps = TablerIconProps & {
7
+ as: React.ComponentType<TablerIconProps>;
6
8
  className?: string;
7
9
  };
8
10
 
@@ -1,10 +1,7 @@
1
1
  import * as SelectPrimitive from "@rn-primitives/select";
2
- import {
3
- Check,
4
- ChevronDown,
5
- ChevronDownIcon,
6
- ChevronUpIcon,
7
- } from "lucide-react-native";
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
+ import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react-native";
8
5
  import * as React from "react";
9
6
  import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
10
7
  import { FadeIn, FadeOut } from "react-native-reanimated";
@@ -72,7 +69,7 @@ const SelectTrigger = React.forwardRef<
72
69
  {...props}
73
70
  >
74
71
  <>{children}</>
75
- <ChevronDown size={16} color={tokens.color.muted[scheme]} />
72
+ <IconChevronDown size={16} color={tokens.color.muted[scheme]} />
76
73
  </SelectPrimitive.Trigger>
77
74
  );
78
75
  });
@@ -153,6 +150,11 @@ const SelectLabel = React.forwardRef<
153
150
  );
154
151
  });
155
152
 
153
+ /**
154
+ * On web `SelectPrimitive.Item` passes these props to a Radix DOM node, not a
155
+ * React Native view, so give it `aria-label` and `data-testid` there, not
156
+ * `accessibilityLabel` or `testID` (`selectItemA11yProps`).
157
+ */
156
158
  type SelectItemProps = React.ComponentPropsWithoutRef<
157
159
  typeof SelectPrimitive.Item
158
160
  > & {
@@ -177,7 +179,7 @@ const SelectItem = React.forwardRef<
177
179
  >
178
180
  <View className="absolute right-2 size-3.5 items-center justify-center">
179
181
  <SelectPrimitive.ItemIndicator>
180
- <Check size={16} color={tokens.color.muted[scheme]} />
182
+ <IconCheck size={16} color={tokens.color.muted[scheme]} />
181
183
  </SelectPrimitive.ItemIndicator>
182
184
  </View>
183
185
  <SelectPrimitive.ItemText
@@ -220,7 +222,7 @@ function SelectScrollUpButton(
220
222
  className="items-center justify-center py-1"
221
223
  {...props}
222
224
  >
223
- <ChevronUpIcon size={16} color="#737373" />
225
+ <IconChevronUp size={16} color="#737373" />
224
226
  </SelectPrimitive.ScrollUpButton>
225
227
  );
226
228
  }
@@ -239,7 +241,7 @@ function SelectScrollDownButton(
239
241
  className="items-center justify-center py-1"
240
242
  {...props}
241
243
  >
242
- <ChevronDownIcon size={16} color="#737373" />
244
+ <IconChevronDown size={16} color="#737373" />
243
245
  </SelectPrimitive.ScrollDownButton>
244
246
  );
245
247
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Accessibility and test props for a `Select` option. On web
3
+ * `@rn-primitives/select` passes the props of its `Item` through a `Slot` to
4
+ * the Radix `Select.Item`, a DOM `<div>`. React Native Web never sees them, so
5
+ * React logs `accessibilityLabel` and `testID` there as unknown DOM props. Web
6
+ * gets `aria-label` and `data-testid`; iOS and Android keep the native props.
7
+ * No React Native import, so the tests can load this file.
8
+ */
9
+
10
+ export type SelectItemA11yProps =
11
+ | { "aria-label": string; "data-testid"?: string }
12
+ | { accessibilityLabel: string; testID?: string };
13
+
14
+ /**
15
+ * Spread on the `SelectItem`. Pass `Platform.OS` as `os`. Without `testID` the
16
+ * result has no test id key, not one set to `undefined`.
17
+ */
18
+ export function selectItemA11yProps(
19
+ { label, testID }: { label: string; testID?: string },
20
+ os: string,
21
+ ): SelectItemA11yProps {
22
+ if (os === "web") {
23
+ return testID === undefined ? { "aria-label": label } : { "aria-label": label, "data-testid": testID };
24
+ }
25
+ return testID === undefined ? { accessibilityLabel: label } : { accessibilityLabel: label, testID };
26
+ }
package/src/svgA11y.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Accessibility and test props for a `react-native-svg` `Svg`. React Native
3
+ * Web maps `accessible`, the `accessibility*` props and `testID` on `View`
4
+ * and `Text`, but on web `Svg` is a DOM `<svg>` that takes its props as they
5
+ * are, so React logs each one as an unknown DOM prop. Web gets ARIA and
6
+ * `data-testid`; iOS and Android keep the native props. No React Native
7
+ * import, so the tests can load this file.
8
+ */
9
+
10
+ export type SvgA11yProps =
11
+ | { role: "img"; "aria-label": string; "data-testid"?: string }
12
+ | { "aria-hidden": true; "data-testid"?: string }
13
+ | { accessible: true; accessibilityRole: "image"; accessibilityLabel: string; testID?: string }
14
+ | {
15
+ accessible: false;
16
+ accessibilityElementsHidden: true;
17
+ importantForAccessibility: "no-hide-descendants";
18
+ testID?: string;
19
+ };
20
+
21
+ /**
22
+ * Spread on the `Svg`. With `title` it is an image with that name; without it,
23
+ * it is hidden from assistive tech. Pass `Platform.OS` as `os`. Without
24
+ * `testID` the result has no test id key, not one set to `undefined`.
25
+ */
26
+ export function svgA11yProps(
27
+ { title, testID }: { title?: string; testID?: string },
28
+ os: string,
29
+ ): SvgA11yProps {
30
+ if (os === "web") {
31
+ const id = testID === undefined ? {} : { "data-testid": testID };
32
+ return title ? { role: "img", "aria-label": title, ...id } : { "aria-hidden": true, ...id };
33
+ }
34
+ const id = testID === undefined ? {} : { testID };
35
+ return title
36
+ ? { accessible: true, accessibilityRole: "image", accessibilityLabel: title, ...id }
37
+ : {
38
+ accessible: false,
39
+ accessibilityElementsHidden: true,
40
+ importantForAccessibility: "no-hide-descendants",
41
+ ...id,
42
+ };
43
+ }