@dloizides/ui-layout 1.41.0 → 1.43.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/dist/index.d.mts +34 -3
- package/dist/index.d.ts +34 -3
- package/dist/index.js +177 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React14, { createContext, useMemo, useState, useRef, useEffect, useCallback, useContext, useLayoutEffect } from 'react';
|
|
2
|
-
import { StyleSheet, Platform, View, Text, useWindowDimensions, Modal as Modal$1, Animated,
|
|
2
|
+
import { StyleSheet, Platform, View, Text, useWindowDimensions, Modal as Modal$1, Animated, ScrollView, TouchableOpacity, Pressable, FlatList, Easing } from 'react-native';
|
|
3
3
|
import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { IconButton, Button } from '@dloizides/ui-buttons';
|
|
@@ -103,10 +103,13 @@ var LAYOUT_TEST_IDS = {
|
|
|
103
103
|
bottomSheet: "bottom-sheet",
|
|
104
104
|
/** Default base testID for `ConfirmDialog`; Confirm/Cancel are `confirm-dialog-{confirm,cancel}`. */
|
|
105
105
|
confirmDialog: "confirm-dialog",
|
|
106
|
+
/** Default base testID for `FormDialog`: `form-dialog`, `form-save`, `form-cancel`. */
|
|
107
|
+
formDialog: "form",
|
|
106
108
|
accordion: "accordion",
|
|
107
109
|
/** Default testID for the `BuildInfoFooter` caption (`v<version>`). */
|
|
108
110
|
buildInfoFooter: "build-info-footer"
|
|
109
111
|
};
|
|
112
|
+
var MODAL_FOOTER_STACK_BELOW = 400;
|
|
110
113
|
var DEFAULT_BILLING_ROUTE = "/settings/billing";
|
|
111
114
|
var LAYOUT_I18N = {
|
|
112
115
|
/** Placeholder shown by `ModalDropdown` when no option matches the current value. */
|
|
@@ -176,6 +179,9 @@ var WEB_PLATFORM = "web";
|
|
|
176
179
|
function isWideWebViewport(width, platformOS, breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
|
|
177
180
|
return platformOS === WEB_PLATFORM && width >= breakpoint;
|
|
178
181
|
}
|
|
182
|
+
function isModalFooterStacked(width) {
|
|
183
|
+
return width < MODAL_FOOTER_STACK_BELOW;
|
|
184
|
+
}
|
|
179
185
|
|
|
180
186
|
// src/hooks/useIsWideViewport.ts
|
|
181
187
|
function useIsWideViewport(breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
|
|
@@ -414,8 +420,14 @@ function getFocusableElements(container) {
|
|
|
414
420
|
function savePreviousFocus() {
|
|
415
421
|
return document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
416
422
|
}
|
|
423
|
+
var MAX_ATTACH_FRAMES = 10;
|
|
424
|
+
function findNamed(domNode, initialFocusTestID) {
|
|
425
|
+
if (initialFocusTestID === void 0) return null;
|
|
426
|
+
const selector = `[data-testid="${initialFocusTestID}"]`;
|
|
427
|
+
return domNode.matches(selector) ? domNode : domNode.querySelector(selector);
|
|
428
|
+
}
|
|
417
429
|
function focusInitial(domNode, initialFocusTestID) {
|
|
418
|
-
const named =
|
|
430
|
+
const named = findNamed(domNode, initialFocusTestID);
|
|
419
431
|
if (named) {
|
|
420
432
|
named.focus();
|
|
421
433
|
return;
|
|
@@ -449,15 +461,29 @@ function useFocusTrap(containerRef, enabled, initialFocusTestID) {
|
|
|
449
461
|
const previousFocusRef = useRef(null);
|
|
450
462
|
useEffect(() => {
|
|
451
463
|
if (Platform.OS !== "web" || !enabled) return;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
464
|
+
let domNode = null;
|
|
465
|
+
let frame = 0;
|
|
466
|
+
let attempts = 0;
|
|
467
|
+
const listener = (e) => {
|
|
468
|
+
if (domNode) handleKeyDown(domNode, e);
|
|
469
|
+
};
|
|
470
|
+
const attach = () => {
|
|
471
|
+
const node = containerRef.current;
|
|
472
|
+
if (!node) {
|
|
473
|
+
attempts += 1;
|
|
474
|
+
if (attempts <= MAX_ATTACH_FRAMES) frame = requestAnimationFrame(attach);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
domNode = node;
|
|
478
|
+
const previous = savePreviousFocus();
|
|
479
|
+
previousFocusRef.current = previous !== null && node.contains(previous) ? null : previous;
|
|
480
|
+
queueMicrotask(() => focusInitial(node, initialFocusTestID));
|
|
481
|
+
node.addEventListener("keydown", listener);
|
|
482
|
+
};
|
|
483
|
+
attach();
|
|
459
484
|
return () => {
|
|
460
|
-
|
|
485
|
+
cancelAnimationFrame(frame);
|
|
486
|
+
domNode?.removeEventListener("keydown", listener);
|
|
461
487
|
previousFocusRef.current?.focus();
|
|
462
488
|
previousFocusRef.current = null;
|
|
463
489
|
};
|
|
@@ -479,6 +505,7 @@ var DIALOG_RADIUS = 12;
|
|
|
479
505
|
var DIALOG_PADDING = 16;
|
|
480
506
|
var HEADER_GAP = 12;
|
|
481
507
|
var FOOTER_MARGIN = 16;
|
|
508
|
+
var FOOTER_GAP = 12;
|
|
482
509
|
var HEADER_MARGIN = 12;
|
|
483
510
|
var DIALOG_MAX_HEIGHT = "90%";
|
|
484
511
|
var PANEL_ENTER_SCALE = 0.96;
|
|
@@ -495,7 +522,9 @@ var styles6 = StyleSheet.create({
|
|
|
495
522
|
// react-native-web, which is why the fade is driven by `Animated` instead. `pointerEvents` lives
|
|
496
523
|
// in style (not the deprecated prop) so taps fall through to the sibling tap-catcher below.
|
|
497
524
|
scrim: { backgroundColor: MODAL_OVERLAY_COLOR, pointerEvents: "none" },
|
|
525
|
+
backdrop: { zIndex: 0 },
|
|
498
526
|
dialog: {
|
|
527
|
+
zIndex: 1,
|
|
499
528
|
width: "100%",
|
|
500
529
|
borderRadius: DIALOG_RADIUS,
|
|
501
530
|
padding: DIALOG_PADDING,
|
|
@@ -510,8 +539,27 @@ var styles6 = StyleSheet.create({
|
|
|
510
539
|
},
|
|
511
540
|
// Occupies the header's leading space so the ✕ pins to the trailing edge even without a title.
|
|
512
541
|
titleWrap: { flex: 1 },
|
|
513
|
-
|
|
542
|
+
footerRow: {
|
|
543
|
+
marginTop: FOOTER_MARGIN,
|
|
544
|
+
flexDirection: "row",
|
|
545
|
+
flexWrap: "wrap",
|
|
546
|
+
justifyContent: "flex-end",
|
|
547
|
+
alignItems: "center",
|
|
548
|
+
columnGap: FOOTER_GAP,
|
|
549
|
+
rowGap: FOOTER_GAP
|
|
550
|
+
},
|
|
551
|
+
footerStack: {
|
|
552
|
+
marginTop: FOOTER_MARGIN,
|
|
553
|
+
flexDirection: "column-reverse",
|
|
554
|
+
alignItems: "stretch",
|
|
555
|
+
rowGap: FOOTER_GAP
|
|
556
|
+
}
|
|
514
557
|
});
|
|
558
|
+
var ModalFooter = ({ children, testID }) => {
|
|
559
|
+
const { width } = useWindowDimensions();
|
|
560
|
+
const style = isModalFooterStacked(width) ? styles6.footerStack : styles6.footerRow;
|
|
561
|
+
return /* @__PURE__ */ jsx(View, { style, testID, children });
|
|
562
|
+
};
|
|
515
563
|
var Modal = ({
|
|
516
564
|
visible,
|
|
517
565
|
onClose,
|
|
@@ -539,6 +587,7 @@ var Modal = ({
|
|
|
539
587
|
[theme.colors.surface, size]
|
|
540
588
|
);
|
|
541
589
|
const hasHeader = title !== void 0 || showClose;
|
|
590
|
+
const focusesDialog = initialFocusTestID === testID;
|
|
542
591
|
const hardwareBackClose = Platform.OS === "web" ? void 0 : onClose;
|
|
543
592
|
return /* @__PURE__ */ jsx(Modal$1, { transparent: true, visible: mounted, onRequestClose: hardwareBackClose, children: /* @__PURE__ */ jsxs(View, { style: styles6.overlay, children: [
|
|
544
593
|
/* @__PURE__ */ jsx(
|
|
@@ -547,19 +596,6 @@ var Modal = ({
|
|
|
547
596
|
style: [StyleSheet.absoluteFill, styles6.scrim, { opacity: backdrop.style.opacity }]
|
|
548
597
|
}
|
|
549
598
|
),
|
|
550
|
-
/* @__PURE__ */ jsx(
|
|
551
|
-
TouchableOpacity,
|
|
552
|
-
{
|
|
553
|
-
accessible: true,
|
|
554
|
-
accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
|
|
555
|
-
accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
|
|
556
|
-
accessibilityRole: "button",
|
|
557
|
-
activeOpacity: 1,
|
|
558
|
-
style: StyleSheet.absoluteFill,
|
|
559
|
-
testID: `${testID}-backdrop`,
|
|
560
|
-
onPress: onClose
|
|
561
|
-
}
|
|
562
|
-
),
|
|
563
599
|
/* @__PURE__ */ jsxs(
|
|
564
600
|
Animated.View,
|
|
565
601
|
{
|
|
@@ -568,6 +604,7 @@ var Modal = ({
|
|
|
568
604
|
"aria-label": accessibleName,
|
|
569
605
|
role: "dialog",
|
|
570
606
|
style: [dialogStyle, panel.style],
|
|
607
|
+
tabIndex: focusesDialog ? -1 : void 0,
|
|
571
608
|
testID,
|
|
572
609
|
children: [
|
|
573
610
|
hasHeader ? /* @__PURE__ */ jsxs(View, { style: styles6.headerRow, children: [
|
|
@@ -588,9 +625,23 @@ var Modal = ({
|
|
|
588
625
|
) : null
|
|
589
626
|
] }) : null,
|
|
590
627
|
/* @__PURE__ */ jsx(ScrollView, { children }),
|
|
591
|
-
footer !== void 0 ? /* @__PURE__ */ jsx(
|
|
628
|
+
footer !== void 0 ? /* @__PURE__ */ jsx(ModalFooter, { testID: `${testID}-footer`, children: footer }) : null
|
|
592
629
|
]
|
|
593
630
|
}
|
|
631
|
+
),
|
|
632
|
+
/* @__PURE__ */ jsx(
|
|
633
|
+
TouchableOpacity,
|
|
634
|
+
{
|
|
635
|
+
accessible: true,
|
|
636
|
+
accessibilityHint: t(LAYOUT_I18N.dismissDropdownHint),
|
|
637
|
+
accessibilityLabel: t(LAYOUT_I18N.dismissDropdown),
|
|
638
|
+
accessibilityRole: "button",
|
|
639
|
+
activeOpacity: 1,
|
|
640
|
+
style: [StyleSheet.absoluteFill, styles6.backdrop],
|
|
641
|
+
focusable: false,
|
|
642
|
+
testID: `${testID}-backdrop`,
|
|
643
|
+
onPress: onClose
|
|
644
|
+
}
|
|
594
645
|
)
|
|
595
646
|
] }) });
|
|
596
647
|
};
|
|
@@ -2018,12 +2069,18 @@ var BottomSheet = ({
|
|
|
2018
2069
|
)
|
|
2019
2070
|
] }) });
|
|
2020
2071
|
};
|
|
2072
|
+
|
|
2073
|
+
// src/Modal/ConfirmDialogFocus.ts
|
|
2074
|
+
var ConfirmDialogFocus = /* @__PURE__ */ ((ConfirmDialogFocus2) => {
|
|
2075
|
+
ConfirmDialogFocus2["Cancel"] = "cancel";
|
|
2076
|
+
ConfirmDialogFocus2["Confirm"] = "confirm";
|
|
2077
|
+
ConfirmDialogFocus2["None"] = "none";
|
|
2078
|
+
return ConfirmDialogFocus2;
|
|
2079
|
+
})(ConfirmDialogFocus || {});
|
|
2021
2080
|
var MESSAGE_FONT_SIZE2 = 14;
|
|
2022
2081
|
var MESSAGE_LINE_HEIGHT = 20;
|
|
2023
|
-
var BUTTON_GAP = 12;
|
|
2024
2082
|
var styles18 = StyleSheet.create({
|
|
2025
|
-
message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT }
|
|
2026
|
-
footer: { flexDirection: "row", justifyContent: "flex-end", columnGap: BUTTON_GAP }
|
|
2083
|
+
message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT }
|
|
2027
2084
|
});
|
|
2028
2085
|
var ConfirmDialog = ({
|
|
2029
2086
|
visible,
|
|
@@ -2035,12 +2092,18 @@ var ConfirmDialog = ({
|
|
|
2035
2092
|
onConfirm,
|
|
2036
2093
|
onCancel,
|
|
2037
2094
|
busy = false,
|
|
2095
|
+
initialFocus = "cancel" /* Cancel */,
|
|
2038
2096
|
testID = LAYOUT_TEST_IDS.confirmDialog
|
|
2039
2097
|
}) => {
|
|
2040
2098
|
const { theme, t } = useUi();
|
|
2041
2099
|
const resolvedConfirm = confirmLabel ?? t(LAYOUT_I18N.confirm);
|
|
2042
2100
|
const resolvedCancel = cancelLabel ?? t(LAYOUT_I18N.cancel);
|
|
2043
|
-
const
|
|
2101
|
+
const focusTestID = {
|
|
2102
|
+
["cancel" /* Cancel */]: `${testID}-cancel`,
|
|
2103
|
+
["confirm" /* Confirm */]: `${testID}-confirm`,
|
|
2104
|
+
["none" /* None */]: testID
|
|
2105
|
+
};
|
|
2106
|
+
const footer = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2044
2107
|
/* @__PURE__ */ jsx(
|
|
2045
2108
|
Button,
|
|
2046
2109
|
{
|
|
@@ -2070,6 +2133,7 @@ var ConfirmDialog = ({
|
|
|
2070
2133
|
Modal,
|
|
2071
2134
|
{
|
|
2072
2135
|
footer,
|
|
2136
|
+
initialFocusTestID: focusTestID[initialFocus],
|
|
2073
2137
|
showClose: false,
|
|
2074
2138
|
size: "sm",
|
|
2075
2139
|
testID,
|
|
@@ -2080,6 +2144,87 @@ var ConfirmDialog = ({
|
|
|
2080
2144
|
}
|
|
2081
2145
|
);
|
|
2082
2146
|
};
|
|
2147
|
+
var FIELD_SELECTOR = "input:not([disabled]), textarea:not([disabled]), select:not([disabled])";
|
|
2148
|
+
var FORM_STYLE = { display: "contents" };
|
|
2149
|
+
var WebFormBody = ({ children, visible, onSubmit }) => {
|
|
2150
|
+
const formRef = useRef(null);
|
|
2151
|
+
useEffect(() => {
|
|
2152
|
+
if (Platform.OS !== "web" || !visible) return;
|
|
2153
|
+
formRef.current?.querySelector(FIELD_SELECTOR)?.focus();
|
|
2154
|
+
}, [visible]);
|
|
2155
|
+
const handleSubmit = useCallback(
|
|
2156
|
+
(event) => {
|
|
2157
|
+
event.preventDefault();
|
|
2158
|
+
onSubmit();
|
|
2159
|
+
},
|
|
2160
|
+
[onSubmit]
|
|
2161
|
+
);
|
|
2162
|
+
if (Platform.OS !== "web") return /* @__PURE__ */ jsx(Fragment, { children });
|
|
2163
|
+
return React14.createElement(
|
|
2164
|
+
"form",
|
|
2165
|
+
{ ref: formRef, noValidate: true, style: FORM_STYLE, onSubmit: handleSubmit },
|
|
2166
|
+
children,
|
|
2167
|
+
React14.createElement("button", { type: "submit", hidden: true, tabIndex: -1, "aria-hidden": true })
|
|
2168
|
+
);
|
|
2169
|
+
};
|
|
2170
|
+
var FormDialogActions = (props) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2171
|
+
/* @__PURE__ */ jsx(
|
|
2172
|
+
Button,
|
|
2173
|
+
{
|
|
2174
|
+
accessibilityHint: props.cancelHint,
|
|
2175
|
+
accessibilityLabel: props.cancelLabel,
|
|
2176
|
+
disabled: props.loading,
|
|
2177
|
+
label: props.cancelLabel,
|
|
2178
|
+
testID: `${props.testID}-cancel`,
|
|
2179
|
+
variant: "secondary",
|
|
2180
|
+
onPress: props.onCancel
|
|
2181
|
+
}
|
|
2182
|
+
),
|
|
2183
|
+
/* @__PURE__ */ jsx(
|
|
2184
|
+
Button,
|
|
2185
|
+
{
|
|
2186
|
+
accessibilityHint: props.submitHint,
|
|
2187
|
+
accessibilityLabel: props.submitLabel,
|
|
2188
|
+
label: props.submitLabel,
|
|
2189
|
+
loading: props.loading,
|
|
2190
|
+
testID: `${props.testID}-save`,
|
|
2191
|
+
variant: "primary",
|
|
2192
|
+
onPress: props.onSubmit
|
|
2193
|
+
}
|
|
2194
|
+
)
|
|
2195
|
+
] });
|
|
2196
|
+
var FormDialog = ({
|
|
2197
|
+
visible,
|
|
2198
|
+
title,
|
|
2199
|
+
children,
|
|
2200
|
+
submitLabel,
|
|
2201
|
+
submitHint,
|
|
2202
|
+
cancelLabel,
|
|
2203
|
+
loading = false,
|
|
2204
|
+
onSubmit,
|
|
2205
|
+
onCancel,
|
|
2206
|
+
size = "md",
|
|
2207
|
+
testID = LAYOUT_TEST_IDS.formDialog
|
|
2208
|
+
}) => {
|
|
2209
|
+
const { t } = useUi();
|
|
2210
|
+
const submit = useCallback(() => {
|
|
2211
|
+
if (!loading) onSubmit();
|
|
2212
|
+
}, [loading, onSubmit]);
|
|
2213
|
+
const footer = /* @__PURE__ */ jsx(
|
|
2214
|
+
FormDialogActions,
|
|
2215
|
+
{
|
|
2216
|
+
cancelHint: t(LAYOUT_I18N.cancelHint),
|
|
2217
|
+
cancelLabel: cancelLabel ?? t(LAYOUT_I18N.cancel),
|
|
2218
|
+
loading,
|
|
2219
|
+
submitHint,
|
|
2220
|
+
submitLabel,
|
|
2221
|
+
testID,
|
|
2222
|
+
onCancel,
|
|
2223
|
+
onSubmit: submit
|
|
2224
|
+
}
|
|
2225
|
+
);
|
|
2226
|
+
return /* @__PURE__ */ jsx(Modal, { footer, size, testID: `${testID}-dialog`, title, visible, onClose: onCancel, children: /* @__PURE__ */ jsx(WebFormBody, { visible, onSubmit: submit, children }) });
|
|
2227
|
+
};
|
|
2083
2228
|
var AccordionContext = createContext(null);
|
|
2084
2229
|
function useAccordionContext() {
|
|
2085
2230
|
const value = useContext(AccordionContext);
|
|
@@ -2948,6 +3093,6 @@ var ListRow = ({
|
|
|
2948
3093
|
] });
|
|
2949
3094
|
};
|
|
2950
3095
|
|
|
2951
|
-
export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BottomSheet, BuildInfoFooter, COPY_FEEDBACK_MS, ConfirmDialog, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, HEADER_STACK_BREAKPOINT, Heading, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, MIN_TARGET_PX, Modal, ModalDropdown, ModalShell, PageFrame, RowSelectedStyle, ScreenColumn, Section, SectionVariant, SegmentedControl, SelectedMarker, SideSheet, StatusBadge, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TextKind, TruncatedText, UpgradePrompt, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
|
|
3096
|
+
export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BottomSheet, BuildInfoFooter, COPY_FEEDBACK_MS, ConfirmDialog, ConfirmDialogFocus, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, FormDialog, HEADER_STACK_BREAKPOINT, Heading, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, RowSelectedStyle, ScreenColumn, Section, SectionVariant, SegmentedControl, SelectedMarker, SideSheet, StatusBadge, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TextKind, TruncatedText, UpgradePrompt, copyText, formatBuildInfo, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isWideWebViewport, pageScale, resolveRowLook, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
|
|
2952
3097
|
//# sourceMappingURL=index.mjs.map
|
|
2953
3098
|
//# sourceMappingURL=index.mjs.map
|