@dloizides/ui-layout 1.7.0 → 1.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.0
4
+
5
+ - **`ModalDropdown`: `renderTrigger` — a custom ANCHOR slot (additive, optional).** The dropdown's
6
+ default trigger is a bordered field box, which is wrong for a *menu* anchored to a compact chip
7
+ (a locale pill, an avatar/user chip, an icon button). Callers can now supply
8
+ `renderTrigger={({ label, isOpen }) => …}` and own the anchor's visuals entirely; the default box
9
+ is then not rendered. The a11y wrapper stays with the dropdown — `role=button`, `aria-expanded`,
10
+ the accessible label + hint, and the `testID` are still applied — so a custom trigger *cannot*
11
+ drop the accessible contract, and the portalled, keyboard-navigable (↑/↓/Home/End/Enter/Escape),
12
+ never-clipped menu comes along for free.
13
+ - **`ModalDropdown`: `optionTestID` — custom per-option testIDs (additive, optional).** Options
14
+ still default to `` `${testID}-option-${value}` ``; a caller turning an existing flat control into
15
+ a dropdown can now keep its established selectors stable
16
+ (`optionTestID={(code) => `lang-${code}`}`).
17
+ - **Backward-compatible:** both props are optional and, when omitted, the render tree is unchanged —
18
+ erevna / katalogos / kefi / agora are unaffected and need no markup changes.
19
+
20
+ ## 1.7.1
21
+
22
+ Fix: the modal-variant dismiss backdrop was a pressable WRAPPING the option buttons,
23
+ producing invalid DOM on web ("<button> cannot contain a nested <button>") + a React
24
+ console.error. The backdrop is now an absolute-fill SIBLING behind the dialog — same
25
+ tap-to-dismiss behaviour, no nesting. No API change.
26
+
27
+
3
28
  ## 1.7.0
4
29
 
5
30
  - **`ModalDropdown` inline-menu (`variant={DropdownVariant.Menu}`) z-index / clipping fix.** On
package/dist/index.d.mts CHANGED
@@ -128,6 +128,13 @@ interface DropdownOption<T> {
128
128
  * Both variants share {@link OptionRow} for option rendering + selection.
129
129
  */
130
130
 
131
+ /** State handed to a custom trigger renderer. */
132
+ interface DropdownTriggerState {
133
+ /** The selected option's label (or the select placeholder when nothing matches). */
134
+ label: string;
135
+ /** Whether the menu is currently open. */
136
+ isOpen: boolean;
137
+ }
131
138
  interface ModalDropdownProps<T> {
132
139
  testID: string;
133
140
  accessibilityLabel: string;
@@ -141,8 +148,22 @@ interface ModalDropdownProps<T> {
141
148
  * (and always a modal on native). An explicit value overrides the auto choice.
142
149
  */
143
150
  variant?: DropdownVariant;
151
+ /**
152
+ * Custom ANCHOR content. When supplied, the caller owns the trigger's visuals
153
+ * entirely (the default bordered field box is not rendered) — use it for compact
154
+ * chips / avatars / icon triggers. The a11y wrapper (role=button, `aria-expanded`,
155
+ * the label + hint, the testID) is still supplied by the dropdown, so a custom
156
+ * trigger cannot drop the accessible contract. Omit for the default field look.
157
+ */
158
+ renderTrigger?: (state: DropdownTriggerState) => React.ReactNode;
159
+ /**
160
+ * Custom testID per option row. Defaults to `` `${testID}-option-${value}` ``.
161
+ * Lets a caller keep a pre-existing selector stable when a flat control becomes
162
+ * a dropdown.
163
+ */
164
+ optionTestID?: (value: T) => string;
144
165
  }
145
- declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
166
+ declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, }: ModalDropdownProps<T>) => React.ReactElement;
146
167
 
147
168
  /**
148
169
  * ModalShell — a slide-up full-screen modal with a themed header (title + close button)
@@ -254,4 +275,4 @@ declare const LAYOUT_TEST_IDS: {
254
275
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
255
276
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
256
277
 
257
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
278
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
package/dist/index.d.ts CHANGED
@@ -128,6 +128,13 @@ interface DropdownOption<T> {
128
128
  * Both variants share {@link OptionRow} for option rendering + selection.
129
129
  */
130
130
 
131
+ /** State handed to a custom trigger renderer. */
132
+ interface DropdownTriggerState {
133
+ /** The selected option's label (or the select placeholder when nothing matches). */
134
+ label: string;
135
+ /** Whether the menu is currently open. */
136
+ isOpen: boolean;
137
+ }
131
138
  interface ModalDropdownProps<T> {
132
139
  testID: string;
133
140
  accessibilityLabel: string;
@@ -141,8 +148,22 @@ interface ModalDropdownProps<T> {
141
148
  * (and always a modal on native). An explicit value overrides the auto choice.
142
149
  */
143
150
  variant?: DropdownVariant;
151
+ /**
152
+ * Custom ANCHOR content. When supplied, the caller owns the trigger's visuals
153
+ * entirely (the default bordered field box is not rendered) — use it for compact
154
+ * chips / avatars / icon triggers. The a11y wrapper (role=button, `aria-expanded`,
155
+ * the label + hint, the testID) is still supplied by the dropdown, so a custom
156
+ * trigger cannot drop the accessible contract. Omit for the default field look.
157
+ */
158
+ renderTrigger?: (state: DropdownTriggerState) => React.ReactNode;
159
+ /**
160
+ * Custom testID per option row. Defaults to `` `${testID}-option-${value}` ``.
161
+ * Lets a caller keep a pre-existing selector stable when a flat control becomes
162
+ * a dropdown.
163
+ */
164
+ optionTestID?: (value: T) => string;
144
165
  }
145
- declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
166
+ declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, }: ModalDropdownProps<T>) => React.ReactElement;
146
167
 
147
168
  /**
148
169
  * ModalShell — a slide-up full-screen modal with a themed header (title + close button)
@@ -254,4 +275,4 @@ declare const LAYOUT_TEST_IDS: {
254
275
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
255
276
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
256
277
 
257
- export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
278
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionVariant, DEFAULT_BILLING_ROUTE, type DropdownOption, type DropdownTriggerState, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, SegmentedControl, type SegmentedControlProps, type SegmentedOption, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
package/dist/index.js CHANGED
@@ -498,6 +498,7 @@ var InlineMenu = ({
498
498
  value,
499
499
  options,
500
500
  containerRef,
501
+ optionTestID,
501
502
  onSelect,
502
503
  onClose
503
504
  }) => {
@@ -551,7 +552,7 @@ var InlineMenu = ({
551
552
  isHighlighted: index === highlightedIndex,
552
553
  isSelected: option.value === value,
553
554
  label: option.label,
554
- testID: `${testID}-option-${String(option.value)}`,
555
+ testID: optionTestID !== void 0 ? optionTestID(option.value) : `${testID}-option-${String(option.value)}`,
555
556
  onSelect: () => onSelect(option.value)
556
557
  },
557
558
  String(option.value)
@@ -609,7 +610,9 @@ var ModalDropdown = ({
609
610
  value,
610
611
  options,
611
612
  onChange,
612
- variant
613
+ variant,
614
+ renderTrigger,
615
+ optionTestID
613
616
  }) => {
614
617
  const { theme, t } = uiFeedback.useUi();
615
618
  const { colors } = theme;
@@ -637,8 +640,12 @@ var ModalDropdown = ({
637
640
  [onChange]
638
641
  );
639
642
  const containerStyle = React8.useMemo(
640
- () => [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
641
- [colors.border, colors.surface]
643
+ () => renderTrigger !== void 0 ? void 0 : [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
644
+ [colors.border, colors.surface, renderTrigger]
645
+ );
646
+ const optionTestIDFor = React8.useCallback(
647
+ (optionValue) => optionTestID !== void 0 ? optionTestID(optionValue) : `${testID}-option-${String(optionValue)}`,
648
+ [optionTestID, testID]
642
649
  );
643
650
  const anchorStyle = React8.useMemo(
644
651
  () => [styles8.anchor, buildAnchorStackStyle(isMenu && isOpen)],
@@ -654,11 +661,11 @@ var ModalDropdown = ({
654
661
  {
655
662
  isSelected: item.value === value,
656
663
  label: item.label,
657
- testID: `${testID}-option-${String(item.value)}`,
664
+ testID: optionTestIDFor(item.value),
658
665
  onSelect: () => handleSelect(item.value)
659
666
  }
660
667
  ),
661
- [handleSelect, testID, value]
668
+ [handleSelect, optionTestIDFor, value]
662
669
  );
663
670
  const keyExtractor = React8.useCallback((item) => String(item.value), []);
664
671
  return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyle, children: [
@@ -674,7 +681,7 @@ var ModalDropdown = ({
674
681
  style: containerStyle,
675
682
  testID,
676
683
  onPress: handleToggle,
677
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
684
+ children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
678
685
  }
679
686
  ),
680
687
  isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
@@ -682,6 +689,7 @@ var ModalDropdown = ({
682
689
  {
683
690
  accessibilityLabel,
684
691
  containerRef: anchorRef,
692
+ optionTestID: optionTestIDFor,
685
693
  options,
686
694
  testID,
687
695
  value,
@@ -689,30 +697,32 @@ var ModalDropdown = ({
689
697
  onSelect: handleSelect
690
698
  }
691
699
  ) : null,
692
- !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
693
- reactNative.TouchableOpacity,
694
- {
695
- accessible: true,
696
- accessibilityHint: t("common.dismissDropdownHint"),
697
- accessibilityLabel: t("common.dismissDropdown"),
698
- accessibilityRole: "button",
699
- activeOpacity: 1,
700
- style: styles8.modalOverlay,
701
- testID: `${testID}-backdrop`,
702
- onPress: handleClose,
703
- children: /* @__PURE__ */ jsxRuntime.jsx(
704
- reactNative.View,
705
- {
706
- ref: dialogRef,
707
- accessibilityViewIsModal: true,
708
- "aria-label": accessibilityLabel,
709
- role: "dialog",
710
- style: modalContentStyle,
711
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
712
- }
713
- )
714
- }
715
- ) }) : null
700
+ !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles8.modalOverlay, children: [
701
+ /* @__PURE__ */ jsxRuntime.jsx(
702
+ reactNative.TouchableOpacity,
703
+ {
704
+ accessible: true,
705
+ accessibilityHint: t("common.dismissDropdownHint"),
706
+ accessibilityLabel: t("common.dismissDropdown"),
707
+ accessibilityRole: "button",
708
+ activeOpacity: 1,
709
+ style: reactNative.StyleSheet.absoluteFill,
710
+ testID: `${testID}-backdrop`,
711
+ onPress: handleClose
712
+ }
713
+ ),
714
+ /* @__PURE__ */ jsxRuntime.jsx(
715
+ reactNative.View,
716
+ {
717
+ ref: dialogRef,
718
+ accessibilityViewIsModal: true,
719
+ "aria-label": accessibilityLabel,
720
+ role: "dialog",
721
+ style: modalContentStyle,
722
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
723
+ }
724
+ )
725
+ ] }) }) : null
716
726
  ] });
717
727
  };
718
728
  var CLOSE_ICON_SIZE = 18;