@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,522 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
formatTime,
|
|
4
|
+
hourOptions,
|
|
5
|
+
isWholeTime,
|
|
6
|
+
minuteOptions,
|
|
7
|
+
parseTime,
|
|
8
|
+
useUiLabels,
|
|
9
|
+
} from '@noix-dev/brix-core';
|
|
10
|
+
import { computed, nextTick, ref, useAttrs, useId, useTemplateRef, watch } from 'vue';
|
|
11
|
+
import type { HTMLAttributes } from 'vue';
|
|
12
|
+
import { cn } from '../../lib/cn';
|
|
13
|
+
import { ClockIcon } from '../icon';
|
|
14
|
+
import { Label } from '../label';
|
|
15
|
+
import { PopoverPanel } from '../popover-panel';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A time-of-day field: a text input that takes `hh:mm`, and a panel of two columns, hours on
|
|
19
|
+
* the left and minutes on the right. The model is `'HH:MM'` and `''` for no time at all, never
|
|
20
|
+
* midnight. `HH:MM:SS` is accepted and shortened to `HH:MM`, once and at once (the field emits
|
|
21
|
+
* the short form on mount), so a form seeded straight from an API never holds the long one.
|
|
22
|
+
*
|
|
23
|
+
* WHY TWO COLUMNS and not 96 ready-made times: two taps instead of a scroll through ninety-six
|
|
24
|
+
* entries, and rows big enough for a thumb. The native control this replaces is good on a
|
|
25
|
+
* phone, so a cramped panel would be a downgrade there.
|
|
26
|
+
*
|
|
27
|
+
* TYPING. A whole time (`14:45`, or `9:30`) commits as it is typed; anything shorter does not,
|
|
28
|
+
* and the text is not rewritten under the fingers. Leaving the field with text that is not a
|
|
29
|
+
* time puts the last committed one back: someone who typed `14:4` and tabbed away meant a
|
|
30
|
+
* time, and clearing the field would be the harsher answer. Clearing the text empties the model.
|
|
31
|
+
* A time typed without the colon (`1430`, as a numeric keypad produces it) commits live ONLY at
|
|
32
|
+
* four digits. Three digits (`930`) are a time too, but `143` is also the start of `1430`, so
|
|
33
|
+
* they are read on Enter or on leaving the field and never while the fingers are still moving.
|
|
34
|
+
*
|
|
35
|
+
* THE PANEL is the `PopoverPanel` shell, named by its trigger: the clock button's accessible
|
|
36
|
+
* name, `timePickerChoose` ("Choose a time"), is what a screen reader announces for the panel,
|
|
37
|
+
* so it reads as a purpose and not as an action. It is anchored to that button, and its right
|
|
38
|
+
* edge is held to the button's so it opens inward under the field. The trigger is a full-height,
|
|
39
|
+
* 36px-wide target and not a glyph-sized box: where the field is the only way in, the glyph's
|
|
40
|
+
* own box would be the smallest target on the screen.
|
|
41
|
+
*
|
|
42
|
+
* A pick sets only its own half and leaves the panel open, since choosing a time takes two
|
|
43
|
+
* taps and the second must not land on a closed panel. On an empty field the half not yet
|
|
44
|
+
* picked is `00`, so one tap always leaves a whole time behind. A minute the raster does not
|
|
45
|
+
* hold (`09:07` with the default step of 15) is added to the column, in its place, and shown
|
|
46
|
+
* as chosen: the value in force is never hidden by the grid it was not picked from. Picking
|
|
47
|
+
* another minute takes it off again.
|
|
48
|
+
*
|
|
49
|
+
* KEYBOARD. Both columns hold ONE tab stop between them, on the option in force (the hour,
|
|
50
|
+
* or 08 when nothing is chosen: the earliest hour a day usually starts, rather than midnight),
|
|
51
|
+
* and every other option is `tabindex="-1"`, so Tab leaves the panel instead of walking
|
|
52
|
+
* twenty-four hours and four minutes. Up and Down, PageUp and PageDown, Home and End move
|
|
53
|
+
* within a column; Left and Right cross to the other. Moving picks nothing: Enter or Space on
|
|
54
|
+
* the focused option does, through its own click.
|
|
55
|
+
*
|
|
56
|
+
* DENSITY, MEASURED. The field box is the `input` slot and the inner input and the trigger both
|
|
57
|
+
* fill it, so a page's density settings size all three together and nothing overflows. On the
|
|
58
|
+
* playground page's form section (the only place the page-density rule's whole ancestor chain
|
|
59
|
+
* `[data-brix-page-shape] [data-slot=form-section] [data-slot=form-field]` exists), measured on a
|
|
60
|
+
* form-section instance with nothing forced in the DOM, in pixels:
|
|
61
|
+
*
|
|
62
|
+
* normal box 36 input 34 trigger 34
|
|
63
|
+
* compact box 28 input 26 trigger 26
|
|
64
|
+
* dense box 26 input 24 trigger 24
|
|
65
|
+
*
|
|
66
|
+
* The playground's variant and state sections are outside that chain by design, as every
|
|
67
|
+
* family's are, so their boxes stay 36.
|
|
68
|
+
*
|
|
69
|
+
* THE GLYPH is the `clock-icon` slot (ADR 0013).
|
|
70
|
+
*
|
|
71
|
+
* CONTRAST, MEASURED with `packages/tokens/src/contrast.ts` over the six theme and mode pairs
|
|
72
|
+
* (kingfisher light and dark, graphite light and dark, noix light and dark). The row's hover
|
|
73
|
+
* wash is `--foreground` on `--muted`, the pairing `PinField` records too, and a CSS `:hover`
|
|
74
|
+
* cannot be set from a script, so the playground's walk never reads it:
|
|
75
|
+
*
|
|
76
|
+
* --foreground on --muted: 18.15 14.48 16.31 12.18 15.96 12.58
|
|
77
|
+
*
|
|
78
|
+
* (`PinField` quotes 18.16 and 14.50 for the first two, read through a canvas; the maths and the
|
|
79
|
+
* canvas differ in the second decimal and agree on every conclusion.)
|
|
80
|
+
*
|
|
81
|
+
* WORDING comes from the labels contract (`timePickerHour`, `timePickerMinute`,
|
|
82
|
+
* `timePickerChoose`); `labels` overrides member by member and the rest keep the contract's.
|
|
83
|
+
*
|
|
84
|
+
* Attributes (`id`, `name`, `data-testid`, `aria-*`) land on the input; `class` and `style` on
|
|
85
|
+
* the outer element. The outer element, its label and the field box carry the `form-field`,
|
|
86
|
+
* `label` and `input` slots, so a page's density settings reach this field as they reach every
|
|
87
|
+
* other.
|
|
88
|
+
*/
|
|
89
|
+
defineOptions({ inheritAttrs: false });
|
|
90
|
+
|
|
91
|
+
interface TimePickerLabels {
|
|
92
|
+
timePickerHour: string;
|
|
93
|
+
timePickerMinute: string;
|
|
94
|
+
timePickerChoose: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const props = withDefaults(
|
|
98
|
+
defineProps<{
|
|
99
|
+
/** `'HH:MM'` (`'HH:MM:SS'` is shortened); `''` for no time. */
|
|
100
|
+
modelValue?: string;
|
|
101
|
+
label?: string;
|
|
102
|
+
placeholder?: string;
|
|
103
|
+
required?: boolean;
|
|
104
|
+
disabled?: boolean;
|
|
105
|
+
/** The error message. It marks the input invalid and is announced with it. */
|
|
106
|
+
error?: string;
|
|
107
|
+
/** A line under the field, announced with it. */
|
|
108
|
+
hint?: string;
|
|
109
|
+
/** The raster of the minute column. */
|
|
110
|
+
minuteStep?: number;
|
|
111
|
+
/** Overrides the three words below member by member; the rest keep the contract's. */
|
|
112
|
+
labels?: Partial<TimePickerLabels>;
|
|
113
|
+
class?: HTMLAttributes['class'];
|
|
114
|
+
}>(),
|
|
115
|
+
{
|
|
116
|
+
modelValue: '',
|
|
117
|
+
label: undefined,
|
|
118
|
+
placeholder: undefined,
|
|
119
|
+
required: false,
|
|
120
|
+
disabled: false,
|
|
121
|
+
error: undefined,
|
|
122
|
+
hint: undefined,
|
|
123
|
+
minuteStep: 15,
|
|
124
|
+
labels: undefined,
|
|
125
|
+
class: undefined,
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>();
|
|
130
|
+
|
|
131
|
+
const attrs = useAttrs();
|
|
132
|
+
const contract = useUiLabels();
|
|
133
|
+
|
|
134
|
+
const text = computed<TimePickerLabels>(() => ({
|
|
135
|
+
timePickerHour: contract.value.timePickerHour,
|
|
136
|
+
timePickerMinute: contract.value.timePickerMinute,
|
|
137
|
+
timePickerChoose: contract.value.timePickerChoose,
|
|
138
|
+
// Members given as `undefined` are dropped, not spread: they would blank the contract's word.
|
|
139
|
+
...Object.fromEntries(Object.entries(props.labels ?? {}).filter(([, v]) => v !== undefined)),
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The trigger's name is the panel's name (the shell names the panel after it), so on a form
|
|
144
|
+
* with two of these ("Start time", "End time") it carries the field as well as the action.
|
|
145
|
+
* It is the trigger's own `aria-label`, not an `aria-labelledby` pointing at the label: the
|
|
146
|
+
* panel reaches the trigger by `aria-labelledby`, and a name computed through one reference
|
|
147
|
+
* ignores the trigger's own `aria-labelledby`, so only a label on the trigger itself is
|
|
148
|
+
* carried across.
|
|
149
|
+
*/
|
|
150
|
+
const triggerName = computed(() =>
|
|
151
|
+
props.label ? `${text.value.timePickerChoose}, ${props.label}` : text.value.timePickerChoose,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
/** The hour a column's tab stop starts on when nothing is chosen. */
|
|
155
|
+
const FALLBACK_HOUR = '08';
|
|
156
|
+
/** Up and Down by this many rows is about what a column shows at once. */
|
|
157
|
+
const PAGE = 6;
|
|
158
|
+
|
|
159
|
+
const fallbackId = useId();
|
|
160
|
+
const fieldId = computed(() => (attrs.id as string | undefined) ?? fallbackId);
|
|
161
|
+
const hintId = `${useId()}-hint`;
|
|
162
|
+
const errorId = `${useId()}-error`;
|
|
163
|
+
const hourHeadingId = useId();
|
|
164
|
+
const minuteHeadingId = useId();
|
|
165
|
+
|
|
166
|
+
/** The model as the parts it holds, or null when it is empty or no time. */
|
|
167
|
+
const parts = computed(() => parseTime(props.modelValue ?? ''));
|
|
168
|
+
/** The canonical string for the model: `'09:30'`, or `''`. */
|
|
169
|
+
const value = computed(() => (parts.value ? formatTime(parts.value) : ''));
|
|
170
|
+
const chosenHour = computed(() => (parts.value ? formatTime(parts.value).slice(0, 2) : null));
|
|
171
|
+
const chosenMinute = computed(() => (parts.value ? formatTime(parts.value).slice(3) : null));
|
|
172
|
+
|
|
173
|
+
const typed = ref(value.value);
|
|
174
|
+
watch(value, (current) => {
|
|
175
|
+
typed.value = current;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// A model that is present but not canonical is corrected on the spot, and not only in what is
|
|
179
|
+
// shown: a form seeded with `HH:MM:SS` that never touches this field would otherwise send the
|
|
180
|
+
// long form back untouched. An empty model is left alone, because emitting `''` over an absent
|
|
181
|
+
// value would make a pristine form dirty, and so is one that is no time at all.
|
|
182
|
+
watch(
|
|
183
|
+
() => props.modelValue,
|
|
184
|
+
(raw) => {
|
|
185
|
+
if (raw && value.value !== '' && value.value !== raw) {
|
|
186
|
+
emit('update:modelValue', value.value);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
{ immediate: true },
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
function onInput(event: Event): void {
|
|
193
|
+
const raw = (event.target as HTMLInputElement).value;
|
|
194
|
+
typed.value = raw;
|
|
195
|
+
if (raw.trim() === '') {
|
|
196
|
+
if (value.value !== '') {
|
|
197
|
+
emit('update:modelValue', '');
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// A colon-free entry commits live ONLY at four digits. Four is terminal (no valid form is
|
|
202
|
+
// longer), whereas `143` and `1430` are both times and one is the prefix of the other: a
|
|
203
|
+
// live commit at three digits would rewrite the field to `01:43` under the fingers.
|
|
204
|
+
// Three digits wait for the blur or Enter.
|
|
205
|
+
if (!raw.includes(':') && raw.trim().length < 4) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
commitTyped(raw);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Emits the time the text holds when it is a whole one and is not already the model. */
|
|
212
|
+
function commitTyped(raw: string): void {
|
|
213
|
+
const parsed = parseTime(raw);
|
|
214
|
+
if (parsed && formatTime(parsed) !== props.modelValue) {
|
|
215
|
+
emit('update:modelValue', formatTime(parsed));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function onEnter(): void {
|
|
220
|
+
commitTyped(typed.value);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function onBlur(): void {
|
|
224
|
+
if (typed.value.trim() === '' || !isWholeTime(typed.value)) {
|
|
225
|
+
typed.value = value.value;
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
commitTyped(typed.value);
|
|
229
|
+
typed.value = formatTime(parseTime(typed.value)!);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// --- The panel. ---
|
|
233
|
+
|
|
234
|
+
const open = ref(false);
|
|
235
|
+
const hours = hourOptions();
|
|
236
|
+
const minutes = computed(() => {
|
|
237
|
+
const raster = minuteOptions(props.minuteStep);
|
|
238
|
+
const off = chosenMinute.value;
|
|
239
|
+
return off !== null && !raster.includes(off) ? [...raster, off].sort() : raster;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
type Column = 'hour' | 'minute';
|
|
243
|
+
const hourList = useTemplateRef<HTMLElement>('hourList');
|
|
244
|
+
const minuteList = useTemplateRef<HTMLElement>('minuteList');
|
|
245
|
+
|
|
246
|
+
/** The one option in the tab order, for both columns together. */
|
|
247
|
+
const stop = ref<{ column: Column; value: string }>({ column: 'hour', value: FALLBACK_HOUR });
|
|
248
|
+
|
|
249
|
+
const columns = computed<Record<Column, string[]>>(() => ({ hour: hours, minute: minutes.value }));
|
|
250
|
+
|
|
251
|
+
/** The stop, unless the option it names has gone (an off-raster minute taken off the column). */
|
|
252
|
+
const tabStop = computed(() =>
|
|
253
|
+
columns.value[stop.value.column].includes(stop.value.value)
|
|
254
|
+
? stop.value
|
|
255
|
+
: { column: 'hour' as Column, value: chosenHour.value ?? FALLBACK_HOUR },
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
function listOf(column: Column): HTMLElement | null {
|
|
259
|
+
return column === 'hour' ? hourList.value : minuteList.value;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function optionEl(column: Column, optionValue: string): HTMLElement | null {
|
|
263
|
+
return listOf(column)?.querySelector<HTMLElement>(`[data-value="${optionValue}"]`) ?? null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function moveTo(column: Column, optionValue: string): Promise<void> {
|
|
267
|
+
stop.value = { column, value: optionValue };
|
|
268
|
+
await nextTick();
|
|
269
|
+
optionEl(column, optionValue)?.focus();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function centre(column: Column, optionValue: string): void {
|
|
273
|
+
const list = listOf(column);
|
|
274
|
+
const cell = optionEl(column, optionValue);
|
|
275
|
+
if (list && cell) {
|
|
276
|
+
// `offsetTop` is measured from the nearest positioned ancestor, which is why the lists
|
|
277
|
+
// are `relative`: without it the figure carried the panel's padding and the heading.
|
|
278
|
+
list.scrollTop = cell.offsetTop - list.clientHeight / 2 + cell.clientHeight / 2;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Whether this opening has been centred yet: the lists may mount after `open` turns true. */
|
|
283
|
+
let centred = false;
|
|
284
|
+
|
|
285
|
+
watch(open, (isOpen) => {
|
|
286
|
+
centred = false;
|
|
287
|
+
if (isOpen) {
|
|
288
|
+
stop.value = { column: 'hour', value: chosenHour.value ?? FALLBACK_HOUR };
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Centred when the lists EXIST, not on a fixed tick after `open` turns true: the panel is
|
|
293
|
+
// portalled and mounted by the popover engine, and a one-shot `nextTick` that found no list
|
|
294
|
+
// would do nothing at all and leave the column at its top for the whole opening. Scrolled by
|
|
295
|
+
// hand (`scrollIntoView()` also scrolls every scrollable ancestor, and the window with them).
|
|
296
|
+
// Both columns are centred on what is chosen in them: a fine raster (a step of 5 gives twelve
|
|
297
|
+
// minutes, and a window shows about six) would otherwise open with the chosen minute out of
|
|
298
|
+
// sight. A jsdom test with stubbed measures cannot tell a first opening from a later one; the
|
|
299
|
+
// first-opening behaviour was checked in a browser.
|
|
300
|
+
watch(
|
|
301
|
+
[open, hourList, minuteList],
|
|
302
|
+
() => {
|
|
303
|
+
if (!open.value || centred || !hourList.value || !minuteList.value) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
centred = true;
|
|
307
|
+
centre('hour', stop.value.value);
|
|
308
|
+
if (chosenMinute.value !== null) {
|
|
309
|
+
centre('minute', chosenMinute.value);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
{ flush: 'post' },
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
function pickHour(hour: string): void {
|
|
316
|
+
emit('update:modelValue', `${hour}:${chosenMinute.value ?? '00'}`);
|
|
317
|
+
stop.value = { column: 'hour', value: hour };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function pickMinute(minute: string): void {
|
|
321
|
+
emit('update:modelValue', `${chosenHour.value ?? '00'}:${minute}`);
|
|
322
|
+
stop.value = { column: 'minute', value: minute };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function target(event: KeyboardEvent, index: number, length: number): number | null {
|
|
326
|
+
switch (event.key) {
|
|
327
|
+
case 'ArrowUp':
|
|
328
|
+
return Math.max(index - 1, 0);
|
|
329
|
+
case 'ArrowDown':
|
|
330
|
+
return Math.min(index + 1, length - 1);
|
|
331
|
+
case 'PageUp':
|
|
332
|
+
return Math.max(index - PAGE, 0);
|
|
333
|
+
case 'PageDown':
|
|
334
|
+
return Math.min(index + PAGE, length - 1);
|
|
335
|
+
case 'Home':
|
|
336
|
+
return 0;
|
|
337
|
+
case 'End':
|
|
338
|
+
return length - 1;
|
|
339
|
+
default:
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function onOptionKeydown(event: KeyboardEvent, column: Column, optionValue: string): void {
|
|
345
|
+
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
|
|
346
|
+
const other: Column = column === 'hour' ? 'minute' : 'hour';
|
|
347
|
+
const wanted = (other === 'hour' ? chosenHour.value : chosenMinute.value) ?? null;
|
|
348
|
+
const list = columns.value[other];
|
|
349
|
+
const next = wanted !== null && list.includes(wanted) ? wanted : list[0]!;
|
|
350
|
+
if ((event.key === 'ArrowRight') === (column === 'hour')) {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
void moveTo(other, next);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const list = columns.value[column];
|
|
357
|
+
const index = target(event, list.indexOf(optionValue), list.length);
|
|
358
|
+
if (index === null) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
void moveTo(column, list[index]!);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const inputAttrs = computed(() =>
|
|
366
|
+
Object.fromEntries(Object.entries(attrs).filter(([key]) => key !== 'style' && key !== 'class')),
|
|
367
|
+
);
|
|
368
|
+
const describedBy = computed(
|
|
369
|
+
() =>
|
|
370
|
+
[
|
|
371
|
+
inputAttrs.value['aria-describedby'],
|
|
372
|
+
props.hint ? hintId : null,
|
|
373
|
+
props.error ? errorId : null,
|
|
374
|
+
]
|
|
375
|
+
.filter(Boolean)
|
|
376
|
+
.join(' ') || undefined,
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
const OPTION =
|
|
380
|
+
'text-foreground hover:bg-muted aria-selected:bg-primary aria-selected:text-primary-foreground aria-selected:hover:bg-primary block w-full rounded-[calc(var(--radius)-6px)] px-2 py-[5px] text-left text-sm tabular-nums transition-colors outline-none focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-inset aria-selected:font-semibold';
|
|
381
|
+
</script>
|
|
382
|
+
|
|
383
|
+
<template>
|
|
384
|
+
<div
|
|
385
|
+
data-slot="form-field"
|
|
386
|
+
:class="cn('grid gap-1.5', props.class)"
|
|
387
|
+
:style="attrs.style as never"
|
|
388
|
+
>
|
|
389
|
+
<Label v-if="props.label" :for="fieldId">
|
|
390
|
+
{{ props.label }}
|
|
391
|
+
<span v-if="props.required" aria-hidden="true" class="text-destructive">*</span>
|
|
392
|
+
</Label>
|
|
393
|
+
<!-- The field box is the `input` slot: it is what a page's density settings size. -->
|
|
394
|
+
<div
|
|
395
|
+
data-slot="input"
|
|
396
|
+
:class="
|
|
397
|
+
cn(
|
|
398
|
+
'border-muted-foreground dark:bg-input/30 relative flex h-9 w-full min-w-0 items-center rounded-lg border bg-transparent transition-colors',
|
|
399
|
+
'focus-within:border-ring focus-within:ring-ring focus-within:ring-offset-background focus-within:ring-2 focus-within:ring-offset-2',
|
|
400
|
+
'has-[input[aria-invalid=true]]:border-destructive has-[input[aria-invalid=true]]:ring-destructive/20 dark:has-[input[aria-invalid=true]]:ring-destructive/40 has-[input[aria-invalid=true]]:ring-3',
|
|
401
|
+
props.disabled && 'bg-input/50 dark:bg-input/80 cursor-not-allowed opacity-50',
|
|
402
|
+
)
|
|
403
|
+
"
|
|
404
|
+
>
|
|
405
|
+
<input
|
|
406
|
+
v-bind="inputAttrs"
|
|
407
|
+
:id="fieldId"
|
|
408
|
+
type="text"
|
|
409
|
+
inputmode="numeric"
|
|
410
|
+
autocomplete="off"
|
|
411
|
+
:value="typed"
|
|
412
|
+
:placeholder="props.placeholder"
|
|
413
|
+
:required="props.required"
|
|
414
|
+
:disabled="props.disabled"
|
|
415
|
+
:aria-invalid="props.error ? 'true' : (inputAttrs['aria-invalid'] as never)"
|
|
416
|
+
:aria-describedby="describedBy"
|
|
417
|
+
class="placeholder:text-muted-foreground h-full min-w-0 flex-1 bg-transparent pr-9 pl-2.5 text-base tabular-nums outline-none disabled:cursor-not-allowed md:text-sm"
|
|
418
|
+
@input="onInput"
|
|
419
|
+
@keydown.enter="onEnter"
|
|
420
|
+
@blur="onBlur"
|
|
421
|
+
/>
|
|
422
|
+
<PopoverPanel v-model:open="open" :disabled="props.disabled" align="end">
|
|
423
|
+
<template #trigger>
|
|
424
|
+
<!--
|
|
425
|
+
An inset focus ring, and why: the field box draws its own outset focus ring
|
|
426
|
+
(2px, with a 2px offset) as soon as the input OR this button holds
|
|
427
|
+
focus, and this button sits flush on the box's right edge, so its own
|
|
428
|
+
outset ring would land on those same 4px. The inset ring says which of
|
|
429
|
+
the two has it, inside the box.
|
|
430
|
+
-->
|
|
431
|
+
<button
|
|
432
|
+
type="button"
|
|
433
|
+
:aria-label="triggerName"
|
|
434
|
+
:disabled="props.disabled"
|
|
435
|
+
class="text-muted-foreground hover:text-foreground absolute inset-y-0 right-0 grid w-9 place-items-center rounded-r-lg transition-colors outline-none focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-inset disabled:pointer-events-none"
|
|
436
|
+
>
|
|
437
|
+
<slot name="clock-icon"><ClockIcon /></slot>
|
|
438
|
+
</button>
|
|
439
|
+
</template>
|
|
440
|
+
<template #panel>
|
|
441
|
+
<div class="flex w-44 gap-2">
|
|
442
|
+
<div class="flex min-w-0 flex-1 flex-col">
|
|
443
|
+
<p
|
|
444
|
+
:id="hourHeadingId"
|
|
445
|
+
class="text-muted-foreground mb-1 px-1 text-xs font-medium"
|
|
446
|
+
>
|
|
447
|
+
{{ text.timePickerHour }}
|
|
448
|
+
</p>
|
|
449
|
+
<div
|
|
450
|
+
ref="hourList"
|
|
451
|
+
role="listbox"
|
|
452
|
+
:aria-labelledby="hourHeadingId"
|
|
453
|
+
class="relative flex max-h-44 flex-col gap-0.5 overflow-auto pr-0.5"
|
|
454
|
+
>
|
|
455
|
+
<button
|
|
456
|
+
v-for="hour in hours"
|
|
457
|
+
:key="hour"
|
|
458
|
+
type="button"
|
|
459
|
+
role="option"
|
|
460
|
+
:data-value="hour"
|
|
461
|
+
:aria-selected="chosenHour === hour"
|
|
462
|
+
:tabindex="
|
|
463
|
+
tabStop.column === 'hour' && tabStop.value === hour ? 0 : -1
|
|
464
|
+
"
|
|
465
|
+
:class="OPTION"
|
|
466
|
+
@click="pickHour(hour)"
|
|
467
|
+
@keydown="onOptionKeydown($event, 'hour', hour)"
|
|
468
|
+
>
|
|
469
|
+
{{ hour }}
|
|
470
|
+
</button>
|
|
471
|
+
</div>
|
|
472
|
+
</div>
|
|
473
|
+
<div class="flex min-w-0 flex-1 flex-col">
|
|
474
|
+
<p
|
|
475
|
+
:id="minuteHeadingId"
|
|
476
|
+
class="text-muted-foreground mb-1 px-1 text-xs font-medium"
|
|
477
|
+
>
|
|
478
|
+
{{ text.timePickerMinute }}
|
|
479
|
+
</p>
|
|
480
|
+
<div
|
|
481
|
+
ref="minuteList"
|
|
482
|
+
role="listbox"
|
|
483
|
+
:aria-labelledby="minuteHeadingId"
|
|
484
|
+
class="relative flex max-h-44 flex-col gap-0.5 overflow-auto pr-0.5"
|
|
485
|
+
>
|
|
486
|
+
<button
|
|
487
|
+
v-for="minute in minutes"
|
|
488
|
+
:key="minute"
|
|
489
|
+
type="button"
|
|
490
|
+
role="option"
|
|
491
|
+
:data-value="minute"
|
|
492
|
+
:aria-selected="chosenMinute === minute"
|
|
493
|
+
:tabindex="
|
|
494
|
+
tabStop.column === 'minute' && tabStop.value === minute
|
|
495
|
+
? 0
|
|
496
|
+
: -1
|
|
497
|
+
"
|
|
498
|
+
:class="OPTION"
|
|
499
|
+
@click="pickMinute(minute)"
|
|
500
|
+
@keydown="onOptionKeydown($event, 'minute', minute)"
|
|
501
|
+
>
|
|
502
|
+
{{ minute }}
|
|
503
|
+
</button>
|
|
504
|
+
</div>
|
|
505
|
+
</div>
|
|
506
|
+
</div>
|
|
507
|
+
</template>
|
|
508
|
+
</PopoverPanel>
|
|
509
|
+
</div>
|
|
510
|
+
<p
|
|
511
|
+
v-if="props.hint"
|
|
512
|
+
:id="hintId"
|
|
513
|
+
data-testid="time-picker-hint"
|
|
514
|
+
class="text-muted-foreground text-xs"
|
|
515
|
+
>
|
|
516
|
+
{{ props.hint }}
|
|
517
|
+
</p>
|
|
518
|
+
<p v-if="props.error" :id="errorId" role="alert" class="text-destructive text-sm">
|
|
519
|
+
{{ props.error }}
|
|
520
|
+
</p>
|
|
521
|
+
</div>
|
|
522
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as TimePicker } from './TimePicker.vue';
|