@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,247 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
formatRange,
|
|
4
|
+
parseRangeInput,
|
|
5
|
+
RANGE_PRESETS,
|
|
6
|
+
rangePreset,
|
|
7
|
+
useUiLabels,
|
|
8
|
+
type RangePresetKey,
|
|
9
|
+
type UiLabels,
|
|
10
|
+
} from '@noix-dev/brix-core';
|
|
11
|
+
import { useMediaQuery } from '@vueuse/core';
|
|
12
|
+
import { computed, ref, useTemplateRef, watch } from 'vue';
|
|
13
|
+
import type { HTMLAttributes } from 'vue';
|
|
14
|
+
import { cn } from '../../lib/cn';
|
|
15
|
+
import CalendarPanel from '../date-picker/CalendarPanel.vue';
|
|
16
|
+
import DateField from '../date-picker/DateField.vue';
|
|
17
|
+
import { useDateField } from '../date-picker/useDateField';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A from/to date field for list filters: one text field (`01.10.2026 – 31.10.2026`, `from …`,
|
|
21
|
+
* `until …`) that can be typed into, and a calendar with presets and two months. The models are
|
|
22
|
+
* two ISO dates ('YYYY-MM-DD'), `''` when empty, and either side may be empty on its own.
|
|
23
|
+
* id / name / data-testid / aria-* / required land on the inner text input.
|
|
24
|
+
*
|
|
25
|
+
* Picking the end day or a preset commits and closes. Closing after only a start was picked
|
|
26
|
+
* commits that start alone. Nothing is committed on the first click, so a filter does not
|
|
27
|
+
* reload on a half-finished choice, and a commit equal to the current range emits nothing.
|
|
28
|
+
*
|
|
29
|
+
* Imported from `@noix-dev/brix-vue/date-range-picker`, and not through the root barrel: it draws the
|
|
30
|
+
* calendar, which carries `@internationalized/date` (ADR 0014).
|
|
31
|
+
*
|
|
32
|
+
* Hidden default: when `document.documentElement.lang` is empty, the calendar panel falls back
|
|
33
|
+
* to the `'de'` locale for its month and weekday names. Set `<html lang>` to get another one.
|
|
34
|
+
* The typed format is day first (`DD.MM.YYYY`) whatever the language.
|
|
35
|
+
*
|
|
36
|
+
* The words in the field come from the `dateRangeFrom` and `dateRangeTo` labels, but typing is
|
|
37
|
+
* parsed by the core with `from` / `ab` and `until` / `bis` only: a catalogue that words them
|
|
38
|
+
* differently shows text this field then rejects.
|
|
39
|
+
*/
|
|
40
|
+
defineOptions({ inheritAttrs: false });
|
|
41
|
+
|
|
42
|
+
const props = withDefaults(
|
|
43
|
+
defineProps<{
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
class?: HTMLAttributes['class'];
|
|
48
|
+
}>(),
|
|
49
|
+
{ disabled: false, class: undefined },
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const emit = defineEmits<{
|
|
53
|
+
(e: 'update:from', value: string): void;
|
|
54
|
+
(e: 'update:to', value: string): void;
|
|
55
|
+
/** Both ends in one event, once per commit: what a filter view binds. */
|
|
56
|
+
(e: 'update:range', value: DateRange): void;
|
|
57
|
+
}>();
|
|
58
|
+
|
|
59
|
+
const labels = useUiLabels();
|
|
60
|
+
|
|
61
|
+
const fieldRef = useTemplateRef<InstanceType<typeof DateField>>('field');
|
|
62
|
+
const panelRef = useTemplateRef<InstanceType<typeof CalendarPanel>>('panel');
|
|
63
|
+
|
|
64
|
+
const { open, error } = useDateField(() => fieldRef.value?.input, seed);
|
|
65
|
+
|
|
66
|
+
interface DateRange {
|
|
67
|
+
from: string;
|
|
68
|
+
to: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The range this field last showed as committed: the models, or what it just emitted. */
|
|
72
|
+
const current = ref<DateRange>({ from: props.from, to: props.to });
|
|
73
|
+
/** Set between the first and the second click: a start that is picked but not committed. */
|
|
74
|
+
const draft = ref<DateRange | null>(null);
|
|
75
|
+
/** What the field and the calendar show: the draft while a start is being picked. */
|
|
76
|
+
const shown = computed<DateRange>(() => draft.value ?? current.value);
|
|
77
|
+
|
|
78
|
+
const text = ref(formatRange(props.from, props.to, labels.value));
|
|
79
|
+
|
|
80
|
+
function show(range: DateRange): void {
|
|
81
|
+
text.value = formatRange(range.from, range.to, labels.value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Shows the models and drops a pending error or pick. Also a date field guard's `reset()`. */
|
|
85
|
+
function seed(): void {
|
|
86
|
+
current.value = { from: props.from, to: props.to };
|
|
87
|
+
draft.value = null;
|
|
88
|
+
show(current.value);
|
|
89
|
+
error.value = false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// A form that re-seeds or resets replaces what is shown, and drops a pending error or pick.
|
|
93
|
+
watch([() => props.from, () => props.to], seed);
|
|
94
|
+
|
|
95
|
+
/** Commits a range. One equal to the current one only tidies up: a filter would reload for nothing. */
|
|
96
|
+
function emitRange(range: DateRange): void {
|
|
97
|
+
const unchanged = range.from === current.value.from && range.to === current.value.to;
|
|
98
|
+
current.value = range;
|
|
99
|
+
draft.value = null;
|
|
100
|
+
show(range);
|
|
101
|
+
error.value = false;
|
|
102
|
+
if (unchanged) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
emit('update:range', { from: range.from, to: range.to });
|
|
106
|
+
emit('update:from', range.from);
|
|
107
|
+
emit('update:to', range.to);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Reads the typed text. Synchronous, so an Enter that submits a form submits this value. */
|
|
111
|
+
function commit(): void {
|
|
112
|
+
const unchanged = formatRange(shown.value.from, shown.value.to, labels.value);
|
|
113
|
+
if (text.value.trim() === unchanged) {
|
|
114
|
+
text.value = unchanged;
|
|
115
|
+
error.value = false;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const parsed = parseRangeInput(text.value);
|
|
119
|
+
if (parsed.kind === 'empty') {
|
|
120
|
+
emitRange({ from: '', to: '' });
|
|
121
|
+
} else if (parsed.kind === 'invalid') {
|
|
122
|
+
error.value = true;
|
|
123
|
+
} else {
|
|
124
|
+
emitRange({ from: parsed.from, to: parsed.to });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// --- The calendar: a popover, or a bottom sheet below 768px (the popover is about 724px wide). ---
|
|
129
|
+
|
|
130
|
+
const narrow = useMediaQuery('(max-width: 767px)');
|
|
131
|
+
|
|
132
|
+
watch(open, (isOpen) => {
|
|
133
|
+
if (!isOpen && draft.value !== null) {
|
|
134
|
+
// Closed with only a start picked (Escape, a click outside): that start is the value.
|
|
135
|
+
emitRange({ from: draft.value.from, to: '' });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/** A day was clicked: the first click starts a range, the second ends it (earlier = swapped). */
|
|
140
|
+
function pick(iso: string): void {
|
|
141
|
+
const start = draft.value;
|
|
142
|
+
if (start === null) {
|
|
143
|
+
draft.value = { from: iso, to: '' };
|
|
144
|
+
show(draft.value);
|
|
145
|
+
error.value = false;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
emitRange(iso < start.from ? { from: iso, to: start.from } : { from: start.from, to: iso });
|
|
149
|
+
open.value = false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function pickPreset(key: RangePresetKey): void {
|
|
153
|
+
emitRange(rangePreset(key, new Date()));
|
|
154
|
+
open.value = false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function reset(): void {
|
|
158
|
+
emitRange({ from: '', to: '' });
|
|
159
|
+
open.value = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const presetLabels = computed<Record<RangePresetKey, string>>(() => {
|
|
163
|
+
const l: UiLabels = labels.value;
|
|
164
|
+
return {
|
|
165
|
+
today: l.datePresetToday,
|
|
166
|
+
thisWeek: l.datePresetThisWeek,
|
|
167
|
+
thisMonth: l.datePresetThisMonth,
|
|
168
|
+
lastMonth: l.datePresetLastMonth,
|
|
169
|
+
last30Days: l.datePresetLast30Days,
|
|
170
|
+
thisYear: l.datePresetThisYear,
|
|
171
|
+
lastYear: l.datePresetLastYear,
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/** The preset the shown range equals, if any (the open calendar marks it). */
|
|
176
|
+
const activePreset = computed<RangePresetKey | null>(() => {
|
|
177
|
+
const now = new Date();
|
|
178
|
+
const { from, to } = shown.value;
|
|
179
|
+
return (
|
|
180
|
+
RANGE_PRESETS.find((key) => {
|
|
181
|
+
const range = rangePreset(key, now);
|
|
182
|
+
return range.from === from && range.to === to;
|
|
183
|
+
}) ?? null
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
</script>
|
|
187
|
+
|
|
188
|
+
<template>
|
|
189
|
+
<DateField
|
|
190
|
+
ref="field"
|
|
191
|
+
v-bind="$attrs"
|
|
192
|
+
v-model:open="open"
|
|
193
|
+
v-model:text="text"
|
|
194
|
+
slot-name="date-range-picker"
|
|
195
|
+
:class="props.class"
|
|
196
|
+
:placeholder="labels.dateRangePlaceholder"
|
|
197
|
+
:narrow="narrow"
|
|
198
|
+
keyboard="text"
|
|
199
|
+
:error="error"
|
|
200
|
+
:disabled="props.disabled"
|
|
201
|
+
@commit="commit"
|
|
202
|
+
@clear="emitRange({ from: '', to: '' })"
|
|
203
|
+
@opened="panelRef?.focus()"
|
|
204
|
+
>
|
|
205
|
+
<!-- On a phone (the sheet): one month, and the presets as chips above it. -->
|
|
206
|
+
<div :class="cn('flex', narrow ? 'flex-col gap-2.5' : 'gap-3.5')">
|
|
207
|
+
<div
|
|
208
|
+
:class="
|
|
209
|
+
cn(
|
|
210
|
+
'flex gap-0.5',
|
|
211
|
+
narrow
|
|
212
|
+
? 'flex-wrap'
|
|
213
|
+
: 'border-border min-w-37.5 shrink-0 flex-col border-r pr-2.5',
|
|
214
|
+
)
|
|
215
|
+
"
|
|
216
|
+
>
|
|
217
|
+
<button
|
|
218
|
+
v-for="key in RANGE_PRESETS"
|
|
219
|
+
:key="key"
|
|
220
|
+
type="button"
|
|
221
|
+
:data-testid="`date-range-preset-${key}`"
|
|
222
|
+
:aria-pressed="activePreset === key ? 'true' : 'false'"
|
|
223
|
+
:class="
|
|
224
|
+
cn(
|
|
225
|
+
'hover:bg-primary/10 rounded-md px-2 py-1.5 text-left text-[12.5px] transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset',
|
|
226
|
+
narrow && 'px-2.5 py-1.5',
|
|
227
|
+
activePreset === key && 'bg-primary/10 text-primary font-semibold',
|
|
228
|
+
)
|
|
229
|
+
"
|
|
230
|
+
@click="pickPreset(key)"
|
|
231
|
+
>
|
|
232
|
+
{{ presetLabels[key] }}
|
|
233
|
+
</button>
|
|
234
|
+
</div>
|
|
235
|
+
<CalendarPanel
|
|
236
|
+
ref="panel"
|
|
237
|
+
:large="narrow"
|
|
238
|
+
:months="narrow ? 1 : 2"
|
|
239
|
+
selected=""
|
|
240
|
+
:range="shown"
|
|
241
|
+
:hint="draft !== null ? labels.dateRangePickEnd : ''"
|
|
242
|
+
@pick="pick"
|
|
243
|
+
@clear="reset"
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
</DateField>
|
|
247
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as DateRangePicker } from './DateRangePicker.vue';
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useMediaQuery } from '@vueuse/core';
|
|
3
|
+
import { computed, ref, useTemplateRef, watch } from 'vue';
|
|
4
|
+
import {
|
|
5
|
+
formatIsoDate,
|
|
6
|
+
maskDateTyping,
|
|
7
|
+
parseDateTimeInput,
|
|
8
|
+
useUiLabels,
|
|
9
|
+
} from '@noix-dev/brix-core';
|
|
10
|
+
import CalendarPanel from '../date-picker/CalendarPanel.vue';
|
|
11
|
+
import DateField from '../date-picker/DateField.vue';
|
|
12
|
+
import { useDateField } from '../date-picker/useDateField';
|
|
13
|
+
import { cn } from '../../lib/cn';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A date and time field: type `DD.MM.YYYY HH:MM` (any minute; a date alone means 09:00) or
|
|
17
|
+
* pick a day from the calendar and a time from the list beside it (00:00–23:45 in quarter
|
|
18
|
+
* hours). The model is an ISO 8601 instant or `null`; the field shows and takes local time.
|
|
19
|
+
* id / name / data-testid / aria-* / required / disabled land on the inner text input.
|
|
20
|
+
*
|
|
21
|
+
* It owns the calendar (`CalendarPanel`), which needs the optional peer
|
|
22
|
+
* `@internationalized/date`; this is why the component is published on its own subpath,
|
|
23
|
+
* `@noix-dev/brix-vue/date-time-picker`, and not through the root barrel (ADR 0014).
|
|
24
|
+
*
|
|
25
|
+
* Picking a day commits it (with the time already set, else 09:00) and keeps the calendar
|
|
26
|
+
* open for the time. Picking a time commits and closes. A time picked before any day waits
|
|
27
|
+
* for the day, which then commits both and closes.
|
|
28
|
+
*
|
|
29
|
+
* Hidden default: when `document.documentElement.lang` is empty, the calendar panel falls back
|
|
30
|
+
* to the `'de'` locale for its month and weekday names. Set `<html lang>` to get another one.
|
|
31
|
+
* The typed format is day first (`DD.MM.YYYY HH:MM`) whatever the language.
|
|
32
|
+
* The time list is 24-hour.
|
|
33
|
+
*/
|
|
34
|
+
defineOptions({ inheritAttrs: false });
|
|
35
|
+
|
|
36
|
+
const props = defineProps<{ modelValue: string | null; id?: string; class?: string }>();
|
|
37
|
+
const emit = defineEmits<{ (e: 'update:modelValue', value: string | null): void }>();
|
|
38
|
+
|
|
39
|
+
const labels = useUiLabels();
|
|
40
|
+
|
|
41
|
+
const fieldRef = useTemplateRef<InstanceType<typeof DateField>>('field');
|
|
42
|
+
const panelRef = useTemplateRef<InstanceType<typeof CalendarPanel>>('panel');
|
|
43
|
+
const timesEl = useTemplateRef<HTMLElement>('times');
|
|
44
|
+
|
|
45
|
+
const { open, error } = useDateField(() => fieldRef.value?.input, seed);
|
|
46
|
+
|
|
47
|
+
/** A local wall-clock moment: 'YYYY-MM-DD' and 'HH:MM'. */
|
|
48
|
+
interface LocalDateTime {
|
|
49
|
+
date: string;
|
|
50
|
+
time: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What picking a day without a time sets (as a typed date without a time means). */
|
|
54
|
+
const DEFAULT_TIME = '09:00';
|
|
55
|
+
/** Where the time list scrolls when no time is set. */
|
|
56
|
+
const SCROLL_DEFAULT = '08:00';
|
|
57
|
+
|
|
58
|
+
const pad = (n: number, width = 2): string => String(n).padStart(width, '0');
|
|
59
|
+
|
|
60
|
+
/** The time list: 00:00 to 23:45 in 15-minute steps. */
|
|
61
|
+
const TIMES = Array.from(
|
|
62
|
+
{ length: 96 },
|
|
63
|
+
(_, i) => `${pad(Math.floor(i / 4))}:${pad((i % 4) * 15)}`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** The model's instant in local time. Read from the local parts, never via toISOString(). */
|
|
67
|
+
function fromModel(value: string | null): LocalDateTime | null {
|
|
68
|
+
if (!value) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const d = new Date(value);
|
|
72
|
+
if (Number.isNaN(d.getTime())) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
date: `${pad(d.getFullYear(), 4)}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`,
|
|
77
|
+
time: `${pad(d.getHours())}:${pad(d.getMinutes())}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function format(value: LocalDateTime | null): string {
|
|
82
|
+
return value ? `${formatIsoDate(value.date)} ${value.time}` : '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function same(a: LocalDateTime | null, b: LocalDateTime | null): boolean {
|
|
86
|
+
return a === null || b === null ? a === b : a.date === b.date && a.time === b.time;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The value this field last showed as committed: the model, or what it just emitted. */
|
|
90
|
+
const current = ref<LocalDateTime | null>(fromModel(props.modelValue));
|
|
91
|
+
const text = ref(format(current.value));
|
|
92
|
+
/** A time picked while no day is set yet: it waits for the day (this opening only). */
|
|
93
|
+
const pendingTime = ref<string | null>(null);
|
|
94
|
+
|
|
95
|
+
/** Shows the model and drops a pending error. Also a date field guard's `reset()`. */
|
|
96
|
+
function seed(): void {
|
|
97
|
+
current.value = fromModel(props.modelValue);
|
|
98
|
+
text.value = format(current.value);
|
|
99
|
+
error.value = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A form that re-seeds or resets replaces what is shown and drops a pending error.
|
|
103
|
+
watch(() => props.modelValue, seed);
|
|
104
|
+
|
|
105
|
+
/** Commits a value; one equal to the current one only tidies the text up. */
|
|
106
|
+
function commitValue(next: LocalDateTime | null): void {
|
|
107
|
+
const unchanged = same(next, current.value);
|
|
108
|
+
current.value = next;
|
|
109
|
+
text.value = format(next);
|
|
110
|
+
error.value = false;
|
|
111
|
+
// A time picked before any day no longer waits: this value carries its own time.
|
|
112
|
+
pendingTime.value = null;
|
|
113
|
+
if (!unchanged) {
|
|
114
|
+
emit(
|
|
115
|
+
'update:modelValue',
|
|
116
|
+
next === null ? null : new Date(`${next.date}T${next.time}`).toISOString(),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Reads the typed text. Synchronous, so an Enter that submits a form submits this value. */
|
|
122
|
+
function commit(): void {
|
|
123
|
+
if (text.value.trim() === format(current.value)) {
|
|
124
|
+
text.value = format(current.value);
|
|
125
|
+
error.value = false;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// Pasted digits ('9999') read the way typed ones would have been masked; with a time after
|
|
129
|
+
// the date the text has a space, which the mask leaves alone.
|
|
130
|
+
const parsed = parseDateTimeInput(maskDateTyping(text.value));
|
|
131
|
+
if (parsed.kind === 'empty') {
|
|
132
|
+
commitValue(null);
|
|
133
|
+
} else if (parsed.kind === 'invalid') {
|
|
134
|
+
error.value = true;
|
|
135
|
+
} else {
|
|
136
|
+
commitValue({ date: parsed.date, time: parsed.time });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// --- The calendar and the time list: a popover, or a bottom sheet on a phone. ---
|
|
141
|
+
|
|
142
|
+
const narrow = useMediaQuery('(max-width: 639px)');
|
|
143
|
+
|
|
144
|
+
watch(open, () => {
|
|
145
|
+
pendingTime.value = null;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/** A day was picked: it keeps the time already set (else 09:00) and waits for a time. */
|
|
149
|
+
function pickDay(iso: string): void {
|
|
150
|
+
const waiting = pendingTime.value;
|
|
151
|
+
commitValue({ date: iso, time: waiting ?? current.value?.time ?? DEFAULT_TIME });
|
|
152
|
+
if (waiting !== null) {
|
|
153
|
+
// The time came first: the choice is complete.
|
|
154
|
+
open.value = false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function pickToday(): void {
|
|
159
|
+
const now = new Date();
|
|
160
|
+
pickDay(`${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function pickTime(time: string): void {
|
|
164
|
+
if (current.value === null) {
|
|
165
|
+
pendingTime.value = time;
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
commitValue({ date: current.value.date, time });
|
|
169
|
+
open.value = false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function reset(): void {
|
|
173
|
+
commitValue(null);
|
|
174
|
+
open.value = false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The time the list marks: one picked this opening, else the committed one. */
|
|
178
|
+
const selectedTime = computed(() => pendingTime.value ?? current.value?.time ?? null);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The row the list scrolls to and the one tab stop in it: the selected time (the quarter
|
|
182
|
+
* hour before an off-list one such as 14:07), else 08:00.
|
|
183
|
+
*/
|
|
184
|
+
const anchorTime = computed(() => {
|
|
185
|
+
const selected = selectedTime.value;
|
|
186
|
+
if (selected === null) {
|
|
187
|
+
return SCROLL_DEFAULT;
|
|
188
|
+
}
|
|
189
|
+
const [hours = 0, minutes = 0] = selected.split(':').map(Number);
|
|
190
|
+
return `${pad(hours)}:${pad(minutes - (minutes % 15))}`;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/** Centres the anchor row in the list (the list only, never the page). */
|
|
194
|
+
function scrollTimes(): void {
|
|
195
|
+
const list = timesEl.value;
|
|
196
|
+
const row = list?.querySelector<HTMLElement>(`[data-time="${anchorTime.value}"]`);
|
|
197
|
+
if (list && row) {
|
|
198
|
+
list.scrollTop = Math.max(0, row.offsetTop - (list.clientHeight - row.offsetHeight) / 2);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** ↑ / ↓ walk the times, so the list costs one Tab rather than 96. */
|
|
203
|
+
function onTimesKeydown(event: KeyboardEvent): void {
|
|
204
|
+
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const row = event.target instanceof HTMLElement ? event.target.closest('[data-time]') : null;
|
|
208
|
+
const next = event.key === 'ArrowDown' ? row?.nextElementSibling : row?.previousElementSibling;
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
if (next instanceof HTMLElement) {
|
|
211
|
+
next.focus();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function onOpened(): void {
|
|
216
|
+
panelRef.value?.focus();
|
|
217
|
+
scrollTimes();
|
|
218
|
+
}
|
|
219
|
+
</script>
|
|
220
|
+
|
|
221
|
+
<template>
|
|
222
|
+
<DateField
|
|
223
|
+
:id="props.id"
|
|
224
|
+
ref="field"
|
|
225
|
+
v-bind="$attrs"
|
|
226
|
+
v-model:open="open"
|
|
227
|
+
v-model:text="text"
|
|
228
|
+
slot-name="date-time-picker"
|
|
229
|
+
keyboard="text"
|
|
230
|
+
:class="props.class"
|
|
231
|
+
:placeholder="labels.dateTimePlaceholder"
|
|
232
|
+
:mask="maskDateTyping"
|
|
233
|
+
:narrow="narrow"
|
|
234
|
+
:error="error"
|
|
235
|
+
@commit="commit"
|
|
236
|
+
@clear="commitValue(null)"
|
|
237
|
+
@opened="onOpened"
|
|
238
|
+
>
|
|
239
|
+
<div :class="cn('flex', narrow ? 'gap-3' : 'gap-2.5')">
|
|
240
|
+
<CalendarPanel
|
|
241
|
+
ref="panel"
|
|
242
|
+
:large="narrow"
|
|
243
|
+
:class="narrow && 'min-w-0 flex-1'"
|
|
244
|
+
:selected="current?.date ?? ''"
|
|
245
|
+
@pick="pickDay"
|
|
246
|
+
@today="pickToday"
|
|
247
|
+
@clear="reset"
|
|
248
|
+
/>
|
|
249
|
+
<!-- As tall as the calendar beside it; the list scrolls inside. -->
|
|
250
|
+
<div class="border-border relative w-19 shrink-0 border-l">
|
|
251
|
+
<div class="absolute inset-0 flex flex-col pl-2">
|
|
252
|
+
<div
|
|
253
|
+
data-testid="date-time-picker-time-heading"
|
|
254
|
+
aria-hidden="true"
|
|
255
|
+
class="text-muted-foreground py-1 text-center text-[10.5px] font-semibold"
|
|
256
|
+
>
|
|
257
|
+
{{ labels.dateTime }}
|
|
258
|
+
</div>
|
|
259
|
+
<div
|
|
260
|
+
ref="times"
|
|
261
|
+
role="group"
|
|
262
|
+
data-testid="date-time-picker-times"
|
|
263
|
+
:aria-label="labels.dateTime"
|
|
264
|
+
class="relative min-h-0 flex-1 overflow-y-auto"
|
|
265
|
+
@keydown="onTimesKeydown"
|
|
266
|
+
>
|
|
267
|
+
<button
|
|
268
|
+
v-for="time in TIMES"
|
|
269
|
+
:key="time"
|
|
270
|
+
type="button"
|
|
271
|
+
:data-time="time"
|
|
272
|
+
:aria-pressed="selectedTime === time ? 'true' : 'false'"
|
|
273
|
+
:tabindex="time === anchorTime ? 0 : -1"
|
|
274
|
+
:class="
|
|
275
|
+
cn(
|
|
276
|
+
'hover:bg-primary/10 block w-full rounded-md py-1.25 text-center tabular-nums transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset',
|
|
277
|
+
narrow ? 'text-sm' : 'text-[12.5px]',
|
|
278
|
+
selectedTime === time &&
|
|
279
|
+
'bg-primary text-primary-foreground hover:bg-primary focus-visible:ring-primary-foreground font-bold',
|
|
280
|
+
)
|
|
281
|
+
"
|
|
282
|
+
@click="pickTime(time)"
|
|
283
|
+
>
|
|
284
|
+
{{ time }}
|
|
285
|
+
</button>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
</div>
|
|
290
|
+
</DateField>
|
|
291
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as DateTimePicker } from './DateTimePicker.vue';
|