@oxy.so/bloom 7.21.0 → 7.23.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 (201) hide show
  1. package/docs/accordion.mdx +5 -0
  2. package/docs/adoption-matrix.mdx +6 -5
  3. package/docs/carousel.mdx +31 -0
  4. package/docs/collapsible.mdx +72 -0
  5. package/docs/migrating-to-1.0.mdx +1 -1
  6. package/docs/radio.mdx +15 -0
  7. package/lib/commonjs/accordion/Accordion.js +18 -45
  8. package/lib/commonjs/accordion/Accordion.js.map +1 -1
  9. package/lib/commonjs/accordion/Accordion.web.js +16 -53
  10. package/lib/commonjs/accordion/Accordion.web.js.map +1 -1
  11. package/lib/commonjs/accordion/use-accordion.js +3 -30
  12. package/lib/commonjs/accordion/use-accordion.js.map +1 -1
  13. package/lib/commonjs/carousel/Carousel.js +21 -13
  14. package/lib/commonjs/carousel/Carousel.js.map +1 -1
  15. package/lib/commonjs/collapsible/Collapsible.js +22 -0
  16. package/lib/commonjs/collapsible/Collapsible.js.map +1 -0
  17. package/lib/commonjs/collapsible/Collapsible.web.js +22 -0
  18. package/lib/commonjs/collapsible/Collapsible.web.js.map +1 -0
  19. package/lib/commonjs/collapsible/CollapsibleFrame.js +97 -0
  20. package/lib/commonjs/collapsible/CollapsibleFrame.js.map +1 -0
  21. package/lib/commonjs/collapsible/CollapsibleFrame.web.js +116 -0
  22. package/lib/commonjs/collapsible/CollapsibleFrame.web.js.map +1 -0
  23. package/lib/commonjs/collapsible/context.js +15 -0
  24. package/lib/commonjs/collapsible/context.js.map +1 -0
  25. package/lib/commonjs/collapsible/frame-types.js +6 -0
  26. package/lib/commonjs/collapsible/frame-types.js.map +1 -0
  27. package/lib/commonjs/collapsible/index.js +13 -0
  28. package/lib/commonjs/collapsible/index.js.map +1 -0
  29. package/lib/commonjs/collapsible/index.web.js +13 -0
  30. package/lib/commonjs/collapsible/index.web.js.map +1 -0
  31. package/lib/commonjs/collapsible/types.js +6 -0
  32. package/lib/commonjs/collapsible/types.js.map +1 -0
  33. package/lib/commonjs/collapsible/use-collapsible-motion.js +60 -0
  34. package/lib/commonjs/collapsible/use-collapsible-motion.js.map +1 -0
  35. package/lib/commonjs/index.js +12 -0
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/index.web.js +12 -0
  38. package/lib/commonjs/index.web.js.map +1 -1
  39. package/lib/commonjs/radio/Radio.js +54 -26
  40. package/lib/commonjs/radio/Radio.js.map +1 -1
  41. package/lib/commonjs/radio/RadioCard.js +8 -1
  42. package/lib/commonjs/radio/RadioCard.js.map +1 -1
  43. package/lib/commonjs/radio/use-radio-group-item.js +3 -1
  44. package/lib/commonjs/radio/use-radio-group-item.js.map +1 -1
  45. package/lib/commonjs/select/Select.js +10 -5
  46. package/lib/commonjs/select/Select.js.map +1 -1
  47. package/lib/commonjs/select/Select.web.js +11 -3
  48. package/lib/commonjs/select/Select.web.js.map +1 -1
  49. package/lib/module/accordion/Accordion.js +19 -46
  50. package/lib/module/accordion/Accordion.js.map +1 -1
  51. package/lib/module/accordion/Accordion.web.js +17 -54
  52. package/lib/module/accordion/Accordion.web.js.map +1 -1
  53. package/lib/module/accordion/use-accordion.js +4 -31
  54. package/lib/module/accordion/use-accordion.js.map +1 -1
  55. package/lib/module/carousel/Carousel.js +21 -13
  56. package/lib/module/carousel/Carousel.js.map +1 -1
  57. package/lib/module/collapsible/Collapsible.js +17 -0
  58. package/lib/module/collapsible/Collapsible.js.map +1 -0
  59. package/lib/module/collapsible/Collapsible.web.js +17 -0
  60. package/lib/module/collapsible/Collapsible.web.js.map +1 -0
  61. package/lib/module/collapsible/CollapsibleFrame.js +92 -0
  62. package/lib/module/collapsible/CollapsibleFrame.js.map +1 -0
  63. package/lib/module/collapsible/CollapsibleFrame.web.js +111 -0
  64. package/lib/module/collapsible/CollapsibleFrame.web.js.map +1 -0
  65. package/lib/module/collapsible/context.js +11 -0
  66. package/lib/module/collapsible/context.js.map +1 -0
  67. package/lib/module/collapsible/frame-types.js +4 -0
  68. package/lib/module/collapsible/frame-types.js.map +1 -0
  69. package/lib/module/collapsible/index.js +4 -0
  70. package/lib/module/collapsible/index.js.map +1 -0
  71. package/lib/module/collapsible/index.web.js +9 -0
  72. package/lib/module/collapsible/index.web.js.map +1 -0
  73. package/lib/module/collapsible/types.js +4 -0
  74. package/lib/module/collapsible/types.js.map +1 -0
  75. package/lib/module/collapsible/use-collapsible-motion.js +55 -0
  76. package/lib/module/collapsible/use-collapsible-motion.js.map +1 -0
  77. package/lib/module/index.js +1 -0
  78. package/lib/module/index.js.map +1 -1
  79. package/lib/module/index.web.js +1 -0
  80. package/lib/module/index.web.js.map +1 -1
  81. package/lib/module/radio/Radio.js +54 -26
  82. package/lib/module/radio/Radio.js.map +1 -1
  83. package/lib/module/radio/RadioCard.js +8 -1
  84. package/lib/module/radio/RadioCard.js.map +1 -1
  85. package/lib/module/radio/use-radio-group-item.js +3 -1
  86. package/lib/module/radio/use-radio-group-item.js.map +1 -1
  87. package/lib/module/select/Select.js +7 -2
  88. package/lib/module/select/Select.js.map +1 -1
  89. package/lib/module/select/Select.web.js +11 -3
  90. package/lib/module/select/Select.web.js.map +1 -1
  91. package/lib/typescript/commonjs/accordion/Accordion.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/accordion/Accordion.web.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/accordion/use-accordion.d.ts +2 -3
  94. package/lib/typescript/commonjs/accordion/use-accordion.d.ts.map +1 -1
  95. package/lib/typescript/commonjs/carousel/Carousel.d.ts +1 -1
  96. package/lib/typescript/commonjs/carousel/Carousel.d.ts.map +1 -1
  97. package/lib/typescript/commonjs/carousel/types.d.ts +7 -0
  98. package/lib/typescript/commonjs/carousel/types.d.ts.map +1 -1
  99. package/lib/typescript/commonjs/collapsible/Collapsible.d.ts +4 -0
  100. package/lib/typescript/commonjs/collapsible/Collapsible.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/collapsible/Collapsible.web.d.ts +4 -0
  102. package/lib/typescript/commonjs/collapsible/Collapsible.web.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts +7 -0
  104. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.web.d.ts +3 -0
  106. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.web.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/collapsible/context.d.ts +4 -0
  108. package/lib/typescript/commonjs/collapsible/context.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/collapsible/frame-types.d.ts +11 -0
  110. package/lib/typescript/commonjs/collapsible/frame-types.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/collapsible/index.d.ts +3 -0
  112. package/lib/typescript/commonjs/collapsible/index.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/collapsible/index.web.d.ts +3 -0
  114. package/lib/typescript/commonjs/collapsible/index.web.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/collapsible/types.d.ts +24 -0
  116. package/lib/typescript/commonjs/collapsible/types.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/collapsible/use-collapsible-motion.d.ts +9 -0
  118. package/lib/typescript/commonjs/collapsible/use-collapsible-motion.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/index.d.ts +1 -0
  120. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  121. package/lib/typescript/commonjs/index.web.d.ts +1 -0
  122. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  123. package/lib/typescript/commonjs/radio/Radio.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/radio/RadioCard.d.ts +1 -1
  125. package/lib/typescript/commonjs/radio/RadioCard.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/radio/index.d.ts +1 -1
  127. package/lib/typescript/commonjs/radio/index.d.ts.map +1 -1
  128. package/lib/typescript/commonjs/radio/types.d.ts +16 -2
  129. package/lib/typescript/commonjs/radio/types.d.ts.map +1 -1
  130. package/lib/typescript/commonjs/radio/use-radio-group-item.d.ts +17 -1
  131. package/lib/typescript/commonjs/radio/use-radio-group-item.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/select/Select.d.ts.map +1 -1
  133. package/lib/typescript/commonjs/select/Select.web.d.ts.map +1 -1
  134. package/lib/typescript/module/accordion/Accordion.d.ts.map +1 -1
  135. package/lib/typescript/module/accordion/Accordion.web.d.ts.map +1 -1
  136. package/lib/typescript/module/accordion/use-accordion.d.ts +2 -3
  137. package/lib/typescript/module/accordion/use-accordion.d.ts.map +1 -1
  138. package/lib/typescript/module/carousel/Carousel.d.ts +1 -1
  139. package/lib/typescript/module/carousel/Carousel.d.ts.map +1 -1
  140. package/lib/typescript/module/carousel/types.d.ts +7 -0
  141. package/lib/typescript/module/carousel/types.d.ts.map +1 -1
  142. package/lib/typescript/module/collapsible/Collapsible.d.ts +4 -0
  143. package/lib/typescript/module/collapsible/Collapsible.d.ts.map +1 -0
  144. package/lib/typescript/module/collapsible/Collapsible.web.d.ts +4 -0
  145. package/lib/typescript/module/collapsible/Collapsible.web.d.ts.map +1 -0
  146. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts +7 -0
  147. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts.map +1 -0
  148. package/lib/typescript/module/collapsible/CollapsibleFrame.web.d.ts +3 -0
  149. package/lib/typescript/module/collapsible/CollapsibleFrame.web.d.ts.map +1 -0
  150. package/lib/typescript/module/collapsible/context.d.ts +4 -0
  151. package/lib/typescript/module/collapsible/context.d.ts.map +1 -0
  152. package/lib/typescript/module/collapsible/frame-types.d.ts +11 -0
  153. package/lib/typescript/module/collapsible/frame-types.d.ts.map +1 -0
  154. package/lib/typescript/module/collapsible/index.d.ts +3 -0
  155. package/lib/typescript/module/collapsible/index.d.ts.map +1 -0
  156. package/lib/typescript/module/collapsible/index.web.d.ts +3 -0
  157. package/lib/typescript/module/collapsible/index.web.d.ts.map +1 -0
  158. package/lib/typescript/module/collapsible/types.d.ts +24 -0
  159. package/lib/typescript/module/collapsible/types.d.ts.map +1 -0
  160. package/lib/typescript/module/collapsible/use-collapsible-motion.d.ts +9 -0
  161. package/lib/typescript/module/collapsible/use-collapsible-motion.d.ts.map +1 -0
  162. package/lib/typescript/module/index.d.ts +1 -0
  163. package/lib/typescript/module/index.d.ts.map +1 -1
  164. package/lib/typescript/module/index.web.d.ts +1 -0
  165. package/lib/typescript/module/index.web.d.ts.map +1 -1
  166. package/lib/typescript/module/radio/Radio.d.ts.map +1 -1
  167. package/lib/typescript/module/radio/RadioCard.d.ts +1 -1
  168. package/lib/typescript/module/radio/RadioCard.d.ts.map +1 -1
  169. package/lib/typescript/module/radio/index.d.ts +1 -1
  170. package/lib/typescript/module/radio/index.d.ts.map +1 -1
  171. package/lib/typescript/module/radio/types.d.ts +16 -2
  172. package/lib/typescript/module/radio/types.d.ts.map +1 -1
  173. package/lib/typescript/module/radio/use-radio-group-item.d.ts +17 -1
  174. package/lib/typescript/module/radio/use-radio-group-item.d.ts.map +1 -1
  175. package/lib/typescript/module/select/Select.d.ts.map +1 -1
  176. package/lib/typescript/module/select/Select.web.d.ts.map +1 -1
  177. package/package.json +23 -1
  178. package/src/accordion/Accordion.tsx +7 -60
  179. package/src/accordion/Accordion.web.tsx +8 -32
  180. package/src/accordion/use-accordion.ts +4 -21
  181. package/src/carousel/Carousel.tsx +22 -14
  182. package/src/carousel/types.ts +7 -0
  183. package/src/collapsible/Collapsible.tsx +15 -0
  184. package/src/collapsible/Collapsible.web.tsx +15 -0
  185. package/src/collapsible/CollapsibleFrame.tsx +120 -0
  186. package/src/collapsible/CollapsibleFrame.web.tsx +131 -0
  187. package/src/collapsible/context.ts +8 -0
  188. package/src/collapsible/frame-types.ts +14 -0
  189. package/src/collapsible/index.ts +2 -0
  190. package/src/collapsible/index.web.ts +7 -0
  191. package/src/collapsible/types.ts +22 -0
  192. package/src/collapsible/use-collapsible-motion.ts +61 -0
  193. package/src/index.ts +2 -0
  194. package/src/index.web.ts +2 -0
  195. package/src/radio/Radio.tsx +31 -12
  196. package/src/radio/RadioCard.tsx +3 -2
  197. package/src/radio/index.ts +1 -1
  198. package/src/radio/types.ts +17 -2
  199. package/src/radio/use-radio-group-item.ts +2 -2
  200. package/src/select/Select.tsx +5 -2
  201. package/src/select/Select.web.tsx +7 -3
@@ -1,5 +1,7 @@
1
- import React, { forwardRef, memo, useContext, useLayoutEffect, useRef, useState } from 'react';
2
- import { Animated, type StyleProp, type ViewStyle } from 'react-native';
1
+ import { CollapsibleFrame } from '../collapsible/CollapsibleFrame.web';
2
+ import { useCollapsibleMotion } from '../collapsible/use-collapsible-motion';
3
+ import React, { memo, useContext } from 'react';
4
+ import { Animated } from 'react-native';
3
5
  import { RiArrowDownSLine } from '../icons/remix/RiArrowDownSLine';
4
6
  import { resolveNativeWebStyle } from '../styles/resolve-native-web-style';
5
7
  import { useInteractiveWebCss } from '../styles/interactive-web-css';
@@ -20,12 +22,6 @@ const CSS = `@layer base {
20
22
  }`;
21
23
  function useStyles() { useInteractiveWebCss('bloom-accordion', CSS); }
22
24
 
23
- /** RN Animated resolves numeric layout/opacity before this DOM host receives them. */
24
- const PanelHost = forwardRef<HTMLDivElement, Omit<React.HTMLAttributes<HTMLDivElement>, 'style'> & { style?: StyleProp<ViewStyle>; collapsable?: boolean }>(function PanelHost({ style, collapsable: _collapsable, ...props }, ref) {
25
- return <div {...props} ref={ref} style={resolveNativeWebStyle(style)} />;
26
- });
27
- const AnimatedPanel = Animated.createAnimatedComponent(PanelHost);
28
-
29
25
  export const Accordion = memo(function Accordion(props: AccordionProps) {
30
26
  useStyles();
31
27
  const state = useAccordionState(props);
@@ -64,28 +60,8 @@ export const AccordionTrigger = memo(function AccordionTrigger({ children, icon,
64
60
  export const AccordionContent = memo(function AccordionContent({ children, style, className, contentClassName }: AccordionContentProps) {
65
61
  useStyles();
66
62
  const { isExpanded, triggerId, contentId } = useContext(AccordionItemContext);
67
- const progress = useAccordionMotion(isExpanded, 'content', false);
68
- const body = useRef<HTMLDivElement>(null);
69
- const panel = useRef<HTMLDivElement>(null);
70
- const [height, setHeight] = useState(0);
71
- useLayoutEffect(() => {
72
- const node = body.current;
73
- if (!node) return;
74
- const measure = () => {
75
- const next = node.getBoundingClientRect().height;
76
- setHeight(previous => Math.abs(previous - next) > .5 ? next : previous);
77
- };
78
- measure();
79
- const observer = new ResizeObserver(measure); observer.observe(node);
80
- return () => observer.disconnect();
81
- }, []);
82
- useLayoutEffect(() => {
83
- if (!isExpanded && panel.current?.contains(document.activeElement)) document.getElementById(triggerId)?.focus();
84
- }, [isExpanded, triggerId]);
85
- const maxHeight = progress.interpolate({ inputRange: [0, 1], outputRange: [0, height] });
86
- return <AnimatedPanel ref={panel} id={contentId} role="region" aria-labelledby={triggerId} aria-hidden={!isExpanded} inert={!isExpanded}
87
- className={['bloom-accordion-panel', className].filter(Boolean).join(' ')}
88
- style={[{ opacity: progress, maxHeight: height === 0 && isExpanded ? undefined : maxHeight }, style]}>
89
- <div ref={body} className={['bloom-accordion-body', contentClassName].filter(Boolean).join(' ')}>{children}</div>
90
- </AnimatedPanel>;
63
+ const { transition } = useContext(AccordionContext);
64
+ const motion = useCollapsibleMotion(isExpanded, transition);
65
+ return <CollapsibleFrame open={isExpanded} {...motion} nativeID={contentId} region labelledBy={triggerId} returnFocusId={triggerId}
66
+ className={['bloom-accordion-panel',className].filter(Boolean).join(' ')} contentClassName={['bloom-accordion-body',contentClassName].filter(Boolean).join(' ')} style={style}>{children}</CollapsibleFrame>;
91
67
  });
@@ -1,7 +1,5 @@
1
- import { useCallback, useContext, useLayoutEffect, useId, useMemo, useRef } from 'react';
2
- import { Animated, Easing } from 'react-native';
3
- import { usePrefersReducedMotion } from '../hooks/use-prefers-reduced-motion';
4
- import { animation } from '../styles/tokens';
1
+ import { useCallback, useContext, useId, useMemo } from 'react';
2
+ import { useCollapsibleMotion } from '../collapsible/use-collapsible-motion';
5
3
  import { AccordionContext } from './context';
6
4
  import type { AccordionProps } from './types';
7
5
 
@@ -25,23 +23,8 @@ export function useAccordionItem(value: string, disabled: boolean) {
25
23
  return useMemo(() => ({ value, disabled, isExpanded, triggerId: `${id}-trigger`, contentId: `${id}-content` }), [value, disabled, isExpanded, id]);
26
24
  }
27
25
 
28
- /** One motion policy for both forks, including a live OS preference change. */
26
+ /** Preserve accordion's spring defaults while sharing reveal cancellation. */
29
27
  export function useAccordionMotion(expanded: boolean, kind: 'trigger' | 'content', useNativeDriver: boolean) {
30
28
  const { transition } = useContext(AccordionContext);
31
- const reduced = usePrefersReducedMotion();
32
- const progress = useRef(new Animated.Value(expanded ? 1 : 0)).current;
33
- const duration = transition === 'spring' ? undefined : transition.duration;
34
- const [x1, y1, x2, y2] = transition === 'spring' || !transition.easing ? [.25, .1, .25, 1] : transition.easing;
35
- const easing = useMemo(() => Easing.bezier(x1, y1, x2, y2), [x1, y1, x2, y2]);
36
- useLayoutEffect(() => {
37
- progress.stopAnimation();
38
- const toValue = expanded ? 1 : 0;
39
- if (reduced || duration === 0) { progress.setValue(toValue); return; }
40
- const motion = duration === undefined
41
- ? Animated.spring(progress, { toValue, useNativeDriver, ...animation.spring[kind === 'trigger' ? 'snappy' : 'gentle'] })
42
- : Animated.timing(progress, { toValue, useNativeDriver, duration: Math.max(0, duration), easing });
43
- motion.start();
44
- return () => motion.stop();
45
- }, [expanded, progress, reduced, duration, easing, kind, useNativeDriver]);
46
- return progress;
29
+ return useCollapsibleMotion(expanded, transition, kind, useNativeDriver).progress;
47
30
  }
@@ -311,9 +311,10 @@ interface Stop {
311
311
  * except the end, which stands for the LAST — the far end is where the last
312
312
  * slide is, and naming anything else would leave it unreachable.
313
313
  */
314
- function toStops(resting: readonly number[]): Stop[] {
314
+ function toStops(resting: readonly number[], groupSize = 1): Stop[] {
315
315
  const stops: Stop[] = [];
316
316
  resting.forEach((offset, slide) => {
317
+ if (slide % groupSize !== 0 && slide !== resting.length - 1) return;
317
318
  const last = stops[stops.length - 1];
318
319
  if (last && Math.abs(offset - last.offset) <= 1) return;
319
320
  stops.push({ offset, slide });
@@ -329,6 +330,7 @@ const CarouselComponent = function Carousel({
329
330
  header,
330
331
  footer,
331
332
  loop = false,
333
+ slidesPerGroup = 1,
332
334
  showArrows = true,
333
335
  arrowsPlacement = 'header',
334
336
  arrowsInset = 8,
@@ -347,6 +349,8 @@ const CarouselComponent = function Carousel({
347
349
  style,
348
350
  testID,
349
351
  }: CarouselProps) {
352
+ const groupSize = Number.isFinite(slidesPerGroup) ? Math.max(1, Math.trunc(slidesPerGroup)) : 1;
353
+ const ownsTrackKeys = loop || groupSize > 1;
350
354
  const { messages } = useMessages(CAROUSEL_MESSAGES);
351
355
  const previousLabel = previousLabelProp ?? messages.previousSlide;
352
356
  const nextLabel = nextLabelProp ?? messages.nextSlide;
@@ -422,14 +426,14 @@ const CarouselComponent = function Carousel({
422
426
 
423
427
  /**
424
428
  * The distinct places the track can rest — or `null` until every slide has
425
- * been measured. Arrows, dots, snapping and the active slide all read this
426
- * ONE list, so they cannot disagree about where the track can go.
429
+ * been measured. Dots, snapping and the active slide use individual stops;
430
+ * grouped controls filter the same measured offsets before deduplicating.
427
431
  */
428
- const computeStops = useCallback((): Stop[] | null => {
432
+ const computeStops = useCallback((navigationGroupSize = 1): Stop[] | null => {
429
433
  if (trackWidth <= 0 || scroll.current.contentWidth <= 0) return null;
430
434
  const all = slideKeys.map(key => offsets.current.get(key));
431
435
  if (all.some(item => !item || item.width <= 0)) return null;
432
- return toStops((all as SlideOffset[]).map(targetFor));
436
+ return toStops((all as SlideOffset[]).map(targetFor), navigationGroupSize);
433
437
  }, [slideKeys, targetFor, trackWidth]);
434
438
 
435
439
  const measure = useCallback(() => {
@@ -564,9 +568,9 @@ const CarouselComponent = function Carousel({
564
568
  window.addEventListener('pointerup', endDrag);
565
569
  window.addEventListener('pointercancel', endDrag);
566
570
  const onKeyDown = (event: KeyboardEvent) => {
567
- // Owned loop navigation must retain its pending destination so rapid
571
+ // Owned grouped/loop navigation must retain its pending destination so rapid
568
572
  // key presses advance from the requested stop, not an animation frame.
569
- if (loop && event.target === node && !event.altKey && !event.ctrlKey && !event.metaKey
573
+ if (ownsTrackKeys && event.target === node && !event.altKey && !event.ctrlKey && !event.metaKey
570
574
  && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) return;
571
575
  interruptControlledScroll();
572
576
  };
@@ -579,7 +583,7 @@ const CarouselComponent = function Carousel({
579
583
  node.removeEventListener('wheel', interruptControlledScroll);
580
584
  node.removeEventListener('keydown', onKeyDown);
581
585
  };
582
- }, [controlledIndex !== undefined, interruptControlledScroll, beginDrag, endDrag, loop]);
586
+ }, [controlledIndex !== undefined, interruptControlledScroll, beginDrag, endDrag, ownsTrackKeys]);
583
587
 
584
588
  const scrollToStop = (stop: Stop | undefined) => {
585
589
  if (!stop) return;
@@ -593,13 +597,17 @@ const CarouselComponent = function Carousel({
593
597
 
594
598
  /**
595
599
  * The arrows step from where the track IS, to the nearest stop before or after
596
- * it (1px of slack, as in `measure`) — never by slide index, which near the
597
- * end names a slide whose stop the track already rests at.
600
+ * it (1px of slack, as in `measure`). Group destinations use every Nth child
601
+ * plus the physical end; individual snap stops and dot destinations remain
602
+ * unchanged. After a swipe/dot between groups, choose the adjacent boundary.
598
603
  */
599
604
  const step = (direction: -1 | 1) => {
600
- const all = computeStops();
605
+ const all = computeStops(groupSize);
601
606
  if (!all) return;
602
- const x = pendingTarget.current ?? scroll.current.x;
607
+ // An accepted controlled destination stays authoritative after its animation
608
+ // settles: browser snapping may round its physical position by a pixel.
609
+ // Real drag/wheel input clears appliedOffset and resumes physical navigation.
610
+ const x = pendingTarget.current ?? appliedOffset.current ?? scroll.current.x;
603
611
  const target = direction === 1
604
612
  ? all.find((stop) => stop.offset > x + 1)
605
613
  : [...all].reverse().find((stop) => stop.offset < x - 1);
@@ -696,10 +704,10 @@ const CarouselComponent = function Carousel({
696
704
  <ScrollView
697
705
  ref={scrollRef}
698
706
  {...webDataSet({ bloomCarouselTrack: align })}
699
- // The browser scrolls a focused track by default; wrapping opts into
707
+ // The browser scrolls a focused track by default; groups/wrapping opt into
700
708
  // stop-based Left/Right navigation without intercepting slide controls.
701
709
  {...(IS_WEB ? { tabIndex: 0, onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => {
702
- if (!loop || event.target !== event.currentTarget || event.altKey || event.ctrlKey || event.metaKey) return;
710
+ if (!ownsTrackKeys || event.target !== event.currentTarget || event.altKey || event.ctrlKey || event.metaKey) return;
703
711
  if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
704
712
  event.preventDefault(); event.stopPropagation();
705
713
  step((event.key === 'ArrowRight') !== rtl ? 1 : -1);
@@ -24,6 +24,13 @@ export interface CarouselProps {
24
24
  footer?: ReactNode;
25
25
  /** Controls and track arrow keys wrap to the other end; no cloned slides. Default false. */
26
26
  loop?: boolean;
27
+ /**
28
+ * Arrow/track-key destinations are anchored at children 0, N, 2N, plus the
29
+ * reachable end. Dots, direct index selection and swipe keep individual stops.
30
+ * Default 1. Finite values truncate to integers and clamp to at least 1;
31
+ * non-finite values use 1. May change responsively without moving selection.
32
+ */
33
+ slidesPerGroup?: number;
27
34
  /** Previous / next buttons. Defaults to `true`; callers may hide them at their mobile breakpoint. */
28
35
  showArrows?: boolean;
29
36
  /** Overlay control offsets from logical track edges. Negative values extend outside. Default 8. */
@@ -0,0 +1,15 @@
1
+ import React, { memo } from 'react';
2
+ import { CollapsibleFrame } from './CollapsibleFrame';
3
+ import {
4
+ DEFAULT_COLLAPSIBLE_TRANSITION,
5
+ useCollapsibleMotion,
6
+ } from './use-collapsible-motion';
7
+ import type { CollapsibleProps } from './types';
8
+
9
+ export const Collapsible = memo(function Collapsible({
10
+ transition = DEFAULT_COLLAPSIBLE_TRANSITION,
11
+ ...props
12
+ }: CollapsibleProps) {
13
+ const motion = useCollapsibleMotion(props.open, transition);
14
+ return <CollapsibleFrame {...props} {...motion} />;
15
+ });
@@ -0,0 +1,15 @@
1
+ import React, { memo } from 'react';
2
+ import { CollapsibleFrame } from './CollapsibleFrame.web';
3
+ import {
4
+ DEFAULT_COLLAPSIBLE_TRANSITION,
5
+ useCollapsibleMotion,
6
+ } from './use-collapsible-motion';
7
+ import type { CollapsibleProps } from './types';
8
+
9
+ export const Collapsible = memo(function Collapsible({
10
+ transition = DEFAULT_COLLAPSIBLE_TRANSITION,
11
+ ...props
12
+ }: CollapsibleProps) {
13
+ const motion = useCollapsibleMotion(props.open, transition);
14
+ return <CollapsibleFrame {...props} {...motion} />;
15
+ });
@@ -0,0 +1,120 @@
1
+ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
2
+ import {
3
+ AccessibilityInfo,
4
+ Animated,
5
+ findNodeHandle,
6
+ TextInput,
7
+ View,
8
+ type LayoutChangeEvent,
9
+ } from 'react-native';
10
+ import { styled } from 'react-native-css';
11
+ import {
12
+ CollapsibleVisibilityContext,
13
+ useCollapsibleVisibility,
14
+ } from './context';
15
+ import type { CollapsibleFrameProps } from './frame-types';
16
+
17
+ function CollapsibleFrameComponent({
18
+ open,
19
+ hidden,
20
+ progress,
21
+ children,
22
+ style,
23
+ contentStyle,
24
+ returnFocusRef,
25
+ nativeID,
26
+ testID,
27
+ labelledBy,
28
+ returnFocusId,
29
+ }: CollapsibleFrameProps) {
30
+ const visible = useCollapsibleVisibility() && open;
31
+ const panel = useRef<View>(null);
32
+ const initiallyOpen = useRef(open).current;
33
+ const focusWithin = useRef(false);
34
+ const [height, setHeight] = useState(0);
35
+ const measure = useCallback((event: LayoutChangeEvent) => {
36
+ const next = event.nativeEvent.layout.height;
37
+ if (next > 0) setHeight((old) => (Math.abs(old - next) > 0.5 ? next : old));
38
+ }, []);
39
+ const restore = useCallback(() => {
40
+ const input = TextInput.State?.currentlyFocusedInput?.();
41
+ // Native host nodes expose contains without importing a private renderer.
42
+ const root = panel.current;
43
+ const inputInside = Boolean(
44
+ root &&
45
+ input &&
46
+ 'contains' in root &&
47
+ typeof root.contains === 'function' &&
48
+ root.contains(input),
49
+ );
50
+ if (!focusWithin.current && !inputInside) return;
51
+ focusWithin.current = false;
52
+ if (inputInside) input?.blur();
53
+ const target =
54
+ returnFocusRef?.current ??
55
+ (returnFocusId && root && 'ownerDocument' in root
56
+ ? root.ownerDocument?.getElementById(returnFocusId)
57
+ : null);
58
+ if (target && 'focus' in target && typeof target.focus === 'function') {
59
+ target.focus();
60
+ const handle =
61
+ 'measureInWindow' in target
62
+ ? findNodeHandle(target as unknown as React.Component)
63
+ : null;
64
+ if (handle != null) AccessibilityInfo.setAccessibilityFocus(handle);
65
+ }
66
+ }, [returnFocusRef, returnFocusId]);
67
+ useLayoutEffect(() => {
68
+ if (!visible) restore();
69
+ }, [visible, restore]);
70
+ const maxHeight = progress.interpolate({
71
+ inputRange: [0, 1],
72
+ outputRange: [0, height],
73
+ });
74
+ return (
75
+ <CollapsibleVisibilityContext.Provider value={visible}>
76
+ <Animated.View
77
+ ref={panel}
78
+ nativeID={nativeID}
79
+ testID={testID}
80
+ {...{ 'aria-labelledby': labelledBy }}
81
+ aria-hidden={!visible}
82
+ accessibilityElementsHidden={!visible}
83
+ importantForAccessibility={visible ? 'auto' : 'no-hide-descendants'}
84
+ pointerEvents={visible ? 'auto' : 'none'}
85
+ onFocus={() => {
86
+ focusWithin.current = true;
87
+ if (!visible) restore();
88
+ }}
89
+ onBlur={() => {
90
+ focusWithin.current = false;
91
+ }}
92
+ style={[
93
+ {
94
+ overflow: 'hidden',
95
+ opacity: progress,
96
+ maxHeight:
97
+ height === 0 && open && initiallyOpen ? undefined : maxHeight,
98
+ },
99
+ style,
100
+ ]}
101
+ >
102
+ <View
103
+ collapsable={false}
104
+ onLayout={measure}
105
+ style={[
106
+ { flexShrink: 0 },
107
+ contentStyle,
108
+ hidden ? { display: 'none' } : undefined,
109
+ ]}
110
+ >
111
+ {children}
112
+ </View>
113
+ </Animated.View>
114
+ </CollapsibleVisibilityContext.Provider>
115
+ );
116
+ }
117
+ export const CollapsibleFrame = styled(CollapsibleFrameComponent, {
118
+ className: 'style',
119
+ contentClassName: 'contentStyle',
120
+ });
@@ -0,0 +1,131 @@
1
+ import React, { forwardRef, useLayoutEffect, useRef, useState } from 'react';
2
+ import { Animated, type StyleProp, type ViewStyle } from 'react-native';
3
+ import { resolveNativeWebStyle } from '../styles/resolve-native-web-style';
4
+ import { useInteractiveWebCss } from '../styles/interactive-web-css';
5
+ import {
6
+ CollapsibleVisibilityContext,
7
+ useCollapsibleVisibility,
8
+ } from './context';
9
+ import type { CollapsibleFrameProps } from './frame-types';
10
+
11
+ const CSS = `@layer base {
12
+ .bloom-collapsible-panel,.bloom-collapsible-content { box-sizing:border-box;display:flex;flex-direction:column;flex-shrink:0;min-width:0; }
13
+ .bloom-collapsible-panel { overflow:hidden; }
14
+ }`;
15
+ const PanelHost = forwardRef<
16
+ HTMLDivElement,
17
+ Omit<React.HTMLAttributes<HTMLDivElement>, 'style'> & {
18
+ style?: StyleProp<ViewStyle>;
19
+ collapsable?: boolean;
20
+ }
21
+ >(function PanelHost({ style, collapsable: _collapsable, ...props }, ref) {
22
+ return <div {...props} ref={ref} style={resolveNativeWebStyle(style)} />;
23
+ });
24
+ const AnimatedPanel = Animated.createAnimatedComponent(PanelHost);
25
+
26
+ export function CollapsibleFrame({
27
+ open,
28
+ progress,
29
+ children,
30
+ style,
31
+ className,
32
+ contentStyle,
33
+ contentClassName,
34
+ returnFocusRef,
35
+ nativeID,
36
+ testID,
37
+ labelledBy,
38
+ returnFocusId,
39
+ region,
40
+ }: CollapsibleFrameProps) {
41
+ useInteractiveWebCss('bloom-collapsible', CSS);
42
+ const visible = useCollapsibleVisibility() && open;
43
+ const panel = useRef<HTMLDivElement>(null);
44
+ const focusWithin = useRef(false);
45
+ const body = useRef<HTMLDivElement>(null);
46
+ const previousOutside = useRef<HTMLElement | null>(null);
47
+ const [height, setHeight] = useState(0);
48
+ useLayoutEffect(() => {
49
+ const node = body.current;
50
+ if (!node) return;
51
+ const measure = () => {
52
+ const next = node.getBoundingClientRect().height;
53
+ if (next > 0)
54
+ setHeight((old) => (Math.abs(old - next) > 0.5 ? next : old));
55
+ };
56
+ measure();
57
+ const observer = new ResizeObserver(measure);
58
+ observer.observe(node);
59
+ return () => observer.disconnect();
60
+ }, []);
61
+ useLayoutEffect(() => {
62
+ const active = document.activeElement;
63
+ if (visible) {
64
+ if (active instanceof HTMLElement && !panel.current?.contains(active))
65
+ previousOutside.current = active;
66
+ return;
67
+ }
68
+ if (!panel.current?.contains(active) && !focusWithin.current) return;
69
+ focusWithin.current = false;
70
+ const target =
71
+ returnFocusRef?.current ??
72
+ (returnFocusId ? document.getElementById(returnFocusId) : null) ??
73
+ previousOutside.current;
74
+ if (
75
+ target instanceof HTMLElement &&
76
+ (!target.isConnected || target.closest('[inert]'))
77
+ ) {
78
+ if (active instanceof HTMLElement) active.blur();
79
+ return;
80
+ }
81
+ target?.focus({ preventScroll: true });
82
+ if (
83
+ panel.current?.contains(document.activeElement) &&
84
+ active instanceof HTMLElement
85
+ )
86
+ active.blur();
87
+ }, [visible, returnFocusRef, returnFocusId]);
88
+ const maxHeight = progress.interpolate({
89
+ inputRange: [0, 1],
90
+ outputRange: [0, height],
91
+ });
92
+ return (
93
+ <CollapsibleVisibilityContext.Provider value={visible}>
94
+ <AnimatedPanel
95
+ ref={panel}
96
+ id={nativeID}
97
+ data-testid={testID}
98
+ role={region ? 'region' : undefined}
99
+ aria-labelledby={labelledBy}
100
+ aria-hidden={!visible}
101
+ inert={!visible}
102
+ onFocusCapture={() => {
103
+ focusWithin.current = true;
104
+ }}
105
+ onBlurCapture={() => {
106
+ focusWithin.current = false;
107
+ }}
108
+ className={['bloom-collapsible-panel', className]
109
+ .filter(Boolean)
110
+ .join(' ')}
111
+ style={[
112
+ {
113
+ opacity: progress,
114
+ maxHeight: height === 0 && open ? undefined : maxHeight,
115
+ },
116
+ style,
117
+ ]}
118
+ >
119
+ <div
120
+ ref={body}
121
+ className={['bloom-collapsible-content', contentClassName]
122
+ .filter(Boolean)
123
+ .join(' ')}
124
+ style={resolveNativeWebStyle(contentStyle)}
125
+ >
126
+ {children}
127
+ </div>
128
+ </AnimatedPanel>
129
+ </CollapsibleVisibilityContext.Provider>
130
+ );
131
+ }
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /** Logical visibility reaches portaled controls, unlike host-only inert/display. */
4
+ export const CollapsibleVisibilityContext = createContext(true);
5
+ CollapsibleVisibilityContext.displayName = 'CollapsibleVisibility';
6
+ export function useCollapsibleVisibility() {
7
+ return useContext(CollapsibleVisibilityContext);
8
+ }
@@ -0,0 +1,14 @@
1
+ import type { Animated } from 'react-native';
2
+ import type { CollapsibleProps } from './types';
3
+
4
+ export interface CollapsibleFrameProps extends Omit<
5
+ CollapsibleProps,
6
+ 'transition'
7
+ > {
8
+ progress: Animated.Value;
9
+ hidden: boolean;
10
+ /** Accordion supplies its real relationship; standalone Collapsible supplies neither. */
11
+ labelledBy?: string;
12
+ returnFocusId?: string;
13
+ region?: boolean;
14
+ }
@@ -0,0 +1,2 @@
1
+ export { Collapsible } from './Collapsible';
2
+ export type { CollapsibleProps, CollapsibleFocusTarget } from './types';
@@ -0,0 +1,7 @@
1
+ // AUTO-GENERATED by scripts/generate-platform-exports.mjs — DO NOT EDIT.
2
+ // Source of truth: src/collapsible/index.ts.
3
+ // Re-run `bun run generate:exports` (or any `bun run build`) after
4
+ // changing that barrel or the set of web-forked subpaths.
5
+
6
+ export { Collapsible } from './Collapsible.web';
7
+ export type { CollapsibleProps, CollapsibleFocusTarget } from './types';
@@ -0,0 +1,22 @@
1
+ import type { ReactNode, RefObject } from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+ import type { SurfaceTransition } from '../motion/types';
4
+
5
+ /** A DOM or native host capable of receiving focus, without a fabricated trigger. */
6
+ export interface CollapsibleFocusTarget {
7
+ focus(options?: { preventScroll?: boolean }): void;
8
+ }
9
+ export interface CollapsibleProps {
10
+ open: boolean;
11
+ children?: ReactNode;
12
+ /** Defaults to 300ms CSS ease-in-out. Live reduced motion settles immediately. */
13
+ transition?: SurfaceTransition;
14
+ /** Used only if focus was inside when closing; never steals deliberate outside focus. */
15
+ returnFocusRef?: RefObject<CollapsibleFocusTarget | null>;
16
+ className?: string;
17
+ style?: StyleProp<ViewStyle>;
18
+ contentClassName?: string;
19
+ contentStyle?: StyleProp<ViewStyle>;
20
+ nativeID?: string;
21
+ testID?: string;
22
+ }
@@ -0,0 +1,61 @@
1
+ import { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
+ import { Animated, Easing } from 'react-native';
3
+ import { usePrefersReducedMotion } from '../hooks/use-prefers-reduced-motion';
4
+ import { resolveSurfaceTransition } from '../motion/surface-transition';
5
+ import type { SurfaceTransition } from '../motion/types';
6
+ import { animation } from '../styles/tokens';
7
+
8
+ export const DEFAULT_COLLAPSIBLE_TRANSITION: SurfaceTransition = {
9
+ duration: 300,
10
+ easing: [0.42, 0, 0.58, 1],
11
+ };
12
+
13
+ /** Shared measured-reveal motion; Accordion retains its existing springs. */
14
+ export function useCollapsibleMotion(
15
+ open: boolean,
16
+ transition: SurfaceTransition | 'spring',
17
+ kind: 'trigger' | 'content' = 'content',
18
+ useNativeDriver = false,
19
+ ) {
20
+ const reduced = usePrefersReducedMotion();
21
+ const progress = useRef(new Animated.Value(open ? 1 : 0)).current;
22
+ const [hidden, setHidden] = useState(!open);
23
+ if (open && hidden) setHidden(false);
24
+ const resolved = resolveSurfaceTransition(
25
+ transition === 'spring' ? undefined : transition,
26
+ );
27
+ const duration = transition === 'spring' ? undefined : resolved.duration;
28
+ const [x1, y1, x2, y2] = resolved.easing;
29
+ const easing = useMemo(() => Easing.bezier(x1, y1, x2, y2), [x1, y1, x2, y2]);
30
+ useLayoutEffect(() => {
31
+ let cancelled = false;
32
+ progress.stopAnimation();
33
+ const toValue = open ? 1 : 0;
34
+ if (reduced || duration === 0) {
35
+ progress.setValue(toValue);
36
+ setHidden(!open);
37
+ return;
38
+ }
39
+ const motion =
40
+ duration === undefined
41
+ ? Animated.spring(progress, {
42
+ toValue,
43
+ useNativeDriver,
44
+ ...animation.spring[kind === 'trigger' ? 'snappy' : 'gentle'],
45
+ })
46
+ : Animated.timing(progress, {
47
+ toValue,
48
+ useNativeDriver,
49
+ duration,
50
+ easing,
51
+ });
52
+ motion.start((result) => {
53
+ if (!cancelled && result?.finished !== false) setHidden(!open);
54
+ });
55
+ return () => {
56
+ cancelled = true;
57
+ motion.stop();
58
+ };
59
+ }, [open, progress, reduced, duration, easing, kind, useNativeDriver]);
60
+ return { progress, hidden };
61
+ }
package/src/index.ts CHANGED
@@ -2144,3 +2144,5 @@ export * from './project-board';
2144
2144
  export * from './multi-agent-chat';
2145
2145
 
2146
2146
  export * from './viewport';
2147
+
2148
+ export * from './collapsible';
package/src/index.web.ts CHANGED
@@ -2149,3 +2149,5 @@ export * from './project-board/index.web';
2149
2149
  export * from './multi-agent-chat/index.web';
2150
2150
 
2151
2151
  export * from './viewport/index.web';
2152
+
2153
+ export * from './collapsible/index.web';