@jobber/components 8.25.0 → 8.25.2

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.
@@ -4,11 +4,11 @@ import { useWindowDimensions } from '@jobber/hooks';
4
4
  import classnames from 'classnames';
5
5
  import { n as normalizeBaseUiButtonProps, i as isAtlantisButtonRenderTarget, s as stripNativeTypeFromButtonRenderTarget, r as renderAtlantisButtonTarget } from './buttonRenderAdapter-es.js';
6
6
  import { B as Button } from './Button-es.js';
7
- import { S as ScrollAreaRoot, e as ScrollAreaViewport, g as DialogRoot$1, h as DialogTrigger$1, i as DialogPortal } from './ScrollAreaViewport-es.js';
7
+ import { S as ScrollAreaRoot, e as ScrollAreaViewport, g as DialogRoot, h as DialogTrigger$1, i as DialogPortal } from './ScrollAreaViewport-es.js';
8
+ import { m as mergeProps } from './useRenderElement-es.js';
8
9
  import { H as Heading } from './Heading-es.js';
9
10
  import { a as BottomSheet, B as BottomSheetScrollAreaContext } from './BottomSheet-es.js';
10
11
  import { D as DrawerTitle, a as DrawerClose, b as DialogTitle$1, c as DialogClose$1 } from './DrawerTitle-es.js';
11
- import { m as mergeProps } from './useRenderElement-es.js';
12
12
  import { D as DrawerDescription, a as DialogBackdrop, b as DialogViewport, c as DialogPopup, d as DialogDescription, e as createDialogHandle } from './DrawerDescription-es.js';
13
13
 
14
14
  // Copied from Menu's constant so the two surfaces agree on what "mobile" means.
@@ -79,6 +79,24 @@ function resolveComposableCloseRender({ children, render, }) {
79
79
  return renderAtlantisButtonTarget(React__default.createElement(Button, { type: "tertiary", variation: "subtle", ariaLabel: "Close dialog" },
80
80
  React__default.createElement(Button.Icon, { name: "remove" })));
81
81
  }
82
+ /**
83
+ * Adapts a `Dialog.Content` `render` for the bottom sheet's drawer popup. A
84
+ * render element passes through; a render function is wrapped to receive the
85
+ * drawer's state re-shaped as the dialog popup's state (e.g. `nestedDrawerOpen`
86
+ * becomes `nestedDialogOpen`), so `render` sees the same shape as the desktop
87
+ * dialog.
88
+ */
89
+ function resolveBottomSheetContentRender(render) {
90
+ if (typeof render !== "function") {
91
+ return render;
92
+ }
93
+ return (props, drawerState) => render(props, {
94
+ open: drawerState.open,
95
+ transitionStatus: drawerState.transitionStatus,
96
+ nested: drawerState.nested,
97
+ nestedDialogOpen: drawerState.nestedDrawerOpen,
98
+ });
99
+ }
82
100
  const DialogContext = React__default.createContext({
83
101
  type: "dialog",
84
102
  size: "base",
@@ -132,15 +150,26 @@ function SharedDialogFooter(_a) {
132
150
  const sticky = !useInsideDialogScrollArea();
133
151
  return (React__default.createElement("div", Object.assign({}, rest, { className: classnames(styles.footer, className), style: style, "data-sticky": sticky || undefined, "data-testid": "ATL-Dialog-Footer" }), children));
134
152
  }
153
+ function renderActionButton(action, defaults) {
154
+ if (!action)
155
+ return null;
156
+ return isValidElement(action) ? (action) : (React__default.createElement(Button, Object.assign({}, mergeProps(defaults, action))));
157
+ }
135
158
  /**
136
159
  * The action-button layout: tertiary on the left, primary/secondary grouped on
137
160
  * the right. Drop it inside a `Dialog.Footer`.
138
161
  */
139
162
  function DialogActions(_a) {
140
163
  var { primary, secondary, tertiary, align = "right", className, style } = _a, rest = __rest(_a, ["primary", "secondary", "tertiary", "align", "className", "style"]);
141
- const secondaryAction = secondary && isValidElement(secondary) ? (secondary) : (React__default.createElement(Button, Object.assign({ type: "primary", variation: "subtle" }, secondary)));
142
- const primaryAction = primary && isValidElement(primary) ? (primary) : (React__default.createElement(Button, Object.assign({ type: "primary" }, primary)));
143
- const tertiaryAction = tertiary && isValidElement(tertiary) ? (tertiary) : (React__default.createElement(Button, Object.assign({ type: "secondary", variation: "destructive" }, tertiary)));
164
+ const primaryAction = renderActionButton(primary, { type: "primary" });
165
+ const secondaryAction = renderActionButton(secondary, {
166
+ type: "primary",
167
+ variation: "subtle",
168
+ });
169
+ const tertiaryAction = renderActionButton(tertiary, {
170
+ type: "secondary",
171
+ variation: "destructive",
172
+ });
144
173
  return (React__default.createElement("div", Object.assign({}, rest, { className: classnames(actionsStyles.actions, [actionsStyles[`align-${align}`]], className), style: style, "data-testid": "ATL-Dialog-Actions" }),
145
174
  tertiary && (React__default.createElement("div", { className: actionsStyles.leftActions }, tertiaryAction)),
146
175
  React__default.createElement("div", { className: classnames(actionsStyles.buttonGroup, actionsStyles[`align-${align}`]) },
@@ -148,20 +177,23 @@ function DialogActions(_a) {
148
177
  primary && primaryAction)));
149
178
  }
150
179
 
151
- function DialogBottomSheetRoot(props) {
180
+ function DialogBottomSheet(props) {
152
181
  return (React__default.createElement(BottomSheet.Root, Object.assign({}, props)));
153
182
  }
154
183
  function DialogBottomSheetTrigger(props) {
155
184
  return (React__default.createElement(BottomSheet.Trigger, Object.assign({}, props)));
156
185
  }
157
186
  function DialogBottomSheetContent(_a) {
158
- var { children, className, style } = _a, rest = __rest(_a, ["children", "className", "style"]);
187
+ var { children, className, style, render } = _a, rest = __rest(_a, ["children", "className", "style", "render"]);
159
188
  const { type, size, finalFocus } = useDialogContext();
160
189
  return (
161
190
  // Opt-out of the BottomSheet's built-in scroll area.
162
191
  // Dialog will handle the scroll area itself.
163
192
  React__default.createElement(BottomSheetScrollAreaContext.Provider, { value: false },
164
- React__default.createElement(BottomSheet.Popup, Object.assign({}, rest, { className: classnames(styles.sheetSurface, className), style: style, role: type, finalFocus: finalFocus, "data-dialog-variant": "sheet", "data-size": size }), children)));
193
+ React__default.createElement(BottomSheet.Popup, Object.assign({}, rest, {
194
+ // The bottom sheet is backed by a drawer popup, so re-shape its state
195
+ // into the dialog popup state the consumer's `render` is typed against.
196
+ render: resolveBottomSheetContentRender(render), className: classnames(styles.sheetSurface, className), style: style, role: type, finalFocus: finalFocus, "data-dialog-variant": "sheet", "data-size": size }), children)));
165
197
  }
166
198
  function DialogBottomSheetTitle(_a) {
167
199
  var { children } = _a, rest = __rest(_a, ["children"]);
@@ -192,19 +224,17 @@ function DialogBottomSheetBody(_a) {
192
224
  return insideScrollArea ? (content) : (React__default.createElement(DialogBottomSheetScrollArea, null, content));
193
225
  }
194
226
  /** Mobile shell: a bottom sheet built on the BottomSheet/Drawer primitives. */
195
- const DialogBottomSheet = Object.assign(DialogBottomSheetRoot, {
196
- Trigger: DialogBottomSheetTrigger,
197
- Content: DialogBottomSheetContent,
198
- Header: SharedDialogHeader,
199
- Title: DialogBottomSheetTitle,
200
- Close: DialogBottomSheetClose,
201
- Body: DialogBottomSheetBody,
202
- Footer: SharedDialogFooter,
203
- ScrollArea: DialogBottomSheetScrollArea,
204
- });
227
+ DialogBottomSheet.Trigger = DialogBottomSheetTrigger;
228
+ DialogBottomSheet.Content = DialogBottomSheetContent;
229
+ DialogBottomSheet.Header = SharedDialogHeader;
230
+ DialogBottomSheet.Title = DialogBottomSheetTitle;
231
+ DialogBottomSheet.Close = DialogBottomSheetClose;
232
+ DialogBottomSheet.Body = DialogBottomSheetBody;
233
+ DialogBottomSheet.Footer = SharedDialogFooter;
234
+ DialogBottomSheet.ScrollArea = DialogBottomSheetScrollArea;
205
235
 
206
- function DialogModalRoot(props) {
207
- return React__default.createElement(DialogRoot$1, Object.assign({}, props));
236
+ function DialogModal(props) {
237
+ return React__default.createElement(DialogRoot, Object.assign({}, props));
208
238
  }
209
239
  function DialogModalTrigger(_a) {
210
240
  var { children, render, handle, payload, className, style } = _a, rest = __rest(_a, ["children", "render", "handle", "payload", "className", "style"]);
@@ -236,17 +266,14 @@ function DialogModalBody(_a) {
236
266
  const content = (React__default.createElement(DialogDescription, { render: descriptionProps => (React__default.createElement("div", Object.assign({}, rest, descriptionProps, { className: classnames(styles.body, { [styles.fullBleed]: fullBleed }, className), style: style }), children)) }));
237
267
  return insideScrollArea ? (content) : (React__default.createElement(DialogScrollArea$1, null, content));
238
268
  }
239
- const DialogModal = Object.assign(DialogModalRoot, {
240
- Trigger: DialogModalTrigger,
241
- Content: DialogModalContent,
242
- Header: SharedDialogHeader,
243
- Title: DialogModalTitle,
244
- Close: DialogModalClose,
245
- Body: DialogModalBody,
246
- Footer: SharedDialogFooter,
247
- // The modal keeps the plain native-scrollbar scroll region.
248
- ScrollArea: DialogScrollArea$1,
249
- });
269
+ DialogModal.Trigger = DialogModalTrigger;
270
+ DialogModal.Content = DialogModalContent;
271
+ DialogModal.Header = SharedDialogHeader;
272
+ DialogModal.Title = DialogModalTitle;
273
+ DialogModal.Close = DialogModalClose;
274
+ DialogModal.Body = DialogModalBody;
275
+ DialogModal.Footer = SharedDialogFooter;
276
+ DialogModal.ScrollArea = DialogScrollArea$1;
250
277
 
251
278
  /**
252
279
  * Creates a handle that opens/closes a `Dialog` from detached triggers (e.g. an
@@ -271,7 +298,7 @@ function useDialogShell() {
271
298
  * desktop, a bottom sheet on mobile. Compose it with `Dialog.Trigger`,
272
299
  * `Dialog.Content`, and the layout parts.
273
300
  */
274
- function DialogRoot(_a) {
301
+ function Dialog(_a) {
275
302
  var { onRequestClose, size = "base", type = "dialog", finalFocus, children, onOpenChange } = _a, rest = __rest(_a, ["onRequestClose", "size", "type", "finalFocus", "children", "onOpenChange"]);
276
303
  function handleOpenChange(nextOpen, eventDetails) {
277
304
  if (!nextOpen) {
@@ -337,7 +364,6 @@ function DialogScrollArea(props) {
337
364
  const Shell = useDialogShell();
338
365
  return React__default.createElement(Shell.ScrollArea, Object.assign({}, props));
339
366
  }
340
- const Dialog = DialogRoot;
341
367
  Dialog.Trigger = DialogTrigger;
342
368
  Dialog.Content = DialogContent;
343
369
  Dialog.Header = DialogHeader;