@dloizides/ui-layout 1.40.3 → 1.42.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.mjs CHANGED
@@ -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. */
@@ -168,6 +171,7 @@ var LAYOUT_I18N = {
168
171
  };
169
172
  var TYPE_SCALE_BREAKPOINT = 600;
170
173
  var LAYOUT_COLLAPSE_BREAKPOINT = 768;
174
+ var HEADER_STACK_BREAKPOINT = 400;
171
175
  var MIN_TARGET_PX = 44;
172
176
 
173
177
  // src/responsive.ts
@@ -175,6 +179,9 @@ var WEB_PLATFORM = "web";
175
179
  function isWideWebViewport(width, platformOS, breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
176
180
  return platformOS === WEB_PLATFORM && width >= breakpoint;
177
181
  }
182
+ function isModalFooterStacked(width) {
183
+ return width < MODAL_FOOTER_STACK_BELOW;
184
+ }
178
185
 
179
186
  // src/hooks/useIsWideViewport.ts
180
187
  function useIsWideViewport(breakpoint = LAYOUT_COLLAPSE_BREAKPOINT) {
@@ -478,6 +485,7 @@ var DIALOG_RADIUS = 12;
478
485
  var DIALOG_PADDING = 16;
479
486
  var HEADER_GAP = 12;
480
487
  var FOOTER_MARGIN = 16;
488
+ var FOOTER_GAP = 12;
481
489
  var HEADER_MARGIN = 12;
482
490
  var DIALOG_MAX_HEIGHT = "90%";
483
491
  var PANEL_ENTER_SCALE = 0.96;
@@ -509,8 +517,27 @@ var styles6 = StyleSheet.create({
509
517
  },
510
518
  // Occupies the header's leading space so the ✕ pins to the trailing edge even without a title.
511
519
  titleWrap: { flex: 1 },
512
- footer: { marginTop: FOOTER_MARGIN }
520
+ footerRow: {
521
+ marginTop: FOOTER_MARGIN,
522
+ flexDirection: "row",
523
+ flexWrap: "wrap",
524
+ justifyContent: "flex-end",
525
+ alignItems: "center",
526
+ columnGap: FOOTER_GAP,
527
+ rowGap: FOOTER_GAP
528
+ },
529
+ footerStack: {
530
+ marginTop: FOOTER_MARGIN,
531
+ flexDirection: "column-reverse",
532
+ alignItems: "stretch",
533
+ rowGap: FOOTER_GAP
534
+ }
513
535
  });
536
+ var ModalFooter = ({ children, testID }) => {
537
+ const { width } = useWindowDimensions();
538
+ const style = isModalFooterStacked(width) ? styles6.footerStack : styles6.footerRow;
539
+ return /* @__PURE__ */ jsx(View, { style, testID, children });
540
+ };
514
541
  var Modal = ({
515
542
  visible,
516
543
  onClose,
@@ -587,7 +614,7 @@ var Modal = ({
587
614
  ) : null
588
615
  ] }) : null,
589
616
  /* @__PURE__ */ jsx(ScrollView, { children }),
590
- footer !== void 0 ? /* @__PURE__ */ jsx(View, { style: styles6.footer, children: footer }) : null
617
+ footer !== void 0 ? /* @__PURE__ */ jsx(ModalFooter, { testID: `${testID}-footer`, children: footer }) : null
591
618
  ]
592
619
  }
593
620
  )
@@ -2019,10 +2046,8 @@ var BottomSheet = ({
2019
2046
  };
2020
2047
  var MESSAGE_FONT_SIZE2 = 14;
2021
2048
  var MESSAGE_LINE_HEIGHT = 20;
2022
- var BUTTON_GAP = 12;
2023
2049
  var styles18 = StyleSheet.create({
2024
- message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT },
2025
- footer: { flexDirection: "row", justifyContent: "flex-end", columnGap: BUTTON_GAP }
2050
+ message: { fontSize: MESSAGE_FONT_SIZE2, lineHeight: MESSAGE_LINE_HEIGHT }
2026
2051
  });
2027
2052
  var ConfirmDialog = ({
2028
2053
  visible,
@@ -2039,7 +2064,7 @@ var ConfirmDialog = ({
2039
2064
  const { theme, t } = useUi();
2040
2065
  const resolvedConfirm = confirmLabel ?? t(LAYOUT_I18N.confirm);
2041
2066
  const resolvedCancel = cancelLabel ?? t(LAYOUT_I18N.cancel);
2042
- const footer = /* @__PURE__ */ jsxs(View, { style: styles18.footer, children: [
2067
+ const footer = /* @__PURE__ */ jsxs(Fragment, { children: [
2043
2068
  /* @__PURE__ */ jsx(
2044
2069
  Button,
2045
2070
  {
@@ -2079,6 +2104,87 @@ var ConfirmDialog = ({
2079
2104
  }
2080
2105
  );
2081
2106
  };
2107
+ var FIELD_SELECTOR = "input:not([disabled]), textarea:not([disabled]), select:not([disabled])";
2108
+ var FORM_STYLE = { display: "contents" };
2109
+ var WebFormBody = ({ children, visible, onSubmit }) => {
2110
+ const formRef = useRef(null);
2111
+ useEffect(() => {
2112
+ if (Platform.OS !== "web" || !visible) return;
2113
+ formRef.current?.querySelector(FIELD_SELECTOR)?.focus();
2114
+ }, [visible]);
2115
+ const handleSubmit = useCallback(
2116
+ (event) => {
2117
+ event.preventDefault();
2118
+ onSubmit();
2119
+ },
2120
+ [onSubmit]
2121
+ );
2122
+ if (Platform.OS !== "web") return /* @__PURE__ */ jsx(Fragment, { children });
2123
+ return React14.createElement(
2124
+ "form",
2125
+ { ref: formRef, noValidate: true, style: FORM_STYLE, onSubmit: handleSubmit },
2126
+ children,
2127
+ React14.createElement("button", { type: "submit", hidden: true, tabIndex: -1, "aria-hidden": true })
2128
+ );
2129
+ };
2130
+ var FormDialogActions = (props) => /* @__PURE__ */ jsxs(Fragment, { children: [
2131
+ /* @__PURE__ */ jsx(
2132
+ Button,
2133
+ {
2134
+ accessibilityHint: props.cancelHint,
2135
+ accessibilityLabel: props.cancelLabel,
2136
+ disabled: props.loading,
2137
+ label: props.cancelLabel,
2138
+ testID: `${props.testID}-cancel`,
2139
+ variant: "secondary",
2140
+ onPress: props.onCancel
2141
+ }
2142
+ ),
2143
+ /* @__PURE__ */ jsx(
2144
+ Button,
2145
+ {
2146
+ accessibilityHint: props.submitHint,
2147
+ accessibilityLabel: props.submitLabel,
2148
+ label: props.submitLabel,
2149
+ loading: props.loading,
2150
+ testID: `${props.testID}-save`,
2151
+ variant: "primary",
2152
+ onPress: props.onSubmit
2153
+ }
2154
+ )
2155
+ ] });
2156
+ var FormDialog = ({
2157
+ visible,
2158
+ title,
2159
+ children,
2160
+ submitLabel,
2161
+ submitHint,
2162
+ cancelLabel,
2163
+ loading = false,
2164
+ onSubmit,
2165
+ onCancel,
2166
+ size = "md",
2167
+ testID = LAYOUT_TEST_IDS.formDialog
2168
+ }) => {
2169
+ const { t } = useUi();
2170
+ const submit = useCallback(() => {
2171
+ if (!loading) onSubmit();
2172
+ }, [loading, onSubmit]);
2173
+ const footer = /* @__PURE__ */ jsx(
2174
+ FormDialogActions,
2175
+ {
2176
+ cancelHint: t(LAYOUT_I18N.cancelHint),
2177
+ cancelLabel: cancelLabel ?? t(LAYOUT_I18N.cancel),
2178
+ loading,
2179
+ submitHint,
2180
+ submitLabel,
2181
+ testID,
2182
+ onCancel,
2183
+ onSubmit: submit
2184
+ }
2185
+ );
2186
+ return /* @__PURE__ */ jsx(Modal, { footer, size, testID: `${testID}-dialog`, title, visible, onClose: onCancel, children: /* @__PURE__ */ jsx(WebFormBody, { visible, onSubmit: submit, children }) });
2187
+ };
2082
2188
  var AccordionContext = createContext(null);
2083
2189
  function useAccordionContext() {
2084
2190
  const value = useContext(AccordionContext);
@@ -2947,6 +3053,6 @@ var ListRow = ({
2947
3053
  ] });
2948
3054
  };
2949
3055
 
2950
- 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, 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 };
3056
+ 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, 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 };
2951
3057
  //# sourceMappingURL=index.mjs.map
2952
3058
  //# sourceMappingURL=index.mjs.map