@canonical/react-ds-global 0.37.0 → 0.38.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/README.md +72 -0
- package/dist/esm/lib/_work_in_progress/Announcement/styles.css +51 -47
- package/dist/esm/lib/_work_in_progress/CategoriesSection/common/Category/styles.css +21 -17
- package/dist/esm/lib/_work_in_progress/CategoriesSection/styles.css +16 -12
- package/dist/esm/lib/_work_in_progress/ChatSection/styles.css +22 -18
- package/dist/esm/lib/_work_in_progress/DescriptionSection/styles.css +14 -10
- package/dist/esm/lib/_work_in_progress/IconSection/styles.css +18 -14
- package/dist/esm/lib/_work_in_progress/Label/styles.css +36 -32
- package/dist/esm/lib/_work_in_progress/Link/styles.css +32 -28
- package/dist/esm/lib/_work_in_progress/Rule/styles.css +21 -14
- package/dist/esm/lib/_work_in_progress/Section/styles.css +66 -62
- package/dist/esm/lib/_work_in_progress/SkipLink/styles.css +35 -32
- package/dist/esm/lib/_work_in_progress/TSection/styles.css +26 -22
- package/dist/esm/lib/_work_in_progress/grid/ApplicationLayout/ApplicationLayout.js +4 -1
- package/dist/esm/lib/_work_in_progress/grid/ApplicationLayout/ApplicationLayout.js.map +1 -1
- package/dist/esm/lib/_work_in_progress/grid/ApplicationLayout/styles.css +21 -17
- package/dist/esm/lib/_work_in_progress/grid/GridCard/GridCard.js +4 -1
- package/dist/esm/lib/_work_in_progress/grid/GridCard/GridCard.js.map +1 -1
- package/dist/esm/lib/_work_in_progress/grid/GridCard/styles.css +8 -4
- package/dist/esm/lib/_work_in_progress/grid/InnerGridDemo/styles.css +38 -33
- package/dist/esm/lib/_work_in_progress/grid/SettingsView/SettingsView.js +4 -1
- package/dist/esm/lib/_work_in_progress/grid/SettingsView/SettingsView.js.map +1 -1
- package/dist/esm/lib/_work_in_progress/grid/SettingsView/styles.css +23 -19
- package/dist/esm/lib/component/Accordion/common/Item/styles.css +305 -299
- package/dist/esm/lib/component/Accordion/styles.css +35 -31
- package/dist/esm/lib/component/Badge/hooks/useBadge.js +1 -1
- package/dist/esm/lib/component/Badge/hooks/useBadge.js.map +1 -1
- package/dist/esm/lib/component/Badge/styles.css +45 -41
- package/dist/esm/lib/component/Breadcrumbs/Breadcrumbs.js +1 -1
- package/dist/esm/lib/component/Breadcrumbs/Breadcrumbs.js.map +1 -1
- package/dist/esm/lib/component/Breadcrumbs/common/Item/styles.css +69 -65
- package/dist/esm/lib/component/Breadcrumbs/styles.css +30 -26
- package/dist/esm/lib/component/Button/styles.css +293 -260
- package/dist/esm/lib/component/Card/common/Content/styles.css +27 -23
- package/dist/esm/lib/component/Card/common/Footer/styles.css +30 -26
- package/dist/esm/lib/component/Card/common/Header/styles.css +25 -21
- package/dist/esm/lib/component/Card/common/Image/styles.css +8 -4
- package/dist/esm/lib/component/Card/styles.css +77 -73
- package/dist/esm/lib/component/Chip/Chip.js.map +1 -1
- package/dist/esm/lib/component/Chip/styles.css +105 -101
- package/dist/esm/lib/component/ContextualMenu/ContextualMenu.js +29 -20
- package/dist/esm/lib/component/ContextualMenu/ContextualMenu.js.map +1 -1
- package/dist/esm/lib/component/ContextualMenu/common/Item/Item.js +25 -2
- package/dist/esm/lib/component/ContextualMenu/common/Item/Item.js.map +1 -1
- package/dist/esm/lib/component/ContextualMenu/common/Item/styles.css +116 -106
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/SubMenu.js +29 -9
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/SubMenu.js.map +1 -1
- package/dist/esm/lib/component/ContextualMenu/styles.css +74 -72
- package/dist/esm/lib/component/Icon/styles.css +24 -20
- package/dist/esm/lib/component/InlineCode/styles.css +19 -15
- package/dist/esm/lib/component/KeyboardKey/styles.css +44 -40
- package/dist/esm/lib/component/Popover/Popover.js.map +1 -1
- package/dist/esm/lib/component/Popover/styles.css +59 -52
- package/dist/esm/lib/component/Tabs/common/Item/styles.css +80 -76
- package/dist/esm/lib/component/Tabs/styles.css +36 -32
- package/dist/esm/lib/component/Tile/common/Content/styles.css +28 -24
- package/dist/esm/lib/component/Tile/common/Header/styles.css +28 -24
- package/dist/esm/lib/component/Tile/styles.css +31 -27
- package/dist/esm/lib/component/Tooltip/styles.css +213 -208
- package/dist/esm/lib/group/Cards/styles.css +26 -22
- package/dist/esm/lib/group/KeyboardKeys/styles.css +14 -10
- package/dist/esm/lib/hooks/useContextualMenu/index.js +1 -0
- package/dist/esm/lib/hooks/useContextualMenu/index.js.map +1 -1
- package/dist/esm/lib/hooks/useContextualMenu/isMenuSeparator.js +11 -0
- package/dist/esm/lib/hooks/useContextualMenu/isMenuSeparator.js.map +1 -0
- package/dist/esm/lib/hooks/useContextualMenu/useContextualMenu.js +54 -34
- package/dist/esm/lib/hooks/useContextualMenu/useContextualMenu.js.map +1 -1
- package/dist/esm/lib/hooks/useDisclosure/useDisclosure.js.map +1 -1
- package/dist/esm/lib/hooks/useWindowDimensions/useWindowDimensions.js +1 -1
- package/dist/esm/lib/hooks/useWindowDimensions/useWindowDimensions.js.map +1 -1
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js +3 -0
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js.map +1 -1
- package/dist/esm/lib/index.css +79 -0
- package/dist/esm/lib/pattern/Modal/Context.js +10 -0
- package/dist/esm/lib/pattern/Modal/Context.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/Provider.js +103 -0
- package/dist/esm/lib/pattern/Modal/Provider.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Content/Content.js +15 -0
- package/dist/esm/lib/pattern/Modal/common/Content/Content.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Content/index.js +3 -0
- package/dist/esm/lib/pattern/Modal/common/Content/index.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Content/styles.css +37 -0
- package/dist/esm/lib/pattern/Modal/common/Content/types.js +2 -0
- package/dist/esm/lib/pattern/Modal/common/Content/types.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/Footer.js +16 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/Footer.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/index.js +3 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/index.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/styles.css +57 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/types.js +2 -0
- package/dist/esm/lib/pattern/Modal/common/Footer/types.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Header/Header.js +27 -0
- package/dist/esm/lib/pattern/Modal/common/Header/Header.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Header/index.js +3 -0
- package/dist/esm/lib/pattern/Modal/common/Header/index.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/Header/styles.css +79 -0
- package/dist/esm/lib/pattern/Modal/common/Header/types.js +2 -0
- package/dist/esm/lib/pattern/Modal/common/Header/types.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/common/index.js +5 -0
- package/dist/esm/lib/pattern/Modal/common/index.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/hooks/useModalContext.js +11 -0
- package/dist/esm/lib/pattern/Modal/hooks/useModalContext.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/hooks/useModalState.js +15 -0
- package/dist/esm/lib/pattern/Modal/hooks/useModalState.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/index.js +4 -0
- package/dist/esm/lib/pattern/Modal/index.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/styles.css +119 -0
- package/dist/esm/lib/pattern/Modal/types.js +2 -0
- package/dist/esm/lib/pattern/Modal/types.js.map +1 -0
- package/dist/esm/lib/pattern/Modal/withModal.js +102 -0
- package/dist/esm/lib/pattern/Modal/withModal.js.map +1 -0
- package/dist/esm/lib/pattern/Timeline/common/Content/styles.css +16 -12
- package/dist/esm/lib/pattern/Timeline/common/Event/styles.css +116 -112
- package/dist/esm/lib/pattern/Timeline/styles.css +16 -12
- package/dist/esm/lib/pattern/index.js +1 -0
- package/dist/esm/lib/pattern/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/Spinner/styles.css +38 -34
- package/dist/types/lib/_work_in_progress/grid/ApplicationLayout/ApplicationLayout.d.ts.map +1 -1
- package/dist/types/lib/_work_in_progress/grid/GridCard/GridCard.d.ts.map +1 -1
- package/dist/types/lib/_work_in_progress/grid/SettingsView/SettingsView.d.ts.map +1 -1
- package/dist/types/lib/component/Badge/types.d.ts +1 -1
- package/dist/types/lib/component/Badge/types.d.ts.map +1 -1
- package/dist/types/lib/component/Breadcrumbs/types.d.ts +2 -2
- package/dist/types/lib/component/Breadcrumbs/types.d.ts.map +1 -1
- package/dist/types/lib/component/Chip/Chip.d.ts +2 -2
- package/dist/types/lib/component/Chip/Chip.d.ts.map +1 -1
- package/dist/types/lib/component/Chip/types.d.ts +10 -8
- package/dist/types/lib/component/Chip/types.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/ContextualMenu.d.ts +4 -4
- package/dist/types/lib/component/ContextualMenu/ContextualMenu.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/common/Item/Item.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/common/MenuContext.d.ts +1 -1
- package/dist/types/lib/component/ContextualMenu/common/MenuContext.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/SubMenu.d.ts +9 -7
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/SubMenu.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/types.d.ts +14 -6
- package/dist/types/lib/component/ContextualMenu/types.d.ts.map +1 -1
- package/dist/types/lib/component/Tabs/types.d.ts +2 -2
- package/dist/types/lib/component/Tabs/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/useContextualMenu/index.d.ts +1 -0
- package/dist/types/lib/hooks/useContextualMenu/index.d.ts.map +1 -1
- package/dist/types/lib/hooks/useContextualMenu/isMenuSeparator.d.ts +13 -0
- package/dist/types/lib/hooks/useContextualMenu/isMenuSeparator.d.ts.map +1 -0
- package/dist/types/lib/hooks/useContextualMenu/types.d.ts +45 -15
- package/dist/types/lib/hooks/useContextualMenu/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/useContextualMenu/useContextualMenu.d.ts +5 -6
- package/dist/types/lib/hooks/useContextualMenu/useContextualMenu.d.ts.map +1 -1
- package/dist/types/lib/hooks/useDisclosure/types.d.ts +7 -2
- package/dist/types/lib/hooks/useDisclosure/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/useDisclosure/useDisclosure.d.ts +1 -1
- package/dist/types/lib/hooks/useDisclosure/useDisclosure.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowFitment/types.d.ts +12 -3
- package/dist/types/lib/hooks/useWindowFitment/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts +1 -1
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -1
- package/dist/types/lib/pattern/Modal/Context.d.ts +10 -0
- package/dist/types/lib/pattern/Modal/Context.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/Provider.d.ts +63 -0
- package/dist/types/lib/pattern/Modal/Provider.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Content/Content.d.ts +17 -0
- package/dist/types/lib/pattern/Modal/common/Content/Content.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Content/index.d.ts +3 -0
- package/dist/types/lib/pattern/Modal/common/Content/index.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Content/types.d.ts +15 -0
- package/dist/types/lib/pattern/Modal/common/Content/types.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Footer/Footer.d.ts +18 -0
- package/dist/types/lib/pattern/Modal/common/Footer/Footer.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Footer/index.d.ts +3 -0
- package/dist/types/lib/pattern/Modal/common/Footer/index.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Footer/types.d.ts +16 -0
- package/dist/types/lib/pattern/Modal/common/Footer/types.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Header/Header.d.ts +24 -0
- package/dist/types/lib/pattern/Modal/common/Header/Header.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Header/index.d.ts +3 -0
- package/dist/types/lib/pattern/Modal/common/Header/index.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/Header/types.d.ts +36 -0
- package/dist/types/lib/pattern/Modal/common/Header/types.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/common/index.d.ts +4 -0
- package/dist/types/lib/pattern/Modal/common/index.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/hooks/useModalContext.d.ts +4 -0
- package/dist/types/lib/pattern/Modal/hooks/useModalContext.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/hooks/useModalState.d.ts +10 -0
- package/dist/types/lib/pattern/Modal/hooks/useModalState.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/index.d.ts +4 -0
- package/dist/types/lib/pattern/Modal/index.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/types.d.ts +122 -0
- package/dist/types/lib/pattern/Modal/types.d.ts.map +1 -0
- package/dist/types/lib/pattern/Modal/withModal.d.ts +74 -0
- package/dist/types/lib/pattern/Modal/withModal.d.ts.map +1 -0
- package/dist/types/lib/pattern/index.d.ts +1 -0
- package/dist/types/lib/pattern/index.d.ts.map +1 -1
- package/package.json +28 -18
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { ModalContextValue } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The provider state threaded to the composed subcomponents: the id that names
|
|
5
|
+
* the dialog, and the dismissal that closes it. Centralising it here keeps the
|
|
6
|
+
* provider free of state logic.
|
|
7
|
+
*/
|
|
8
|
+
declare const useModalState: (dialogRef: RefObject<HTMLDialogElement | null>) => ModalContextValue;
|
|
9
|
+
export default useModalState;
|
|
10
|
+
//# sourceMappingURL=useModalState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useModalState.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/pattern/Modal/hooks/useModalState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AACH,QAAA,MAAM,aAAa,GACjB,WAAW,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAC7C,iBAMF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/pattern/Modal/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AACjD,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ComponentProps, MouseEventHandler, ReactElement, ReactNode, RefCallback, RefObject } from "react";
|
|
2
|
+
type OwnProps = {
|
|
3
|
+
/**
|
|
4
|
+
* The handle on the underlying `<dialog>`, and the only way the modal opens:
|
|
5
|
+
* `ref.current?.showModal()`, with `ref.current?.close()` closing it. The prop
|
|
6
|
+
* is required because the modal is only ever opened through `showModal()`, so
|
|
7
|
+
* a modal with no ref is a modal that can never open — every modal needs a ref:
|
|
8
|
+
* withModal hands its factory the ref to attach and a
|
|
9
|
+
* directly-composed modal driven by a trigger takes a stored ref. Requiring the prop turns
|
|
10
|
+
* the withModal factory's duty — attaching the ref it receives —
|
|
11
|
+
* into a compile error instead of a silent nothing.
|
|
12
|
+
*
|
|
13
|
+
* `showModal()` throws on a dialog that is already open. A trigger sitting
|
|
14
|
+
* on the page cannot be clicked while the modal holds it inert, so it needs
|
|
15
|
+
* no guard; anything that can fire twice — a keyboard shortcut, an effect —
|
|
16
|
+
* should check `ref.current.open` first.
|
|
17
|
+
*/
|
|
18
|
+
ref: RefCallback<HTMLDialogElement> | RefObject<HTMLDialogElement | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether clicking the backdrop dismisses the modal. Defaults to `false`, so
|
|
21
|
+
* backdrop dismissal is opt-in. Independent of the header's `undismissible`.
|
|
22
|
+
*/
|
|
23
|
+
closeOnBackdropClick?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The composed sections — `Modal.Header`, `Modal.Content` and
|
|
26
|
+
* `Modal.Footer`, in that order. The header and footer are optional; the
|
|
27
|
+
* content carries the main information the modal conveys.
|
|
28
|
+
*/
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Props for the Modal pattern
|
|
33
|
+
*
|
|
34
|
+
* @implements ds:global.pattern.modal
|
|
35
|
+
*
|
|
36
|
+
* `open` is omitted because a `<dialog>` carrying the `open` attribute is
|
|
37
|
+
* *non-modal*: no top layer, no backdrop, no focus trap. The modal is only
|
|
38
|
+
* ever opened through `showModal()`, so the open state lives in the DOM
|
|
39
|
+
* element and not in a prop. Use the `ref` to open or close it.
|
|
40
|
+
*
|
|
41
|
+
* `onClose` is *not* omitted: the native `close` event is how a consumer hears
|
|
42
|
+
* that the modal is gone, whichever way out the user took, and it replaces the
|
|
43
|
+
* `onOpenChange` callback a controlled modal would need. It does not say *which*
|
|
44
|
+
* way out that was — an action that needs to be told apart from a dismissal
|
|
45
|
+
* should close the modal with `ref.current?.close(value)` and read
|
|
46
|
+
* `event.currentTarget.returnValue`.
|
|
47
|
+
*/
|
|
48
|
+
export type ModalProps = OwnProps & Omit<ComponentProps<"dialog">, keyof OwnProps | "open">;
|
|
49
|
+
/**
|
|
50
|
+
* The shared modal API threaded to the composed subcomponents through the
|
|
51
|
+
* Modal context: the id the dialog's `aria-labelledby` points at (set on the
|
|
52
|
+
* Header's title, which is what gives the dialog its accessible name), and
|
|
53
|
+
* the dismissal that closes the dialog (what the Header's close button calls).
|
|
54
|
+
*/
|
|
55
|
+
export interface ModalContextValue {
|
|
56
|
+
/**
|
|
57
|
+
* The id the dialog's `aria-labelledby` points at. The Header sets it on the
|
|
58
|
+
* title, which is what gives the dialog its accessible name.
|
|
59
|
+
*/
|
|
60
|
+
titleId: string;
|
|
61
|
+
/** Closes the dialog. What the Header's close button calls. */
|
|
62
|
+
onDismiss: () => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The one requirement {@link withModal} places on the component it wraps: it
|
|
66
|
+
* must accept an `onClick` handler. The HOC composes its open handler onto
|
|
67
|
+
* the trigger itself — no wrapper element — so a trigger that accepts
|
|
68
|
+
* `onClick` but never forwards it to a clickable element never opens its
|
|
69
|
+
* modal. An `onClick` the consumer passes still runs: the HOC calls it first,
|
|
70
|
+
* then opens the modal.
|
|
71
|
+
*
|
|
72
|
+
* The event is typed against plain `Element` so triggers rooted at any
|
|
73
|
+
* element — `<button>`, `<a>`, a clickable `<span>` — satisfy the constraint:
|
|
74
|
+
* React's event handlers are bivariant (the `bivarianceHack`), so a
|
|
75
|
+
* `MouseEventHandler<HTMLButtonElement>` prop fits where a
|
|
76
|
+
* `MouseEventHandler<Element>` is expected.
|
|
77
|
+
*/
|
|
78
|
+
export type WithModalTriggerProps = {
|
|
79
|
+
onClick?: MouseEventHandler<Element>;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* The props the modal element returned by a {@link WithModalRender} carries:
|
|
83
|
+
* everything `Modal` accepts — including the required `ref`, which the factory
|
|
84
|
+
* sets on the `<Modal>` so the trigger can open it.
|
|
85
|
+
*/
|
|
86
|
+
export type WithModalModalProps = ModalProps;
|
|
87
|
+
/**
|
|
88
|
+
* What {@link withModal} hands a {@link WithModalRender} function: a props
|
|
89
|
+
* object.
|
|
90
|
+
*/
|
|
91
|
+
export type WithModalRenderProps = {
|
|
92
|
+
/** Closes the modal. What a footer button wires its `onClick` to. */
|
|
93
|
+
close: () => void;
|
|
94
|
+
/**
|
|
95
|
+
* The handle on the `<dialog>` the trigger opens. The factory MUST set it
|
|
96
|
+
* on the `<Modal>` it returns — `<Modal ref={ref}>`. `Modal` requires its
|
|
97
|
+
* `ref`, so a factory that forgets it fails to compile.
|
|
98
|
+
*/
|
|
99
|
+
ref: RefObject<HTMLDialogElement | null>;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The second argument of {@link withModal}: a render contract. The HOC calls
|
|
103
|
+
* it during render with a {@link WithModalRenderProps} object — `{ close,
|
|
104
|
+
* ref }` — and it returns the complete `<Modal>` element.
|
|
105
|
+
*
|
|
106
|
+
* **Every factory must attach the `ref` it receives to the `<Modal>` it
|
|
107
|
+
* returns.** The trigger opens the dialog through that ref. `Modal` requires
|
|
108
|
+
* its `ref`, so a factory that forgets it fails to compile:
|
|
109
|
+
*
|
|
110
|
+
* `({ ref }) => <Modal ref={ref}>…</Modal>`
|
|
111
|
+
*
|
|
112
|
+
* or, with a footer button that closes the modal:
|
|
113
|
+
*
|
|
114
|
+
* `({ close, ref }) => <Modal ref={ref}><Modal.Footer><Button onClick={close}>Got it</Button></Modal.Footer></Modal>`
|
|
115
|
+
*
|
|
116
|
+
* A footer action can only close. If it must do more — submit data, close
|
|
117
|
+
* conditionally, open another modal — skip the HOC and compose `Modal`
|
|
118
|
+
* directly, driving it through its `ref`.
|
|
119
|
+
*/
|
|
120
|
+
export type WithModalRender = (props: WithModalRenderProps) => ReactElement<WithModalModalProps>;
|
|
121
|
+
export {};
|
|
122
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/lib/pattern/Modal/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACV,MAAM,OAAO,CAAC;AAEf,KAAK,QAAQ,GAAG;IACd;;;;;;;;;;;;;;OAcG;IACH,GAAG,EAAE,WAAW,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC1E;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAC/B,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACtC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,qEAAqE;IACrE,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;OAIG;IACH,GAAG,EAAE,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,KAAK,EAAE,oBAAoB,KACxB,YAAY,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { WithModalRender, WithModalTriggerProps } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a trigger with a modal. Click the trigger → the modal opens.
|
|
5
|
+
*
|
|
6
|
+
* **The wrapped component must accept `onClick`** and forward it to the
|
|
7
|
+
* clickable element at its root — the HOC composes its open handler onto the
|
|
8
|
+
* trigger itself, with no wrapper element in between. An `onClick` the
|
|
9
|
+
* consumer passes keeps working: it runs first, then the modal opens.
|
|
10
|
+
*
|
|
11
|
+
* The second argument is a function: the HOC calls it with a props object
|
|
12
|
+
* carrying `close` and `ref`, and it returns a complete `<Modal>` element —
|
|
13
|
+
* sections, props and all:
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const OpenButton = withModal(
|
|
17
|
+
* Button,
|
|
18
|
+
* ({ ref }) => (
|
|
19
|
+
* <Modal ref={ref}>
|
|
20
|
+
* <Modal.Content>Hello</Modal.Content>
|
|
21
|
+
* </Modal>
|
|
22
|
+
* ),
|
|
23
|
+
* );
|
|
24
|
+
* <OpenButton>Open</OpenButton>;
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Everything `Modal` accepts lives on the element the function returns —
|
|
28
|
+
* `closeOnBackdropClick`, `aria-label`, `className` — so the consumer sees the
|
|
29
|
+
* real modal, not an options bag. **One duty comes with that freedom: the
|
|
30
|
+
* factory must attach the `ref` it receives to the `<Modal>`** (`<Modal
|
|
31
|
+
* ref={ref}>`). The trigger opens the dialog through that ref — and `Modal`
|
|
32
|
+
* requires its `ref`, so a factory that forgets it fails to compile.
|
|
33
|
+
*
|
|
34
|
+
* **How it closes:** the header's X button and Escape always work. Add
|
|
35
|
+
* `closeOnBackdropClick` to the modal element and a backdrop click works too.
|
|
36
|
+
*
|
|
37
|
+
* **Footer buttons can only close the modal.** That is the one and only
|
|
38
|
+
* action this HOC provides — wire one to the `close` the function receives:
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* const confirmationModal: WithModalRender = ({ close, ref }) => (
|
|
42
|
+
* <Modal ref={ref}>
|
|
43
|
+
* <Modal.Footer>
|
|
44
|
+
* <Button onClick={close}>Got it</Button>
|
|
45
|
+
* </Modal.Footer>
|
|
46
|
+
* </Modal>
|
|
47
|
+
* );
|
|
48
|
+
*
|
|
49
|
+
* const OpenButton = withModal(Button, confirmationModal);
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* If an action needs to do more than close — save data, open another modal,
|
|
53
|
+
* close conditionally — don't use this HOC: compose `Modal` directly and drive
|
|
54
|
+
* it through its `ref`.
|
|
55
|
+
*
|
|
56
|
+
* `withModal` is meant for static content and belongs at module scope, called
|
|
57
|
+
* once. The function it is handed is invoked on every render of the trigger,
|
|
58
|
+
* but at module scope it can only see module-level values, so what it returns
|
|
59
|
+
* is the same on every render. If the modal must show data from the parent —
|
|
60
|
+
* for example a different `userId` depending on which user is selected —
|
|
61
|
+
* don't call this HOC inside the component; compose `Modal` directly and
|
|
62
|
+
* drive it through its `ref`.
|
|
63
|
+
*
|
|
64
|
+
* A pure composition wrapper: it renders the wrapped component and the modal
|
|
65
|
+
* as siblings, so it carries no root element of its own.
|
|
66
|
+
*
|
|
67
|
+
* `import { withModal } from "@canonical/react-ds-global";`
|
|
68
|
+
*
|
|
69
|
+
* @param Component The trigger component to wrap (e.g. `Button`). It must accept `onClick` and forward it to its root element; clicking it opens the modal.
|
|
70
|
+
* @param modal A {@link WithModalRender} function: it receives `{ close, ref }`, must attach `ref` to the `<Modal>` it returns, and the trigger opens it.
|
|
71
|
+
*/
|
|
72
|
+
declare const withModal: <TProps extends WithModalTriggerProps>(Component: ComponentType<TProps>, modal: WithModalRender) => ComponentType<TProps>;
|
|
73
|
+
export default withModal;
|
|
74
|
+
//# sourceMappingURL=withModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withModal.d.ts","sourceRoot":"","sources":["../../../../../src/lib/pattern/Modal/withModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,OAAO,CAAC;AAEzD,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,QAAA,MAAM,SAAS,GAAI,MAAM,SAAS,qBAAqB,EACrD,WAAW,aAAa,CAAC,MAAM,CAAC,EAChC,OAAO,eAAe,KACrB,aAAa,CAAC,MAAM,CAyCtB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/pattern/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/pattern/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-ds-global",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/types/index.d.ts",
|
|
8
|
+
"style": "dist/esm/lib/index.css",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"default": "./dist/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./index.css": "./dist/esm/lib/index.css",
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
"./dist/*": "./dist/*"
|
|
17
|
+
},
|
|
8
18
|
"files": [
|
|
9
19
|
"dist"
|
|
10
20
|
],
|
|
@@ -43,26 +53,26 @@
|
|
|
43
53
|
"test:vitest:watch": "vitest"
|
|
44
54
|
},
|
|
45
55
|
"dependencies": {
|
|
46
|
-
"@canonical/design-tokens": "0.
|
|
47
|
-
"@canonical/ds-assets": "^0.
|
|
48
|
-
"@canonical/
|
|
49
|
-
"@canonical/
|
|
50
|
-
"@canonical/
|
|
51
|
-
"@canonical/
|
|
56
|
+
"@canonical/design-tokens": "0.10.0",
|
|
57
|
+
"@canonical/ds-assets": "^0.38.0",
|
|
58
|
+
"@canonical/ds-utils": "^0.38.0",
|
|
59
|
+
"@canonical/react-hooks": "^0.38.0",
|
|
60
|
+
"@canonical/storybook-config": "^0.38.0",
|
|
61
|
+
"@canonical/styles": "^0.38.0",
|
|
52
62
|
"react": "^19.2.4",
|
|
53
63
|
"react-dom": "^19.2.4"
|
|
54
64
|
},
|
|
55
65
|
"devDependencies": {
|
|
56
|
-
"@biomejs/biome": "2.
|
|
57
|
-
"@canonical/biome-config": "^0.
|
|
58
|
-
"@canonical/ds-types": "^0.
|
|
59
|
-
"@canonical/router-core": "^0.
|
|
60
|
-
"@canonical/router-react": "^0.
|
|
61
|
-
"@canonical/storybook-addon-utils": "^0.
|
|
62
|
-
"@canonical/storybook-helpers": "^0.
|
|
63
|
-
"@canonical/typescript-config-react": "^0.
|
|
64
|
-
"@canonical/vitest-config-react": "^0.
|
|
65
|
-
"@canonical/webarchitect": "^0.
|
|
66
|
+
"@biomejs/biome": "2.5.13",
|
|
67
|
+
"@canonical/biome-config": "^0.38.0",
|
|
68
|
+
"@canonical/ds-types": "^0.38.0",
|
|
69
|
+
"@canonical/router-core": "^0.38.0",
|
|
70
|
+
"@canonical/router-react": "^0.38.0",
|
|
71
|
+
"@canonical/storybook-addon-utils": "^0.38.0",
|
|
72
|
+
"@canonical/storybook-helpers": "^0.38.0",
|
|
73
|
+
"@canonical/typescript-config-react": "^0.38.0",
|
|
74
|
+
"@canonical/vitest-config-react": "^0.38.0",
|
|
75
|
+
"@canonical/webarchitect": "^0.38.0",
|
|
66
76
|
"@chromatic-com/storybook": "^5.0.1",
|
|
67
77
|
"@storybook/addon-docs": "^10.3.1",
|
|
68
78
|
"@storybook/react-vite": "^10.3.1",
|
|
@@ -80,5 +90,5 @@
|
|
|
80
90
|
"vite": "^8.0.1",
|
|
81
91
|
"vitest": "^4.0.18"
|
|
82
92
|
},
|
|
83
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "4d10a68a9b299af6fe3d1d7d053e54ca128944ad"
|
|
84
94
|
}
|