@dloizides/ui-layout 1.0.1 → 1.2.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 +23 -0
- package/README.md +30 -1
- package/dist/index.d.mts +53 -5
- package/dist/index.d.ts +53 -5
- package/dist/index.js +325 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +326 -67
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
- `ModalDropdown` can now render as an **inline anchored menu** (native `<select>` feel), not only a
|
|
6
|
+
modal. New `variant?: DropdownVariant` prop (`Menu` | `Modal`) selects the presentation per screen.
|
|
7
|
+
- **Responsive default** (when `variant` is omitted): inline `Menu` on wide/desktop web
|
|
8
|
+
(viewport ≥ 768px), `Modal` on narrow/mobile and on any native platform. An explicit `variant`
|
|
9
|
+
overrides the auto choice.
|
|
10
|
+
- The inline menu anchors under the trigger, is dismissible via click-outside / `Esc`, is
|
|
11
|
+
keyboard-navigable (↑/↓, `Home`/`End`, `Enter`), scrolls when long, and does not push layout.
|
|
12
|
+
The modal path is unchanged. Both variants share the same option-rendering/selection logic
|
|
13
|
+
(`OptionRow`), so nothing is duplicated.
|
|
14
|
+
- **Additive / backward-compatible**: existing `ModalDropdown` callers (erevna / katalogos / aml-v2)
|
|
15
|
+
keep their exact API and now get the inline-on-desktop menu automatically. New export:
|
|
16
|
+
`DropdownVariant` (a runtime enum — deliberately not `const enum`, which cannot cross a published
|
|
17
|
+
package boundary under `isolatedModules`).
|
|
18
|
+
|
|
19
|
+
## 1.1.0
|
|
20
|
+
|
|
21
|
+
- Add `ModalShell` — slide-up full-screen modal with a themed header (title + close) and scrollable body.
|
|
22
|
+
Composes `Heading` (this package) + `SvgIcon` (`@dloizides/ui-icons`). This was the batch-1 deferred
|
|
23
|
+
ModalShell, now landed (ui-icons + Heading both shared). Adds `@dloizides/ui-icons` + `react-native-svg`
|
|
24
|
+
as peers.
|
|
25
|
+
|
|
3
26
|
## 1.0.0
|
|
4
27
|
|
|
5
28
|
Initial release (Capability Wave C1, batch 5 — the ui-layout pivot after full settings-hub proved
|
package/README.md
CHANGED
|
@@ -11,9 +11,38 @@ Read theme + translations from the shared `@dloizides/ui-feedback` context (`use
|
|
|
11
11
|
| `Heading` | Themed section heading text. |
|
|
12
12
|
| `StatusBadge` | Status pill — caller supplies `label`/`color`/`backgroundColor`. |
|
|
13
13
|
| `UpgradePrompt` | Free-tier upgrade nudge; CTA navigates to the billing route via `useUi().navigate`. |
|
|
14
|
-
| `ModalDropdown` | Generic
|
|
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
|
+
| `DropdownVariant` | Enum (`Menu` / `Modal`) to force a `ModalDropdown` rendering variant. |
|
|
15
16
|
| `useFocusTrap` | Web keyboard focus-trap hook (no-op on native). |
|
|
16
17
|
|
|
18
|
+
### `ModalDropdown` variants
|
|
19
|
+
|
|
20
|
+
`ModalDropdown` picks its presentation automatically:
|
|
21
|
+
|
|
22
|
+
- **Wide / desktop web** (viewport ≥ 768px) → an **inline anchored menu** that opens directly
|
|
23
|
+
under the trigger (native `<select>` feel): dismissible via click-outside / `Esc`,
|
|
24
|
+
keyboard-navigable (↑/↓, `Home`/`End`, `Enter`), scrolls when long, and never pushes layout.
|
|
25
|
+
- **Narrow / mobile, or any native platform** → the original **modal** / bottom-sheet.
|
|
26
|
+
|
|
27
|
+
Pass `variant` to force either behaviour regardless of viewport — the prop overrides the auto choice:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { ModalDropdown, DropdownVariant } from '@dloizides/ui-layout';
|
|
31
|
+
|
|
32
|
+
// Responsive (default): inline menu on desktop, modal on mobile.
|
|
33
|
+
<ModalDropdown testID="risk" accessibilityLabel="Risk" accessibilityHint="Pick a risk level"
|
|
34
|
+
value={risk} options={riskOptions} onChange={setRisk} />
|
|
35
|
+
|
|
36
|
+
// Force the inline menu everywhere:
|
|
37
|
+
<ModalDropdown /* …props… */ variant={DropdownVariant.Menu} />
|
|
38
|
+
|
|
39
|
+
// Force the modal everywhere:
|
|
40
|
+
<ModalDropdown /* …props… */ variant={DropdownVariant.Modal} />
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The public API is additive — callers that never pass `variant` keep working and now
|
|
44
|
+
get the inline-on-desktop menu for free.
|
|
45
|
+
|
|
17
46
|
## Install
|
|
18
47
|
|
|
19
48
|
```bash
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import { ViewStyle, View } from 'react-native';
|
|
2
|
+
import { ViewStyle, StyleProp, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Section — a bordered card container that themes its border + surface.
|
|
@@ -54,14 +54,39 @@ interface UpgradePromptProps {
|
|
|
54
54
|
declare const UpgradePrompt: ({ requiredTier, currentTier, onDismiss, billingRoute, }: UpgradePromptProps) => React.ReactElement;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* How a {@link ModalDropdown} renders its list of options.
|
|
58
|
+
*
|
|
59
|
+
* Exported as a regular (non-`const`) enum on purpose: `const enum` values are
|
|
60
|
+
* inlined at compile time and cannot cross a published-package boundary when the
|
|
61
|
+
* consumer bundles with `isolatedModules` (esbuild / vite / babel — i.e. every
|
|
62
|
+
* app that consumes this package). A regular enum emits a runtime object that is
|
|
63
|
+
* safe to import and compare in any consumer.
|
|
59
64
|
*/
|
|
65
|
+
declare enum DropdownVariant {
|
|
66
|
+
/** Inline popover anchored directly under the trigger — the native `<select>` feel. */
|
|
67
|
+
Menu = "menu",
|
|
68
|
+
/** Full modal / bottom-sheet overlay with a scrim (the original behaviour). */
|
|
69
|
+
Modal = "modal"
|
|
70
|
+
}
|
|
60
71
|
|
|
72
|
+
/** Shared option shape for the ModalDropdown family (kept separate to avoid import cycles). */
|
|
61
73
|
interface DropdownOption<T> {
|
|
62
74
|
readonly label: string;
|
|
63
75
|
readonly value: T;
|
|
64
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ModalDropdown — generic dropdown selector (any value type via generics).
|
|
80
|
+
*
|
|
81
|
+
* Renders as either an inline anchored menu (web-native `<select>` feel) or a
|
|
82
|
+
* modal / bottom-sheet, selectable per screen via the `variant` prop. When
|
|
83
|
+
* `variant` is omitted the choice is **responsive**: inline menu on wide/desktop
|
|
84
|
+
* web, modal on narrow/mobile (and always modal on native). Existing callers that
|
|
85
|
+
* never passed `variant` therefore get the inline-on-desktop behaviour for free.
|
|
86
|
+
*
|
|
87
|
+
* Both variants share {@link OptionRow} for option rendering + selection.
|
|
88
|
+
*/
|
|
89
|
+
|
|
65
90
|
interface ModalDropdownProps<T> {
|
|
66
91
|
testID: string;
|
|
67
92
|
accessibilityLabel: string;
|
|
@@ -69,8 +94,29 @@ interface ModalDropdownProps<T> {
|
|
|
69
94
|
value: T;
|
|
70
95
|
options: ReadonlyArray<DropdownOption<T>>;
|
|
71
96
|
onChange: (value: T) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Force a rendering variant. When omitted the dropdown is **responsive**:
|
|
99
|
+
* an inline anchored menu on wide/desktop web, a modal on narrow/mobile
|
|
100
|
+
* (and always a modal on native). An explicit value overrides the auto choice.
|
|
101
|
+
*/
|
|
102
|
+
variant?: DropdownVariant;
|
|
103
|
+
}
|
|
104
|
+
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* ModalShell — a slide-up full-screen modal with a themed header (title + close button)
|
|
108
|
+
* and a scrollable body. Composes Heading (this package) + SvgIcon (@dloizides/ui-icons).
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
interface ModalShellProps {
|
|
112
|
+
visible: boolean;
|
|
113
|
+
onCancel: () => void;
|
|
114
|
+
title?: string | React.ReactNode;
|
|
115
|
+
children?: React.ReactNode;
|
|
116
|
+
contentStyle?: StyleProp<ViewStyle>;
|
|
117
|
+
showClose?: boolean;
|
|
72
118
|
}
|
|
73
|
-
declare const
|
|
119
|
+
declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
|
|
74
120
|
|
|
75
121
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
76
122
|
|
|
@@ -81,8 +127,10 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
81
127
|
readonly upgradePrompt: "upgrade-prompt";
|
|
82
128
|
readonly upgradePromptCta: "upgrade-prompt-cta";
|
|
83
129
|
readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
|
|
130
|
+
readonly modalShell: "template-modal";
|
|
131
|
+
readonly modalShellClose: "cancel-button";
|
|
84
132
|
};
|
|
85
133
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
86
134
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
87
135
|
|
|
88
|
-
export { DEFAULT_BILLING_ROUTE, type DropdownOption, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, Section, type SectionProps, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { RefObject } from 'react';
|
|
2
|
-
import { ViewStyle, View } from 'react-native';
|
|
2
|
+
import { ViewStyle, StyleProp, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Section — a bordered card container that themes its border + surface.
|
|
@@ -54,14 +54,39 @@ interface UpgradePromptProps {
|
|
|
54
54
|
declare const UpgradePrompt: ({ requiredTier, currentTier, onDismiss, billingRoute, }: UpgradePromptProps) => React.ReactElement;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* How a {@link ModalDropdown} renders its list of options.
|
|
58
|
+
*
|
|
59
|
+
* Exported as a regular (non-`const`) enum on purpose: `const enum` values are
|
|
60
|
+
* inlined at compile time and cannot cross a published-package boundary when the
|
|
61
|
+
* consumer bundles with `isolatedModules` (esbuild / vite / babel — i.e. every
|
|
62
|
+
* app that consumes this package). A regular enum emits a runtime object that is
|
|
63
|
+
* safe to import and compare in any consumer.
|
|
59
64
|
*/
|
|
65
|
+
declare enum DropdownVariant {
|
|
66
|
+
/** Inline popover anchored directly under the trigger — the native `<select>` feel. */
|
|
67
|
+
Menu = "menu",
|
|
68
|
+
/** Full modal / bottom-sheet overlay with a scrim (the original behaviour). */
|
|
69
|
+
Modal = "modal"
|
|
70
|
+
}
|
|
60
71
|
|
|
72
|
+
/** Shared option shape for the ModalDropdown family (kept separate to avoid import cycles). */
|
|
61
73
|
interface DropdownOption<T> {
|
|
62
74
|
readonly label: string;
|
|
63
75
|
readonly value: T;
|
|
64
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ModalDropdown — generic dropdown selector (any value type via generics).
|
|
80
|
+
*
|
|
81
|
+
* Renders as either an inline anchored menu (web-native `<select>` feel) or a
|
|
82
|
+
* modal / bottom-sheet, selectable per screen via the `variant` prop. When
|
|
83
|
+
* `variant` is omitted the choice is **responsive**: inline menu on wide/desktop
|
|
84
|
+
* web, modal on narrow/mobile (and always modal on native). Existing callers that
|
|
85
|
+
* never passed `variant` therefore get the inline-on-desktop behaviour for free.
|
|
86
|
+
*
|
|
87
|
+
* Both variants share {@link OptionRow} for option rendering + selection.
|
|
88
|
+
*/
|
|
89
|
+
|
|
65
90
|
interface ModalDropdownProps<T> {
|
|
66
91
|
testID: string;
|
|
67
92
|
accessibilityLabel: string;
|
|
@@ -69,8 +94,29 @@ interface ModalDropdownProps<T> {
|
|
|
69
94
|
value: T;
|
|
70
95
|
options: ReadonlyArray<DropdownOption<T>>;
|
|
71
96
|
onChange: (value: T) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Force a rendering variant. When omitted the dropdown is **responsive**:
|
|
99
|
+
* an inline anchored menu on wide/desktop web, a modal on narrow/mobile
|
|
100
|
+
* (and always a modal on native). An explicit value overrides the auto choice.
|
|
101
|
+
*/
|
|
102
|
+
variant?: DropdownVariant;
|
|
103
|
+
}
|
|
104
|
+
declare const ModalDropdown: <T extends string | number>({ testID, accessibilityLabel, accessibilityHint, value, options, onChange, variant, }: ModalDropdownProps<T>) => React.ReactElement;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* ModalShell — a slide-up full-screen modal with a themed header (title + close button)
|
|
108
|
+
* and a scrollable body. Composes Heading (this package) + SvgIcon (@dloizides/ui-icons).
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
interface ModalShellProps {
|
|
112
|
+
visible: boolean;
|
|
113
|
+
onCancel: () => void;
|
|
114
|
+
title?: string | React.ReactNode;
|
|
115
|
+
children?: React.ReactNode;
|
|
116
|
+
contentStyle?: StyleProp<ViewStyle>;
|
|
117
|
+
showClose?: boolean;
|
|
72
118
|
}
|
|
73
|
-
declare const
|
|
119
|
+
declare const ModalShell: ({ visible, onCancel, title, children, contentStyle, showClose, }: ModalShellProps) => React.ReactElement;
|
|
74
120
|
|
|
75
121
|
declare function useFocusTrap(containerRef: RefObject<View | null>, enabled: boolean): void;
|
|
76
122
|
|
|
@@ -81,8 +127,10 @@ declare const LAYOUT_TEST_IDS: {
|
|
|
81
127
|
readonly upgradePrompt: "upgrade-prompt";
|
|
82
128
|
readonly upgradePromptCta: "upgrade-prompt-cta";
|
|
83
129
|
readonly upgradePromptDismiss: "upgrade-prompt-dismiss";
|
|
130
|
+
readonly modalShell: "template-modal";
|
|
131
|
+
readonly modalShellClose: "cancel-button";
|
|
84
132
|
};
|
|
85
133
|
/** Route the UpgradePrompt CTA navigates to by default (the apps' billing settings path). */
|
|
86
134
|
declare const DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
87
135
|
|
|
88
|
-
export { DEFAULT_BILLING_ROUTE, type DropdownOption, Heading, type HeadingProps, LAYOUT_TEST_IDS, ModalDropdown, type ModalDropdownProps, Section, type SectionProps, StatusBadge, type StatusBadgeProps, UpgradePrompt, type UpgradePromptProps, useFocusTrap };
|
|
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 };
|