panelui-native 1.2.0 → 1.4.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 (138) hide show
  1. package/lib/module/components/area-chart/index.js +4 -1
  2. package/lib/module/components/area-chart/index.js.map +1 -1
  3. package/lib/module/components/bar-chart/index.js +4 -1
  4. package/lib/module/components/bar-chart/index.js.map +1 -1
  5. package/lib/module/components/bubble-chart/index.js +4 -1
  6. package/lib/module/components/bubble-chart/index.js.map +1 -1
  7. package/lib/module/components/bump-chart/index.js +4 -1
  8. package/lib/module/components/bump-chart/index.js.map +1 -1
  9. package/lib/module/components/calendar/index.js +15 -2
  10. package/lib/module/components/calendar/index.js.map +1 -1
  11. package/lib/module/components/candlestick-chart/index.js +4 -1
  12. package/lib/module/components/candlestick-chart/index.js.map +1 -1
  13. package/lib/module/components/checkbox/index.js +2 -1
  14. package/lib/module/components/checkbox/index.js.map +1 -1
  15. package/lib/module/components/combobox/index.js +28 -7
  16. package/lib/module/components/combobox/index.js.map +1 -1
  17. package/lib/module/components/heatmap-chart/index.js +4 -1
  18. package/lib/module/components/heatmap-chart/index.js.map +1 -1
  19. package/lib/module/components/line-chart/index.js +4 -1
  20. package/lib/module/components/line-chart/index.js.map +1 -1
  21. package/lib/module/components/live-line-chart/index.js +4 -1
  22. package/lib/module/components/live-line-chart/index.js.map +1 -1
  23. package/lib/module/components/mirror-area-chart/index.js +4 -1
  24. package/lib/module/components/mirror-area-chart/index.js.map +1 -1
  25. package/lib/module/components/plot/index.js +4 -1
  26. package/lib/module/components/plot/index.js.map +1 -1
  27. package/lib/module/components/pyramid-chart/index.js +4 -1
  28. package/lib/module/components/pyramid-chart/index.js.map +1 -1
  29. package/lib/module/components/questionnaire/index.js +1 -0
  30. package/lib/module/components/questionnaire/index.js.map +1 -1
  31. package/lib/module/components/radio-group/index.js +2 -1
  32. package/lib/module/components/radio-group/index.js.map +1 -1
  33. package/lib/module/components/scatter-chart/index.js +4 -1
  34. package/lib/module/components/scatter-chart/index.js.map +1 -1
  35. package/lib/module/components/scroll-blur/index.js +25 -7
  36. package/lib/module/components/scroll-blur/index.js.map +1 -1
  37. package/lib/module/components/scroll-header/index.js +44 -24
  38. package/lib/module/components/scroll-header/index.js.map +1 -1
  39. package/lib/module/components/search-bar/index.js +2 -1
  40. package/lib/module/components/search-bar/index.js.map +1 -1
  41. package/lib/module/components/section-progress/index.js +1 -1
  42. package/lib/module/components/section-progress/index.js.map +1 -1
  43. package/lib/module/components/section-rail/index.js +1 -1
  44. package/lib/module/components/section-rail/index.js.map +1 -1
  45. package/lib/module/components/select/index.js +28 -7
  46. package/lib/module/components/select/index.js.map +1 -1
  47. package/lib/module/components/switch/index.js +51 -15
  48. package/lib/module/components/switch/index.js.map +1 -1
  49. package/lib/module/components/table/index.js +17 -3
  50. package/lib/module/components/table/index.js.map +1 -1
  51. package/lib/module/components/toast/index.js +13 -3
  52. package/lib/module/components/toast/index.js.map +1 -1
  53. package/lib/module/components/waterfall-chart/index.js +4 -1
  54. package/lib/module/components/waterfall-chart/index.js.map +1 -1
  55. package/lib/module/components/week-hours-grid/index.js +187 -0
  56. package/lib/module/components/week-hours-grid/index.js.map +1 -0
  57. package/lib/module/components/week-strip/index.js +232 -0
  58. package/lib/module/components/week-strip/index.js.map +1 -0
  59. package/lib/module/index.js +3 -1
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/primitives/scrim.js +50 -2
  62. package/lib/module/primitives/scrim.js.map +1 -1
  63. package/lib/module/theme/use-theme.js +55 -4
  64. package/lib/module/theme/use-theme.js.map +1 -1
  65. package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -1
  66. package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -1
  67. package/lib/typescript/src/components/bubble-chart/index.d.ts.map +1 -1
  68. package/lib/typescript/src/components/bump-chart/index.d.ts.map +1 -1
  69. package/lib/typescript/src/components/calendar/index.d.ts.map +1 -1
  70. package/lib/typescript/src/components/candlestick-chart/index.d.ts.map +1 -1
  71. package/lib/typescript/src/components/combobox/index.d.ts +2 -1
  72. package/lib/typescript/src/components/combobox/index.d.ts.map +1 -1
  73. package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
  74. package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
  75. package/lib/typescript/src/components/live-line-chart/index.d.ts.map +1 -1
  76. package/lib/typescript/src/components/mirror-area-chart/index.d.ts.map +1 -1
  77. package/lib/typescript/src/components/plot/index.d.ts.map +1 -1
  78. package/lib/typescript/src/components/pyramid-chart/index.d.ts.map +1 -1
  79. package/lib/typescript/src/components/questionnaire/index.d.ts.map +1 -1
  80. package/lib/typescript/src/components/radio-group/index.d.ts.map +1 -1
  81. package/lib/typescript/src/components/scatter-chart/index.d.ts.map +1 -1
  82. package/lib/typescript/src/components/scroll-blur/index.d.ts.map +1 -1
  83. package/lib/typescript/src/components/scroll-header/index.d.ts +4 -2
  84. package/lib/typescript/src/components/scroll-header/index.d.ts.map +1 -1
  85. package/lib/typescript/src/components/search-bar/index.d.ts +3 -0
  86. package/lib/typescript/src/components/search-bar/index.d.ts.map +1 -1
  87. package/lib/typescript/src/components/select/index.d.ts +2 -1
  88. package/lib/typescript/src/components/select/index.d.ts.map +1 -1
  89. package/lib/typescript/src/components/switch/index.d.ts +7 -0
  90. package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
  91. package/lib/typescript/src/components/table/index.d.ts.map +1 -1
  92. package/lib/typescript/src/components/toast/index.d.ts +7 -2
  93. package/lib/typescript/src/components/toast/index.d.ts.map +1 -1
  94. package/lib/typescript/src/components/waterfall-chart/index.d.ts.map +1 -1
  95. package/lib/typescript/src/components/week-hours-grid/index.d.ts +56 -0
  96. package/lib/typescript/src/components/week-hours-grid/index.d.ts.map +1 -0
  97. package/lib/typescript/src/components/week-strip/index.d.ts +173 -0
  98. package/lib/typescript/src/components/week-strip/index.d.ts.map +1 -0
  99. package/lib/typescript/src/index.d.ts +3 -1
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/primitives/scrim.d.ts +56 -2
  102. package/lib/typescript/src/primitives/scrim.d.ts.map +1 -1
  103. package/lib/typescript/src/theme/use-theme.d.ts +32 -1
  104. package/lib/typescript/src/theme/use-theme.d.ts.map +1 -1
  105. package/package.json +1 -1
  106. package/src/components/area-chart/index.tsx +3 -1
  107. package/src/components/bar-chart/index.tsx +3 -1
  108. package/src/components/bubble-chart/index.tsx +3 -1
  109. package/src/components/bump-chart/index.tsx +3 -1
  110. package/src/components/calendar/index.tsx +15 -3
  111. package/src/components/candlestick-chart/index.tsx +3 -1
  112. package/src/components/checkbox/index.tsx +1 -1
  113. package/src/components/combobox/index.tsx +27 -8
  114. package/src/components/heatmap-chart/index.tsx +3 -1
  115. package/src/components/line-chart/index.tsx +3 -1
  116. package/src/components/live-line-chart/index.tsx +3 -1
  117. package/src/components/mirror-area-chart/index.tsx +3 -1
  118. package/src/components/plot/index.tsx +3 -1
  119. package/src/components/pyramid-chart/index.tsx +3 -1
  120. package/src/components/questionnaire/index.tsx +1 -0
  121. package/src/components/radio-group/index.tsx +5 -1
  122. package/src/components/scatter-chart/index.tsx +3 -1
  123. package/src/components/scroll-blur/index.tsx +32 -4
  124. package/src/components/scroll-header/index.tsx +63 -25
  125. package/src/components/search-bar/index.tsx +1 -1
  126. package/src/components/section-progress/index.tsx +1 -1
  127. package/src/components/section-rail/index.tsx +1 -1
  128. package/src/components/select/index.tsx +27 -8
  129. package/src/components/switch/index.tsx +54 -5
  130. package/src/components/table/index.tsx +17 -3
  131. package/src/components/toast/index.tsx +24 -4
  132. package/src/components/waterfall-chart/index.tsx +3 -1
  133. package/src/components/week-hours-grid/index.tsx +238 -0
  134. package/src/components/week-strip/index.tsx +272 -0
  135. package/src/index.ts +16 -0
  136. package/src/primitives/scrim.tsx +56 -4
  137. package/src/theme/use-theme.ts +57 -4
  138. package/theme.css +5 -5
@@ -62,9 +62,11 @@ import {
62
62
  Children,
63
63
  isValidElement,
64
64
  useMemo,
65
+ useRef,
65
66
  type ComponentType,
66
67
  type ReactElement,
67
68
  type ReactNode,
69
+ type RefObject,
68
70
  } from 'react';
69
71
  import {
70
72
  StyleSheet,
@@ -83,7 +85,12 @@ import Animated, {
83
85
  type DerivedValue,
84
86
  } from 'react-native-reanimated';
85
87
  import { useCSSVariable } from 'uniwind';
86
- import { hasBlur, useReduceTransparency } from '../../primitives/scrim';
88
+ import {
89
+ androidBlurProps,
90
+ BlurTargetView,
91
+ canBlurHere,
92
+ useReduceTransparency,
93
+ } from '../../primitives/scrim';
87
94
  import { useThemeMode } from '../../theme/use-theme';
88
95
 
89
96
  /**
@@ -95,6 +102,8 @@ const BlurView: ComponentType<{
95
102
  intensity?: number;
96
103
  tint?: ScrollBlurTint;
97
104
  style?: unknown;
105
+ blurMethod?: string;
106
+ blurTarget?: RefObject<View | null>;
98
107
  }> | null = (() => {
99
108
  try {
100
109
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -190,7 +199,11 @@ export function ScrollBlur({
190
199
  * arriving a frame late costs nothing, while a blur flashed at somebody who
191
200
  * switched Reduce Transparency on is the whole thing that setting is for.
192
201
  */
193
- const blurring = hasBlur && BlurView !== null && reduceTransparency === false;
202
+ const blurring = canBlurHere && BlurView !== null && reduceTransparency === false;
203
+ // Android blurs only a view it is pointed at, so the scroller is wrapped in a
204
+ // target when there is a blur to draw over it.
205
+ const targetRef = useRef<View>(null);
206
+ const wantsTarget = blurring && BlurTargetView !== null;
194
207
  const materialTint: ScrollBlurTint = material === 'default' ? mode : material;
195
208
 
196
209
  const themeBackground = useCSSVariable('--color-background');
@@ -278,6 +291,7 @@ export function ScrollBlur({
278
291
  }
279
292
 
280
293
  const edgeProps = {
294
+ blurTarget: wantsTarget ? targetRef : null,
281
295
  size,
282
296
  horizontal,
283
297
  layers: Math.max(1, Math.round(layers)),
@@ -290,7 +304,13 @@ export function ScrollBlur({
290
304
 
291
305
  return (
292
306
  <View {...props} className={className}>
293
- {scrollable}
307
+ {wantsTarget && BlurTargetView ? (
308
+ <BlurTargetView ref={targetRef} collapsable={false} style={{ flex: 1 }}>
309
+ {scrollable}
310
+ </BlurTargetView>
311
+ ) : (
312
+ scrollable
313
+ )}
294
314
 
295
315
  {edges !== 'end' ? (
296
316
  <Edge {...edgeProps} opacity={startOpacity} edge="start" />
@@ -306,6 +326,7 @@ ScrollBlur.displayName = 'ScrollBlur';
306
326
 
307
327
  /** One edge's band: the stack of blur views, and the wash that joins them up. */
308
328
  function Edge({
329
+ blurTarget,
309
330
  size,
310
331
  horizontal,
311
332
  layers,
@@ -317,6 +338,7 @@ function Edge({
317
338
  opacity,
318
339
  edge,
319
340
  }: {
341
+ blurTarget: RefObject<View | null> | null;
320
342
  size: number;
321
343
  horizontal: boolean;
322
344
  layers: number;
@@ -385,9 +407,15 @@ function Edge({
385
407
  style={[{ position: 'absolute', opacity: step.opacity }, along(step.span)]}
386
408
  >
387
409
  <BlurView
388
- intensity={intensity / layers}
410
+ // Elsewhere each layer blurs the layers under it, so the
411
+ // strength adds up towards the edge. Android's layers each
412
+ // blur the scroller itself, so each carries its own share.
413
+ intensity={
414
+ blurTarget ? (intensity * (step.key + 1)) / layers : intensity / layers
415
+ }
389
416
  tint={material}
390
417
  style={StyleSheet.absoluteFill}
418
+ {...androidBlurProps(blurTarget)}
391
419
  />
392
420
  </View>
393
421
  ))
@@ -81,10 +81,12 @@ import {
81
81
  useCallback,
82
82
  useContext,
83
83
  useMemo,
84
+ useRef,
84
85
  useState,
85
86
  type ComponentType,
86
87
  type ReactNode,
87
88
  type Ref,
89
+ type RefObject,
88
90
  } from 'react';
89
91
  import {
90
92
  Image,
@@ -120,7 +122,12 @@ import Animated, {
120
122
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
121
123
  import { tv, type VariantProps } from 'tailwind-variants';
122
124
  import { useCSSVariable } from 'uniwind';
123
- import { hasBlur, useReduceTransparency } from '../../primitives/scrim';
125
+ import {
126
+ androidBlurProps,
127
+ BlurTargetView,
128
+ canBlurHere,
129
+ useReduceTransparency,
130
+ } from '../../primitives/scrim';
124
131
  import { Text, textChildren, type TextProps } from '../../primitives/text';
125
132
  import { useThemeMode } from '../../theme/use-theme';
126
133
  import { cn } from '../../utils/cn';
@@ -164,6 +171,8 @@ const BlurView: ComponentType<{
164
171
  intensity?: number;
165
172
  tint?: ScrollHeaderMaterial;
166
173
  style?: unknown;
174
+ blurMethod?: string;
175
+ blurTarget?: RefObject<View | null>;
167
176
  }> | null = (() => {
168
177
  try {
169
178
  // eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -234,6 +243,11 @@ interface ScrollHeaderContextValue {
234
243
  /** Whether there is a large block at all. A bar-only header has no crossing. */
235
244
  hasLarge: boolean;
236
245
  measureLarge: (event: LayoutChangeEvent) => void;
246
+ /**
247
+ * The view wrapping the scroller on Android, which a blurred bar samples.
248
+ * Null on other platforms, and when the bar is not blurred.
249
+ */
250
+ blurTarget: RefObject<View | null> | null;
237
251
  }
238
252
 
239
253
  const ScrollHeaderContext = createContext<ScrollHeaderContextValue | undefined>(undefined);
@@ -500,35 +514,54 @@ const ScrollHeaderRoot = forwardRef<ViewRef, ScrollHeaderProps>(
500
514
 
501
515
  const hasLarge = largeSize >= 1;
502
516
 
517
+ // Android blurs only a view it is pointed at, so a blurred bar needs the
518
+ // scroller wrapped in a target. Only then: the wrapper records every frame
519
+ // the scroller draws.
520
+ const targetRef = useRef<View>(null);
521
+ const wantsTarget =
522
+ BlurTargetView !== null &&
523
+ isValidElement(parts.bar) &&
524
+ (parts.bar.props as { surface?: ScrollHeaderSurface }).surface === 'blur';
525
+ const blurTarget = wantsTarget ? targetRef : null;
526
+
503
527
  const context = useMemo<ScrollHeaderContextValue>(
504
- () => ({ progress, offset, largeHeight, collapsed, hasLarge, measureLarge }),
505
- [progress, offset, largeHeight, collapsed, hasLarge, measureLarge]
528
+ () => ({ progress, offset, largeHeight, collapsed, hasLarge, measureLarge, blurTarget }),
529
+ [progress, offset, largeHeight, collapsed, hasLarge, measureLarge, blurTarget]
506
530
  );
507
531
 
508
532
  const { root, band } = scrollHeaderVariants();
509
533
 
534
+ const scroller =
535
+ AnimatedScrollable && isValidElement(scrollable) ? (
536
+ <AnimatedScrollable
537
+ {...childProps}
538
+ ref={composeRefs(scrollRef, childProps.ref)}
539
+ onScroll={onScroll}
540
+ scrollEventThrottle={childProps.scrollEventThrottle ?? 16}
541
+ // The band is the inset. iOS would otherwise add one of its own
542
+ // on top of it, for a header it cannot see.
543
+ contentInsetAdjustmentBehavior={
544
+ childProps.contentInsetAdjustmentBehavior ?? 'never'
545
+ }
546
+ contentContainerStyle={[
547
+ childProps.contentContainerStyle,
548
+ { paddingTop: headerHeight },
549
+ ]}
550
+ scrollIndicatorInsets={{ top: barBand, ...childProps.scrollIndicatorInsets }}
551
+ />
552
+ ) : (
553
+ scrollable
554
+ );
555
+
510
556
  return (
511
557
  <ScrollHeaderContext.Provider value={context}>
512
558
  <View {...props} ref={ref} className={root({ className })}>
513
- {AnimatedScrollable && isValidElement(scrollable) ? (
514
- <AnimatedScrollable
515
- {...childProps}
516
- ref={composeRefs(scrollRef, childProps.ref)}
517
- onScroll={onScroll}
518
- scrollEventThrottle={childProps.scrollEventThrottle ?? 16}
519
- // The band is the inset. iOS would otherwise add one of its own
520
- // on top of it, for a header it cannot see.
521
- contentInsetAdjustmentBehavior={
522
- childProps.contentInsetAdjustmentBehavior ?? 'never'
523
- }
524
- contentContainerStyle={[
525
- childProps.contentContainerStyle,
526
- { paddingTop: headerHeight },
527
- ]}
528
- scrollIndicatorInsets={{ top: barBand, ...childProps.scrollIndicatorInsets }}
529
- />
559
+ {wantsTarget && BlurTargetView ? (
560
+ <BlurTargetView ref={targetRef} collapsable={false} style={styles.target}>
561
+ {scroller}
562
+ </BlurTargetView>
530
563
  ) : (
531
- scrollable
564
+ scroller
532
565
  )}
533
566
 
534
567
  <Animated.View
@@ -569,8 +602,10 @@ export interface ScrollHeaderBarProps extends ViewProps {
569
602
  * content passing under the bar stays legible as shape and colour.
570
603
  *
571
604
  * `blur` needs `expo-blur`, which is optional, and it is replaced by an
572
- * opaque bar under Reduce Transparency. Both fall back to `plain` — a bar
573
- * whose title cannot be read is a worse answer than one that is not frosted.
605
+ * opaque bar under Reduce Transparency. On Android it needs Android 12 (API
606
+ * 31) or later, and the header wraps its scroller in the view the blur
607
+ * samples. Each of these falls back to `plain` — a bar whose title cannot be
608
+ * read is a worse answer than one that is not frosted.
574
609
  */
575
610
  surface?: ScrollHeaderSurface;
576
611
  /** A hairline under the bar, drawn with its surface. */
@@ -609,7 +644,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
609
644
  },
610
645
  ref
611
646
  ) => {
612
- const { progress } = useScrollHeader('ScrollHeader.Bar');
647
+ const { progress, blurTarget } = useScrollHeader('ScrollHeader.Bar');
613
648
  const { barBand, insetTop } = useContext(BandMetricsContext);
614
649
  const { mode } = useThemeMode();
615
650
  const reduceTransparency = useReduceTransparency();
@@ -617,7 +652,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
617
652
  // Three gates, and a preference that has not been answered yet counts as
618
653
  // switched on: the case worth being careful about is the one where it is.
619
654
  const blurring =
620
- surface === 'blur' && hasBlur && BlurView !== null && reduceTransparency === false;
655
+ surface === 'blur' && canBlurHere && BlurView !== null && reduceTransparency === false;
621
656
  const fill = surface === 'blur' && !blurring ? 'plain' : surface;
622
657
  const { bar, barSurface } = scrollHeaderVariants({ surface: fill, divider });
623
658
 
@@ -652,6 +687,7 @@ const ScrollHeaderBar = forwardRef<ViewRef, ScrollHeaderBarProps>(
652
687
  intensity={intensity}
653
688
  tint={material === 'default' ? mode : material}
654
689
  style={StyleSheet.absoluteFill}
690
+ {...androidBlurProps(blurTarget)}
655
691
  />
656
692
  ) : null}
657
693
  </Animated.View>
@@ -893,6 +929,8 @@ const styles = StyleSheet.create({
893
929
  // Android draws by elevation before z-order, so a band with none of its own
894
930
  // ends up under the scroller's own background.
895
931
  lift: { elevation: 4 },
932
+ // Takes the scroller's place in the root, which it fills.
933
+ target: { flex: 1 },
896
934
  });
897
935
 
898
936
  export const ScrollHeader = Object.assign(ScrollHeaderRoot, {
@@ -363,7 +363,7 @@ const searchBarVariants = tv({
363
363
  bottom: { field: 'rounded-b-none rounded-t-2xl border-0' },
364
364
  },
365
365
  selected: {
366
- true: { item: 'bg-accent' },
366
+ true: { item: 'bg-accent', itemLabel: 'text-accent-foreground' },
367
367
  },
368
368
  },
369
369
  defaultVariants: {
@@ -795,7 +795,7 @@ function SectionProgressItem({ className, value, children }: SectionProgressItem
795
795
  <Text
796
796
  size="sm"
797
797
  weight={selected ? 'medium' : 'normal'}
798
- className={selected ? 'text-foreground' : 'text-muted-foreground'}
798
+ className={selected ? 'text-accent-foreground' : 'text-muted-foreground'}
799
799
  // Two lines rather than one: an ellipsis in a navigator hides the very
800
800
  // word that says which section the row would jump to.
801
801
  numberOfLines={2}
@@ -612,7 +612,7 @@ function SectionRailItem({ className, value, level = 0, children }: SectionRailI
612
612
  <Text
613
613
  size="sm"
614
614
  weight={selected ? 'medium' : 'normal'}
615
- className={selected ? 'text-foreground' : 'text-muted-foreground'}
615
+ className={selected ? 'text-accent-foreground' : 'text-muted-foreground'}
616
616
  // Two lines rather than one: a long section title is worth wrapping,
617
617
  // and an ellipsis in a navigator hides the very word that tells you
618
618
  // which section you are about to jump to.
@@ -89,7 +89,9 @@ const selectVariants = tv({
89
89
  search: 'pb-2',
90
90
  empty: 'px-3 py-6 text-center text-sm text-muted-foreground',
91
91
  item: 'flex-row items-center gap-2 rounded-lg px-3 py-3',
92
- itemLabel: 'flex-1 text-base font-medium text-foreground',
92
+ // Grows to fill the row but keeps its natural width as its basis, so an
93
+ // overlay sized to `content` can measure the longest label.
94
+ itemLabel: 'grow shrink text-base font-medium text-foreground',
93
95
  itemIndicator: 'h-5 w-5 items-center justify-center',
94
96
  group: 'gap-1',
95
97
  groupLabel: 'px-3 pb-1 pt-2',
@@ -123,7 +125,7 @@ const selectVariants = tv({
123
125
  },
124
126
  },
125
127
  selected: {
126
- true: { item: 'bg-accent' },
128
+ true: { item: 'bg-accent', itemLabel: 'text-accent-foreground' },
127
129
  },
128
130
  disabled: {
129
131
  true: { trigger: 'opacity-[0.64]' },
@@ -225,7 +227,9 @@ function SelectItem({ value, label, disabled, className, labelClassName }: Selec
225
227
  selected,
226
228
  itemDisabled: !!disabled,
227
229
  });
228
- const checkColor = useCSSVariable('--color-muted-foreground');
230
+ // Drawn only on a selected row, so on the accent fill: it takes the colour
231
+ // made to be read there.
232
+ const checkColor = useCSSVariable('--color-accent-foreground');
229
233
 
230
234
  return (
231
235
  <Pressable
@@ -483,7 +487,8 @@ export interface SelectProps {
483
487
  sheetProps?: SelectSheetProps;
484
488
  /**
485
489
  * Width of the floating list. `trigger` matches the trigger, `content` sizes
486
- * to the longest option, or pass a pixel value. `overlay` only.
490
+ * to the longest option, or pass a pixel value. A list wider than the
491
+ * trigger moves left to stay on screen. `overlay` only.
487
492
  */
488
493
  contentWidth?: 'trigger' | 'content' | number;
489
494
  /** Gap between the trigger and the floating list. `overlay` only. */
@@ -521,6 +526,18 @@ export interface SelectProps {
521
526
  children: ReactNode;
522
527
  }
523
528
 
529
+ /** Space kept between a floating list and the side of the screen. */
530
+ const OVERLAY_EDGE = 8;
531
+
532
+ /**
533
+ * Where a floating list starts. It lines up with the trigger, and moves left
534
+ * when a list wider than the trigger would run off the right of the screen.
535
+ */
536
+ function overlayLeft(anchor: { x: number }, width: number, screenWidth: number) {
537
+ const furthest = screenWidth - OVERLAY_EDGE - width;
538
+ return Math.max(Math.min(anchor.x, furthest), Math.min(anchor.x, OVERLAY_EDGE));
539
+ }
540
+
524
541
  function SelectRoot({
525
542
  className,
526
543
  value,
@@ -554,9 +571,10 @@ function SelectRoot({
554
571
  const [query, setQuery] = useState('');
555
572
  const [anchor, setAnchor] = useState<Anchor | null>(null);
556
573
  const [listHeight, setListHeight] = useState(0);
574
+ const [listWidth, setListWidth] = useState(0);
557
575
  const triggerRef = useRef<ViewRef>(null);
558
576
  const chevron = useSharedValue(0);
559
- const { height: screenHeight } = useWindowDimensions();
577
+ const { height: screenHeight, width: screenWidth } = useWindowDimensions();
560
578
  const insets = useSafeAreaInsets();
561
579
 
562
580
  const options = useMemo(() => {
@@ -866,15 +884,15 @@ function SelectRoot({
866
884
  const overlayPosition = anchor
867
885
  ? {
868
886
  position: 'absolute' as const,
869
- left: anchor.x,
887
+ left: overlayLeft(anchor, contentWidth === 'trigger' ? anchor.width : listWidth, screenWidth),
870
888
  ...(flip
871
889
  ? { bottom: screenHeight - anchor.y + offset }
872
890
  : { top: anchor.y + anchor.height + offset }),
873
891
  ...(contentWidth === 'trigger'
874
892
  ? { width: anchor.width }
875
893
  : typeof contentWidth === 'number'
876
- ? { width: contentWidth }
877
- : { minWidth: anchor.width }),
894
+ ? { width: contentWidth, maxWidth: screenWidth - OVERLAY_EDGE * 2 }
895
+ : { minWidth: anchor.width, maxWidth: screenWidth - OVERLAY_EDGE * 2 }),
878
896
  // Never collapse to nothing in a cramped viewport — the list scrolls.
879
897
  maxHeight: Math.max((flip ? anchor.y : spaceBelow) - offset, 160),
880
898
  }
@@ -882,6 +900,7 @@ function SelectRoot({
882
900
 
883
901
  const onListLayout = (event: LayoutChangeEvent) => {
884
902
  setListHeight(event.nativeEvent.layout.height);
903
+ setListWidth(event.nativeEvent.layout.width);
885
904
  };
886
905
 
887
906
  return (
@@ -1,5 +1,5 @@
1
1
  import { forwardRef, useEffect } from 'react';
2
- import { Pressable, View, type PressableProps } from 'react-native';
2
+ import { Platform, Pressable, View, type PressableProps } from 'react-native';
3
3
  import Animated, {
4
4
  interpolate,
5
5
  useAnimatedStyle,
@@ -62,6 +62,25 @@ const SWITCH_HIT_SLOP: Record<SwitchSize, { top: number; bottom: number; left: n
62
62
  xl: { top: 6, bottom: 6, left: 0, right: 0 },
63
63
  };
64
64
 
65
+ /**
66
+ * The same room as padding, with a negative margin that gives it back to the
67
+ * layout. The web ignores `hitSlop`, so without this its target would be the
68
+ * bare track.
69
+ */
70
+ const webTarget = (size: SwitchSize) => {
71
+ const slop = SWITCH_HIT_SLOP[size];
72
+ return {
73
+ paddingTop: slop.top,
74
+ paddingBottom: slop.bottom,
75
+ paddingLeft: slop.left,
76
+ paddingRight: slop.right,
77
+ marginTop: -slop.top,
78
+ marginBottom: -slop.bottom,
79
+ marginLeft: -slop.left,
80
+ marginRight: -slop.right,
81
+ };
82
+ };
83
+
65
84
  export interface SwitchProps
66
85
  extends VariantProps<typeof switchVariants>,
67
86
  Pick<PressableProps, 'accessibilityLabel' | 'accessibilityHint' | 'accessibilityLabelledBy'> {
@@ -86,6 +105,13 @@ export interface SwitchProps
86
105
  * the platform control owns its own feedback.
87
106
  */
88
107
  haptics?: boolean;
108
+ /**
109
+ * Set to `false` to draw only the track, with no press and no role of its
110
+ * own. Use it when a whole row is the switch: the row is the one
111
+ * `Pressable` with `accessibilityRole="switch"`, and a second switch inside
112
+ * it would be announced twice and take two Tab stops.
113
+ */
114
+ interactive?: boolean;
89
115
  }
90
116
 
91
117
  /**
@@ -115,6 +141,7 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
115
141
  accessibilityLabel,
116
142
  accessibilityHint,
117
143
  accessibilityLabelledBy,
144
+ interactive = true,
118
145
  },
119
146
  ref
120
147
  ) => {
@@ -173,11 +200,35 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
173
200
  );
174
201
  }
175
202
 
203
+ const track = (
204
+ <View className={slots.track({ className })}>
205
+ <Animated.View style={activeTrackStyle} className={slots.activeTrack()} />
206
+ <Animated.View style={thumbStyle} className={slots.thumb()} />
207
+ </View>
208
+ );
209
+
210
+ if (!interactive) {
211
+ return (
212
+ <View
213
+ ref={ref}
214
+ accessible={false}
215
+ aria-hidden
216
+ importantForAccessibility="no-hide-descendants"
217
+ pointerEvents="none"
218
+ >
219
+ {track}
220
+ </View>
221
+ );
222
+ }
223
+
176
224
  return (
177
225
  <Pressable
178
226
  ref={ref}
179
227
  accessibilityRole="switch"
180
228
  accessibilityState={{ checked: value, disabled: !!disabled }}
229
+ // Stated as well, because the web drops `checked: false` from the
230
+ // state and a switch with no `aria-checked` is an incomplete one.
231
+ aria-checked={value}
181
232
  accessibilityLabel={accessibilityLabel ?? label}
182
233
  accessibilityHint={accessibilityHint}
183
234
  accessibilityLabelledBy={
@@ -189,11 +240,9 @@ export const Switch = forwardRef<ViewRef, SwitchProps>(
189
240
  onValueChange?.(!value);
190
241
  }}
191
242
  hitSlop={SWITCH_HIT_SLOP[size]}
243
+ style={Platform.OS === 'web' ? webTarget(size) : undefined}
192
244
  >
193
- <View className={slots.track({ className })}>
194
- <Animated.View style={activeTrackStyle} className={slots.activeTrack()} />
195
- <Animated.View style={thumbStyle} className={slots.thumb()} />
196
- </View>
245
+ {track}
197
246
  </Pressable>
198
247
  );
199
248
  }
@@ -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
  );
@@ -20,6 +20,7 @@ import {
20
20
  } from 'react';
21
21
  import {
22
22
  AppState,
23
+ Platform,
23
24
  View,
24
25
  type ViewProps,
25
26
  } from 'react-native';
@@ -266,11 +267,29 @@ const ToastAction = ({ variant = 'secondary', size = 'sm', onPress, ...props }:
266
267
  };
267
268
  ToastAction.displayName = 'Toast.Action';
268
269
 
269
- export interface ToastCloseProps extends ViewProps {
270
+ export interface ToastCloseProps extends Omit<ViewProps, 'accessibilityLabel'> {
270
271
  className?: string;
272
+ /**
273
+ * What a screen reader calls the button. Defaults to "Dismiss notification";
274
+ * pass your own in an app that is not in English.
275
+ */
276
+ accessibilityLabel?: string;
271
277
  }
272
278
 
273
- const ToastClose = ({ className, ...props }: ToastCloseProps) => {
279
+ /*
280
+ * The cross is drawn at 24 points so it stays quiet beside the text, and its
281
+ * target reaches 44 on both axes. Natively that is hit slop. The web ignores
282
+ * hit slop, so there the button itself is 44 and a negative margin gives the
283
+ * room back to the layout.
284
+ */
285
+ const CLOSE_SIZE = Platform.OS === 'web' ? '-m-2.5 h-11 w-11' : 'h-6 w-6';
286
+ const CLOSE_SLOP = Platform.OS === 'web' ? undefined : 10;
287
+
288
+ const ToastClose = ({
289
+ className,
290
+ accessibilityLabel = 'Dismiss notification',
291
+ ...props
292
+ }: ToastCloseProps) => {
274
293
  const { hide } = useContext(ToastContext);
275
294
  const color = useCSSVariable('--color-muted-foreground');
276
295
 
@@ -279,8 +298,9 @@ const ToastClose = ({ className, ...props }: ToastCloseProps) => {
279
298
  <Button
280
299
  variant="ghost"
281
300
  size="icon"
282
- accessibilityLabel="Dismiss notification"
283
- className="h-6 w-6 rounded-full"
301
+ accessibilityLabel={accessibilityLabel}
302
+ className={cn(CLOSE_SIZE, 'rounded-full')}
303
+ hitSlop={CLOSE_SLOP}
284
304
  onPress={hide}
285
305
  >
286
306
  <XIcon size={14} color={typeof color === 'string' ? color : undefined} />
@@ -1386,7 +1386,9 @@ function WaterfallChartTooltip({
1386
1386
  };
1387
1387
 
1388
1388
  return Gesture.Pan()
1389
- .minDistance(0)
1389
+ // With a hold, only the timer may start the readout: a distance of 0 would
1390
+ // activate on the first move event and take the touch from a Pressable above.
1391
+ .minDistance(activateAfterLongPress > 0 ? 10_000 : 0)
1390
1392
  .activateAfterLongPress(activateAfterLongPress)
1391
1393
  .onStart((event) => {
1392
1394
  'worklet';