@oxy.so/bloom 7.21.0 → 7.22.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 (186) hide show
  1. package/docs/accordion.mdx +5 -0
  2. package/docs/adoption-matrix.mdx +6 -5
  3. package/docs/collapsible.mdx +72 -0
  4. package/docs/migrating-to-1.0.mdx +1 -1
  5. package/docs/radio.mdx +15 -0
  6. package/lib/commonjs/accordion/Accordion.js +18 -45
  7. package/lib/commonjs/accordion/Accordion.js.map +1 -1
  8. package/lib/commonjs/accordion/Accordion.web.js +16 -53
  9. package/lib/commonjs/accordion/Accordion.web.js.map +1 -1
  10. package/lib/commonjs/accordion/use-accordion.js +3 -30
  11. package/lib/commonjs/accordion/use-accordion.js.map +1 -1
  12. package/lib/commonjs/collapsible/Collapsible.js +22 -0
  13. package/lib/commonjs/collapsible/Collapsible.js.map +1 -0
  14. package/lib/commonjs/collapsible/Collapsible.web.js +22 -0
  15. package/lib/commonjs/collapsible/Collapsible.web.js.map +1 -0
  16. package/lib/commonjs/collapsible/CollapsibleFrame.js +97 -0
  17. package/lib/commonjs/collapsible/CollapsibleFrame.js.map +1 -0
  18. package/lib/commonjs/collapsible/CollapsibleFrame.web.js +116 -0
  19. package/lib/commonjs/collapsible/CollapsibleFrame.web.js.map +1 -0
  20. package/lib/commonjs/collapsible/context.js +15 -0
  21. package/lib/commonjs/collapsible/context.js.map +1 -0
  22. package/lib/commonjs/collapsible/frame-types.js +6 -0
  23. package/lib/commonjs/collapsible/frame-types.js.map +1 -0
  24. package/lib/commonjs/collapsible/index.js +13 -0
  25. package/lib/commonjs/collapsible/index.js.map +1 -0
  26. package/lib/commonjs/collapsible/index.web.js +13 -0
  27. package/lib/commonjs/collapsible/index.web.js.map +1 -0
  28. package/lib/commonjs/collapsible/types.js +6 -0
  29. package/lib/commonjs/collapsible/types.js.map +1 -0
  30. package/lib/commonjs/collapsible/use-collapsible-motion.js +60 -0
  31. package/lib/commonjs/collapsible/use-collapsible-motion.js.map +1 -0
  32. package/lib/commonjs/index.js +12 -0
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/index.web.js +12 -0
  35. package/lib/commonjs/index.web.js.map +1 -1
  36. package/lib/commonjs/radio/Radio.js +54 -26
  37. package/lib/commonjs/radio/Radio.js.map +1 -1
  38. package/lib/commonjs/radio/RadioCard.js +8 -1
  39. package/lib/commonjs/radio/RadioCard.js.map +1 -1
  40. package/lib/commonjs/radio/use-radio-group-item.js +3 -1
  41. package/lib/commonjs/radio/use-radio-group-item.js.map +1 -1
  42. package/lib/commonjs/select/Select.js +10 -5
  43. package/lib/commonjs/select/Select.js.map +1 -1
  44. package/lib/commonjs/select/Select.web.js +11 -3
  45. package/lib/commonjs/select/Select.web.js.map +1 -1
  46. package/lib/module/accordion/Accordion.js +19 -46
  47. package/lib/module/accordion/Accordion.js.map +1 -1
  48. package/lib/module/accordion/Accordion.web.js +17 -54
  49. package/lib/module/accordion/Accordion.web.js.map +1 -1
  50. package/lib/module/accordion/use-accordion.js +4 -31
  51. package/lib/module/accordion/use-accordion.js.map +1 -1
  52. package/lib/module/collapsible/Collapsible.js +17 -0
  53. package/lib/module/collapsible/Collapsible.js.map +1 -0
  54. package/lib/module/collapsible/Collapsible.web.js +17 -0
  55. package/lib/module/collapsible/Collapsible.web.js.map +1 -0
  56. package/lib/module/collapsible/CollapsibleFrame.js +92 -0
  57. package/lib/module/collapsible/CollapsibleFrame.js.map +1 -0
  58. package/lib/module/collapsible/CollapsibleFrame.web.js +111 -0
  59. package/lib/module/collapsible/CollapsibleFrame.web.js.map +1 -0
  60. package/lib/module/collapsible/context.js +11 -0
  61. package/lib/module/collapsible/context.js.map +1 -0
  62. package/lib/module/collapsible/frame-types.js +4 -0
  63. package/lib/module/collapsible/frame-types.js.map +1 -0
  64. package/lib/module/collapsible/index.js +4 -0
  65. package/lib/module/collapsible/index.js.map +1 -0
  66. package/lib/module/collapsible/index.web.js +9 -0
  67. package/lib/module/collapsible/index.web.js.map +1 -0
  68. package/lib/module/collapsible/types.js +4 -0
  69. package/lib/module/collapsible/types.js.map +1 -0
  70. package/lib/module/collapsible/use-collapsible-motion.js +55 -0
  71. package/lib/module/collapsible/use-collapsible-motion.js.map +1 -0
  72. package/lib/module/index.js +1 -0
  73. package/lib/module/index.js.map +1 -1
  74. package/lib/module/index.web.js +1 -0
  75. package/lib/module/index.web.js.map +1 -1
  76. package/lib/module/radio/Radio.js +54 -26
  77. package/lib/module/radio/Radio.js.map +1 -1
  78. package/lib/module/radio/RadioCard.js +8 -1
  79. package/lib/module/radio/RadioCard.js.map +1 -1
  80. package/lib/module/radio/use-radio-group-item.js +3 -1
  81. package/lib/module/radio/use-radio-group-item.js.map +1 -1
  82. package/lib/module/select/Select.js +7 -2
  83. package/lib/module/select/Select.js.map +1 -1
  84. package/lib/module/select/Select.web.js +11 -3
  85. package/lib/module/select/Select.web.js.map +1 -1
  86. package/lib/typescript/commonjs/accordion/Accordion.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/accordion/Accordion.web.d.ts.map +1 -1
  88. package/lib/typescript/commonjs/accordion/use-accordion.d.ts +2 -3
  89. package/lib/typescript/commonjs/accordion/use-accordion.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/collapsible/Collapsible.d.ts +4 -0
  91. package/lib/typescript/commonjs/collapsible/Collapsible.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/collapsible/Collapsible.web.d.ts +4 -0
  93. package/lib/typescript/commonjs/collapsible/Collapsible.web.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts +7 -0
  95. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.web.d.ts +3 -0
  97. package/lib/typescript/commonjs/collapsible/CollapsibleFrame.web.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/collapsible/context.d.ts +4 -0
  99. package/lib/typescript/commonjs/collapsible/context.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/collapsible/frame-types.d.ts +11 -0
  101. package/lib/typescript/commonjs/collapsible/frame-types.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/collapsible/index.d.ts +3 -0
  103. package/lib/typescript/commonjs/collapsible/index.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/collapsible/index.web.d.ts +3 -0
  105. package/lib/typescript/commonjs/collapsible/index.web.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/collapsible/types.d.ts +24 -0
  107. package/lib/typescript/commonjs/collapsible/types.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/collapsible/use-collapsible-motion.d.ts +9 -0
  109. package/lib/typescript/commonjs/collapsible/use-collapsible-motion.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/index.d.ts +1 -0
  111. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  112. package/lib/typescript/commonjs/index.web.d.ts +1 -0
  113. package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/radio/Radio.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/radio/RadioCard.d.ts +1 -1
  116. package/lib/typescript/commonjs/radio/RadioCard.d.ts.map +1 -1
  117. package/lib/typescript/commonjs/radio/index.d.ts +1 -1
  118. package/lib/typescript/commonjs/radio/index.d.ts.map +1 -1
  119. package/lib/typescript/commonjs/radio/types.d.ts +16 -2
  120. package/lib/typescript/commonjs/radio/types.d.ts.map +1 -1
  121. package/lib/typescript/commonjs/radio/use-radio-group-item.d.ts +17 -1
  122. package/lib/typescript/commonjs/radio/use-radio-group-item.d.ts.map +1 -1
  123. package/lib/typescript/commonjs/select/Select.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/select/Select.web.d.ts.map +1 -1
  125. package/lib/typescript/module/accordion/Accordion.d.ts.map +1 -1
  126. package/lib/typescript/module/accordion/Accordion.web.d.ts.map +1 -1
  127. package/lib/typescript/module/accordion/use-accordion.d.ts +2 -3
  128. package/lib/typescript/module/accordion/use-accordion.d.ts.map +1 -1
  129. package/lib/typescript/module/collapsible/Collapsible.d.ts +4 -0
  130. package/lib/typescript/module/collapsible/Collapsible.d.ts.map +1 -0
  131. package/lib/typescript/module/collapsible/Collapsible.web.d.ts +4 -0
  132. package/lib/typescript/module/collapsible/Collapsible.web.d.ts.map +1 -0
  133. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts +7 -0
  134. package/lib/typescript/module/collapsible/CollapsibleFrame.d.ts.map +1 -0
  135. package/lib/typescript/module/collapsible/CollapsibleFrame.web.d.ts +3 -0
  136. package/lib/typescript/module/collapsible/CollapsibleFrame.web.d.ts.map +1 -0
  137. package/lib/typescript/module/collapsible/context.d.ts +4 -0
  138. package/lib/typescript/module/collapsible/context.d.ts.map +1 -0
  139. package/lib/typescript/module/collapsible/frame-types.d.ts +11 -0
  140. package/lib/typescript/module/collapsible/frame-types.d.ts.map +1 -0
  141. package/lib/typescript/module/collapsible/index.d.ts +3 -0
  142. package/lib/typescript/module/collapsible/index.d.ts.map +1 -0
  143. package/lib/typescript/module/collapsible/index.web.d.ts +3 -0
  144. package/lib/typescript/module/collapsible/index.web.d.ts.map +1 -0
  145. package/lib/typescript/module/collapsible/types.d.ts +24 -0
  146. package/lib/typescript/module/collapsible/types.d.ts.map +1 -0
  147. package/lib/typescript/module/collapsible/use-collapsible-motion.d.ts +9 -0
  148. package/lib/typescript/module/collapsible/use-collapsible-motion.d.ts.map +1 -0
  149. package/lib/typescript/module/index.d.ts +1 -0
  150. package/lib/typescript/module/index.d.ts.map +1 -1
  151. package/lib/typescript/module/index.web.d.ts +1 -0
  152. package/lib/typescript/module/index.web.d.ts.map +1 -1
  153. package/lib/typescript/module/radio/Radio.d.ts.map +1 -1
  154. package/lib/typescript/module/radio/RadioCard.d.ts +1 -1
  155. package/lib/typescript/module/radio/RadioCard.d.ts.map +1 -1
  156. package/lib/typescript/module/radio/index.d.ts +1 -1
  157. package/lib/typescript/module/radio/index.d.ts.map +1 -1
  158. package/lib/typescript/module/radio/types.d.ts +16 -2
  159. package/lib/typescript/module/radio/types.d.ts.map +1 -1
  160. package/lib/typescript/module/radio/use-radio-group-item.d.ts +17 -1
  161. package/lib/typescript/module/radio/use-radio-group-item.d.ts.map +1 -1
  162. package/lib/typescript/module/select/Select.d.ts.map +1 -1
  163. package/lib/typescript/module/select/Select.web.d.ts.map +1 -1
  164. package/package.json +23 -1
  165. package/src/accordion/Accordion.tsx +7 -60
  166. package/src/accordion/Accordion.web.tsx +8 -32
  167. package/src/accordion/use-accordion.ts +4 -21
  168. package/src/collapsible/Collapsible.tsx +15 -0
  169. package/src/collapsible/Collapsible.web.tsx +15 -0
  170. package/src/collapsible/CollapsibleFrame.tsx +120 -0
  171. package/src/collapsible/CollapsibleFrame.web.tsx +131 -0
  172. package/src/collapsible/context.ts +8 -0
  173. package/src/collapsible/frame-types.ts +14 -0
  174. package/src/collapsible/index.ts +2 -0
  175. package/src/collapsible/index.web.ts +7 -0
  176. package/src/collapsible/types.ts +22 -0
  177. package/src/collapsible/use-collapsible-motion.ts +61 -0
  178. package/src/index.ts +2 -0
  179. package/src/index.web.ts +2 -0
  180. package/src/radio/Radio.tsx +31 -12
  181. package/src/radio/RadioCard.tsx +3 -2
  182. package/src/radio/index.ts +1 -1
  183. package/src/radio/types.ts +17 -2
  184. package/src/radio/use-radio-group-item.ts +2 -2
  185. package/src/select/Select.tsx +5 -2
  186. package/src/select/Select.web.tsx +7 -3
@@ -1,15 +1,15 @@
1
+ import { CollapsibleFrame } from '../collapsible/CollapsibleFrame';
2
+ import { useCollapsibleMotion } from '../collapsible/use-collapsible-motion';
1
3
  import React, {
2
4
  memo,
3
5
  useCallback,
4
6
  useContext,
5
- useState,
6
7
  } from 'react';
7
8
  import {
8
9
  View,
9
10
  Text,
10
11
  Pressable,
11
12
  Animated,
12
- type LayoutChangeEvent,
13
13
  StyleSheet,
14
14
  type TextStyle,
15
15
  } from 'react-native';
@@ -176,65 +176,12 @@ const AccordionTriggerComponent: React.FC<AccordionTriggerProps> = ({
176
176
 
177
177
  // ---- Accordion Content ----
178
178
 
179
- const AccordionContentComponent: React.FC<AccordionContentProps & { contentStyle?: AccordionContentProps['style'] }> = ({
180
- children,
181
- style,
182
- contentStyle,
183
- }) => {
179
+ const AccordionContentComponent: React.FC<AccordionContentProps & { contentStyle?: AccordionContentProps['style'] }> = ({children,style,contentStyle}) => {
184
180
  const { isExpanded, contentId, triggerId } = useContext(AccordionItemContext);
185
- const heightAnim = useAccordionMotion(isExpanded, 'content', false);
186
- // The content's own height, measured. The reveal used to interpolate to a
187
- // hardcoded 500 ("reasonable max"), which is not a max at all: `overflow:
188
- // hidden` above it meant anything taller was CLIPPED, silently, with no error
189
- // and no scrollbar — an accordion holding a form or a paragraph of prose just
190
- // lost its bottom. The content still lays out at its natural height inside the
191
- // clip, so `onLayout` reports the real one whether the item is open or shut.
192
- const [contentHeight, setContentHeight] = useState(0);
193
- const handleContentLayout = useCallback((event: LayoutChangeEvent) => {
194
- const next = event.nativeEvent.layout.height;
195
- // Sub-pixel churn would re-render on every frame of the spring.
196
- setContentHeight((prev) => (Math.abs(prev - next) > 0.5 ? next : prev));
197
- }, []);
198
-
199
- const opacity = heightAnim.interpolate({
200
- inputRange: [0, 1],
201
- outputRange: [0, 1],
202
- });
203
-
204
- const maxHeight = heightAnim.interpolate({
205
- inputRange: [0, 1],
206
- outputRange: [0, contentHeight],
207
- });
208
-
209
- return (
210
- <Animated.View
211
- nativeID={contentId}
212
- {...{ 'aria-labelledby': triggerId }}
213
- aria-hidden={!isExpanded}
214
- pointerEvents={isExpanded ? 'auto' : 'none'}
215
- accessibilityElementsHidden={!isExpanded}
216
- importantForAccessibility={isExpanded ? 'auto' : 'no-hide-descendants'}
217
- style={[
218
- {
219
- overflow: 'hidden',
220
- opacity,
221
- // Before the first measurement an OPEN item must not be clipped to
222
- // zero, and a SHUT one must not flash open — so the unmeasured frame
223
- // takes the answer its state already implies, and every frame after
224
- // that is driven by the real height.
225
- maxHeight: contentHeight === 0 && isExpanded ? undefined : maxHeight,
226
- },
227
- style,
228
- ]}
229
- >
230
- <View
231
- onLayout={handleContentLayout}
232
- style={[{ paddingBottom: space.md, paddingLeft: space.xs, paddingRight: space.xs }, contentStyle]}
233
- >
234
- {children}
235
- </View>
236
- </Animated.View>
237
- );
181
+ const { transition } = useContext(AccordionContext);
182
+ const motion = useCollapsibleMotion(isExpanded, transition);
183
+ return <CollapsibleFrame open={isExpanded} {...motion} nativeID={contentId} labelledBy={triggerId} returnFocusId={triggerId}
184
+ style={style} contentStyle={[{paddingBottom:space.md,paddingLeft:space.xs,paddingRight:space.xs},contentStyle]}>{children}</CollapsibleFrame>;
238
185
  };
239
186
 
240
187
  export const Accordion = memo(styled(AccordionComponent, { className: 'style' }));
@@ -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
  }
@@ -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';