panelui-native 1.3.0 → 1.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.
Files changed (63) hide show
  1. package/lib/module/components/bottom-sheet/index.js +5 -1
  2. package/lib/module/components/bottom-sheet/index.js.map +1 -1
  3. package/lib/module/components/calendar/index.js +17 -3
  4. package/lib/module/components/calendar/index.js.map +1 -1
  5. package/lib/module/components/checkbox/index.js +2 -1
  6. package/lib/module/components/checkbox/index.js.map +1 -1
  7. package/lib/module/components/combobox/index.js +5 -2
  8. package/lib/module/components/combobox/index.js.map +1 -1
  9. package/lib/module/components/questionnaire/index.js +1 -0
  10. package/lib/module/components/questionnaire/index.js.map +1 -1
  11. package/lib/module/components/radio-group/index.js +2 -1
  12. package/lib/module/components/radio-group/index.js.map +1 -1
  13. package/lib/module/components/search-bar/index.js +2 -1
  14. package/lib/module/components/search-bar/index.js.map +1 -1
  15. package/lib/module/components/section-progress/index.js +1 -1
  16. package/lib/module/components/section-progress/index.js.map +1 -1
  17. package/lib/module/components/section-rail/index.js +1 -1
  18. package/lib/module/components/section-rail/index.js.map +1 -1
  19. package/lib/module/components/select/index.js +49 -10
  20. package/lib/module/components/select/index.js.map +1 -1
  21. package/lib/module/components/table/index.js +17 -3
  22. package/lib/module/components/table/index.js.map +1 -1
  23. package/lib/module/components/tabs/index.js +10 -1
  24. package/lib/module/components/tabs/index.js.map +1 -1
  25. package/lib/module/components/time-picker/index.js +41 -7
  26. package/lib/module/components/time-picker/index.js.map +1 -1
  27. package/lib/module/index.js +1 -1
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/theme/use-theme.js +55 -4
  30. package/lib/module/theme/use-theme.js.map +1 -1
  31. package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
  32. package/lib/typescript/src/components/calendar/index.d.ts.map +1 -1
  33. package/lib/typescript/src/components/combobox/index.d.ts.map +1 -1
  34. package/lib/typescript/src/components/questionnaire/index.d.ts.map +1 -1
  35. package/lib/typescript/src/components/radio-group/index.d.ts.map +1 -1
  36. package/lib/typescript/src/components/search-bar/index.d.ts +3 -0
  37. package/lib/typescript/src/components/search-bar/index.d.ts.map +1 -1
  38. package/lib/typescript/src/components/select/index.d.ts +9 -1
  39. package/lib/typescript/src/components/select/index.d.ts.map +1 -1
  40. package/lib/typescript/src/components/table/index.d.ts.map +1 -1
  41. package/lib/typescript/src/components/tabs/index.d.ts.map +1 -1
  42. package/lib/typescript/src/components/time-picker/index.d.ts.map +1 -1
  43. package/lib/typescript/src/index.d.ts +1 -1
  44. package/lib/typescript/src/index.d.ts.map +1 -1
  45. package/lib/typescript/src/theme/use-theme.d.ts +32 -1
  46. package/lib/typescript/src/theme/use-theme.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/components/bottom-sheet/index.tsx +3 -0
  49. package/src/components/calendar/index.tsx +17 -4
  50. package/src/components/checkbox/index.tsx +1 -1
  51. package/src/components/combobox/index.tsx +4 -2
  52. package/src/components/questionnaire/index.tsx +1 -0
  53. package/src/components/radio-group/index.tsx +5 -1
  54. package/src/components/search-bar/index.tsx +1 -1
  55. package/src/components/section-progress/index.tsx +1 -1
  56. package/src/components/section-rail/index.tsx +1 -1
  57. package/src/components/select/index.tsx +60 -8
  58. package/src/components/table/index.tsx +17 -3
  59. package/src/components/tabs/index.tsx +6 -0
  60. package/src/components/time-picker/index.tsx +51 -11
  61. package/src/index.ts +1 -0
  62. package/src/theme/use-theme.ts +57 -4
  63. package/theme.css +5 -5
@@ -227,6 +227,13 @@ const TableRowContext = createContext<{
227
227
  last: false,
228
228
  });
229
229
 
230
+ /**
231
+ * Whether the row a cell is in is selected. A selected row is drawn on the
232
+ * accent fill, so the text in its cells has to switch to the colour made to be
233
+ * read on that fill rather than keep the table's own.
234
+ */
235
+ const TableRowSelectedContext = createContext(false);
236
+
230
237
  export interface TableProps extends ViewProps, VariantProps<typeof tableVariants> {
231
238
  className?: string;
232
239
  /**
@@ -420,7 +427,7 @@ const TableRow = forwardRef<ViewRef, TableRowProps>(
420
427
  accessibilityState={{ disabled: !!disabled, selected: !!selected }}
421
428
  className={classes}
422
429
  >
423
- {cells}
430
+ <TableRowSelectedContext.Provider value={!!selected}>{cells}</TableRowSelectedContext.Provider>
424
431
  </View>
425
432
  );
426
433
  }
@@ -437,7 +444,7 @@ const TableRow = forwardRef<ViewRef, TableRowProps>(
437
444
  onPress={onPress}
438
445
  className={classes}
439
446
  >
440
- {cells}
447
+ <TableRowSelectedContext.Provider value={!!selected}>{cells}</TableRowSelectedContext.Provider>
441
448
  </AnimatedPressable>
442
449
  );
443
450
  }
@@ -668,6 +675,7 @@ const TableCell = forwardRef<ViewRef, TableCellProps>(
668
675
  width: ownWidth,
669
676
  align: ownAlign,
670
677
  });
678
+ const rowSelected = useContext(TableRowSelectedContext);
671
679
  const { cell, cellLabel } = tableVariants({ size });
672
680
 
673
681
  return (
@@ -679,7 +687,13 @@ const TableCell = forwardRef<ViewRef, TableCellProps>(
679
687
  {...props}
680
688
  >
681
689
  {textChildren(children, (text) => (
682
- <Text className={cellLabel({ className: labelClassName })}>{text}</Text>
690
+ <Text
691
+ className={cellLabel({
692
+ className: cn(rowSelected && 'text-accent-foreground', labelClassName),
693
+ })}
694
+ >
695
+ {text}
696
+ </Text>
683
697
  ))}
684
698
  </View>
685
699
  );
@@ -76,6 +76,8 @@ import { webDeps } from '../../primitives/web-deps';
76
76
 
77
77
  const SPRING = { damping: 24, stiffness: 300, mass: 0.7 } as const;
78
78
 
79
+ const SCROLLER_STYLE = { flexGrow: 0, flexShrink: 0 } as const;
80
+
79
81
  /**
80
82
  * How far sideways a finger must travel before the panel takes the gesture
81
83
  * from whatever is scrolling above it, and how far up or down before it gives
@@ -942,6 +944,10 @@ function TabsList({
942
944
  // The row measures itself, and the indicator is positioned against it,
943
945
  // so the scroller must not stretch it to the viewport width.
944
946
  contentContainerStyle={{ flexGrow: 0 }}
947
+ // A ScrollView grows and shrinks on its main axis by default, and in a
948
+ // column with a fixed height that means the bar takes a share of the free
949
+ // space from the panel below it. The bar is as tall as its triggers.
950
+ style={SCROLLER_STYLE}
945
951
  onContentSizeChange={restore}
946
952
  >
947
953
  {scoped}
@@ -52,6 +52,7 @@ import {
52
52
  type ReactNode,
53
53
  } from 'react';
54
54
  import {
55
+ Pressable,
55
56
  ScrollView,
56
57
  View,
57
58
  type AccessibilityActionEvent,
@@ -402,6 +403,21 @@ function Column<T>({
402
403
 
403
404
  useEffect(() => cancelTimer, [cancelTimer]);
404
405
 
406
+ /*
407
+ * A row you can see is a row you can tap. Dragging is not something every
408
+ * pointer can do reliably — a tremor, a head pointer, a switch — and the
409
+ * neighbouring rows are the ones being compared against anyway. The column
410
+ * scrolls there through the same effect a controlled value change uses.
411
+ */
412
+ const pick = useCallback(
413
+ (to: number) => {
414
+ if (disabled || moving.current || to === index) return;
415
+ selectionTick();
416
+ onIndexChange(to);
417
+ },
418
+ [disabled, index, onIndexChange]
419
+ );
420
+
405
421
  const selectedItem = items[index];
406
422
 
407
423
  const onAccessibilityAction = useCallback(
@@ -454,7 +470,7 @@ function Column<T>({
454
470
  onAccessibilityAction={onAccessibilityAction}
455
471
  >
456
472
  {items.map((item, i) => (
457
- <ColumnRow key={i} offset={offset} index={i} selected={i === index}>
473
+ <ColumnRow key={i} offset={offset} index={i} selected={i === index} onPick={pick}>
458
474
  {label(item)}
459
475
  </ColumnRow>
460
476
  ))}
@@ -473,11 +489,13 @@ function ColumnRow({
473
489
  offset,
474
490
  index,
475
491
  selected,
492
+ onPick,
476
493
  children,
477
494
  }: {
478
495
  offset: SharedValue<number>;
479
496
  index: number;
480
497
  selected: boolean;
498
+ onPick: (index: number) => void;
481
499
  children: string;
482
500
  }) {
483
501
  const slots = timePickerVariants();
@@ -499,13 +517,20 @@ function ColumnRow({
499
517
  });
500
518
 
501
519
  return (
502
- <Animated.View
503
- style={[style, { height: ROW_HEIGHT }]}
504
- className={slots.row()}
505
- >
506
- <Text className={cn(slots.rowLabel(), selected && slots.rowLabelSelected())}>
507
- {children}
508
- </Text>
520
+ <Animated.View style={[style, { height: ROW_HEIGHT }]}>
521
+ {/* Hidden from screen readers: the column is one adjustable control to
522
+ them, stepped with increment and decrement, not a list of buttons. */}
523
+ <Pressable
524
+ accessible={false}
525
+ importantForAccessibility="no"
526
+ onPress={() => onPick(index)}
527
+ className={slots.row()}
528
+ style={{ height: ROW_HEIGHT }}
529
+ >
530
+ <Text className={cn(slots.rowLabel(), selected && slots.rowLabelSelected())}>
531
+ {children}
532
+ </Text>
533
+ </Pressable>
509
534
  </Animated.View>
510
535
  );
511
536
  }
@@ -958,6 +983,18 @@ function RulerFace({
958
983
 
959
984
  useEffect(() => cancelTimer, [cancelTimer]);
960
985
 
986
+ // Tapping a tick picks it, for the same reason a wheel's rows can be tapped.
987
+ const pick = useCallback(
988
+ (to: number) => {
989
+ if (disabled || moving.current || to === index) return;
990
+ const time = times[to];
991
+ if (!time) return;
992
+ selectionTick();
993
+ onValueChange(time);
994
+ },
995
+ [disabled, index, onValueChange, times]
996
+ );
997
+
961
998
  const stepsPerHour = Math.max(1, Math.round(60 / minuteStep));
962
999
 
963
1000
  /*
@@ -1037,10 +1074,13 @@ function RulerFace({
1037
1074
  {times.slice(window.start, window.end).map((_, offset) => {
1038
1075
  const i = window.start + offset;
1039
1076
  return (
1040
- <View
1077
+ <Pressable
1041
1078
  key={i}
1079
+ accessible={false}
1080
+ importantForAccessibility="no"
1081
+ onPress={() => pick(i)}
1042
1082
  style={{ width: TICK_SPACING }}
1043
- className="items-center justify-center"
1083
+ className="h-14 items-center justify-center"
1044
1084
  >
1045
1085
  <View
1046
1086
  className={cn(
@@ -1050,7 +1090,7 @@ function RulerFace({
1050
1090
  i % stepsPerHour === 0 ? 'h-7 bg-muted-foreground' : 'h-4 bg-border'
1051
1091
  )}
1052
1092
  />
1053
- </View>
1093
+ </Pressable>
1054
1094
  );
1055
1095
  })}
1056
1096
  <View style={{ width: (times.length - window.end) * TICK_SPACING }} />
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { PanelUIProvider, type PanelUIProviderProps } from './providers/panel-ui
5
5
  export {
6
6
  useTheme,
7
7
  useThemeMode,
8
+ PanelUITheme,
8
9
  PANEL_THEMES,
9
10
  PANEL_THEME_NAMES,
10
11
  PANEL_EXTRA_THEMES,
@@ -1,3 +1,4 @@
1
+ import { Appearance, Platform } from 'react-native';
1
2
  import { Uniwind, useUniwind } from 'uniwind';
2
3
 
3
4
  /** Themes shipped in `panelui-native/theme.css`. */
@@ -83,6 +84,58 @@ function findFamily(theme: string): PanelThemeFamily {
83
84
  );
84
85
  }
85
86
 
87
+ /**
88
+ * The light/dark side of a theme PanelUI knows, or `undefined` for one it does
89
+ * not. A theme registered by the app itself has no mode PanelUI can know, and
90
+ * guessing it from the name would pin the system to the wrong one.
91
+ */
92
+ function modeOf(theme: string): ThemeMode | undefined {
93
+ const family = PANEL_THEMES.find(
94
+ (candidate) => candidate.light === theme || candidate.dark === theme
95
+ );
96
+ if (!family) return undefined;
97
+ return family.dark === theme ? 'dark' : 'light';
98
+ }
99
+
100
+ /**
101
+ * Applies a theme, and tells the operating system which side of light and dark
102
+ * it is on.
103
+ *
104
+ * Uniwind keeps the system appearance in step only for `light` and `dark`.
105
+ * Every other name resets it to the device's own setting, so `grass-dark` on a
106
+ * phone set to Light leaves everything the system draws — the native tab bar,
107
+ * alerts, action sheets, the keyboard — in light. The correction runs in the
108
+ * same tick as the theme change, so no frame is drawn with the two disagreeing.
109
+ *
110
+ * `system` is left alone: pinning the appearance there would stop the app
111
+ * hearing about the device changing.
112
+ */
113
+ function applyTheme(name: ThemeName): void {
114
+ Uniwind.setTheme(name);
115
+ if (Platform.OS === 'web' || name === 'system' || name === 'light' || name === 'dark') {
116
+ return;
117
+ }
118
+ const mode = modeOf(name);
119
+ if (mode) Appearance.setColorScheme(mode);
120
+ }
121
+
122
+ /**
123
+ * Sets the theme from outside React — at module scope before the app mounts,
124
+ * from a deep link, or from a settings store.
125
+ *
126
+ * Use this rather than calling `Uniwind.setTheme` directly: it is the same
127
+ * change, plus the system appearance that a named theme needs to match.
128
+ * `useTheme` and `useThemeMode` go through it too.
129
+ *
130
+ * ```ts
131
+ * // app/_layout.tsx, before the root component
132
+ * PanelUITheme.setTheme('grass-dark');
133
+ * ```
134
+ */
135
+ export const PanelUITheme = {
136
+ setTheme: applyTheme,
137
+ } as const;
138
+
86
139
  /**
87
140
  * Reactive access to the current Uniwind theme plus a setter.
88
141
  * Theme changes are applied natively by Uniwind without re-rendering the tree.
@@ -94,7 +147,7 @@ export function useTheme() {
94
147
  /** The active theme name, e.g. `'dark'` or `'moon-dark'`. */
95
148
  theme: theme as PanelTheme,
96
149
  /** Switch theme by name, or `'system'` to follow the device. */
97
- setTheme: (name: ThemeName) => Uniwind.setTheme(name),
150
+ setTheme: applyTheme,
98
151
  };
99
152
  }
100
153
 
@@ -123,11 +176,11 @@ export function useThemeMode() {
123
176
  /** Switch brand, staying in the current light/dark mode. */
124
177
  setFamily: (id: string) => {
125
178
  const next = PANEL_THEMES.find((candidate) => candidate.id === id);
126
- if (next) Uniwind.setTheme(next[mode]);
179
+ if (next) applyTheme(next[mode]);
127
180
  },
128
181
  /** Set the mode, staying in the current family. */
129
- setMode: (next: ThemeMode) => Uniwind.setTheme(family[next]),
182
+ setMode: (next: ThemeMode) => applyTheme(family[next]),
130
183
  /** Flip light ↔ dark within the current family. */
131
- toggleMode: () => Uniwind.setTheme(mode === 'dark' ? family.light : family.dark),
184
+ toggleMode: () => applyTheme(mode === 'dark' ? family.light : family.dark),
132
185
  };
133
186
  }
package/theme.css CHANGED
@@ -453,8 +453,8 @@
453
453
  --color-muted: rgba(0, 0, 0, 0.05);
454
454
  --color-muted-foreground: #6b6f76;
455
455
 
456
- --color-accent: rgba(0, 0, 0, 0.06);
457
- --color-accent-foreground: #08090a;
456
+ --color-accent: rgba(94, 106, 210, 0.1);
457
+ --color-accent-foreground: #3d47a8;
458
458
 
459
459
  --color-destructive: #eb5757;
460
460
  --color-destructive-foreground: #c62b30;
@@ -536,14 +536,14 @@
536
536
  --color-primary: #5e6ad2;
537
537
  --color-primary-foreground: #ffffff;
538
538
 
539
- --color-secondary: rgba(255, 255, 255, 0.06);
539
+ --color-secondary: rgba(255, 255, 255, 0.08);
540
540
  --color-secondary-foreground: #f7f8f8;
541
541
 
542
542
  --color-muted: rgba(255, 255, 255, 0.06);
543
543
  --color-muted-foreground: #8a8f98;
544
544
 
545
- --color-accent: rgba(255, 255, 255, 0.08);
546
- --color-accent-foreground: #f7f8f8;
545
+ --color-accent: rgba(94, 106, 210, 0.18);
546
+ --color-accent-foreground: #b4baf5;
547
547
 
548
548
  --color-destructive: #eb5757;
549
549
  --color-destructive-foreground: #ff8a8a;