@dloizides/ui-layout 1.2.0 → 1.4.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,43 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ - Add **`SegmentedControl`** — a single rounded pill *track* holding N mutually-exclusive
6
+ segments (the iOS-style segmented / tab toggle). The selected segment lifts onto a raised
7
+ surface (`colors.surface`) with a subtle shadow; the rest stay transparent over the soft
8
+ track (`colors.background`). Promoted from the v1 AML console's `.lf-mode` mode switch so
9
+ erevna/katalogos/kefi share ONE toggle instead of hand-rolling two primary/ghost buttons.
10
+ - **Generic over the value union** (`SegmentedControl<'peps' | 'leaders'>`) for a typed
11
+ `onChange`; each segment carries its own `label` / `value` / optional `testID` +
12
+ `accessibilityLabel` / `accessibilityHint`.
13
+ - **a11y**: the group renders as a `tablist`, each segment as a `tab` with
14
+ `accessibilityState={{ selected }}` (react-native-web forwards `role` + `aria-selected`).
15
+ - **Themed** entirely from the `@dloizides/ui-feedback` theme (surface / background / border /
16
+ text colours); no colour literal except the selected-segment drop shadow.
17
+ - **Additive / backward-compatible**: purely new exports (`SegmentedControl`,
18
+ `SegmentedControlProps`, `SegmentedOption`). Existing consumers are unaffected.
19
+
20
+ ## 1.3.0
21
+
22
+ - Add **`Accordion`** + **`AccordionItem`** — a themed expand/collapse disclosure group that
23
+ replaces per-app hand-rolled `<details>` / expanders (AML "More options" + expandable
24
+ matched-candidate rows, Erevna survey groups, Katalogos menu sections…).
25
+ - Compound API: an `Accordion` container owns the open state and shares it with `AccordionItem`
26
+ children via context. Each item = a pressable header (title left, optional `right`
27
+ adornment/badge slot, a rotating chevron) over a collapsible body `region`.
28
+ - **Controlled** (`openIds` + `onOpenChange`) **and uncontrolled** (`defaultOpenIds`, plus
29
+ per-item `defaultOpen`). `allowMultiple` (default `true`) vs single-open. Per-item `disabled`.
30
+ - **a11y**: header is an accessible `button` (`accessibilityRole="button"`,
31
+ `accessibilityState={{ expanded }}`, web `aria-expanded` + `aria-controls`); body is a
32
+ `role="region"`. Renders as a native `<button>`, so **Enter / Space toggle** it.
33
+ - **Themed** entirely from the `@dloizides/ui-feedback` theme (border / surface / text colours),
34
+ no hardcoded palette; renders borderless so it nests inside a `Section` / `Card`.
35
+ - **Animated** open/close via a guarded `LayoutAnimation` (web- and native-safe no-op fallback,
36
+ never throws) + an `Animated` chevron rotation. Hook-safe (lazy `useState`, no ref reads in render).
37
+ - **Additive / backward-compatible**: purely new exports (`Accordion`, `AccordionItem`,
38
+ `AccordionProps`, `AccordionItemProps`). Existing consumers (erevna / katalogos / aml-v2) are
39
+ unaffected.
40
+
3
41
  ## 1.2.0
4
42
 
5
43
  - `ModalDropdown` can now render as an **inline anchored menu** (native `<select>` feel), not only a
package/README.md CHANGED
@@ -13,8 +13,62 @@ Read theme + translations from the shared `@dloizides/ui-feedback` context (`use
13
13
  | `UpgradePrompt` | Free-tier upgrade nudge; CTA navigates to the billing route via `useUi().navigate`. |
14
14
  | `ModalDropdown` | Generic dropdown selector. **Responsive by default**: an inline anchored menu on wide/desktop web, a modal on narrow/mobile — override per screen with `variant`. |
15
15
  | `DropdownVariant` | Enum (`Menu` / `Modal`) to force a `ModalDropdown` rendering variant. |
16
+ | `Accordion` / `AccordionItem` | Themed expand/collapse disclosure group (replaces hand-rolled `<details>`/expanders). Controlled or uncontrolled, single- or multi-open, animated, keyboard + screen-reader accessible. |
16
17
  | `useFocusTrap` | Web keyboard focus-trap hook (no-op on native). |
17
18
 
19
+ ### `Accordion`
20
+
21
+ A compound component: an `Accordion` container that owns the open state + `AccordionItem`
22
+ children that read it via context. Each item is a pressable header (title left, optional
23
+ `right` adornment/badge slot, a rotating chevron) over a collapsible body `region`.
24
+
25
+ - **Controlled** — pass `openIds` + `onOpenChange`.
26
+ - **Uncontrolled** — pass `defaultOpenIds` on the container and/or `defaultOpen` per item.
27
+ - **`allowMultiple`** (default `true`) keeps any number of items open; `false` = single-open.
28
+ - **Per-item `disabled`.**
29
+ - **a11y** — header is an accessible `button` (`accessibilityRole="button"`,
30
+ `accessibilityState={{ expanded }}`, web `aria-expanded` + `aria-controls`); the body is a
31
+ `role="region"`. The header renders as a native `<button>`, so **Enter / Space toggle** it.
32
+ - **Themed** entirely from the active `useUi()` theme (border / surface / text colours). Renders
33
+ borderless so it drops cleanly inside a `Section` / `Card`.
34
+ - **Animated** open/close via guarded `LayoutAnimation` (a no-op where unavailable — never errors
35
+ on web or native) plus an `Animated` chevron rotation.
36
+ - **testIDs** — container `testID` (default `accordion`); per item the header is
37
+ `testID` (default `accordion-item-<id>`), the body `<header>-body`, the chevron `<header>-chevron`.
38
+
39
+ ```tsx
40
+ import { Accordion, AccordionItem, Section, StatusBadge } from '@dloizides/ui-layout';
41
+
42
+ // 1) A form "More options" disclosure (single collapsible section, starts closed):
43
+ <Section>
44
+ <Accordion>
45
+ <AccordionItem id="more" title="More options">
46
+ <FuzzinessSlider />
47
+ <DatasetPicker />
48
+ </AccordionItem>
49
+ </Accordion>
50
+ </Section>
51
+
52
+ // 2) An expandable list row per matched candidate (single-open, badge in the right slot):
53
+ <Accordion allowMultiple={false} onOpenChange={(ids) => setOpenRow(ids[0])}>
54
+ {candidates.map((c) => (
55
+ <AccordionItem
56
+ key={c.id}
57
+ id={c.id}
58
+ title={c.name}
59
+ right={<StatusBadge label={c.tier} color={c.fg} backgroundColor={c.bg} />}
60
+ >
61
+ <CandidateDetail candidate={c} />
62
+ </AccordionItem>
63
+ ))}
64
+ </Accordion>
65
+
66
+ // Controlled variant:
67
+ <Accordion openIds={openIds} onOpenChange={setOpenIds}>{/* …items… */}</Accordion>
68
+ ```
69
+
70
+ The apps supply the header hint string via the shared translate: key `common.accordionToggleHint`.
71
+
18
72
  ### `ModalDropdown` variants
19
73
 
20
74
  `ModalDropdown` picks its presentation automatically:
package/dist/index.d.mts CHANGED
@@ -36,6 +36,47 @@ interface StatusBadgeProps {
36
36
  }
37
37
  declare const StatusBadge: ({ label, color, backgroundColor, testID, accessibilityLabel, accessibilityHint, }: StatusBadgeProps) => React.ReactElement;
38
38
 
39
+ /**
40
+ * SegmentedControl — a single rounded pill *track* holding N mutually-exclusive segments
41
+ * (the iOS-style segmented / tab toggle). The selected segment lifts onto a raised surface
42
+ * with a subtle shadow; the rest stay transparent. Promoted from the v1 AML console's
43
+ * `.lf-mode` mode switch so erevna/katalogos/kefi can share ONE toggle instead of
44
+ * hand-rolling two primary/ghost buttons.
45
+ *
46
+ * Contract discipline (same as the rest of `@dloizides/ui-layout`): NO FM/router/store/icon
47
+ * imports. Labels are pre-localized strings; every colour is read from the
48
+ * `@dloizides/ui-feedback` UiProvider theme, so it re-skins on tenant swap. Renders as a
49
+ * `tablist` of `tab`s (`accessibilityRole` + `accessibilityState.selected`, which
50
+ * react-native-web forwards to `role`/`aria-selected` on the DOM).
51
+ */
52
+
53
+ /** One selectable segment. `value` is what `onChange` emits when it's pressed. */
54
+ interface SegmentedOption<V extends string = string> {
55
+ label: string;
56
+ value: V;
57
+ testID?: string;
58
+ accessibilityLabel?: string;
59
+ accessibilityHint?: string;
60
+ }
61
+ interface SegmentedControlProps<V extends string = string> {
62
+ /** The segments, left → right. */
63
+ options: ReadonlyArray<SegmentedOption<V>>;
64
+ /** The currently-selected value. */
65
+ value: V;
66
+ /** Fired with a segment's `value` when it is pressed. */
67
+ onChange: (value: V) => void;
68
+ /** Accessible name for the whole group (the `tablist`). */
69
+ accessibilityLabel: string;
70
+ /** Optional style override merged LAST onto the track. */
71
+ style?: StyleProp<ViewStyle>;
72
+ testID?: string;
73
+ }
74
+ /**
75
+ * A segmented toggle. Generic over the value union so callers get a typed `onChange`
76
+ * (e.g. `SegmentedControl<'peps' | 'leaders'>`).
77
+ */
78
+ declare function SegmentedControl<V extends string = string>({ options, value, onChange, accessibilityLabel, style, testID, }: SegmentedControlProps<V>): React.ReactElement;
79
+
39
80
  /**
40
81
  * UpgradePrompt — shown when a free-tier user hits a feature limit. CTA navigates to the
41
82
  * billing route via the injected navigate (default route overridable).
@@ -118,6 +159,62 @@ interface ModalShellProps {
118
159
  }
119
160
  declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
120
161
 
162
+ /**
163
+ * Accordion — a themed expand/collapse disclosure group.
164
+ *
165
+ * Owns the open-item state and shares it with its {@link AccordionItem} children via
166
+ * context. Works controlled (`openIds` + `onOpenChange`) or uncontrolled
167
+ * (`defaultOpenIds`, plus per-item `defaultOpen`). `allowMultiple` (default) lets any
168
+ * number of items be open at once; set it false for single-open (radio-like) behaviour.
169
+ *
170
+ * Renders borderless so it drops cleanly inside a `Section` / `Card`.
171
+ */
172
+
173
+ interface AccordionProps {
174
+ /** `AccordionItem` children. */
175
+ children?: React.ReactNode;
176
+ /** Controlled open ids. When provided, the accordion is controlled. */
177
+ openIds?: readonly string[];
178
+ /** Initial open ids in uncontrolled mode. */
179
+ defaultOpenIds?: readonly string[];
180
+ /** Fired with the next open-id set whenever an item toggles. */
181
+ onOpenChange?: (openIds: string[]) => void;
182
+ /** Allow several items open at once (default true). False = single-open. */
183
+ allowMultiple?: boolean;
184
+ testID?: string;
185
+ style?: ViewStyle | ViewStyle[];
186
+ }
187
+ declare const Accordion: ({ children, openIds, defaultOpenIds, onOpenChange, allowMultiple, testID, style, }: AccordionProps) => React.ReactElement;
188
+
189
+ /**
190
+ * AccordionItem — one disclosure row: a pressable header (title left, optional right
191
+ * adornment/badge slot, a rotating chevron) plus a collapsible body region.
192
+ *
193
+ * Reads its open state + toggle from the enclosing {@link Accordion} via context.
194
+ */
195
+
196
+ interface AccordionItemProps {
197
+ /** Stable unique id used for open-state tracking + derived testIDs. */
198
+ id: string;
199
+ /** Header title — a string (rendered as themed text) or custom node. */
200
+ title: string | React.ReactNode;
201
+ /** Optional right-hand adornment (badge, count, icon…) shown before the chevron. */
202
+ right?: React.ReactNode;
203
+ /** Collapsible body content. */
204
+ children?: React.ReactNode;
205
+ /** Start open in uncontrolled mode (ignored when the container is controlled). */
206
+ defaultOpen?: boolean;
207
+ /** Disable toggling for this item. */
208
+ disabled?: boolean;
209
+ /** testID for the header button. Body = `${testID}-body`, chevron = `${testID}-chevron`. */
210
+ testID?: string;
211
+ /** Accessible name for the header button (defaults to `title` when it is a string). */
212
+ accessibilityLabel?: string;
213
+ /** Accessible hint for the header button. */
214
+ accessibilityHint?: string;
215
+ }
216
+ declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
217
+
121
218
  declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
122
219
 
123
220
  /** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
@@ -129,8 +226,9 @@ declare const LAYOUT_TEST_IDS: {
129
226
  readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
130
227
  readonly modalShell: "template-modal";
131
228
  readonly modalShellClose: "cancel-button";
229
+ readonly accordion: "accordion";
132
230
  };
133
231
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
134
232
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
135
233
 
136
- export { DEFAULT_BILLING_ROUTE, type DropdownOption, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
234
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, 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 };
package/dist/index.d.ts CHANGED
@@ -36,6 +36,47 @@ interface StatusBadgeProps {
36
36
  }
37
37
  declare const StatusBadge: ({ label, color, backgroundColor, testID, accessibilityLabel, accessibilityHint, }: StatusBadgeProps) => React.ReactElement;
38
38
 
39
+ /**
40
+ * SegmentedControl — a single rounded pill *track* holding N mutually-exclusive segments
41
+ * (the iOS-style segmented / tab toggle). The selected segment lifts onto a raised surface
42
+ * with a subtle shadow; the rest stay transparent. Promoted from the v1 AML console's
43
+ * `.lf-mode` mode switch so erevna/katalogos/kefi can share ONE toggle instead of
44
+ * hand-rolling two primary/ghost buttons.
45
+ *
46
+ * Contract discipline (same as the rest of `@dloizides/ui-layout`): NO FM/router/store/icon
47
+ * imports. Labels are pre-localized strings; every colour is read from the
48
+ * `@dloizides/ui-feedback` UiProvider theme, so it re-skins on tenant swap. Renders as a
49
+ * `tablist` of `tab`s (`accessibilityRole` + `accessibilityState.selected`, which
50
+ * react-native-web forwards to `role`/`aria-selected` on the DOM).
51
+ */
52
+
53
+ /** One selectable segment. `value` is what `onChange` emits when it's pressed. */
54
+ interface SegmentedOption<V extends string = string> {
55
+ label: string;
56
+ value: V;
57
+ testID?: string;
58
+ accessibilityLabel?: string;
59
+ accessibilityHint?: string;
60
+ }
61
+ interface SegmentedControlProps<V extends string = string> {
62
+ /** The segments, left → right. */
63
+ options: ReadonlyArray<SegmentedOption<V>>;
64
+ /** The currently-selected value. */
65
+ value: V;
66
+ /** Fired with a segment's `value` when it is pressed. */
67
+ onChange: (value: V) => void;
68
+ /** Accessible name for the whole group (the `tablist`). */
69
+ accessibilityLabel: string;
70
+ /** Optional style override merged LAST onto the track. */
71
+ style?: StyleProp<ViewStyle>;
72
+ testID?: string;
73
+ }
74
+ /**
75
+ * A segmented toggle. Generic over the value union so callers get a typed `onChange`
76
+ * (e.g. `SegmentedControl<'peps' | 'leaders'>`).
77
+ */
78
+ declare function SegmentedControl<V extends string = string>({ options, value, onChange, accessibilityLabel, style, testID, }: SegmentedControlProps<V>): React.ReactElement;
79
+
39
80
  /**
40
81
  * UpgradePrompt — shown when a free-tier user hits a feature limit. CTA navigates to the
41
82
  * billing route via the injected navigate (default route overridable).
@@ -118,6 +159,62 @@ interface ModalShellProps {
118
159
  }
119
160
  declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
120
161
 
162
+ /**
163
+ * Accordion — a themed expand/collapse disclosure group.
164
+ *
165
+ * Owns the open-item state and shares it with its {@link AccordionItem} children via
166
+ * context. Works controlled (`openIds` + `onOpenChange`) or uncontrolled
167
+ * (`defaultOpenIds`, plus per-item `defaultOpen`). `allowMultiple` (default) lets any
168
+ * number of items be open at once; set it false for single-open (radio-like) behaviour.
169
+ *
170
+ * Renders borderless so it drops cleanly inside a `Section` / `Card`.
171
+ */
172
+
173
+ interface AccordionProps {
174
+ /** `AccordionItem` children. */
175
+ children?: React.ReactNode;
176
+ /** Controlled open ids. When provided, the accordion is controlled. */
177
+ openIds?: readonly string[];
178
+ /** Initial open ids in uncontrolled mode. */
179
+ defaultOpenIds?: readonly string[];
180
+ /** Fired with the next open-id set whenever an item toggles. */
181
+ onOpenChange?: (openIds: string[]) => void;
182
+ /** Allow several items open at once (default true). False = single-open. */
183
+ allowMultiple?: boolean;
184
+ testID?: string;
185
+ style?: ViewStyle | ViewStyle[];
186
+ }
187
+ declare const Accordion: ({ children, openIds, defaultOpenIds, onOpenChange, allowMultiple, testID, style, }: AccordionProps) => React.ReactElement;
188
+
189
+ /**
190
+ * AccordionItem — one disclosure row: a pressable header (title left, optional right
191
+ * adornment/badge slot, a rotating chevron) plus a collapsible body region.
192
+ *
193
+ * Reads its open state + toggle from the enclosing {@link Accordion} via context.
194
+ */
195
+
196
+ interface AccordionItemProps {
197
+ /** Stable unique id used for open-state tracking + derived testIDs. */
198
+ id: string;
199
+ /** Header title — a string (rendered as themed text) or custom node. */
200
+ title: string | React.ReactNode;
201
+ /** Optional right-hand adornment (badge, count, icon…) shown before the chevron. */
202
+ right?: React.ReactNode;
203
+ /** Collapsible body content. */
204
+ children?: React.ReactNode;
205
+ /** Start open in uncontrolled mode (ignored when the container is controlled). */
206
+ defaultOpen?: boolean;
207
+ /** Disable toggling for this item. */
208
+ disabled?: boolean;
209
+ /** testID for the header button. Body = `${testID}-body`, chevron = `${testID}-chevron`. */
210
+ testID?: string;
211
+ /** Accessible name for the header button (defaults to `title` when it is a string). */
212
+ accessibilityLabel?: string;
213
+ /** Accessible hint for the header button. */
214
+ accessibilityHint?: string;
215
+ }
216
+ declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
217
+
121
218
  declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
122
219
 
123
220
  /** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
@@ -129,8 +226,9 @@ declare const LAYOUT_TEST_IDS: {
129
226
  readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
130
227
  readonly modalShell: "template-modal";
131
228
  readonly modalShellClose: "cancel-button";
229
+ readonly accordion: "accordion";
132
230
  };
133
231
  /** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
134
232
  declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
135
233
 
136
- export { DEFAULT_BILLING_ROUTE, type DropdownOption, DropdownVariant, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, ModalShell, type ModalShellProps, Section, type SectionProps, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
234
+ export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, 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 };