@noix-dev/brix-vue 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +74 -2
- package/package.json +117 -3
- package/src/components/address-field/AddressField.vue +337 -0
- package/src/components/address-field/index.ts +1 -0
- package/src/components/appearance-picker/AppearancePicker.vue +502 -0
- package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
- package/src/components/appearance-picker/index.ts +44 -0
- package/src/components/autofill/AutoFillDialog.vue +264 -0
- package/src/components/autofill/index.ts +1 -0
- package/src/components/badge/Badge.vue +23 -0
- package/src/components/badge/index.ts +106 -0
- package/src/components/build-stamp/BuildStamp.vue +62 -0
- package/src/components/build-stamp/index.ts +1 -0
- package/src/components/button/Button.vue +31 -0
- package/src/components/button/index.ts +122 -0
- package/src/components/card/Card.vue +29 -0
- package/src/components/card/CardAction.vue +17 -0
- package/src/components/card/CardContent.vue +14 -0
- package/src/components/card/CardDescription.vue +14 -0
- package/src/components/card/CardFooter.vue +22 -0
- package/src/components/card/CardHeader.vue +22 -0
- package/src/components/card/CardTitle.vue +29 -0
- package/src/components/card/index.ts +47 -0
- package/src/components/chart/BarChart.vue +123 -0
- package/src/components/chart/StackedBarChart.vue +149 -0
- package/src/components/chart/appearanceRevision.ts +22 -0
- package/src/components/chart/chartColor.ts +59 -0
- package/src/components/chart/index.ts +6 -0
- package/src/components/checkbox/Checkbox.vue +61 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/code-editor/CodeEditor.vue +352 -0
- package/src/components/code-editor/index.ts +9 -0
- package/src/components/code-editor/syntaxTheme.ts +110 -0
- package/src/components/colour-picker/ColourPicker.vue +421 -0
- package/src/components/colour-picker/index.ts +1 -0
- package/src/components/combobox/Combobox.vue +337 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/comments/CommentComposer.vue +302 -0
- package/src/components/comments/CommentMessage.vue +259 -0
- package/src/components/comments/CommentThread.vue +250 -0
- package/src/components/comments/commentBody.ts +185 -0
- package/src/components/comments/commentLevels.ts +139 -0
- package/src/components/comments/commentNode.ts +35 -0
- package/src/components/comments/composer.ts +20 -0
- package/src/components/comments/index.ts +29 -0
- package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/containers/Box.vue +42 -0
- package/src/components/containers/Section.vue +88 -0
- package/src/components/containers/SectionAction.vue +17 -0
- package/src/components/containers/SectionContent.vue +14 -0
- package/src/components/containers/SectionDescription.vue +14 -0
- package/src/components/containers/SectionHeader.vue +22 -0
- package/src/components/containers/SectionTitle.vue +17 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/data-table/ColumnMenu.vue +241 -0
- package/src/components/data-table/DataTable.vue +447 -0
- package/src/components/data-table/ExpandCaret.vue +34 -0
- package/src/components/data-table/SortableHead.vue +184 -0
- package/src/components/data-table/TableLoadingRow.vue +13 -0
- package/src/components/data-table/TableProgressRow.vue +26 -0
- package/src/components/data-table/columns.ts +13 -0
- package/src/components/data-table/index.ts +3 -0
- package/src/components/data-table/pinned.ts +19 -0
- package/src/components/data-table/rowActivation.ts +14 -0
- package/src/components/data-table/sort.ts +13 -0
- package/src/components/data-table/types.ts +23 -0
- package/src/components/date-picker/CalendarPanel.vue +432 -0
- package/src/components/date-picker/DateField.vue +293 -0
- package/src/components/date-picker/DatePicker.vue +147 -0
- package/src/components/date-picker/UntilDatePicker.vue +96 -0
- package/src/components/date-picker/dateFieldGuard.ts +87 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/useDateField.ts +37 -0
- package/src/components/date-range-picker/DateRangePicker.vue +247 -0
- package/src/components/date-range-picker/index.ts +1 -0
- package/src/components/date-time-picker/DateTimePicker.vue +291 -0
- package/src/components/date-time-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +250 -0
- package/src/components/dialog/DialogSurface.vue +214 -0
- package/src/components/dialog/dialogEdges.ts +65 -0
- package/src/components/dialog/dialogSizes.ts +35 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dialog/toastHost.ts +18 -0
- package/src/components/dropdown/Dropdown.vue +101 -0
- package/src/components/dropdown/DropdownItems.vue +154 -0
- package/src/components/dropdown/dropdown.ts +64 -0
- package/src/components/dropdown/index.ts +2 -0
- package/src/components/file-preview/FilePreview.vue +78 -0
- package/src/components/file-preview/index.ts +1 -0
- package/src/components/file-upload/FileUpload.vue +234 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
- package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
- package/src/components/filter-check-menu/index.ts +2 -0
- package/src/components/form-field/FormField.vue +74 -0
- package/src/components/form-field/index.ts +2 -0
- package/src/components/form-field/types.ts +5 -0
- package/src/components/frames/FrameCentred.vue +137 -0
- package/src/components/frames/FrameSidebar.vue +113 -0
- package/src/components/frames/FrameSplit.vue +109 -0
- package/src/components/frames/index.ts +3 -0
- package/src/components/icon/BellIcon.vue +27 -0
- package/src/components/icon/BoldIcon.vue +31 -0
- package/src/components/icon/CalendarDaysIcon.vue +33 -0
- package/src/components/icon/CheckIcon.vue +31 -0
- package/src/components/icon/ChevronDownIcon.vue +30 -0
- package/src/components/icon/ChevronLeftIcon.vue +31 -0
- package/src/components/icon/ChevronRightIcon.vue +31 -0
- package/src/components/icon/ChevronUpIcon.vue +30 -0
- package/src/components/icon/CircleAlertIcon.vue +29 -0
- package/src/components/icon/ClockIcon.vue +31 -0
- package/src/components/icon/Columns3Icon.vue +32 -0
- package/src/components/icon/FlipHorizontalIcon.vue +29 -0
- package/src/components/icon/ItalicIcon.vue +28 -0
- package/src/components/icon/LinkIcon.vue +27 -0
- package/src/components/icon/ListIcon.vue +29 -0
- package/src/components/icon/ListOrderedIcon.vue +28 -0
- package/src/components/icon/PenLineIcon.vue +31 -0
- package/src/components/icon/PlusIcon.vue +28 -0
- package/src/components/icon/RotateCcwIcon.vue +28 -0
- package/src/components/icon/RotateCwIcon.vue +28 -0
- package/src/components/icon/SearchIcon.vue +31 -0
- package/src/components/icon/StarIcon.vue +29 -0
- package/src/components/icon/TriangleAlertIcon.vue +29 -0
- package/src/components/icon/UnderlineIcon.vue +27 -0
- package/src/components/icon/Undo2Icon.vue +28 -0
- package/src/components/icon/XIcon.vue +31 -0
- package/src/components/icon/ZoomInIcon.vue +30 -0
- package/src/components/icon/ZoomOutIcon.vue +29 -0
- package/src/components/icon/index.ts +37 -0
- package/src/components/icon-picker/IconPicker.vue +560 -0
- package/src/components/icon-picker/index.ts +1 -0
- package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
- package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
- package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
- package/src/components/image-crop-dialog/index.ts +16 -0
- package/src/components/image-upload/ImageUpload.vue +345 -0
- package/src/components/image-upload/index.ts +2 -0
- package/src/components/input/Input.vue +48 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/keycap/Keycap.vue +49 -0
- package/src/components/keycap/index.ts +1 -0
- package/src/components/label/Label.vue +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/menu/MenuCheckboxItem.vue +63 -0
- package/src/components/menu/MenuContent.vue +45 -0
- package/src/components/menu/MenuGroup.vue +22 -0
- package/src/components/menu/MenuItem.vue +34 -0
- package/src/components/menu/MenuLabel.vue +22 -0
- package/src/components/menu/MenuRadioGroup.vue +22 -0
- package/src/components/menu/MenuRadioItem.vue +50 -0
- package/src/components/menu/MenuRoot.vue +25 -0
- package/src/components/menu/MenuSeparator.vue +27 -0
- package/src/components/menu/MenuSub.vue +29 -0
- package/src/components/menu/MenuSubContent.vue +48 -0
- package/src/components/menu/MenuSubTrigger.vue +49 -0
- package/src/components/menu/MenuTrigger.vue +22 -0
- package/src/components/menu/index.ts +20 -0
- package/src/components/menu/menuClasses.ts +74 -0
- package/src/components/morph-select/MorphSelect.vue +150 -0
- package/src/components/morph-select/index.ts +1 -0
- package/src/components/nav/NavFlyout.vue +343 -0
- package/src/components/nav/NavGroup.vue +306 -0
- package/src/components/nav/NavItem.vue +243 -0
- package/src/components/nav/NavNodes.ts +66 -0
- package/src/components/nav/NavSection.vue +105 -0
- package/src/components/nav/NavSidebar.vue +137 -0
- package/src/components/nav/index.ts +5 -0
- package/src/components/nav/navChain.ts +112 -0
- package/src/components/nav/navClasses.ts +229 -0
- package/src/components/nav/navNode.ts +10 -0
- package/src/components/nav/navRegistry.ts +24 -0
- package/src/components/notification-list/NotificationList.vue +314 -0
- package/src/components/notification-list/index.ts +2 -0
- package/src/components/notification-list/notifications.ts +21 -0
- package/src/components/pagination/Pagination.vue +296 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pin-field/PinField.vue +332 -0
- package/src/components/pin-field/index.ts +1 -0
- package/src/components/popover-panel/PopoverPanel.vue +115 -0
- package/src/components/popover-panel/index.ts +5 -0
- package/src/components/rating/Rating.vue +201 -0
- package/src/components/rating/index.ts +1 -0
- package/src/components/record-avatar/RecordAvatar.vue +76 -0
- package/src/components/record-avatar/index.ts +1 -0
- package/src/components/result-window/ResultWindow.vue +399 -0
- package/src/components/result-window/index.ts +2 -0
- package/src/components/result-window/results.ts +75 -0
- package/src/components/rich-editor/RichEditor.vue +370 -0
- package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
- package/src/components/rich-editor/index.ts +8 -0
- package/src/components/row-actions/RowActions.vue +262 -0
- package/src/components/row-actions/index.ts +2 -0
- package/src/components/row-actions/rowActions.ts +44 -0
- package/src/components/search-select/SearchSelect.vue +599 -0
- package/src/components/search-select/index.ts +2 -0
- package/src/components/search-select/types.ts +14 -0
- package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
- package/src/components/segmented-choice/index.ts +2 -0
- package/src/components/segmented-choice/segmentedOption.ts +6 -0
- package/src/components/select/Select.vue +18 -0
- package/src/components/select/SelectContent.vue +73 -0
- package/src/components/select/SelectGroup.vue +21 -0
- package/src/components/select/SelectItem.vue +47 -0
- package/src/components/select/SelectItemText.vue +12 -0
- package/src/components/select/SelectLabel.vue +17 -0
- package/src/components/select/SelectScrollDownButton.vue +36 -0
- package/src/components/select/SelectScrollUpButton.vue +36 -0
- package/src/components/select/SelectSeparator.vue +19 -0
- package/src/components/select/SelectTrigger.vue +52 -0
- package/src/components/select/SelectValue.vue +12 -0
- package/src/components/select/index.ts +11 -0
- package/src/components/session/IdleTimer.vue +71 -0
- package/src/components/session/SessionDialogs.vue +177 -0
- package/src/components/session/index.ts +2 -0
- package/src/components/split-button/SplitButton.vue +122 -0
- package/src/components/split-button/index.ts +2 -0
- package/src/components/split-button/splitButtonItem.ts +7 -0
- package/src/components/switch/Switch.vue +60 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.vue +51 -0
- package/src/components/table/TableBody.vue +14 -0
- package/src/components/table/TableCaption.vue +17 -0
- package/src/components/table/TableCell.vue +22 -0
- package/src/components/table/TableEmpty.vue +72 -0
- package/src/components/table/TableFooter.vue +17 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeader.vue +14 -0
- package/src/components/table/TableRow.vue +22 -0
- package/src/components/table/index.ts +9 -0
- package/src/components/tabs/Tabs.vue +173 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tabItem.ts +12 -0
- package/src/components/textarea/LimitedTextarea.vue +81 -0
- package/src/components/textarea/TextLimitCounter.vue +107 -0
- package/src/components/textarea/Textarea.vue +42 -0
- package/src/components/textarea/index.ts +4 -0
- package/src/components/textarea/textLimit.ts +43 -0
- package/src/components/time-picker/TimePicker.vue +522 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/toast/ToastHost.vue +276 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/update-notice/UpdateNotice.vue +103 -0
- package/src/components/update-notice/index.ts +1 -0
- package/src/components/user-menu/UserMenu.vue +154 -0
- package/src/components/user-menu/index.ts +1 -0
- package/src/index.ts +182 -0
- package/src/lib/cn.ts +21 -0
- package/src/lib/panelFocus.ts +65 -0
- package/src/lib/sessionMonitor.ts +390 -0
- package/src/lib/slotContent.ts +17 -0
- package/src/lib/updateCheck.ts +133 -0
- package/src/styles.css +82 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import { DialogClose, DialogDescription, DialogTitle } from 'reka-ui';
|
|
4
|
+
import type { HTMLAttributes } from 'vue';
|
|
5
|
+
import { onBeforeUnmount, useAttrs, useSlots, watch } from 'vue';
|
|
6
|
+
import { cn } from '../../lib/cn';
|
|
7
|
+
import { Button } from '../button';
|
|
8
|
+
import { XIcon } from '../icon';
|
|
9
|
+
import type { DialogEdge } from './dialogEdges';
|
|
10
|
+
import type { DialogSize } from './dialogSizes';
|
|
11
|
+
import DialogSurface from './DialogSurface.vue';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A modal panel over a scrim: a title, a body that scrolls, an optional footer row and a close
|
|
15
|
+
* button. Controlled — `open` in, `update:open` out — and it has no trigger of its own, so the
|
|
16
|
+
* opener is whatever the caller already has.
|
|
17
|
+
*
|
|
18
|
+
* It is `DialogSurface` plus its chrome: the surface owns the overlay composition, the colour,
|
|
19
|
+
* the scrim, `persistent`, the toast-host exception, the description wiring and the role, and
|
|
20
|
+
* its docblock carries what was measured about each. `Dialog` contributes the grid, the gap and
|
|
21
|
+
* the padding through the surface's `class`, so the content element is one element and carries
|
|
22
|
+
* the same classes it always has. With neither a heading nor a close button there is nothing for
|
|
23
|
+
* a header row to hold, so it is not drawn and the grid has two rows instead of three.
|
|
24
|
+
*
|
|
25
|
+
* AN EDGE IS A MODE OF THIS SAME COMPONENT. `edge` draws the panel against a side or the top or
|
|
26
|
+
* bottom of the viewport instead of the middle, so a slide-over is a `Dialog` with `edge="end"`:
|
|
27
|
+
* the same title, body and footer, the same props, the same events, and the header row, the
|
|
28
|
+
* scrolling body and the footer are untouched. This component adds no geometry for it; it only
|
|
29
|
+
* hands the prop to the surface. The two switches keep their meanings from an edge, too:
|
|
30
|
+
* `hideClose` still removes only the close button, and `persistent` still holds the panel open
|
|
31
|
+
* against Escape and a press outside while the close button keeps working.
|
|
32
|
+
*
|
|
33
|
+
* The close glyph is `close-icon`, a named slot (ADR 0013).
|
|
34
|
+
*
|
|
35
|
+
* THE ACCESSIBLE NAME has three routes, and one must resolve or the dialog is announced as
|
|
36
|
+
* "dialog" and nothing else (a warning says so in development):
|
|
37
|
+
* - the `title` prop;
|
|
38
|
+
* - the `title` slot, for a heading that holds more than a string (a glyph beside the words);
|
|
39
|
+
* - an `aria-label` attribute, for a dialog that shows no heading. It reaches the content
|
|
40
|
+
* element because `inheritAttrs` is off, and is also passed to the surface as its `label`,
|
|
41
|
+
* drawn as a visually hidden title so reka's own title check is satisfied. **If a `title`
|
|
42
|
+
* or a `title` slot is also given, the label is ignored**: the visible heading names the
|
|
43
|
+
* dialog.
|
|
44
|
+
*
|
|
45
|
+
* `hideClose` drops the close button for a dialog that must be answered with its own buttons.
|
|
46
|
+
* It does not stop Escape or a press outside from closing it: a confirm dialog wants
|
|
47
|
+
* `hideClose` **and** `persistent`.
|
|
48
|
+
*
|
|
49
|
+
* `aria-describedby`: a consumer's own value is kept, never erased. Reka looks for its own
|
|
50
|
+
* description element whenever that attribute is present, so passing one without a
|
|
51
|
+
* `description` (or a `description` slot) makes reka log its "Missing `Description`" warning.
|
|
52
|
+
* Give a `description` instead, or accept the warning.
|
|
53
|
+
*
|
|
54
|
+
* `class` reaches the panel only; the overlay takes none.
|
|
55
|
+
*
|
|
56
|
+
* `label` AND `described` ARE NOT ATTRIBUTES HERE. Attributes are forwarded to the surface with
|
|
57
|
+
* `v-bind`, and the surface declares those two as props, which the dialog then sets itself (from
|
|
58
|
+
* `aria-label` and from its description). A `label="..."` on a `Dialog` is therefore absorbed as
|
|
59
|
+
* a prop and overridden: it names nothing and reaches no element, and no warning says so. Use
|
|
60
|
+
* `aria-label` to name a dialog that shows no heading.
|
|
61
|
+
*/
|
|
62
|
+
// The root is reka's renderless DialogRoot, so fallthrough attributes (a data-testid) would be
|
|
63
|
+
// dropped; they belong on the content element.
|
|
64
|
+
defineOptions({ inheritAttrs: false });
|
|
65
|
+
|
|
66
|
+
const props = defineProps<{
|
|
67
|
+
open: boolean;
|
|
68
|
+
title?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
class?: HTMLAttributes['class'];
|
|
71
|
+
/** The close button's accessible name. Defaults to the `close` label of the contract. */
|
|
72
|
+
closeLabel?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Keeps the dialog open on Escape and on a click outside, for content a slip must not lose.
|
|
75
|
+
* The X and the caller's own buttons still close it.
|
|
76
|
+
*/
|
|
77
|
+
persistent?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Draws no close button. Escape and a press outside still close it: pair it with
|
|
80
|
+
* `persistent` for a dialog that must be answered with its own buttons.
|
|
81
|
+
*/
|
|
82
|
+
hideClose?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The panel's width, a named step of `DIALOG_SIZES`; the surface owns it. Left out, the
|
|
85
|
+
* dialog is the width it has always been. Width only: there is no height prop.
|
|
86
|
+
*
|
|
87
|
+
* | step | class | width |
|
|
88
|
+
* | ------ | -------------------------- | ------------------------------ |
|
|
89
|
+
* | `sm` | `max-w-sm` | 384px |
|
|
90
|
+
* | `md` | `max-w-md` | 448px |
|
|
91
|
+
* | `lg` | `max-w-2xl` (the default) | 672px |
|
|
92
|
+
* | `xl` | `max-w-5xl` | 1024px |
|
|
93
|
+
* | `full` | `max-w-[calc(100vw-2rem)]` | the viewport less a 16px gutter |
|
|
94
|
+
*
|
|
95
|
+
* The names are this package's, not Tailwind's: `sm` and `md` match Tailwind's own, but `lg`
|
|
96
|
+
* is `2xl` and `xl` is `5xl`, so do not read a step as the Tailwind class of the same name.
|
|
97
|
+
* The panel is also `w-[95vw]`, so the drawn width is the smaller of the two bounds.
|
|
98
|
+
*/
|
|
99
|
+
size?: DialogSize;
|
|
100
|
+
/**
|
|
101
|
+
* Draws the panel from an edge instead of the middle: a slide-over is `'end'`, the trailing
|
|
102
|
+
* edge. Forwarded to the surface, which owns the geometry; absent is the centred dialog, and
|
|
103
|
+
* that is not the same as `'end'`. A size step governs a side panel and a top or bottom one
|
|
104
|
+
* ignores it. See `dialogEdges.ts`.
|
|
105
|
+
*/
|
|
106
|
+
edge?: DialogEdge;
|
|
107
|
+
}>();
|
|
108
|
+
const emits = defineEmits<{
|
|
109
|
+
(e: 'update:open', value: boolean): void;
|
|
110
|
+
/**
|
|
111
|
+
* reka's own, forwarded: it fires once the content has mounted and reka is
|
|
112
|
+
* about to focus its first focusable element — the close X. A caller that
|
|
113
|
+
* wants the focus elsewhere (a destructive dialog putting it on the way
|
|
114
|
+
* out) calls preventDefault() here and focuses its own element.
|
|
115
|
+
*/
|
|
116
|
+
(e: 'openAutoFocus', event: Event): void;
|
|
117
|
+
/**
|
|
118
|
+
* reka's own, forwarded: it fires as the content goes away and reka is about to hand the
|
|
119
|
+
* focus back. A dialog opened from a plain button has no trigger for reka to return it to
|
|
120
|
+
* (the focus would fall to the page), so a caller calls preventDefault() here and focuses
|
|
121
|
+
* the element it was opened from.
|
|
122
|
+
*/
|
|
123
|
+
(e: 'closeAutoFocus', event: Event): void;
|
|
124
|
+
}>();
|
|
125
|
+
|
|
126
|
+
const labels = useUiLabels();
|
|
127
|
+
const slots = useSlots();
|
|
128
|
+
const attrs = useAttrs();
|
|
129
|
+
|
|
130
|
+
// `slots` is not reactive, so a computed over it would be cached for good and a slot that
|
|
131
|
+
// appears later would never be seen. These are plain functions, called on every render.
|
|
132
|
+
const hasDescription = (): boolean => props.description != null || slots.description != null;
|
|
133
|
+
const hasTitleSlot = (): boolean => slots.title != null;
|
|
134
|
+
const ariaLabel = (): string | null => {
|
|
135
|
+
const label = attrs['aria-label'];
|
|
136
|
+
return typeof label === 'string' && label.trim() !== '' ? label : null;
|
|
137
|
+
};
|
|
138
|
+
const isNamed = (): boolean => !!props.title || hasTitleSlot() || ariaLabel() !== null;
|
|
139
|
+
const hasHeading = (): boolean => !!props.title || hasTitleSlot();
|
|
140
|
+
const hasHeader = (): boolean => hasHeading() || !props.hideClose;
|
|
141
|
+
|
|
142
|
+
// Same register as reka's own title warning, which this replaces for the two routes it cannot
|
|
143
|
+
// see (the slot and the label are named through `DialogTitle` below and in the surface, so reka
|
|
144
|
+
// stays quiet).
|
|
145
|
+
//
|
|
146
|
+
// It looks again after a grace period instead of at the moment of opening, so a title that
|
|
147
|
+
// arrives later (loaded from an API) does not provoke a false alarm, and it is dropped if the
|
|
148
|
+
// dialog closes first. The guard is reka's own, `process.env.NODE_ENV`, so both halves of this
|
|
149
|
+
// dialog agree about what development means and a consumer's production build stays silent
|
|
150
|
+
// under whatever bundler they use. It is deliberately not `import.meta.env`, which a bundler
|
|
151
|
+
// other than Vite leaves undefined.
|
|
152
|
+
const NAME_GRACE_MS = 1500;
|
|
153
|
+
let nameTimer: ReturnType<typeof setTimeout> | undefined;
|
|
154
|
+
|
|
155
|
+
function stopNameCheck(): void {
|
|
156
|
+
if (nameTimer !== undefined) {
|
|
157
|
+
clearTimeout(nameTimer);
|
|
158
|
+
nameTimer = undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
watch(
|
|
163
|
+
() => props.open,
|
|
164
|
+
(open) => {
|
|
165
|
+
stopNameCheck();
|
|
166
|
+
if (!open || process.env.NODE_ENV === 'production') {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
nameTimer = setTimeout(() => {
|
|
170
|
+
nameTimer = undefined;
|
|
171
|
+
if (props.open && !isNamed()) {
|
|
172
|
+
console.warn(
|
|
173
|
+
'Warning: `Dialog` requires a title for the component to be accessible for screen reader users.\n\n' +
|
|
174
|
+
'Give it a `title` prop, a `title` slot or an `aria-label` attribute.',
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}, NAME_GRACE_MS);
|
|
178
|
+
},
|
|
179
|
+
{ immediate: true },
|
|
180
|
+
);
|
|
181
|
+
onBeforeUnmount(stopNameCheck);
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<template>
|
|
185
|
+
<DialogSurface
|
|
186
|
+
v-bind="attrs"
|
|
187
|
+
:open="open"
|
|
188
|
+
:persistent="persistent"
|
|
189
|
+
:described="hasDescription()"
|
|
190
|
+
:size="size"
|
|
191
|
+
:edge="edge"
|
|
192
|
+
:label="hasHeading() ? undefined : (ariaLabel() ?? undefined)"
|
|
193
|
+
:class="
|
|
194
|
+
cn(
|
|
195
|
+
'grid gap-4 p-6',
|
|
196
|
+
hasHeader()
|
|
197
|
+
? 'grid-rows-[auto_minmax(0,1fr)_auto]'
|
|
198
|
+
: 'grid-rows-[minmax(0,1fr)_auto]',
|
|
199
|
+
props.class,
|
|
200
|
+
)
|
|
201
|
+
"
|
|
202
|
+
@update:open="(v: boolean) => emits('update:open', v)"
|
|
203
|
+
@open-auto-focus="(e: Event) => emits('openAutoFocus', e)"
|
|
204
|
+
@close-auto-focus="(e: Event) => emits('closeAutoFocus', e)"
|
|
205
|
+
>
|
|
206
|
+
<div v-if="hasHeader()" class="flex items-start justify-between gap-4">
|
|
207
|
+
<DialogTitle v-if="hasHeading()" class="text-primary text-lg font-bold tracking-tight">
|
|
208
|
+
<slot name="title">{{ title }}</slot>
|
|
209
|
+
</DialogTitle>
|
|
210
|
+
<!-- `Button` is the recipe's own site for the focus ring (full strength, on
|
|
211
|
+
a `--background` gap), so the close button inherits it rather than
|
|
212
|
+
restating it. -->
|
|
213
|
+
<DialogClose v-if="!hideClose" as-child>
|
|
214
|
+
<Button
|
|
215
|
+
variant="ghost"
|
|
216
|
+
size="icon-sm"
|
|
217
|
+
class="text-muted-foreground ml-auto shrink-0"
|
|
218
|
+
:aria-label="closeLabel ?? labels.close"
|
|
219
|
+
data-testid="dialog-close"
|
|
220
|
+
>
|
|
221
|
+
<slot name="close-icon">
|
|
222
|
+
<XIcon />
|
|
223
|
+
</slot>
|
|
224
|
+
</Button>
|
|
225
|
+
</DialogClose>
|
|
226
|
+
</div>
|
|
227
|
+
<!-- Screen-reader-only description: supplies an accessible description and
|
|
228
|
+
silences reka's "Missing Description" warning without altering the visuals. It
|
|
229
|
+
sits outside the header row, so a dialog without one draws no row for it. -->
|
|
230
|
+
<DialogDescription v-if="hasDescription()" class="sr-only">
|
|
231
|
+
<slot name="description">{{ description }}</slot>
|
|
232
|
+
</DialogDescription>
|
|
233
|
+
<!-- The scrolling body clips in both axes (a scrolling axis makes the other clip too), so
|
|
234
|
+
it owes the focus ring's 4px the way the scrolling tab list does: `p-1` for the
|
|
235
|
+
ring, an equal `-m-1` so nothing moves. A field in a dialog is the ordinary
|
|
236
|
+
case — the "form inside a dialog" demo is one — and before this was paid its
|
|
237
|
+
ring was cut on all four sides, measured on the playground. The panel's own
|
|
238
|
+
`p-6` and the grid's `gap-4` absorb the negative margin, so no edge moves. -->
|
|
239
|
+
<div class="-m-1 min-h-0 overflow-y-auto p-1">
|
|
240
|
+
<slot />
|
|
241
|
+
</div>
|
|
242
|
+
<div
|
|
243
|
+
v-if="$slots.footer"
|
|
244
|
+
data-testid="dialog-footer"
|
|
245
|
+
class="border-border flex flex-wrap items-center justify-end gap-2 border-t pt-4"
|
|
246
|
+
>
|
|
247
|
+
<slot name="footer" />
|
|
248
|
+
</div>
|
|
249
|
+
</DialogSurface>
|
|
250
|
+
</template>
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { DialogContent, DialogOverlay, DialogPortal, DialogRoot, DialogTitle } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { computed, useAttrs, watch } from 'vue';
|
|
5
|
+
import { cn } from '../../lib/cn';
|
|
6
|
+
import {
|
|
7
|
+
DIALOG_EDGE_TRANSITION,
|
|
8
|
+
DIALOG_EDGES,
|
|
9
|
+
edgeTakesWidth,
|
|
10
|
+
type DialogEdge,
|
|
11
|
+
} from './dialogEdges';
|
|
12
|
+
import { DEFAULT_DIALOG_SIZE, DIALOG_SIZES, type DialogSize } from './dialogSizes';
|
|
13
|
+
import { TOAST_HOST_ATTRIBUTE } from './toastHost';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The overlay composition with nothing on it: a panel over a scrim, and no padding, no grid, no
|
|
17
|
+
* gap, no header row and no close button. `Dialog` is this plus its chrome; a surface that wants
|
|
18
|
+
* none of that — a command window, which is a search field and a list and has no heading — mounts
|
|
19
|
+
* this and draws what it wants. Controlled: `open` in, `update:open` out, and no trigger.
|
|
20
|
+
*
|
|
21
|
+
* **This is the overlay composition the rest of the package builds on**: reka's `DialogRoot`
|
|
22
|
+
* around a `DialogPortal` holding a `DialogOverlay` and a `DialogContent`. The portal has no
|
|
23
|
+
* `to`, so the surface lands as a child of `document.body`, which is also the only place the
|
|
24
|
+
* playground's contrast walk can see it (a portal aimed at a container inside the application
|
|
25
|
+
* shell is invisible to it). Reka stacks layers itself: with two dialogs open, Escape and an
|
|
26
|
+
* outside press reach the innermost only, and focus goes back to whatever held it when that
|
|
27
|
+
* dialog opened — `Dialog.test.ts` drives both rather than assuming them.
|
|
28
|
+
*
|
|
29
|
+
* COLOUR. The panel is `--popover`: the role for a surface that floats over the page. It is
|
|
30
|
+
* the same colour as `--card` in all six theme/mode pairs, so the choice moves no pixel and
|
|
31
|
+
* is made on meaning. It is **not** `--background`, and that matters in dark, where the
|
|
32
|
+
* popover is lighter than the page: every figure for text inside the panel is taken against
|
|
33
|
+
* the panel.
|
|
34
|
+
*
|
|
35
|
+
* THE SCRIM is a fixed swatch, deliberately. `bg-black/40` is the one fixed-palette utility
|
|
36
|
+
* left in this family: a scrim's whole job is to darken whatever is behind it, and black is
|
|
37
|
+
* the end of the scale in both modes. There is no `--overlay` role, and no pair in the gate
|
|
38
|
+
* could express one — a pair is ink on a ground, and a scrim is neither. The measurements
|
|
39
|
+
* and the reasoning are in the task report for this port; the short form is that no scrim
|
|
40
|
+
* colour at any alpha separates a dark panel from a dark page by 3:1 (black itself tops out
|
|
41
|
+
* at 1.26), so the role would be a colour nothing can check that changes nothing in dark.
|
|
42
|
+
*
|
|
43
|
+
* NAME IT. Reka names a dialog from a `DialogTitle` it finds in the content, and a surface
|
|
44
|
+
* with no heading has none. Give it a `label`, drawn as a visually hidden title, or render a
|
|
45
|
+
* `DialogTitle` of your own in the slot; a surface that has neither is announced as "dialog"
|
|
46
|
+
* and nothing else. (`Dialog` warns about this in development; the surface does not, because it
|
|
47
|
+
* cannot see a title nested inside a component of yours.)
|
|
48
|
+
*
|
|
49
|
+
* DESCRIPTION. Reka generates an `aria-describedby` id on every dialog and logs its "Missing
|
|
50
|
+
* `Description`" warning when nothing in the content carries that id. The surface keeps the id by
|
|
51
|
+
* default, so a surface that draws a `DialogDescription` is linked without being asked, and one
|
|
52
|
+
* that draws it wrongly is warned about, in development, rather than left unlinked in silence.
|
|
53
|
+
* A surface that draws no description passes `:described="false"`, which clears the id and the
|
|
54
|
+
* warning with it. A consumer's own `aria-describedby` attribute is never erased, whatever
|
|
55
|
+
* `described` says. A surface that describes itself with *visible* text, not a `DialogDescription`,
|
|
56
|
+
* links it with its own `aria-describedby`.
|
|
57
|
+
*
|
|
58
|
+
* ROLE. A consumer's `role="alertdialog"` replaces reka's `role="dialog"`: attributes are
|
|
59
|
+
* merged after reka's own, and `Dialog.test.ts` mounts it, on the surface and on `Dialog`, to prove it. There is no `role` prop.
|
|
60
|
+
* **Pass it conditionally**: a `role` attribute whose value is `undefined` is still a present key
|
|
61
|
+
* in the attributes spread here, and erases reka's `role="dialog"` rather than falling back to
|
|
62
|
+
* it. Spread an object only when you have a role (`v-bind="cond ? { role: 'alertdialog' } : {}"`).
|
|
63
|
+
*
|
|
64
|
+
* `class` reaches the panel only; the overlay takes none. It merges after the surface's own
|
|
65
|
+
* classes, so a caller's `max-w-sm` wins over the `size` step's width. `size` names the width
|
|
66
|
+
* (see `dialogSizes.ts`); it is the one axis the surface takes.
|
|
67
|
+
*/
|
|
68
|
+
// The root is reka's renderless DialogRoot, so fallthrough attributes (a data-testid) would be
|
|
69
|
+
// dropped; they belong on the content element.
|
|
70
|
+
defineOptions({ inheritAttrs: false });
|
|
71
|
+
|
|
72
|
+
const props = withDefaults(
|
|
73
|
+
defineProps<{
|
|
74
|
+
open: boolean;
|
|
75
|
+
class?: HTMLAttributes['class'];
|
|
76
|
+
/**
|
|
77
|
+
* Keeps the dialog open on Escape and on a click outside, for content a slip must not lose.
|
|
78
|
+
* A control of the caller's own still closes it.
|
|
79
|
+
*/
|
|
80
|
+
persistent?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Names a surface that draws no heading of its own, as a visually hidden title.
|
|
83
|
+
* A surface whose slot renders its own `DialogTitle` needs none.
|
|
84
|
+
*/
|
|
85
|
+
label?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Says whether anything in this surface describes it. Reka generates an
|
|
88
|
+
* `aria-describedby` id on every dialog; the default keeps it, so a surface that draws a
|
|
89
|
+
* description is linked without being asked. A surface that draws none passes `false`,
|
|
90
|
+
* which clears the id and with it reka's "Missing `Description`" warning.
|
|
91
|
+
*/
|
|
92
|
+
described?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The panel's width, as a named step of `DIALOG_SIZES`. Width only: the panel's maximum
|
|
95
|
+
* height is fixed and there is no height prop. The default is the width the dialog has
|
|
96
|
+
* always had. A caller's own `class` still wins over the step. A top or bottom edge is
|
|
97
|
+
* full width and ignores it, with a development warning; cap such a sheet with
|
|
98
|
+
* `class="max-w-md"` instead.
|
|
99
|
+
*/
|
|
100
|
+
size?: DialogSize;
|
|
101
|
+
/**
|
|
102
|
+
* Draws the panel from an edge instead of the middle. Absent is the centred dialog, which
|
|
103
|
+
* is not the same as `'end'`: see `dialogEdges.ts`. The size step governs a side panel
|
|
104
|
+
* (`start`, `end`) and is ignored by a top or bottom one.
|
|
105
|
+
*/
|
|
106
|
+
edge?: DialogEdge;
|
|
107
|
+
}>(),
|
|
108
|
+
{ described: true },
|
|
109
|
+
);
|
|
110
|
+
const emits = defineEmits<{
|
|
111
|
+
(e: 'update:open', value: boolean): void;
|
|
112
|
+
/**
|
|
113
|
+
* reka's own, forwarded: it fires once the content has mounted and reka is
|
|
114
|
+
* about to focus its first focusable element. A caller that wants the focus
|
|
115
|
+
* elsewhere (a destructive dialog putting it on the way out) calls
|
|
116
|
+
* preventDefault() here and focuses its own element.
|
|
117
|
+
*/
|
|
118
|
+
(e: 'openAutoFocus', event: Event): void;
|
|
119
|
+
/**
|
|
120
|
+
* reka's own, forwarded: it fires as the content goes away and reka is about to hand the
|
|
121
|
+
* focus back. A dialog opened from a plain button has no trigger for reka to return it to
|
|
122
|
+
* (the focus would fall to the page), so a caller calls preventDefault() here and focuses
|
|
123
|
+
* the element it was opened from.
|
|
124
|
+
*/
|
|
125
|
+
(e: 'closeAutoFocus', event: Event): void;
|
|
126
|
+
}>();
|
|
127
|
+
defineSlots<{ default?: () => unknown }>();
|
|
128
|
+
|
|
129
|
+
// The toast stack sits outside the dialog (see the toast host). Reaching for a toast's close
|
|
130
|
+
// button or link while a dialog is open is not "clicking outside": it must not dismiss the
|
|
131
|
+
// dialog and lose its input. The toast host marks itself with `TOAST_HOST_ATTRIBUTE`.
|
|
132
|
+
function onInteractOutside(event: Event): void {
|
|
133
|
+
const detail = (event as CustomEvent<{ originalEvent?: Event }>).detail;
|
|
134
|
+
const target = detail?.originalEvent?.target ?? event.target;
|
|
135
|
+
if (
|
|
136
|
+
props.persistent ||
|
|
137
|
+
(target instanceof Element && target.closest(`[${TOAST_HOST_ATTRIBUTE}]`) !== null)
|
|
138
|
+
) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function onEscapeKeyDown(event: Event): void {
|
|
144
|
+
if (props.persistent) {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// A consumer's own `aria-describedby` is theirs and is left alone; reka's id is cleared only when
|
|
150
|
+
// the caller says positively that nothing describes the surface.
|
|
151
|
+
const attrs = useAttrs();
|
|
152
|
+
|
|
153
|
+
// A block edge is full width, so the size step has nothing to govern and is dropped. That is the
|
|
154
|
+
// right behaviour, but silence plus an obvious override that misfires is a dead end, so say so in
|
|
155
|
+
// development. The guard is `process.env.NODE_ENV`, like `Dialog`'s name check.
|
|
156
|
+
const sizeIgnored = computed(
|
|
157
|
+
() => props.open && props.size !== undefined && !!props.edge && !edgeTakesWidth(props.edge),
|
|
158
|
+
);
|
|
159
|
+
watch(
|
|
160
|
+
sizeIgnored,
|
|
161
|
+
(ignored) => {
|
|
162
|
+
if (ignored && process.env.NODE_ENV !== 'production') {
|
|
163
|
+
console.warn(
|
|
164
|
+
`Warning: \`size\` has no effect on a \`${props.edge}\` edge, which is full width. ` +
|
|
165
|
+
'Cap it with a class such as `max-w-md` instead.',
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{ immediate: true },
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
// An edge the map does not know (a dynamic `edge="right"`) falls back to the centred dialog rather
|
|
173
|
+
// than leaving a `fixed` box with no insets.
|
|
174
|
+
const CENTRED = 'left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2';
|
|
175
|
+
const known = (): boolean => !!props.edge && props.edge in DIALOG_EDGES;
|
|
176
|
+
const contentAttrs = (): Record<string, unknown> => ({
|
|
177
|
+
...attrs,
|
|
178
|
+
...(props.described || 'aria-describedby' in attrs ? {} : { 'aria-describedby': undefined }),
|
|
179
|
+
});
|
|
180
|
+
</script>
|
|
181
|
+
|
|
182
|
+
<template>
|
|
183
|
+
<DialogRoot :open="open" @update:open="(v: boolean) => emits('update:open', v)">
|
|
184
|
+
<DialogPortal>
|
|
185
|
+
<!-- The one fixed-palette colour left in this family; see the note above. -->
|
|
186
|
+
<DialogOverlay
|
|
187
|
+
data-testid="dialog-overlay"
|
|
188
|
+
class="fixed inset-0 z-50 bg-black/40 backdrop-blur-sm"
|
|
189
|
+
/>
|
|
190
|
+
<DialogContent
|
|
191
|
+
v-bind="contentAttrs()"
|
|
192
|
+
:class="
|
|
193
|
+
cn(
|
|
194
|
+
'fixed z-50 max-h-[90vh] w-[95vw]',
|
|
195
|
+
'bg-popover text-popover-foreground ring-foreground/10 rounded-2xl shadow-xl ring-1 focus:outline-none',
|
|
196
|
+
known() ? DIALOG_EDGES[edge!] : CENTRED,
|
|
197
|
+
known() ? DIALOG_EDGE_TRANSITION : undefined,
|
|
198
|
+
!known() || edgeTakesWidth(edge!)
|
|
199
|
+
? DIALOG_SIZES[size ?? DEFAULT_DIALOG_SIZE]
|
|
200
|
+
: undefined,
|
|
201
|
+
props.class,
|
|
202
|
+
)
|
|
203
|
+
"
|
|
204
|
+
@open-auto-focus="(e: Event) => emits('openAutoFocus', e)"
|
|
205
|
+
@close-auto-focus="(e: Event) => emits('closeAutoFocus', e)"
|
|
206
|
+
@interact-outside="onInteractOutside"
|
|
207
|
+
@escape-key-down="onEscapeKeyDown"
|
|
208
|
+
>
|
|
209
|
+
<DialogTitle v-if="label" class="sr-only">{{ label }}</DialogTitle>
|
|
210
|
+
<slot />
|
|
211
|
+
</DialogContent>
|
|
212
|
+
</DialogPortal>
|
|
213
|
+
</DialogRoot>
|
|
214
|
+
</template>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The edges a dialog's surface can be drawn from. Four, and each is a position plus the resting
|
|
3
|
+
* transform that places the panel against that edge. The width is not here: a side panel takes
|
|
4
|
+
* its width from the size step (`dialogSizes.ts`), and a top or bottom panel takes none.
|
|
5
|
+
*
|
|
6
|
+
* AN ABSENT EDGE IS THE CENTRED DIALOG, AND THAT IS NOT THE SAME AS `'end'`. `DEFAULT_DIALOG_EDGE`
|
|
7
|
+
* is the trailing edge, and it applies only once a caller asks for an edge at all (a `Dialog`
|
|
8
|
+
* switched into a slide-over without saying which side). A surface given no `edge` at all is the
|
|
9
|
+
* dialog this package has always drawn, in the middle of the screen. Seven dialogs are mounted
|
|
10
|
+
* inside this package with no `edge`; if absence meant "trailing", all seven would move off the
|
|
11
|
+
* centre in one change.
|
|
12
|
+
*
|
|
13
|
+
* `start` AND `end` ARE LOGICAL, NOT LEFT AND RIGHT. They are written with `start-0` / `end-0`
|
|
14
|
+
* and the entry offset is mirrored with `rtl:`, so a right-to-left document puts a `start`
|
|
15
|
+
* panel on the right without a second map. `top` and `bottom` are physical because the block
|
|
16
|
+
* axis does not flip with the writing direction.
|
|
17
|
+
*
|
|
18
|
+
* A SIZE STEP GOVERNS A SIDE PANEL AND IS IGNORED BY A TOP OR BOTTOM ONE. This slice adds no
|
|
19
|
+
* height axis. Tailwind's named `max-w-*` scale has no `max-h-*` twin, so a parallel named height
|
|
20
|
+
* map would be invented rather than derived, which is what the size scale's own rule forbids.
|
|
21
|
+
* A top or bottom panel is full width and as tall as its content, under the surface's existing
|
|
22
|
+
* `max-h-[90vh]`. `edgeTakesWidth` is the one place that says which edges those are.
|
|
23
|
+
*
|
|
24
|
+
* THE ENTRY IS A TRANSFORM AND NEVER AN OPACITY. The panel slides from its edge through the
|
|
25
|
+
* `starting:` variant, which sets the offset the first frame is drawn at. No opacity utility
|
|
26
|
+
* enters this file or the surface: an opacity animation is read by the playground's contrast
|
|
27
|
+
* walk as a half-faded surface, which `menu/menuClasses.ts` records and is why the menu panels
|
|
28
|
+
* animate nothing at all. Only the entry moves; the surface unmounts on close. The transition
|
|
29
|
+
* tokens are the edge's own (`DIALOG_EDGE_TRANSITION`), so a centred dialog carries none.
|
|
30
|
+
*
|
|
31
|
+
* NO `h-full` ON A SIDE PANEL. A `fixed` box with `inset-y-0` and an auto height already fills the
|
|
32
|
+
* viewport, and `h-full` is a different merge group from `top-*`: a caller pushing the panel below
|
|
33
|
+
* a top bar would leave `h-full` standing, drop `bottom`, and run the footer off-screen. `mx-auto`
|
|
34
|
+
* on a top or bottom panel is inert with `inset-x-0` and an auto width, and centres the sheet the
|
|
35
|
+
* moment a caller caps it with `max-w-*`.
|
|
36
|
+
*
|
|
37
|
+
* BROWSER FLOOR. This is the package's first use of `@starting-style` (the `starting:` variant).
|
|
38
|
+
* A browser without it drops the at-rule and draws the panel at rest: no animation, no broken
|
|
39
|
+
* layout.
|
|
40
|
+
*/
|
|
41
|
+
export type DialogEdge = 'start' | 'end' | 'top' | 'bottom';
|
|
42
|
+
|
|
43
|
+
/** The position and resting transform each edge draws. Width is the size step's job. */
|
|
44
|
+
export const DIALOG_EDGES = {
|
|
45
|
+
start:
|
|
46
|
+
'inset-y-0 start-0 max-h-none w-[95vw] rounded-none ' +
|
|
47
|
+
'starting:-translate-x-full rtl:starting:translate-x-full',
|
|
48
|
+
end:
|
|
49
|
+
'inset-y-0 end-0 max-h-none w-[95vw] rounded-none ' +
|
|
50
|
+
'starting:translate-x-full rtl:starting:-translate-x-full',
|
|
51
|
+
top: 'inset-x-0 top-0 mx-auto w-full rounded-t-none starting:-translate-y-full',
|
|
52
|
+
bottom: 'inset-x-0 bottom-0 mx-auto w-full rounded-b-none starting:translate-y-full',
|
|
53
|
+
} as const satisfies Record<DialogEdge, string>;
|
|
54
|
+
|
|
55
|
+
/** The transition an edge panel enters with. Transform only, never opacity; reduced motion drops it. */
|
|
56
|
+
export const DIALOG_EDGE_TRANSITION =
|
|
57
|
+
'transition-transform duration-200 ease-out motion-reduce:transition-none';
|
|
58
|
+
|
|
59
|
+
/** The edge a panel takes once a caller asks for one: the trailing edge. */
|
|
60
|
+
export const DEFAULT_DIALOG_EDGE: DialogEdge = 'end';
|
|
61
|
+
|
|
62
|
+
/** True where the edge is a side, and the size step therefore governs. */
|
|
63
|
+
export function edgeTakesWidth(edge: DialogEdge): boolean {
|
|
64
|
+
return edge !== 'top' && edge !== 'bottom';
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dialog's named widths. Five steps, and every one of them is a width this repository
|
|
3
|
+
* already draws: `md` is the confirm dialog's, `lg` is the dialog's own, `xl` is the image crop
|
|
4
|
+
* dialog's, `sm` is the rich-editor link dialog's (`rich-editor/RichEditorLinkDialog.vue`, which drew
|
|
5
|
+
* `max-w-sm` before there was a scale), and `full` is the constrained full width the spec's
|
|
6
|
+
* section 3 names. The scale was derived from those; it is not a design of its
|
|
7
|
+
* own, and a step is added when something draws a width the scale lacks, not before.
|
|
8
|
+
*
|
|
9
|
+
* THE DEFAULT IS `lg`, AND THAT IS NOT NEGOTIABLE. `lg` is `max-w-2xl`, the width `Dialog` had
|
|
10
|
+
* before there was a scale. A consumer who never heard of `size` must see the same dialog after
|
|
11
|
+
* this prop landed as before, so the default is whichever step carries that width, whatever it
|
|
12
|
+
* is called.
|
|
13
|
+
*
|
|
14
|
+
* WHY `full` IS NOT `max-w-full`. The panel is `w-[95vw]` and the step is a `max-w`, so the drawn
|
|
15
|
+
* width is the smaller of the two. For `full` the two cross at a viewport of 640px (`0.95 * V`
|
|
16
|
+
* equals `V - 2rem` there, at the default 16px root size). Above 640px `w-[95vw]` is the smaller
|
|
17
|
+
* bound, so the step is not the binding constraint and `full` draws the same as the viewport term
|
|
18
|
+
* alone (1368px at a 1440px viewport). Below 640px the step is the tighter bound and the panel is
|
|
19
|
+
* narrower than 95vw: a 16px gutter each side, where 95vw would leave 9.4px at a 375px viewport
|
|
20
|
+
* (343px drawn against 356.3px). That gutter on a phone is what the constrained form buys, and why
|
|
21
|
+
* the step is not bare `max-w-full`. The other steps cross `w-[95vw]` elsewhere; `sm` is 384px,
|
|
22
|
+
* so it is the binding bound from a viewport of about 404px up. A step sets a width and nothing
|
|
23
|
+
* else: there is no height axis, because the panel already carries a maximum height.
|
|
24
|
+
*/
|
|
25
|
+
export type DialogSize = 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
26
|
+
|
|
27
|
+
export const DIALOG_SIZES = {
|
|
28
|
+
sm: 'max-w-sm',
|
|
29
|
+
md: 'max-w-md',
|
|
30
|
+
lg: 'max-w-2xl',
|
|
31
|
+
xl: 'max-w-5xl',
|
|
32
|
+
full: 'max-w-[calc(100vw-2rem)]',
|
|
33
|
+
} as const satisfies Record<DialogSize, string>;
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_DIALOG_SIZE: DialogSize = 'lg';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { default as Dialog } from './Dialog.vue';
|
|
2
|
+
/**
|
|
3
|
+
* The overlay composition `Dialog` is built on, published so a surface that wants none of the
|
|
4
|
+
* dialog's chrome — no padding, no heading, no close button — can mount it and draw its own.
|
|
5
|
+
* `Dialog` composes this; it keeps nothing private beneath it.
|
|
6
|
+
*/
|
|
7
|
+
export { default as DialogSurface } from './DialogSurface.vue';
|
|
8
|
+
export { TOAST_HOST_ATTRIBUTE } from './toastHost';
|
|
9
|
+
export { DEFAULT_DIALOG_SIZE, DIALOG_SIZES } from './dialogSizes';
|
|
10
|
+
export type { DialogSize } from './dialogSizes';
|
|
11
|
+
export { DEFAULT_DIALOG_EDGE, DIALOG_EDGES, edgeTakesWidth } from './dialogEdges';
|
|
12
|
+
export type { DialogEdge } from './dialogEdges';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attribute a toast host puts on its viewport so a dialog can tell "pressed inside a
|
|
3
|
+
* toast" from "pressed outside the dialog". Imported by the toast family: do not retype the
|
|
4
|
+
* string.
|
|
5
|
+
*
|
|
6
|
+
* Why it exists: a toast sits outside the dialog's DOM, so reaching for its close button or
|
|
7
|
+
* link while a dialog is open is, to reka, an outside interaction, and would dismiss the dialog
|
|
8
|
+
* and throw away whatever the user had typed into it. The dialog reads
|
|
9
|
+
* `closest('[data-toast-host]')` off the original event's target, so pointer presses and focus
|
|
10
|
+
* moving into the toast are both covered.
|
|
11
|
+
*
|
|
12
|
+
* Two things the toast host has to know:
|
|
13
|
+
* - its viewport must stack above the panel's `z-50`, or it is drawn under the scrim it is
|
|
14
|
+
* meant to be reachable over;
|
|
15
|
+
* - `Dialog`'s `class` prop reaches the panel only. The overlay takes none, so nothing a
|
|
16
|
+
* consumer passes can restyle or raise it.
|
|
17
|
+
*/
|
|
18
|
+
export const TOAST_HOST_ATTRIBUTE = 'data-toast-host';
|