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