@dloizides/ui-layout 1.2.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/CHANGELOG.md +21 -0
- package/README.md +54 -0
- package/dist/index.d.mts +58 -1
- package/dist/index.d.ts +58 -1
- package/dist/index.js +234 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +211 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
- Add **`Accordion`** + **`AccordionItem`** — a themed expand/collapse disclosure group that
|
|
6
|
+
replaces per-app hand-rolled `<details>` / expanders (AML "More options" + expandable
|
|
7
|
+
matched-candidate rows, Erevna survey groups, Katalogos menu sections…).
|
|
8
|
+
- Compound API: an `Accordion` container owns the open state and shares it with `AccordionItem`
|
|
9
|
+
children via context. Each item = a pressable header (title left, optional `right`
|
|
10
|
+
adornment/badge slot, a rotating chevron) over a collapsible body `region`.
|
|
11
|
+
- **Controlled** (`openIds` + `onOpenChange`) **and uncontrolled** (`defaultOpenIds`, plus
|
|
12
|
+
per-item `defaultOpen`). `allowMultiple` (default `true`) vs single-open. Per-item `disabled`.
|
|
13
|
+
- **a11y**: header is an accessible `button` (`accessibilityRole="button"`,
|
|
14
|
+
`accessibilityState={{ expanded }}`, web `aria-expanded` + `aria-controls`); body is a
|
|
15
|
+
`role="region"`. Renders as a native `<button>`, so **Enter / Space toggle** it.
|
|
16
|
+
- **Themed** entirely from the `@dloizides/ui-feedback` theme (border / surface / text colours),
|
|
17
|
+
no hardcoded palette; renders borderless so it nests inside a `Section` / `Card`.
|
|
18
|
+
- **Animated** open/close via a guarded `LayoutAnimation` (web- and native-safe no-op fallback,
|
|
19
|
+
never throws) + an `Animated` chevron rotation. Hook-safe (lazy `useState`, no ref reads in render).
|
|
20
|
+
- **Additive / backward-compatible**: purely new exports (`Accordion`, `AccordionItem`,
|
|
21
|
+
`AccordionProps`, `AccordionItemProps`). Existing consumers (erevna / katalogos / aml-v2) are
|
|
22
|
+
unaffected.
|
|
23
|
+
|
|
3
24
|
## 1.2.0
|
|
4
25
|
|
|
5
26
|
- `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
|
@@ -118,6 +118,62 @@ interface ModalShellProps {
|
|
|
118
118
|
}
|
|
119
119
|
declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Accordion — a themed expand/collapse disclosure group.
|
|
123
|
+
*
|
|
124
|
+
* Owns the open-item state and shares it with its {@link AccordionItem} children via
|
|
125
|
+
* context. Works controlled (`openIds` + `onOpenChange`) or uncontrolled
|
|
126
|
+
* (`defaultOpenIds`, plus per-item `defaultOpen`). `allowMultiple` (default) lets any
|
|
127
|
+
* number of items be open at once; set it false for single-open (radio-like) behaviour.
|
|
128
|
+
*
|
|
129
|
+
* Renders borderless so it drops cleanly inside a `Section` / `Card`.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
interface AccordionProps {
|
|
133
|
+
/** `AccordionItem` children. */
|
|
134
|
+
children?: React.ReactNode;
|
|
135
|
+
/** Controlled open ids. When provided, the accordion is controlled. */
|
|
136
|
+
openIds?: readonly string[];
|
|
137
|
+
/** Initial open ids in uncontrolled mode. */
|
|
138
|
+
defaultOpenIds?: readonly string[];
|
|
139
|
+
/** Fired with the next open-id set whenever an item toggles. */
|
|
140
|
+
onOpenChange?: (openIds: string[]) => void;
|
|
141
|
+
/** Allow several items open at once (default true). False = single-open. */
|
|
142
|
+
allowMultiple?: boolean;
|
|
143
|
+
testID?: string;
|
|
144
|
+
style?: ViewStyle | ViewStyle[];
|
|
145
|
+
}
|
|
146
|
+
declare const Accordion: ({ children, openIds, defaultOpenIds, onOpenChange, allowMultiple, testID, style, }: AccordionProps) => React.ReactElement;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* AccordionItem — one disclosure row: a pressable header (title left, optional right
|
|
150
|
+
* adornment/badge slot, a rotating chevron) plus a collapsible body region.
|
|
151
|
+
*
|
|
152
|
+
* Reads its open state + toggle from the enclosing {@link Accordion} via context.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
interface AccordionItemProps {
|
|
156
|
+
/** Stable unique id used for open-state tracking + derived testIDs. */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Header title — a string (rendered as themed text) or custom node. */
|
|
159
|
+
title: string | React.ReactNode;
|
|
160
|
+
/** Optional right-hand adornment (badge, count, icon…) shown before the chevron. */
|
|
161
|
+
right?: React.ReactNode;
|
|
162
|
+
/** Collapsible body content. */
|
|
163
|
+
children?: React.ReactNode;
|
|
164
|
+
/** Start open in uncontrolled mode (ignored when the container is controlled). */
|
|
165
|
+
defaultOpen?: boolean;
|
|
166
|
+
/** Disable toggling for this item. */
|
|
167
|
+
disabled?: boolean;
|
|
168
|
+
/** testID for the header button. Body = `${testID}-body`, chevron = `${testID}-chevron`. */
|
|
169
|
+
testID?: string;
|
|
170
|
+
/** Accessible name for the header button (defaults to `title` when it is a string). */
|
|
171
|
+
accessibilityLabel?: string;
|
|
172
|
+
/** Accessible hint for the header button. */
|
|
173
|
+
accessibilityHint?: string;
|
|
174
|
+
}
|
|
175
|
+
declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
|
|
176
|
+
|
|
121
177
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
122
178
|
|
|
123
179
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -129,8 +185,9 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
129
185
|
readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
|
|
130
186
|
readonly modalShell: "template-modal";
|
|
131
187
|
readonly modalShellClose: "cancel-button";
|
|
188
|
+
readonly accordion: "accordion";
|
|
132
189
|
};
|
|
133
190
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
134
191
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
135
192
|
|
|
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 };
|
|
193
|
+
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, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
package/dist/index.d.ts
CHANGED
|
@@ -118,6 +118,62 @@ interface ModalShellProps {
|
|
|
118
118
|
}
|
|
119
119
|
declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Accordion — a themed expand/collapse disclosure group.
|
|
123
|
+
*
|
|
124
|
+
* Owns the open-item state and shares it with its {@link AccordionItem} children via
|
|
125
|
+
* context. Works controlled (`openIds` + `onOpenChange`) or uncontrolled
|
|
126
|
+
* (`defaultOpenIds`, plus per-item `defaultOpen`). `allowMultiple` (default) lets any
|
|
127
|
+
* number of items be open at once; set it false for single-open (radio-like) behaviour.
|
|
128
|
+
*
|
|
129
|
+
* Renders borderless so it drops cleanly inside a `Section` / `Card`.
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
interface AccordionProps {
|
|
133
|
+
/** `AccordionItem` children. */
|
|
134
|
+
children?: React.ReactNode;
|
|
135
|
+
/** Controlled open ids. When provided, the accordion is controlled. */
|
|
136
|
+
openIds?: readonly string[];
|
|
137
|
+
/** Initial open ids in uncontrolled mode. */
|
|
138
|
+
defaultOpenIds?: readonly string[];
|
|
139
|
+
/** Fired with the next open-id set whenever an item toggles. */
|
|
140
|
+
onOpenChange?: (openIds: string[]) => void;
|
|
141
|
+
/** Allow several items open at once (default true). False = single-open. */
|
|
142
|
+
allowMultiple?: boolean;
|
|
143
|
+
testID?: string;
|
|
144
|
+
style?: ViewStyle | ViewStyle[];
|
|
145
|
+
}
|
|
146
|
+
declare const Accordion: ({ children, openIds, defaultOpenIds, onOpenChange, allowMultiple, testID, style, }: AccordionProps) => React.ReactElement;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* AccordionItem — one disclosure row: a pressable header (title left, optional right
|
|
150
|
+
* adornment/badge slot, a rotating chevron) plus a collapsible body region.
|
|
151
|
+
*
|
|
152
|
+
* Reads its open state + toggle from the enclosing {@link Accordion} via context.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
interface AccordionItemProps {
|
|
156
|
+
/** Stable unique id used for open-state tracking + derived testIDs. */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Header title — a string (rendered as themed text) or custom node. */
|
|
159
|
+
title: string | React.ReactNode;
|
|
160
|
+
/** Optional right-hand adornment (badge, count, icon…) shown before the chevron. */
|
|
161
|
+
right?: React.ReactNode;
|
|
162
|
+
/** Collapsible body content. */
|
|
163
|
+
children?: React.ReactNode;
|
|
164
|
+
/** Start open in uncontrolled mode (ignored when the container is controlled). */
|
|
165
|
+
defaultOpen?: boolean;
|
|
166
|
+
/** Disable toggling for this item. */
|
|
167
|
+
disabled?: boolean;
|
|
168
|
+
/** testID for the header button. Body = `${testID}-body`, chevron = `${testID}-chevron`. */
|
|
169
|
+
testID?: string;
|
|
170
|
+
/** Accessible name for the header button (defaults to `title` when it is a string). */
|
|
171
|
+
accessibilityLabel?: string;
|
|
172
|
+
/** Accessible hint for the header button. */
|
|
173
|
+
accessibilityHint?: string;
|
|
174
|
+
}
|
|
175
|
+
declare const AccordionItem: ({ id, title, right, children, defaultOpen: _defaultOpen, disabled, testID, accessibilityLabel, accessibilityHint, }: AccordionItemProps) => React.ReactElement;
|
|
176
|
+
|
|
121
177
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
122
178
|
|
|
123
179
|
/** Default testIDs — match the apps' existing values so Playwright selectors keep working. */
|
|
@@ -129,8 +185,9 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
129
185
|
readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
|
|
130
186
|
readonly modalShell: "template-modal";
|
|
131
187
|
readonly modalShellClose: "cancel-button";
|
|
188
|
+
readonly accordion: "accordion";
|
|
132
189
|
};
|
|
133
190
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
134
191
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
135
192
|
|
|
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 };
|
|
193
|
+
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, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
81
|
-
const dynamicText =
|
|
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 =
|
|
204
|
-
|
|
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;
|
|
@@ -246,7 +247,7 @@ var OptionRow = ({
|
|
|
246
247
|
}) => {
|
|
247
248
|
const { theme, t } = uiFeedback.useUi();
|
|
248
249
|
const { colors } = theme;
|
|
249
|
-
const handlePress =
|
|
250
|
+
const handlePress = React8.useCallback(() => {
|
|
250
251
|
onSelect();
|
|
251
252
|
}, [onSelect]);
|
|
252
253
|
const isActive = isSelected || isHighlighted;
|
|
@@ -305,7 +306,7 @@ function buildKeyHandler(params) {
|
|
|
305
306
|
}
|
|
306
307
|
function useMenuKeyboard(params) {
|
|
307
308
|
const { containerRef, enabled, onClose } = params;
|
|
308
|
-
|
|
309
|
+
React8.useEffect(() => {
|
|
309
310
|
if (reactNative.Platform.OS !== "web" || !enabled) return;
|
|
310
311
|
const onKeyDown = buildKeyHandler(params);
|
|
311
312
|
const onMouseDown = (event) => {
|
|
@@ -357,19 +358,19 @@ var InlineMenu = ({
|
|
|
357
358
|
}) => {
|
|
358
359
|
const { theme } = uiFeedback.useUi();
|
|
359
360
|
const { colors } = theme;
|
|
360
|
-
const selectedIndex =
|
|
361
|
+
const selectedIndex = React8.useMemo(
|
|
361
362
|
() => Math.max(0, options.findIndex((opt) => opt.value === value)),
|
|
362
363
|
[options, value]
|
|
363
364
|
);
|
|
364
|
-
const [highlightedIndex, setHighlightedIndex] =
|
|
365
|
-
const selectAt =
|
|
365
|
+
const [highlightedIndex, setHighlightedIndex] = React8.useState(() => selectedIndex);
|
|
366
|
+
const selectAt = React8.useCallback(
|
|
366
367
|
(index) => {
|
|
367
368
|
const option = options[index];
|
|
368
369
|
if (option !== void 0) onSelect(option.value);
|
|
369
370
|
},
|
|
370
371
|
[options, onSelect]
|
|
371
372
|
);
|
|
372
|
-
const selectHighlighted =
|
|
373
|
+
const selectHighlighted = React8.useCallback(
|
|
373
374
|
() => {
|
|
374
375
|
selectAt(highlightedIndex);
|
|
375
376
|
},
|
|
@@ -383,7 +384,7 @@ var InlineMenu = ({
|
|
|
383
384
|
onSelectHighlighted: selectHighlighted,
|
|
384
385
|
onClose
|
|
385
386
|
});
|
|
386
|
-
const popoverStyle =
|
|
387
|
+
const popoverStyle = React8.useMemo(
|
|
387
388
|
() => [styles6.popover, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
388
389
|
[colors.border, colors.surface]
|
|
389
390
|
);
|
|
@@ -462,36 +463,36 @@ var ModalDropdown = ({
|
|
|
462
463
|
const { colors } = theme;
|
|
463
464
|
const resolvedVariant = useResolvedDropdownVariant(variant);
|
|
464
465
|
const isMenu = resolvedVariant === "menu" /* Menu */;
|
|
465
|
-
const [isOpen, setIsOpen] =
|
|
466
|
-
const anchorRef =
|
|
467
|
-
const dialogRef =
|
|
466
|
+
const [isOpen, setIsOpen] = React8.useState(false);
|
|
467
|
+
const anchorRef = React8.useRef(null);
|
|
468
|
+
const dialogRef = React8.useRef(null);
|
|
468
469
|
useFocusTrap(dialogRef, isOpen && !isMenu);
|
|
469
|
-
const selectedLabel =
|
|
470
|
+
const selectedLabel = React8.useMemo(() => {
|
|
470
471
|
const found = options.find((opt) => opt.value === value);
|
|
471
472
|
return found?.label ?? t("common.selectPlaceholder");
|
|
472
473
|
}, [options, value, t]);
|
|
473
|
-
const handleToggle =
|
|
474
|
+
const handleToggle = React8.useCallback(() => {
|
|
474
475
|
setIsOpen((prev) => !prev);
|
|
475
476
|
}, []);
|
|
476
|
-
const handleClose =
|
|
477
|
+
const handleClose = React8.useCallback(() => {
|
|
477
478
|
setIsOpen(false);
|
|
478
479
|
}, []);
|
|
479
|
-
const handleSelect =
|
|
480
|
+
const handleSelect = React8.useCallback(
|
|
480
481
|
(optionValue) => {
|
|
481
482
|
onChange(optionValue);
|
|
482
483
|
setIsOpen(false);
|
|
483
484
|
},
|
|
484
485
|
[onChange]
|
|
485
486
|
);
|
|
486
|
-
const containerStyle =
|
|
487
|
+
const containerStyle = React8.useMemo(
|
|
487
488
|
() => [styles7.container, { borderColor: colors.border, backgroundColor: colors.surface }],
|
|
488
489
|
[colors.border, colors.surface]
|
|
489
490
|
);
|
|
490
|
-
const modalContentStyle =
|
|
491
|
+
const modalContentStyle = React8.useMemo(
|
|
491
492
|
() => [styles7.modalContent, { backgroundColor: colors.surface }],
|
|
492
493
|
[colors.surface]
|
|
493
494
|
);
|
|
494
|
-
const renderModalOption =
|
|
495
|
+
const renderModalOption = React8.useCallback(
|
|
495
496
|
({ item }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
496
497
|
OptionRow,
|
|
497
498
|
{
|
|
@@ -503,7 +504,7 @@ var ModalDropdown = ({
|
|
|
503
504
|
),
|
|
504
505
|
[handleSelect, testID, value]
|
|
505
506
|
);
|
|
506
|
-
const keyExtractor =
|
|
507
|
+
const keyExtractor = React8.useCallback((item) => String(item.value), []);
|
|
507
508
|
return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: styles7.anchor, children: [
|
|
508
509
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
509
510
|
reactNative.TouchableOpacity,
|
|
@@ -582,7 +583,7 @@ var ModalShell = ({
|
|
|
582
583
|
showClose = true
|
|
583
584
|
}) => {
|
|
584
585
|
const { theme, t } = uiFeedback.useUi();
|
|
585
|
-
const containerStyle =
|
|
586
|
+
const containerStyle = React8__default.default.useMemo(
|
|
586
587
|
() => [styles8.container, { backgroundColor: theme.colors.background }, contentStyle],
|
|
587
588
|
[theme.colors.background, contentStyle]
|
|
588
589
|
);
|
|
@@ -625,7 +626,212 @@ var ModalShell = ({
|
|
|
625
626
|
}
|
|
626
627
|
);
|
|
627
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
|
+
};
|
|
628
832
|
|
|
833
|
+
exports.Accordion = Accordion;
|
|
834
|
+
exports.AccordionItem = AccordionItem;
|
|
629
835
|
exports.DEFAULT_BILLING_ROUTE = DEFAULT_BILLING_ROUTE;
|
|
630
836
|
exports.DropdownVariant = DropdownVariant;
|
|
631
837
|
exports.Heading = Heading;
|