@dloizides/ui-layout 1.7.1 → 1.9.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,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.9.0
4
+
5
+ - **`ModalDropdown`: `menuMinWidth` — a width FLOOR for the open inline menu (additive, optional).**
6
+ The menu matches the TRIGGER's width, which is right for a full-width field but leaves a compact
7
+ anchor (the 1.8.0 `renderTrigger` case: a locale pill, an avatar chip, an icon button) with a menu
8
+ too narrow to read its own option labels — a 52px "EN ▾" pill produced a 52px menu whose rows were
9
+ clipped to a dark strip. `menuMinWidth` floors it; a wider trigger still wins.
10
+ - **Backward-compatible:** omitted, the width is the trigger's, exactly as before.
11
+
12
+ ## 1.8.0
13
+
14
+ - **`ModalDropdown`: `renderTrigger` — a custom ANCHOR slot (additive, optional).** The dropdown's
15
+ default trigger is a bordered field box, which is wrong for a *menu* anchored to a compact chip
16
+ (a locale pill, an avatar/user chip, an icon button). Callers can now supply
17
+ `renderTrigger={({ label, isOpen }) => …}` and own the anchor's visuals entirely; the default box
18
+ is then not rendered. The a11y wrapper stays with the dropdown — `role=button`, `aria-expanded`,
19
+ the accessible label + hint, and the `testID` are still applied — so a custom trigger *cannot*
20
+ drop the accessible contract, and the portalled, keyboard-navigable (↑/↓/Home/End/Enter/Escape),
21
+ never-clipped menu comes along for free.
22
+ - **`ModalDropdown`: `optionTestID` — custom per-option testIDs (additive, optional).** Options
23
+ still default to `` `${testID}-option-${value}` ``; a caller turning an existing flat control into
24
+ a dropdown can now keep its established selectors stable
25
+ (`optionTestID={(code) => `lang-${code}`}`).
26
+ - **Backward-compatible:** both props are optional and, when omitted, the render tree is unchanged —
27
+ erevna / katalogos / kefi / agora are unaffected and need no markup changes.
28
+
3
29
  ## 1.7.1
4
30
 
5
31
  Fix: the modal-variant dismiss backdrop was a pressable WRAPPING the option buttons,
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,29 @@ 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;
165
+ /**
166
+ * Minimum width of the open inline menu. The menu otherwise matches the TRIGGER's width, which
167
+ * is right for a full-width field but leaves a COMPACT anchor (a locale pill, an avatar chip, an
168
+ * icon button — see `renderTrigger`) with a menu too narrow to read its own option labels. It is
169
+ * a floor only: a wider trigger still wins. Omit to keep the trigger-width behaviour.
170
+ */
171
+ menuMinWidth?: number;
144
172
  }
145
- declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
173
+ declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, menuMinWidth, }: ModalDropdownProps<T>) => React.ReactElement;
146
174
 
147
175
  /**
148
176
  * ModalShell — a slide-up full-screen modal with a themed header (title + close button)
@@ -254,4 +282,4 @@ declare const LAYOUT_TEST_IDS: {
254
282
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
255
283
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
256
284
 
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 };
285
+ 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,29 @@ 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;
165
+ /**
166
+ * Minimum width of the open inline menu. The menu otherwise matches the TRIGGER's width, which
167
+ * is right for a full-width field but leaves a COMPACT anchor (a locale pill, an avatar chip, an
168
+ * icon button — see `renderTrigger`) with a menu too narrow to read its own option labels. It is
169
+ * a floor only: a wider trigger still wins. Omit to keep the trigger-width behaviour.
170
+ */
171
+ menuMinWidth?: number;
144
172
  }
145
- declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
173
+ declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, renderTrigger, optionTestID, menuMinWidth, }: ModalDropdownProps<T>) => React.ReactElement;
146
174
 
147
175
  /**
148
176
  * ModalShell — a slide-up full-screen modal with a themed header (title + close button)
@@ -254,4 +282,4 @@ declare const LAYOUT_TEST_IDS: {
254
282
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
255
283
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
256
284
 
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 };
285
+ 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
@@ -323,14 +323,14 @@ var BORDER_RADIUS = 8;
323
323
  var BORDER_WIDTH2 = 1;
324
324
  var MENU_PADDING = 4;
325
325
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
326
- function buildPortalPopoverStyle(rect) {
326
+ function buildPortalPopoverStyle(rect, minWidth = 0) {
327
327
  return {
328
328
  // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
329
329
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
330
330
  position: "fixed",
331
331
  top: rect.bottom + MENU_TOP_GAP,
332
332
  left: rect.left,
333
- width: rect.width,
333
+ width: Math.max(rect.width, minWidth),
334
334
  zIndex: MENU_Z_INDEX,
335
335
  borderWidth: BORDER_WIDTH2,
336
336
  borderRadius: BORDER_RADIUS,
@@ -498,6 +498,8 @@ var InlineMenu = ({
498
498
  value,
499
499
  options,
500
500
  containerRef,
501
+ optionTestID,
502
+ menuMinWidth = 0,
501
503
  onSelect,
502
504
  onClose
503
505
  }) => {
@@ -534,9 +536,13 @@ var InlineMenu = ({
534
536
  });
535
537
  const popoverStyle = React8.useMemo(() => {
536
538
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
537
- if (IS_WEB) return [buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }), themed];
538
- return [styles7.popover, themed];
539
- }, [colors.border, colors.surface, rect]);
539
+ if (IS_WEB)
540
+ return [
541
+ buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
542
+ themed
543
+ ];
544
+ return [styles7.popover, { minWidth: menuMinWidth }, themed];
545
+ }, [colors.border, colors.surface, menuMinWidth, rect]);
540
546
  const menu = /* @__PURE__ */ jsxRuntime.jsx(
541
547
  reactNative.View,
542
548
  {
@@ -551,7 +557,7 @@ var InlineMenu = ({
551
557
  isHighlighted: index === highlightedIndex,
552
558
  isSelected: option.value === value,
553
559
  label: option.label,
554
- testID: `${testID}-option-${String(option.value)}`,
560
+ testID: optionTestID !== void 0 ? optionTestID(option.value) : `${testID}-option-${String(option.value)}`,
555
561
  onSelect: () => onSelect(option.value)
556
562
  },
557
563
  String(option.value)
@@ -609,7 +615,10 @@ var ModalDropdown = ({
609
615
  value,
610
616
  options,
611
617
  onChange,
612
- variant
618
+ variant,
619
+ renderTrigger,
620
+ optionTestID,
621
+ menuMinWidth
613
622
  }) => {
614
623
  const { theme, t } = uiFeedback.useUi();
615
624
  const { colors } = theme;
@@ -637,8 +646,12 @@ var ModalDropdown = ({
637
646
  [onChange]
638
647
  );
639
648
  const containerStyle = React8.useMemo(
640
- () => [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
641
- [colors.border, colors.surface]
649
+ () => renderTrigger !== void 0 ? void 0 : [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
650
+ [colors.border, colors.surface, renderTrigger]
651
+ );
652
+ const optionTestIDFor = React8.useCallback(
653
+ (optionValue) => optionTestID !== void 0 ? optionTestID(optionValue) : `${testID}-option-${String(optionValue)}`,
654
+ [optionTestID, testID]
642
655
  );
643
656
  const anchorStyle = React8.useMemo(
644
657
  () => [styles8.anchor, buildAnchorStackStyle(isMenu && isOpen)],
@@ -654,11 +667,11 @@ var ModalDropdown = ({
654
667
  {
655
668
  isSelected: item.value === value,
656
669
  label: item.label,
657
- testID: `${testID}-option-${String(item.value)}`,
670
+ testID: optionTestIDFor(item.value),
658
671
  onSelect: () => handleSelect(item.value)
659
672
  }
660
673
  ),
661
- [handleSelect, testID, value]
674
+ [handleSelect, optionTestIDFor, value]
662
675
  );
663
676
  const keyExtractor = React8.useCallback((item) => String(item.value), []);
664
677
  return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyle, children: [
@@ -674,7 +687,7 @@ var ModalDropdown = ({
674
687
  style: containerStyle,
675
688
  testID,
676
689
  onPress: handleToggle,
677
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
690
+ children: renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
678
691
  }
679
692
  ),
680
693
  isMenu && isOpen ? /* @__PURE__ */ jsxRuntime.jsx(
@@ -682,6 +695,8 @@ var ModalDropdown = ({
682
695
  {
683
696
  accessibilityLabel,
684
697
  containerRef: anchorRef,
698
+ menuMinWidth,
699
+ optionTestID: optionTestIDFor,
685
700
  options,
686
701
  testID,
687
702
  value,