@dloizides/ui-layout 1.1.0 → 1.3.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.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React = require('react');
3
+ var React8 = require('react');
4
4
  var reactNative = require('react-native');
5
5
  var uiFeedback = require('@dloizides/ui-feedback');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -8,7 +8,7 @@ var uiIcons = require('@dloizides/ui-icons');
8
8
 
9
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
10
 
11
- var React__default = /*#__PURE__*/_interopDefault(React);
11
+ var React8__default = /*#__PURE__*/_interopDefault(React8);
12
12
 
13
13
  // src/Section/Section.tsx
14
14
  var styles = reactNative.StyleSheet.create({
@@ -20,7 +20,7 @@ var styles = reactNative.StyleSheet.create({
20
20
  });
21
21
  var Section = ({ children, style }) => {
22
22
  const { theme } = uiFeedback.useUi();
23
- const containerStyle = React__default.default.useMemo(
23
+ const containerStyle = React8__default.default.useMemo(
24
24
  () => [styles.card, { borderColor: theme.colors.border, backgroundColor: theme.colors.surface }, style],
25
25
  [theme.colors.border, theme.colors.surface, style]
26
26
  );
@@ -35,7 +35,8 @@ var LAYOUT_TEST_IDS = {
35
35
  upgradePromptCta: "upgrade-prompt-cta",
36
36
  upgradePromptDismiss: "upgrade-prompt-dismiss",
37
37
  modalShell: "template-modal",
38
- modalShellClose: "cancel-button"
38
+ modalShellClose: "cancel-button",
39
+ accordion: "accordion"
39
40
  };
40
41
  var DEFAULT_BILLING_ROUTE = "/settings/billing";
41
42
  var styles2 = reactNative.StyleSheet.create({
@@ -46,7 +47,7 @@ var styles2 = reactNative.StyleSheet.create({
46
47
  });
47
48
  var Heading = ({ text, children }) => {
48
49
  const { theme } = uiFeedback.useUi();
49
- const headingStyle = React__default.default.useMemo(
50
+ const headingStyle = React8__default.default.useMemo(
50
51
  () => [styles2.heading, { color: theme.colors.text }],
51
52
  [theme.colors.text]
52
53
  );
@@ -77,8 +78,8 @@ var StatusBadge = ({
77
78
  accessibilityHint
78
79
  }) => {
79
80
  const { t } = uiFeedback.useUi();
80
- const dynamicBadge = React.useMemo(() => ({ backgroundColor }), [backgroundColor]);
81
- const dynamicText = React.useMemo(() => ({ color }), [color]);
81
+ const dynamicBadge = React8.useMemo(() => ({ backgroundColor }), [backgroundColor]);
82
+ const dynamicText = React8.useMemo(() => ({ color }), [color]);
82
83
  return /* @__PURE__ */ jsxRuntime.jsx(
83
84
  reactNative.View,
84
85
  {
@@ -200,8 +201,8 @@ function handleKeyDown(domNode, event) {
200
201
  }
201
202
  }
202
203
  function useFocusTrap(containerRef, enabled) {
203
- const previousFocusRef = React.useRef(null);
204
- React.useEffect(() => {
204
+ const previousFocusRef = React8.useRef(null);
205
+ React8.useEffect(() => {
205
206
  if (reactNative.Platform.OS !== "web" || !enabled) return;
206
207
  const domNode = containerRef.current;
207
208
  if (!domNode) return;
@@ -216,24 +217,226 @@ function useFocusTrap(containerRef, enabled) {
216
217
  };
217
218
  }, [containerRef, enabled]);
218
219
  }
219
- var BORDER_RADIUS = 8;
220
- var BORDER_WIDTH = 1;
220
+
221
+ // src/ModalDropdown/DropdownVariant.ts
222
+ var DropdownVariant = /* @__PURE__ */ ((DropdownVariant2) => {
223
+ DropdownVariant2["Menu"] = "menu";
224
+ DropdownVariant2["Modal"] = "modal";
225
+ return DropdownVariant2;
226
+ })(DropdownVariant || {});
221
227
  var OPTION_BORDER_RADIUS = 4;
222
228
  var BODY_FONT_SIZE = 14;
223
229
  var SELECTED_FONT_WEIGHT = "600";
230
+ var OPTION_PADDING_H = 16;
231
+ var OPTION_PADDING_V = 12;
232
+ var styles5 = reactNative.StyleSheet.create({
233
+ option: {
234
+ paddingHorizontal: OPTION_PADDING_H,
235
+ paddingVertical: OPTION_PADDING_V,
236
+ borderRadius: OPTION_BORDER_RADIUS
237
+ },
238
+ optionText: { fontSize: BODY_FONT_SIZE },
239
+ selectedText: { fontWeight: SELECTED_FONT_WEIGHT }
240
+ });
241
+ var OptionRow = ({
242
+ testID,
243
+ label,
244
+ isSelected,
245
+ isHighlighted = false,
246
+ onSelect
247
+ }) => {
248
+ const { theme, t } = uiFeedback.useUi();
249
+ const { colors } = theme;
250
+ const handlePress = React8.useCallback(() => {
251
+ onSelect();
252
+ }, [onSelect]);
253
+ const isActive = isSelected || isHighlighted;
254
+ const rowStyle = [styles5.option, isActive ? { backgroundColor: colors.surfaceElevated } : null];
255
+ const textStyle = [styles5.optionText, { color: colors.text }, isSelected ? styles5.selectedText : null];
256
+ return /* @__PURE__ */ jsxRuntime.jsx(
257
+ reactNative.TouchableOpacity,
258
+ {
259
+ accessible: true,
260
+ accessibilityHint: t("common.selectOptionHint"),
261
+ accessibilityLabel: label,
262
+ accessibilityRole: "button",
263
+ "aria-selected": isSelected,
264
+ style: rowStyle,
265
+ testID,
266
+ onPress: handlePress,
267
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: textStyle, children: label })
268
+ }
269
+ );
270
+ };
271
+ var clampIndex = (index, itemCount) => {
272
+ if (index < 0) return 0;
273
+ const lastIndex = itemCount - 1;
274
+ return index > lastIndex ? lastIndex : index;
275
+ };
276
+ function buildKeyHandler(params) {
277
+ const { itemCount, onHighlightChange, onSelectHighlighted, onClose } = params;
278
+ return (event) => {
279
+ switch (event.key) {
280
+ case "ArrowDown":
281
+ event.preventDefault();
282
+ onHighlightChange((prev) => clampIndex(prev + 1, itemCount));
283
+ return;
284
+ case "ArrowUp":
285
+ event.preventDefault();
286
+ onHighlightChange((prev) => clampIndex(prev - 1, itemCount));
287
+ return;
288
+ case "Home":
289
+ event.preventDefault();
290
+ onHighlightChange(() => 0);
291
+ return;
292
+ case "End":
293
+ event.preventDefault();
294
+ onHighlightChange(() => clampIndex(itemCount - 1, itemCount));
295
+ return;
296
+ case "Enter":
297
+ event.preventDefault();
298
+ onSelectHighlighted();
299
+ return;
300
+ case "Escape":
301
+ event.preventDefault();
302
+ onClose();
303
+ return;
304
+ }
305
+ };
306
+ }
307
+ function useMenuKeyboard(params) {
308
+ const { containerRef, enabled, onClose } = params;
309
+ React8.useEffect(() => {
310
+ if (reactNative.Platform.OS !== "web" || !enabled) return;
311
+ const onKeyDown = buildKeyHandler(params);
312
+ const onMouseDown = (event) => {
313
+ const node = containerRef.current;
314
+ const target = event.target instanceof Node ? event.target : null;
315
+ const clickedOutside = node !== null && (target === null || !node.contains(target));
316
+ if (clickedOutside) onClose();
317
+ };
318
+ document.addEventListener("keydown", onKeyDown);
319
+ document.addEventListener("mousedown", onMouseDown);
320
+ return () => {
321
+ document.removeEventListener("keydown", onKeyDown);
322
+ document.removeEventListener("mousedown", onMouseDown);
323
+ };
324
+ }, [containerRef, enabled, onClose, params]);
325
+ }
326
+ var BORDER_RADIUS = 8;
327
+ var BORDER_WIDTH = 1;
328
+ var MENU_PADDING = 4;
329
+ var MENU_MAX_HEIGHT = 300;
330
+ var MENU_TOP_GAP = 4;
331
+ var MENU_Z_INDEX = 1e3;
332
+ var MENU_ELEVATION = 8;
333
+ var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
334
+ var styles6 = reactNative.StyleSheet.create({
335
+ popover: {
336
+ position: "absolute",
337
+ top: "100%",
338
+ left: 0,
339
+ right: 0,
340
+ marginTop: MENU_TOP_GAP,
341
+ zIndex: MENU_Z_INDEX,
342
+ borderWidth: BORDER_WIDTH,
343
+ borderRadius: BORDER_RADIUS,
344
+ padding: MENU_PADDING,
345
+ maxHeight: MENU_MAX_HEIGHT,
346
+ boxShadow: MENU_BOX_SHADOW,
347
+ elevation: MENU_ELEVATION
348
+ }
349
+ });
350
+ var InlineMenu = ({
351
+ testID,
352
+ accessibilityLabel,
353
+ value,
354
+ options,
355
+ containerRef,
356
+ onSelect,
357
+ onClose
358
+ }) => {
359
+ const { theme } = uiFeedback.useUi();
360
+ const { colors } = theme;
361
+ const selectedIndex = React8.useMemo(
362
+ () => Math.max(0, options.findIndex((opt) => opt.value === value)),
363
+ [options, value]
364
+ );
365
+ const [highlightedIndex, setHighlightedIndex] = React8.useState(() => selectedIndex);
366
+ const selectAt = React8.useCallback(
367
+ (index) => {
368
+ const option = options[index];
369
+ if (option !== void 0) onSelect(option.value);
370
+ },
371
+ [options, onSelect]
372
+ );
373
+ const selectHighlighted = React8.useCallback(
374
+ () => {
375
+ selectAt(highlightedIndex);
376
+ },
377
+ [selectAt, highlightedIndex]
378
+ );
379
+ useMenuKeyboard({
380
+ containerRef,
381
+ enabled: true,
382
+ itemCount: options.length,
383
+ onHighlightChange: setHighlightedIndex,
384
+ onSelectHighlighted: selectHighlighted,
385
+ onClose
386
+ });
387
+ const popoverStyle = React8.useMemo(
388
+ () => [styles6.popover, { borderColor: colors.border, backgroundColor: colors.surface }],
389
+ [colors.border, colors.surface]
390
+ );
391
+ return /* @__PURE__ */ jsxRuntime.jsx(
392
+ reactNative.View,
393
+ {
394
+ accessibilityRole: "menu",
395
+ "aria-label": accessibilityLabel,
396
+ style: popoverStyle,
397
+ testID: `${testID}-menu`,
398
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
399
+ OptionRow,
400
+ {
401
+ isHighlighted: index === highlightedIndex,
402
+ isSelected: option.value === value,
403
+ label: option.label,
404
+ testID: `${testID}-option-${String(option.value)}`,
405
+ onSelect: () => onSelect(option.value)
406
+ },
407
+ String(option.value)
408
+ )) })
409
+ }
410
+ );
411
+ };
412
+ var MENU_BREAKPOINT = 768;
413
+ var WEB_PLATFORM = "web";
414
+ function resolveDropdownVariant(explicit, width, platformOS) {
415
+ if (explicit !== void 0) return explicit;
416
+ const isWideWeb = platformOS === WEB_PLATFORM && width >= MENU_BREAKPOINT;
417
+ return isWideWeb ? "menu" /* Menu */ : "modal" /* Modal */;
418
+ }
419
+ function useResolvedDropdownVariant(explicit) {
420
+ const { width } = reactNative.useWindowDimensions();
421
+ return resolveDropdownVariant(explicit, width, reactNative.Platform.OS);
422
+ }
423
+ var BORDER_RADIUS2 = 8;
424
+ var BORDER_WIDTH2 = 1;
425
+ var BODY_FONT_SIZE2 = 14;
224
426
  var MODAL_PADDING = 8;
225
427
  var MODAL_MIN_WIDTH = 200;
226
428
  var MODAL_MAX_HEIGHT = 300;
227
429
  var CONTAINER_PADDING_H = 12;
228
430
  var CONTAINER_PADDING_V = 10;
229
- var styles5 = reactNative.StyleSheet.create({
431
+ var styles7 = reactNative.StyleSheet.create({
432
+ anchor: { position: "relative" },
230
433
  container: {
231
- borderWidth: BORDER_WIDTH,
232
- borderRadius: BORDER_RADIUS,
434
+ borderWidth: BORDER_WIDTH2,
435
+ borderRadius: BORDER_RADIUS2,
233
436
  paddingHorizontal: CONTAINER_PADDING_H,
234
437
  paddingVertical: CONTAINER_PADDING_V
235
438
  },
236
- selectedText: { fontSize: BODY_FONT_SIZE },
439
+ selectedText: { fontSize: BODY_FONT_SIZE2 },
237
440
  modalOverlay: {
238
441
  flex: 1,
239
442
  justifyContent: "center",
@@ -241,18 +444,11 @@ var styles5 = reactNative.StyleSheet.create({
241
444
  backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR
242
445
  },
243
446
  modalContent: {
244
- borderRadius: BORDER_RADIUS,
447
+ borderRadius: BORDER_RADIUS2,
245
448
  padding: MODAL_PADDING,
246
449
  minWidth: MODAL_MIN_WIDTH,
247
450
  maxHeight: MODAL_MAX_HEIGHT
248
- },
249
- option: {
250
- paddingHorizontal: 16,
251
- paddingVertical: 12,
252
- borderRadius: OPTION_BORDER_RADIUS
253
- },
254
- optionText: { fontSize: BODY_FONT_SIZE },
255
- selectedOption: { fontWeight: SELECTED_FONT_WEIGHT }
451
+ }
256
452
  });
257
453
  var ModalDropdown = ({
258
454
  testID,
@@ -260,69 +456,56 @@ var ModalDropdown = ({
260
456
  accessibilityHint,
261
457
  value,
262
458
  options,
263
- onChange
459
+ onChange,
460
+ variant
264
461
  }) => {
265
462
  const { theme, t } = uiFeedback.useUi();
266
463
  const { colors } = theme;
267
- const [isOpen, setIsOpen] = React.useState(false);
268
- const dialogRef = React.useRef(null);
269
- useFocusTrap(dialogRef, isOpen);
270
- const selectedLabel = React.useMemo(() => {
464
+ const resolvedVariant = useResolvedDropdownVariant(variant);
465
+ const isMenu = resolvedVariant === "menu" /* Menu */;
466
+ const [isOpen, setIsOpen] = React8.useState(false);
467
+ const anchorRef = React8.useRef(null);
468
+ const dialogRef = React8.useRef(null);
469
+ useFocusTrap(dialogRef, isOpen && !isMenu);
470
+ const selectedLabel = React8.useMemo(() => {
271
471
  const found = options.find((opt) => opt.value === value);
272
472
  return found?.label ?? t("common.selectPlaceholder");
273
473
  }, [options, value, t]);
274
- const handleOpen = React.useCallback(() => {
275
- setIsOpen(true);
474
+ const handleToggle = React8.useCallback(() => {
475
+ setIsOpen((prev) => !prev);
276
476
  }, []);
277
- const handleClose = React.useCallback(() => {
477
+ const handleClose = React8.useCallback(() => {
278
478
  setIsOpen(false);
279
479
  }, []);
280
- const handleSelect = React.useCallback(
480
+ const handleSelect = React8.useCallback(
281
481
  (optionValue) => {
282
482
  onChange(optionValue);
283
483
  setIsOpen(false);
284
484
  },
285
485
  [onChange]
286
486
  );
287
- const containerStyle = React.useMemo(
288
- () => [styles5.container, { borderColor: colors.border, backgroundColor: colors.surface }],
487
+ const containerStyle = React8.useMemo(
488
+ () => [styles7.container, { borderColor: colors.border, backgroundColor: colors.surface }],
289
489
  [colors.border, colors.surface]
290
490
  );
291
- const modalContentStyle = React.useMemo(
292
- () => [styles5.modalContent, { backgroundColor: colors.surface }],
491
+ const modalContentStyle = React8.useMemo(
492
+ () => [styles7.modalContent, { backgroundColor: colors.surface }],
293
493
  [colors.surface]
294
494
  );
295
- const renderOption = React.useCallback(
296
- ({ item }) => {
297
- const isSelected = item.value === value;
298
- return /* @__PURE__ */ jsxRuntime.jsx(
299
- reactNative.TouchableOpacity,
300
- {
301
- accessible: true,
302
- accessibilityHint: t("common.selectOptionHint"),
303
- accessibilityLabel: item.label,
304
- accessibilityRole: "button",
305
- style: [styles5.option, isSelected ? { backgroundColor: colors.surfaceElevated } : null],
306
- testID: `${testID}-option-${String(item.value)}`,
307
- onPress: () => handleSelect(item.value),
308
- children: /* @__PURE__ */ jsxRuntime.jsx(
309
- reactNative.Text,
310
- {
311
- style: [
312
- styles5.optionText,
313
- { color: colors.text },
314
- isSelected ? styles5.selectedOption : null
315
- ],
316
- children: item.label
317
- }
318
- )
319
- }
320
- );
321
- },
322
- [colors.surfaceElevated, colors.text, handleSelect, testID, value, t]
495
+ const renderModalOption = React8.useCallback(
496
+ ({ item }) => /* @__PURE__ */ jsxRuntime.jsx(
497
+ OptionRow,
498
+ {
499
+ isSelected: item.value === value,
500
+ label: item.label,
501
+ testID: `${testID}-option-${String(item.value)}`,
502
+ onSelect: () => handleSelect(item.value)
503
+ }
504
+ ),
505
+ [handleSelect, testID, value]
323
506
  );
324
- const keyExtractor = React.useCallback((item) => String(item.value), []);
325
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
507
+ const keyExtractor = React8.useCallback((item) => String(item.value), []);
508
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: styles7.anchor, children: [
326
509
  /* @__PURE__ */ jsxRuntime.jsx(
327
510
  reactNative.TouchableOpacity,
328
511
  {
@@ -330,13 +513,26 @@ var ModalDropdown = ({
330
513
  accessibilityHint,
331
514
  accessibilityLabel,
332
515
  accessibilityRole: "button",
516
+ "aria-expanded": isOpen,
333
517
  style: containerStyle,
334
518
  testID,
335
- onPress: handleOpen,
336
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles5.selectedText, { color: colors.text }], children: selectedLabel })
519
+ onPress: handleToggle,
520
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel })
337
521
  }
338
522
  ),
339
- /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
523
+ isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
524
+ InlineMenu,
525
+ {
526
+ accessibilityLabel,
527
+ containerRef: anchorRef,
528
+ options,
529
+ testID,
530
+ value,
531
+ onClose: handleClose,
532
+ onSelect: handleSelect
533
+ }
534
+ ) : null,
535
+ !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
340
536
  reactNative.TouchableOpacity,
341
537
  {
342
538
  accessible: true,
@@ -344,7 +540,7 @@ var ModalDropdown = ({
344
540
  accessibilityLabel: t("common.dismissDropdown"),
345
541
  accessibilityRole: "button",
346
542
  activeOpacity: 1,
347
- style: styles5.modalOverlay,
543
+ style: styles7.modalOverlay,
348
544
  testID: `${testID}-backdrop`,
349
545
  onPress: handleClose,
350
546
  children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -355,22 +551,15 @@ var ModalDropdown = ({
355
551
  "aria-label": accessibilityLabel,
356
552
  role: "dialog",
357
553
  style: modalContentStyle,
358
- children: /* @__PURE__ */ jsxRuntime.jsx(
359
- reactNative.FlatList,
360
- {
361
- data: [...options],
362
- keyExtractor,
363
- renderItem: renderOption
364
- }
365
- )
554
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
366
555
  }
367
556
  )
368
557
  }
369
- ) })
558
+ ) }) : null
370
559
  ] });
371
560
  };
372
561
  var CLOSE_ICON_SIZE = 18;
373
- var styles6 = reactNative.StyleSheet.create({
562
+ var styles8 = reactNative.StyleSheet.create({
374
563
  container: {
375
564
  flex: 1,
376
565
  padding: 16
@@ -394,8 +583,8 @@ var ModalShell = ({
394
583
  showClose = true
395
584
  }) => {
396
585
  const { theme, t } = uiFeedback.useUi();
397
- const containerStyle = React__default.default.useMemo(
398
- () => [styles6.container, { backgroundColor: theme.colors.background }, contentStyle],
586
+ const containerStyle = React8__default.default.useMemo(
587
+ () => [styles8.container, { backgroundColor: theme.colors.background }, contentStyle],
399
588
  [theme.colors.background, contentStyle]
400
589
  );
401
590
  const closeA11yLabel = t("quizTemplates.cancel");
@@ -415,7 +604,7 @@ var ModalShell = ({
415
604
  role: "dialog",
416
605
  style: containerStyle,
417
606
  children: [
418
- /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles6.headerRow, children: [
607
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles8.headerRow, children: [
419
608
  /* @__PURE__ */ jsxRuntime.jsx(Heading, { children: title ?? t("close") }),
420
609
  showClose ? /* @__PURE__ */ jsxRuntime.jsx(
421
610
  reactNative.TouchableOpacity,
@@ -423,7 +612,7 @@ var ModalShell = ({
423
612
  accessibilityHint: t("common.closeDialogHint"),
424
613
  accessibilityLabel: closeA11yLabel,
425
614
  accessibilityRole: "button",
426
- style: styles6.closeButton,
615
+ style: styles8.closeButton,
427
616
  testID: LAYOUT_TEST_IDS.modalShellClose,
428
617
  onPress: onCancel,
429
618
  children: /* @__PURE__ */ jsxRuntime.jsx(uiIcons.SvgIcon, { color: theme.colors.textSecondary, name: "close", size: CLOSE_ICON_SIZE })
@@ -437,8 +626,214 @@ var ModalShell = ({
437
626
  }
438
627
  );
439
628
  };
629
+ var AccordionContext = React8.createContext(null);
630
+ function useAccordionContext() {
631
+ const value = React8.useContext(AccordionContext);
632
+ if (value === null) {
633
+ throw new Error("AccordionItem must be rendered inside an <Accordion>.");
634
+ }
635
+ return value;
636
+ }
637
+ var androidEnabled = false;
638
+ function enableAndroidLayoutAnimationOnce() {
639
+ if (androidEnabled) return;
640
+ androidEnabled = true;
641
+ const isAndroid = reactNative.Platform.OS === "android";
642
+ const setter = reactNative.UIManager.setLayoutAnimationEnabledExperimental;
643
+ if (isAndroid && typeof setter === "function") {
644
+ setter(true);
645
+ }
646
+ }
647
+ function animateNextLayout() {
648
+ enableAndroidLayoutAnimationOnce();
649
+ const configure = reactNative.LayoutAnimation.configureNext;
650
+ if (typeof configure !== "function") return;
651
+ try {
652
+ configure(reactNative.LayoutAnimation.Presets.easeInEaseOut);
653
+ } catch {
654
+ }
655
+ }
656
+ var styles9 = reactNative.StyleSheet.create({
657
+ container: { alignSelf: "stretch" }
658
+ });
659
+ function computeInitialOpen(children, defaultOpenIds, allowMultiple) {
660
+ const ids = new Set(defaultOpenIds ?? []);
661
+ React8__default.default.Children.forEach(children, (child) => {
662
+ if (!React8__default.default.isValidElement(child)) return;
663
+ const props = child.props;
664
+ if (props.defaultOpen === true && typeof props.id === "string") {
665
+ ids.add(props.id);
666
+ }
667
+ });
668
+ if (!allowMultiple && ids.size > 1) {
669
+ const first = ids.values().next().value;
670
+ return new Set(first === void 0 ? [] : [first]);
671
+ }
672
+ return ids;
673
+ }
674
+ var Accordion = ({
675
+ children,
676
+ openIds,
677
+ defaultOpenIds,
678
+ onOpenChange,
679
+ allowMultiple = true,
680
+ testID = "accordion",
681
+ style
682
+ }) => {
683
+ const isControlled = openIds !== void 0;
684
+ const [internalOpen, setInternalOpen] = React8.useState(
685
+ () => computeInitialOpen(children, defaultOpenIds, allowMultiple)
686
+ );
687
+ const openSet = React8.useMemo(
688
+ () => isControlled ? new Set(openIds) : internalOpen,
689
+ [isControlled, openIds, internalOpen]
690
+ );
691
+ const toggle = React8.useCallback(
692
+ (id) => {
693
+ animateNextLayout();
694
+ const next = new Set(openSet);
695
+ const willOpen = !next.has(id);
696
+ if (!allowMultiple) next.clear();
697
+ if (willOpen) {
698
+ next.add(id);
699
+ } else {
700
+ next.delete(id);
701
+ }
702
+ if (!isControlled) setInternalOpen(next);
703
+ if (onOpenChange !== void 0) onOpenChange(Array.from(next));
704
+ },
705
+ [allowMultiple, isControlled, onOpenChange, openSet]
706
+ );
707
+ const contextValue = React8.useMemo(
708
+ () => ({ openIds: openSet, toggle, allowMultiple }),
709
+ [openSet, toggle, allowMultiple]
710
+ );
711
+ const containerStyle = React8.useMemo(
712
+ () => style === void 0 ? [styles9.container] : [styles9.container, ...Array.isArray(style) ? style : [style]],
713
+ [style]
714
+ );
715
+ return /* @__PURE__ */ jsxRuntime.jsx(AccordionContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: containerStyle, testID, children }) });
716
+ };
717
+ var HEADER_PADDING_H = 16;
718
+ var HEADER_PADDING_V = 12;
719
+ var BODY_PADDING_H = 16;
720
+ var BODY_PADDING_V = 12;
721
+ var HEADER_GAP = 8;
722
+ var TITLE_FONT_SIZE2 = 15;
723
+ var TITLE_FONT_WEIGHT = "600";
724
+ var CHEVRON_SIZE = 18;
725
+ var ROTATE_DURATION_MS = 160;
726
+ var ROTATE_COLLAPSED = 0;
727
+ var ROTATE_EXPANDED = 1;
728
+ var COLLAPSED_DEG = "0deg";
729
+ var EXPANDED_DEG = "180deg";
730
+ var DISABLED_OPACITY = 0.5;
731
+ var FULL_OPACITY = 1;
732
+ var ROLE_REGION = "region";
733
+ var styles10 = reactNative.StyleSheet.create({
734
+ item: { borderTopWidth: reactNative.StyleSheet.hairlineWidth },
735
+ header: {
736
+ flexDirection: "row",
737
+ alignItems: "center",
738
+ justifyContent: "space-between",
739
+ paddingHorizontal: HEADER_PADDING_H,
740
+ paddingVertical: HEADER_PADDING_V
741
+ },
742
+ headerLeft: { flexShrink: 1, flexGrow: 1 },
743
+ headerRight: { flexDirection: "row", alignItems: "center", marginLeft: HEADER_GAP },
744
+ title: { fontSize: TITLE_FONT_SIZE2, fontWeight: TITLE_FONT_WEIGHT },
745
+ chevron: { marginLeft: HEADER_GAP },
746
+ body: { paddingHorizontal: BODY_PADDING_H, paddingBottom: BODY_PADDING_V }
747
+ });
748
+ var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
749
+ var AccordionItem = ({
750
+ id,
751
+ title,
752
+ right,
753
+ children,
754
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- read by the container's initial-open scan, not here
755
+ defaultOpen: _defaultOpen,
756
+ disabled = false,
757
+ testID,
758
+ accessibilityLabel,
759
+ accessibilityHint
760
+ }) => {
761
+ const { theme, t } = uiFeedback.useUi();
762
+ const { colors } = theme;
763
+ const { openIds, toggle } = useAccordionContext();
764
+ const expanded = openIds.has(id);
765
+ const headerTestID = testID ?? `accordion-item-${id}`;
766
+ const bodyTestID = `${headerTestID}-body`;
767
+ const chevronTestID = `${headerTestID}-chevron`;
768
+ const [rotation] = React8.useState(() => new reactNative.Animated.Value(expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED));
769
+ React8.useEffect(() => {
770
+ reactNative.Animated.timing(rotation, {
771
+ toValue: expanded ? ROTATE_EXPANDED : ROTATE_COLLAPSED,
772
+ duration: ROTATE_DURATION_MS,
773
+ easing: reactNative.Easing.out(reactNative.Easing.ease),
774
+ useNativeDriver: reactNative.Platform.OS !== "web"
775
+ }).start();
776
+ }, [expanded, rotation]);
777
+ const rotate = rotation.interpolate({
778
+ inputRange: [ROTATE_COLLAPSED, ROTATE_EXPANDED],
779
+ outputRange: [COLLAPSED_DEG, EXPANDED_DEG]
780
+ });
781
+ const handlePress = React8.useCallback(() => {
782
+ if (!disabled) toggle(id);
783
+ }, [disabled, id, toggle]);
784
+ const handleKeyDown2 = React8.useCallback(
785
+ (event) => {
786
+ if (disabled) return;
787
+ const key = event.key ?? "";
788
+ const isActivation = ACTIVATION_KEYS.includes(key);
789
+ if (!isActivation) return;
790
+ if (typeof event.preventDefault === "function") event.preventDefault();
791
+ toggle(id);
792
+ },
793
+ [disabled, id, toggle]
794
+ );
795
+ const keyboardProps = reactNative.Platform.OS === "web" ? { onKeyDown: handleKeyDown2 } : {};
796
+ const itemStyle = React8.useMemo(
797
+ () => [styles10.item, { borderTopColor: colors.border }],
798
+ [colors.border]
799
+ );
800
+ const headerStyle = React8.useMemo(
801
+ () => [styles10.header, { opacity: disabled ? DISABLED_OPACITY : FULL_OPACITY }],
802
+ [disabled]
803
+ );
804
+ const resolvedLabel = accessibilityLabel ?? (typeof title === "string" ? title : void 0);
805
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: itemStyle, children: [
806
+ /* @__PURE__ */ jsxRuntime.jsxs(
807
+ reactNative.Pressable,
808
+ {
809
+ accessibilityHint: accessibilityHint ?? t("common.accordionToggleHint"),
810
+ accessibilityLabel: resolvedLabel,
811
+ accessibilityRole: "button",
812
+ accessibilityState: { expanded, disabled },
813
+ "aria-controls": bodyTestID,
814
+ "aria-expanded": expanded,
815
+ disabled,
816
+ style: headerStyle,
817
+ testID: headerTestID,
818
+ onPress: handlePress,
819
+ ...keyboardProps,
820
+ children: [
821
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: styles10.headerLeft, children: typeof title === "string" ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles10.title, { color: colors.text }], children: title }) : title }),
822
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles10.headerRight, children: [
823
+ right,
824
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles10.chevron, { transform: [{ rotate }] }], children: /* @__PURE__ */ jsxRuntime.jsx(uiIcons.SvgIcon, { color: colors.textSecondary, name: "chevronDown", size: CHEVRON_SIZE, testID: chevronTestID }) })
825
+ ] })
826
+ ]
827
+ }
828
+ ),
829
+ expanded ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { accessibilityLabel: resolvedLabel, nativeID: bodyTestID, role: ROLE_REGION, style: styles10.body, testID: bodyTestID, children }) : null
830
+ ] });
831
+ };
440
832
 
833
+ exports.Accordion = Accordion;
834
+ exports.AccordionItem = AccordionItem;
441
835
  exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
836
+ exports.DropdownVariant = DropdownVariant;
442
837
  exports.Heading = Heading;
443
838
  exports.LAYOUT_TEST_IDS = LAYOUT_TEST_IDS;
444
839
  exports.ModalDropdown = ModalDropdown;