datocms-react-ui 3.1.0-next.6 → 3.1.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/DateInput.d.ts +2 -0
- package/dist/DateInput.js +2 -0
- package/dist/DateTimeInput.d.ts +2 -0
- package/dist/DateTimeInput.js +2 -0
- package/dist/DateTimeRangeInput.d.ts +2 -0
- package/dist/DateTimeRangeInput.js +2 -0
- package/dist/FieldTypeAvatar.d.ts +2 -0
- package/dist/FieldTypeAvatar.js +2 -0
- package/dist/FieldTypeName.d.ts +2 -0
- package/dist/FieldTypeName.js +2 -0
- package/dist/FilterBuilder.d.ts +2 -0
- package/dist/FilterBuilder.js +2 -0
- package/dist/RecordRow.d.ts +2 -0
- package/dist/RecordRow.js +2 -0
- package/dist/UploadCard.js +2 -2
- package/dist/UploadPreview.d.ts +2 -2
- package/dist/UploadPreview.js +1 -1
- package/dist/UserRow.d.ts +2 -0
- package/dist/UserRow.js +2 -0
- package/dist/react-ui/src/Canvas.d.ts +7 -1
- package/dist/react-ui/src/Canvas.js +26 -4
- package/dist/react-ui/src/ctxAnswer.js +21 -0
- package/dist/react-ui/src/ctxDateSettings.js +7 -5
- package/dist/react-ui/src/ctxRecordPresentation.js +34 -0
- package/dist/react-ui/src/ctxUploads.js +23 -0
- package/dist/styles.css +634 -45
- package/dist/ui-public/icons/index.js +285 -280
- package/dist/ui-public/icons/lucide/braces.js +22 -0
- package/dist/ui-public/icons/lucide/hash.js +47 -0
- package/dist/ui-public/icons/lucide/letter-text.js +28 -0
- package/dist/ui-public/icons/lucide/rows-3.js +32 -0
- package/dist/ui-public/icons/lucide/toggle-right.js +32 -0
- package/dist/ui-public/locales/en.js +74 -5
- package/dist/ui-public/src/Message.d.ts +3 -4
- package/dist/ui-public/src/UiTextKey.d.ts +1 -1
- package/dist/ui-public/src/actions/Actions/ActionTooltip.js +1 -1
- package/dist/ui-public/src/actions/Actions/registry.d.ts +2 -2
- package/dist/ui-public/src/actions/Actions/registry.js +2 -2
- package/dist/ui-public/src/actions/Button.d.ts +10 -10
- package/dist/ui-public/src/actions/Button.js +1 -1
- package/dist/ui-public/src/actions/Dropdown/Menu.d.ts +2 -2
- package/dist/ui-public/src/actions/Dropdown/Option.d.ts +7 -7
- package/dist/ui-public/src/actions/Dropdown/index.d.ts +1 -1
- package/dist/ui-public/src/actions/Dropdown/triggers/ButtonTrigger.d.ts +5 -5
- package/dist/ui-public/src/actions/Dropdown/triggers/DropdownTriggerButton.d.ts +2 -2
- package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.d.ts +6 -6
- package/dist/ui-public/src/actions/Dropdown/triggers/IconTrigger.js +1 -1
- package/dist/ui-public/src/actions/EditorToolbar/Button.d.ts +1 -1
- package/dist/ui-public/src/actions/MultipleSelectionActionBar.d.ts +1 -1
- package/dist/ui-public/src/actions/SplitButton/Caret.js +2 -2
- package/dist/ui-public/src/actions/SplitButton/Halves.js +1 -1
- package/dist/ui-public/src/actions/SplitButton/index.d.ts +3 -3
- package/dist/ui-public/src/actions/disabledReason.d.ts +4 -4
- package/dist/ui-public/src/content/Avatar.d.ts +3 -3
- package/dist/ui-public/src/content/Avatar.js +2 -2
- package/dist/ui-public/src/content/CodeSnippet.d.ts +1 -1
- package/dist/ui-public/src/content/CopyableValue.d.ts +1 -1
- package/dist/ui-public/src/content/EnvironmentPill.d.ts +1 -1
- package/dist/ui-public/src/content/EnvironmentPill.js +1 -1
- package/dist/ui-public/src/content/FieldTypeAvatar.d.ts +22 -0
- package/dist/ui-public/src/content/FieldTypeAvatar.js +35 -0
- package/dist/ui-public/src/content/FieldTypeName.d.ts +19 -0
- package/dist/ui-public/src/content/FieldTypeName.js +25 -0
- package/dist/ui-public/src/content/IconAvatar.d.ts +3 -2
- package/dist/ui-public/src/content/ItemStatus.d.ts +1 -1
- package/dist/ui-public/src/content/Pill.d.ts +1 -1
- package/dist/ui-public/src/content/SmartDate.d.ts +1 -1
- package/dist/ui-public/src/content/UploadPreview/asset.js +200 -0
- package/dist/ui-public/src/content/UploadPreview/audio.js +120 -0
- package/dist/ui-public/src/content/{UploadPreview.d.ts → UploadPreview/box.d.ts} +10 -10
- package/dist/ui-public/src/content/{UploadPreview.js → UploadPreview/box.js} +7 -7
- package/dist/ui-public/src/content/{uploadPreviewFit.d.ts → UploadPreview/fit.d.ts} +2 -2
- package/dist/ui-public/src/content/{uploadPreviewFit.js → UploadPreview/fit.js} +3 -3
- package/dist/ui-public/src/content/UploadPreview/index.d.ts +61 -0
- package/dist/ui-public/src/content/UploadPreview/index.js +36 -0
- package/dist/ui-public/src/content/UploadPreview/presentation.js +63 -0
- package/dist/ui-public/src/content/UploadPreview/thumbhash.js +91 -0
- package/dist/ui-public/src/content/UploadPreview/upload.d.ts +104 -0
- package/dist/ui-public/src/content/UploadPreview/upload.js +112 -0
- package/dist/ui-public/src/content/UsageMeter.d.ts +1 -1
- package/dist/ui-public/src/content/ValidityTriangles.d.ts +1 -1
- package/dist/ui-public/src/feedback/BlankSlate.d.ts +5 -5
- package/dist/ui-public/src/feedback/Callout.d.ts +5 -5
- package/dist/ui-public/src/feedback/Callout.js +1 -1
- package/dist/ui-public/src/feedback/ProgressBar.d.ts +4 -4
- package/dist/ui-public/src/feedback/Spinner.d.ts +6 -6
- package/dist/ui-public/src/feedback/Spinner.js +1 -1
- package/dist/ui-public/src/form/DateInput.d.ts +13 -0
- package/dist/ui-public/src/form/DateInput.js +16 -0
- package/dist/ui-public/src/form/DateTimeInput/Base.d.ts +89 -0
- package/dist/ui-public/src/form/DateTimeInput/Base.js +330 -0
- package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.d.ts +29 -0
- package/dist/ui-public/src/form/DateTimeInput/CalendarGrid.js +195 -0
- package/dist/ui-public/src/form/DateTimeInput/dateText.js +38 -0
- package/dist/ui-public/src/form/DateTimeInput/index.d.ts +10 -0
- package/dist/ui-public/src/form/DateTimeInput/index.js +18 -0
- package/dist/ui-public/src/form/DateTimeInput/value.js +31 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/Panel.js +167 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/index.d.ts +123 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/index.js +186 -0
- package/dist/ui-public/src/form/DateTimeRangeInput/rangeLabel.js +46 -0
- package/dist/ui-public/src/form/FieldHint.d.ts +2 -2
- package/dist/ui-public/src/form/FieldWrapper.d.ts +9 -9
- package/dist/ui-public/src/form/FieldWrapper.js +3 -3
- package/dist/ui-public/src/form/FilterBuilder/Editor.js +123 -0
- package/dist/ui-public/src/form/FilterBuilder/index.d.ts +9 -0
- package/dist/ui-public/src/form/FilterBuilder/index.js +294 -0
- package/dist/ui-public/src/form/FilterBuilder/types.d.ts +188 -0
- package/dist/ui-public/src/form/FilterBuilder/values.js +86 -0
- package/dist/ui-public/src/form/InputGroup.d.ts +2 -2
- package/dist/ui-public/src/form/InputGroup.js +1 -1
- package/dist/ui-public/src/form/KeyValueList.d.ts +1 -1
- package/dist/ui-public/src/form/Label.d.ts +2 -2
- package/dist/ui-public/src/form/RadioGroupInput.d.ts +2 -2
- package/dist/ui-public/src/form/RadioGroupInput.js +1 -1
- package/dist/ui-public/src/form/SelectInput/SelectMenu.d.ts +2 -2
- package/dist/ui-public/src/form/SelectInput/index.d.ts +3 -3
- package/dist/ui-public/src/form/SwitchInput.d.ts +2 -2
- package/dist/ui-public/src/form/SwitchList.d.ts +1 -1
- package/dist/ui-public/src/form/SwitchList.js +1 -1
- package/dist/ui-public/src/form/TableList.d.ts +2 -2
- package/dist/ui-public/src/form/TextareaInput.js +1 -1
- package/dist/ui-public/src/form/inputProps.d.ts +6 -6
- package/dist/ui-public/src/hooks/useAsyncSelectOptions.d.ts +1 -1
- package/dist/ui-public/src/hooks/useSmartRowClick.d.ts +1 -1
- package/dist/ui-public/src/hooks/useSmartRowClick.js +1 -1
- package/dist/ui-public/src/layout/Page/PageGroup.d.ts +2 -2
- package/dist/ui-public/src/layout/Page/PageGroup.js +1 -1
- package/dist/ui-public/src/layout/Pane/FormHeader.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/FormHeader.js +1 -1
- package/dist/ui-public/src/layout/Pane/ListFilter.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/ListPresets.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/PaneHeader.d.ts +1 -1
- package/dist/ui-public/src/layout/Pane/index.d.ts +8 -8
- package/dist/ui-public/src/layout/Pane/index.js +17 -8
- package/dist/ui-public/src/layout/SidebarPanel.d.ts +1 -1
- package/dist/ui-public/src/layout/SplitPane/Rail.js +1 -1
- package/dist/ui-public/src/layout/SplitPane/index.d.ts +6 -6
- package/dist/ui-public/src/layout/SplitPane/index.js +16 -2
- package/dist/ui-public/src/layout/Toolbar/AddNewButton.d.ts +2 -2
- package/dist/ui-public/src/layout/Toolbar/Help.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/Help.js +2 -2
- package/dist/ui-public/src/layout/Toolbar/Note.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Note.js +1 -1
- package/dist/ui-public/src/layout/Toolbar/Pagination.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Pagination.js +1 -1
- package/dist/ui-public/src/layout/Toolbar/PresetsTitle.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/PresetsTitle.js +2 -2
- package/dist/ui-public/src/layout/Toolbar/PrimaryButton.d.ts +3 -3
- package/dist/ui-public/src/layout/Toolbar/Root.d.ts +1 -1
- package/dist/ui-public/src/layout/Toolbar/Root.js +4 -1
- package/dist/ui-public/src/layout/Toolbar/ToolbarTitleTrigger.js +1 -1
- package/dist/ui-public/src/lists/CardList.d.ts +3 -3
- package/dist/ui-public/src/lists/EmptySlot.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/User.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/Value.d.ts +1 -1
- package/dist/ui-public/src/lists/InfoList/Value.js +1 -1
- package/dist/ui-public/src/lists/InfoList/index.d.ts +3 -3
- package/dist/ui-public/src/lists/InfoList/index.js +1 -1
- package/dist/ui-public/src/lists/MediaCard.d.ts +7 -7
- package/dist/ui-public/src/lists/RecordRow/Image.d.ts +24 -0
- package/dist/ui-public/src/lists/RecordRow/Image.js +22 -0
- package/dist/ui-public/src/lists/RecordRow/List.d.ts +26 -0
- package/dist/ui-public/src/lists/RecordRow/List.js +30 -0
- package/dist/ui-public/src/lists/RecordRow/context.js +31 -0
- package/dist/ui-public/src/lists/RecordRow/index.d.ts +94 -0
- package/dist/ui-public/src/lists/RecordRow/index.js +122 -0
- package/dist/ui-public/src/lists/RecordRow/presentation.js +73 -0
- package/dist/ui-public/src/lists/RecordRow/types.d.ts +58 -0
- package/dist/ui-public/src/lists/RowList.d.ts +5 -5
- package/dist/ui-public/src/lists/SettingsList.d.ts +3 -3
- package/dist/ui-public/src/lists/SettingsList.js +2 -2
- package/dist/ui-public/src/lists/Table/Row.d.ts +5 -5
- package/dist/ui-public/src/lists/Table/Table.d.ts +3 -3
- package/dist/ui-public/src/lists/Table/TreeToggle.d.ts +2 -2
- package/dist/ui-public/src/lists/Table/TreeToggle.js +5 -4
- package/dist/ui-public/src/lists/Table/cells/LinkCell.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Action.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Action.js +1 -1
- package/dist/ui-public/src/lists/TreeRow/Link.d.ts +1 -1
- package/dist/ui-public/src/lists/TreeRow/Link.js +1 -1
- package/dist/ui-public/src/lists/UploadCard.d.ts +66 -3
- package/dist/ui-public/src/lists/UploadCard.js +116 -7
- package/dist/ui-public/src/lists/UserRow.d.ts +122 -0
- package/dist/ui-public/src/lists/UserRow.js +104 -0
- package/dist/ui-public/src/lists/dnd/DragHandle.d.ts +2 -2
- package/dist/ui-public/src/lists/dnd/SortableList.d.ts +1 -1
- package/dist/ui-public/src/lists/dnd/dropTargetClassName.d.ts +1 -1
- package/dist/ui-public/src/lists/dnd/tree/SortableTree.d.ts +2 -2
- package/dist/ui-public/src/navigation/Chevron.d.ts +4 -4
- package/dist/ui-public/src/navigation/Chevron.js +1 -1
- package/dist/ui-public/src/navigation/Link.d.ts +5 -5
- package/dist/ui-public/src/navigation/Link.js +1 -1
- package/dist/ui-public/src/navigation/NavList.d.ts +1 -1
- package/dist/ui-public/src/navigation/NavList.js +1 -1
- package/dist/ui-public/src/navigation/NavigationProvider.d.ts +1 -1
- package/dist/ui-public/src/navigation/SegmentedControl.d.ts +2 -2
- package/dist/ui-public/src/navigation/SettingsMenu.d.ts +8 -8
- package/dist/ui-public/src/navigation/SettingsMenu.js +1 -1
- package/dist/ui-public/src/navigation/SidebarTree/SidebarTreeNode.d.ts +4 -4
- package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.d.ts +1 -1
- package/dist/ui-public/src/overlays/FullscreenModal/TitleContext.js +1 -1
- package/dist/ui-public/src/overlays/NewZIndex.d.ts +1 -1
- package/dist/ui-public/src/overlays/NewZIndex.js +1 -1
- package/dist/ui-public/src/overlays/Popover.d.ts +1 -1
- package/dist/ui-public/src/overlays/PortalWrapper.js +1 -1
- package/dist/ui-public/src/overlays/useModalClose.js +3 -3
- package/dist/ui-public/src/patterns/ListDetail/FloatingDetail.js +2 -2
- package/dist/ui-public/src/patterns/ListDetail/Page.d.ts +8 -9
- package/dist/ui-public/src/patterns/ListDetail/Page.js +4 -5
- package/dist/ui-public/src/patterns/ListDetail/Panel.d.ts +2 -2
- package/dist/ui-public/src/patterns/ListDetail/Panel.js +1 -1
- package/dist/ui-public/src/patterns/ListDetail/Split.d.ts +9 -10
- package/dist/ui-public/src/patterns/ListDetail/Split.js +5 -5
- package/dist/ui-public/src/patterns/ListFormPage.d.ts +3 -3
- package/dist/ui-public/src/patterns/ListFormPage.js +1 -1
- package/dist/ui-public/src/semantic/Heading.d.ts +1 -1
- package/dist/ui-public/src/semantic/Heading.js +1 -1
- package/dist/ui-public/src/semantic/Image.js +1 -1
- package/dist/ui-public/src/semantic/Nav.d.ts +3 -3
- package/dist/ui-public/src/semantic/Nav.js +3 -3
- package/dist/ui-public/src/semantic/RawButton.d.ts +3 -3
- package/dist/ui-public/src/semantic/RawButton.js +1 -1
- package/dist/ui-public/src/semantic/Search.d.ts +1 -1
- package/dist/ui-public/src/semantic/Search.js +1 -1
- package/dist/ui-public/src/utils/fieldTypes.d.ts +29 -0
- package/dist/ui-public/src/utils/fieldTypes.js +94 -0
- package/dist/ui-public/src/utils/format.d.ts +21 -0
- package/dist/ui-public/src/utils/format.js +20 -0
- package/dist/ui-public/src/utils/formatDate.d.ts +10 -2
- package/dist/ui-public/src/utils/formatDate.js +4 -4
- package/dist/ui-public/src/utils/tickBatcher.js +44 -0
- package/dist/ui-public/src/utils/timezones.js +277 -0
- package/dist/ui-public/src/utils/weekStartForLocale.js +25 -0
- package/dist/utils/fieldTypes.d.ts +1 -0
- package/dist/utils/fieldTypes.js +2 -0
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.js +2 -0
- package/package.json +2 -2
- package/dist/ui-public/icons/custom/fieldgroup-boolean.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-color.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-datetime.js +0 -49
- package/dist/ui-public/icons/custom/fieldgroup-json.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-location.js +0 -19
- package/dist/ui-public/icons/custom/fieldgroup-media.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-number.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-reference.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-rich_text.js +0 -18
- package/dist/ui-public/icons/custom/fieldgroup-seo.js +0 -22
- package/dist/ui-public/icons/custom/fieldgroup-structured_text.js +0 -61
- package/dist/ui-public/icons/lucide/receipt.js +0 -26
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Navigation, UI } from "../../../icons/index.js";
|
|
2
|
+
import { useTranslation } from "../../i18n.js";
|
|
3
|
+
import { useDateSettings } from "../../content/DateSettings.js";
|
|
4
|
+
import RawButton from "../../semantic/RawButton.js";
|
|
5
|
+
import Button from "../../actions/Button.js";
|
|
6
|
+
import { useAutoincrementIntegerId } from "../../hooks/useAutoincrementIntegerId.js";
|
|
7
|
+
import { weekStartForLocale } from "../../utils/weekStartForLocale.js";
|
|
8
|
+
import { intlDateTimeFormat } from "./dateText.js";
|
|
9
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
+
import classNames from "classnames";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { addDays, addMonths, addYears, differenceInCalendarWeeks, endOfMonth, endOfWeek, format, isAfter, isBefore, isSameDay, isSameMonth, isToday, parseISO, startOfDay, startOfMonth, startOfWeek } from "date-fns";
|
|
13
|
+
//#region ../ui-public/src/form/DateTimeInput/CalendarGrid.tsx
|
|
14
|
+
function generateMatrix(month, weekStartsOn) {
|
|
15
|
+
const firstDay = startOfMonth(month);
|
|
16
|
+
const lastDay = endOfMonth(month);
|
|
17
|
+
const start = startOfWeek(firstDay, { weekStartsOn });
|
|
18
|
+
const rows = differenceInCalendarWeeks(lastDay, firstDay, { weekStartsOn }) + 1;
|
|
19
|
+
return Array.from({ length: rows }, (_, row) => Array.from({ length: 7 }, (_, col) => addDays(start, row * 7 + col)));
|
|
20
|
+
}
|
|
21
|
+
function useCalendarNames(locale) {
|
|
22
|
+
return useMemo(() => ({
|
|
23
|
+
month: intlDateTimeFormat(locale, {
|
|
24
|
+
month: "long",
|
|
25
|
+
year: "numeric"
|
|
26
|
+
}),
|
|
27
|
+
weekdayShort: intlDateTimeFormat(locale, { weekday: "short" }),
|
|
28
|
+
weekdayLong: intlDateTimeFormat(locale, { weekday: "long" }),
|
|
29
|
+
day: intlDateTimeFormat(locale, { dateStyle: "full" })
|
|
30
|
+
}), [locale]);
|
|
31
|
+
}
|
|
32
|
+
/** The day that a key moves the focus to, or null for another key */
|
|
33
|
+
function dayForKey(event, day, weekStartsOn) {
|
|
34
|
+
switch (event.key) {
|
|
35
|
+
case "ArrowLeft": return addDays(day, -1);
|
|
36
|
+
case "ArrowRight": return addDays(day, 1);
|
|
37
|
+
case "ArrowUp": return addDays(day, -7);
|
|
38
|
+
case "ArrowDown": return addDays(day, 7);
|
|
39
|
+
case "Home": return startOfWeek(day, { weekStartsOn });
|
|
40
|
+
case "End": return startOfDay(endOfWeek(day, { weekStartsOn }));
|
|
41
|
+
case "PageUp": return event.shiftKey ? addYears(day, -1) : addMonths(day, -1);
|
|
42
|
+
case "PageDown": return event.shiftKey ? addYears(day, 1) : addMonths(day, 1);
|
|
43
|
+
default: return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The selector of the day that has the focus, or that gets it with Tab */
|
|
47
|
+
var CALENDAR_FOCUS_TARGET = ".DateTimeInput__CalendarDayCell[tabindex=\"0\"]";
|
|
48
|
+
/**
|
|
49
|
+
* Moves the focused day to an end of the selection when the end changes
|
|
50
|
+
* from outside the grid: the user types a date in the text. A pick in the
|
|
51
|
+
* grid does not move it, because the focus stays on the picked day. The
|
|
52
|
+
* effect runs after each render, so a pick that does not change the
|
|
53
|
+
* selection clears its flag on the next render.
|
|
54
|
+
*/
|
|
55
|
+
function useFollowSelection(selection, setFocusedDay) {
|
|
56
|
+
const previous = useRef(selection);
|
|
57
|
+
const pickedInGrid = useRef(false);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const { start, end } = previous.current;
|
|
60
|
+
const picked = pickedInGrid.current;
|
|
61
|
+
previous.current = selection;
|
|
62
|
+
pickedInGrid.current = false;
|
|
63
|
+
const moved = selection.end !== end ? selection.end : selection.start !== start ? selection.start : null;
|
|
64
|
+
if (moved && !picked) setFocusedDay(parseISO(moved));
|
|
65
|
+
});
|
|
66
|
+
return pickedInGrid;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The days of a month in a grid, for one date or for a range. The arrows,
|
|
70
|
+
* Home, End, Page Up and Page Down move the focus between the days, as in
|
|
71
|
+
* the date picker of the WAI-ARIA Authoring Practices. Only one day is in
|
|
72
|
+
* the Tab order.
|
|
73
|
+
*/
|
|
74
|
+
function CalendarGrid({ selection, selectableDays, onChange }) {
|
|
75
|
+
const { t } = useTranslation();
|
|
76
|
+
const { locale } = useDateSettings();
|
|
77
|
+
const names = useCalendarNames(locale);
|
|
78
|
+
const weekStartsOn = weekStartForLocale(locale);
|
|
79
|
+
const titleId = `DateTimeInput-calendar-${useAutoincrementIntegerId()}`;
|
|
80
|
+
const startDate = selection.start ? parseISO(selection.start) : null;
|
|
81
|
+
const endDate = selection.end ? parseISO(selection.end) : null;
|
|
82
|
+
const [focusedDay, setFocusedDay] = useState(() => startOfDay(startDate ?? endDate ?? /* @__PURE__ */ new Date()));
|
|
83
|
+
const pickedInGrid = useFollowSelection(selection, setFocusedDay);
|
|
84
|
+
const month = startOfMonth(focusedDay);
|
|
85
|
+
const monthKey = month.getTime();
|
|
86
|
+
const matrix = useMemo(() => generateMatrix(month, weekStartsOn), [monthKey, weekStartsOn]);
|
|
87
|
+
const gridRef = useRef(null);
|
|
88
|
+
const focusAfterRender = useRef(false);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!focusAfterRender.current) return;
|
|
91
|
+
focusAfterRender.current = false;
|
|
92
|
+
gridRef.current?.querySelector(CALENDAR_FOCUS_TARGET)?.focus({ preventScroll: true });
|
|
93
|
+
}, [focusedDay]);
|
|
94
|
+
const handleKeyDown = (event) => {
|
|
95
|
+
const next = dayForKey(event, focusedDay, weekStartsOn);
|
|
96
|
+
if (!next) return;
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
focusAfterRender.current = true;
|
|
99
|
+
setFocusedDay(next);
|
|
100
|
+
};
|
|
101
|
+
const handlePick = (day) => {
|
|
102
|
+
pickedInGrid.current = true;
|
|
103
|
+
onChange(day);
|
|
104
|
+
};
|
|
105
|
+
const today = startOfDay(/* @__PURE__ */ new Date());
|
|
106
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
|
|
107
|
+
className: "DateTimeInput__CalendarHeader",
|
|
108
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
109
|
+
className: "DateTimeInput__CalendarHeader__title",
|
|
110
|
+
id: titleId,
|
|
111
|
+
"aria-live": "polite",
|
|
112
|
+
children: names.month.format(month)
|
|
113
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
114
|
+
className: "DateTimeInput__CalendarHeader__actions",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx(Button, {
|
|
117
|
+
tone: "ghost",
|
|
118
|
+
size: "micro",
|
|
119
|
+
iconOnly: true,
|
|
120
|
+
icon: Navigation.ChevronLeftIcon,
|
|
121
|
+
label: t("dateTimeInput.previousMonth"),
|
|
122
|
+
className: "DateTimeInput__CalendarHeader__action--prev",
|
|
123
|
+
onClick: () => setFocusedDay((day) => addMonths(day, -1))
|
|
124
|
+
}),
|
|
125
|
+
/* @__PURE__ */ jsx(Button, {
|
|
126
|
+
tone: "ghost",
|
|
127
|
+
size: "micro",
|
|
128
|
+
iconOnly: true,
|
|
129
|
+
icon: UI.CircleDotIcon,
|
|
130
|
+
label: t("dateTimeInput.currentMonth"),
|
|
131
|
+
className: "DateTimeInput__CalendarHeader__action--today",
|
|
132
|
+
onClick: () => setFocusedDay(startOfDay(/* @__PURE__ */ new Date()))
|
|
133
|
+
}),
|
|
134
|
+
/* @__PURE__ */ jsx(Button, {
|
|
135
|
+
tone: "ghost",
|
|
136
|
+
size: "micro",
|
|
137
|
+
iconOnly: true,
|
|
138
|
+
icon: Navigation.ChevronRightIcon,
|
|
139
|
+
label: t("dateTimeInput.nextMonth"),
|
|
140
|
+
className: "DateTimeInput__CalendarHeader__action--next",
|
|
141
|
+
onClick: () => setFocusedDay((day) => addMonths(day, 1))
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
})]
|
|
145
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
146
|
+
ref: gridRef,
|
|
147
|
+
role: "grid",
|
|
148
|
+
"aria-labelledby": titleId,
|
|
149
|
+
className: "DateTimeInput__CalendarGrid",
|
|
150
|
+
style: { gridTemplateRows: `auto repeat(${matrix.length}, 1fr)` },
|
|
151
|
+
onKeyDown: handleKeyDown,
|
|
152
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
153
|
+
role: "row",
|
|
154
|
+
className: "DateTimeInput__CalendarRow",
|
|
155
|
+
children: matrix[0].map((day) => /* @__PURE__ */ jsx("div", {
|
|
156
|
+
role: "columnheader",
|
|
157
|
+
className: "DateTimeInput__CalendarWeekDay",
|
|
158
|
+
"aria-label": names.weekdayLong.format(day),
|
|
159
|
+
children: names.weekdayShort.format(day)
|
|
160
|
+
}, day.getTime()))
|
|
161
|
+
}), matrix.map((week) => /* @__PURE__ */ jsx("div", {
|
|
162
|
+
role: "row",
|
|
163
|
+
className: "DateTimeInput__CalendarRow",
|
|
164
|
+
children: week.map((day) => {
|
|
165
|
+
const isEdge = Boolean(startDate && isSameDay(day, startDate) || endDate && isSameDay(day, endDate));
|
|
166
|
+
const isBetween = Boolean(startDate && endDate && isAfter(day, startDate) && isBefore(day, endDate));
|
|
167
|
+
const isDisabled = selectableDays === "future" ? isBefore(day, today) : selectableDays === "past" ? isAfter(day, today) : false;
|
|
168
|
+
return /* @__PURE__ */ jsx("div", {
|
|
169
|
+
role: "gridcell",
|
|
170
|
+
className: "DateTimeInput__CalendarCell",
|
|
171
|
+
"aria-selected": isEdge || isBetween,
|
|
172
|
+
children: /* @__PURE__ */ jsx(RawButton, {
|
|
173
|
+
className: classNames("DateTimeInput__CalendarDayCell", {
|
|
174
|
+
"DateTimeInput__CalendarDayCell--isToday": isToday(day),
|
|
175
|
+
"DateTimeInput__CalendarDayCell--isSelected": isEdge,
|
|
176
|
+
"DateTimeInput__CalendarDayCell--inRange": isBetween,
|
|
177
|
+
"DateTimeInput__CalendarDayCell--inAdjacentMonth": !isSameMonth(day, month)
|
|
178
|
+
}),
|
|
179
|
+
ariaLabel: names.day.format(day),
|
|
180
|
+
"aria-current": isToday(day) ? "date" : void 0,
|
|
181
|
+
tabIndex: isSameDay(day, focusedDay) ? 0 : -1,
|
|
182
|
+
disabled: isDisabled ? "focusable" : false,
|
|
183
|
+
onFocus: () => {
|
|
184
|
+
if (isSameMonth(day, month)) setFocusedDay(day);
|
|
185
|
+
},
|
|
186
|
+
onClick: () => handlePick(day),
|
|
187
|
+
children: format(day, "d")
|
|
188
|
+
})
|
|
189
|
+
}, day.getTime());
|
|
190
|
+
})
|
|
191
|
+
}, week[0].getTime()))]
|
|
192
|
+
})] });
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { CALENDAR_FOCUS_TARGET, CalendarGrid as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isDefined } from "../../utils/isDefined.js";
|
|
2
|
+
import { isValid, parse } from "date-fns";
|
|
3
|
+
//#region ../ui-public/src/form/DateTimeInput/dateText.ts
|
|
4
|
+
/**
|
|
5
|
+
* The date-fns patterns that the time text accepts, in order. The first one
|
|
6
|
+
* is the pattern of the text that the input shows.
|
|
7
|
+
*/
|
|
8
|
+
function timeInputFormats(twentyFourHour, seconds) {
|
|
9
|
+
return twentyFourHour ? [
|
|
10
|
+
seconds && "HH:mm:ss",
|
|
11
|
+
"HH:mm",
|
|
12
|
+
"HH"
|
|
13
|
+
].filter(isDefined) : [
|
|
14
|
+
seconds && "hh:mm:ss aa",
|
|
15
|
+
seconds && "HH:mm:ss",
|
|
16
|
+
"hh:mm aa",
|
|
17
|
+
"HH:mm",
|
|
18
|
+
"hh aa",
|
|
19
|
+
"HH"
|
|
20
|
+
].filter(isDefined);
|
|
21
|
+
}
|
|
22
|
+
/** Parses the text of the user with the first pattern that matches */
|
|
23
|
+
function parseDateText(text, formats) {
|
|
24
|
+
for (const pattern of formats) {
|
|
25
|
+
const parsed = parse(text, pattern, /* @__PURE__ */ new Date());
|
|
26
|
+
if (isValid(parsed)) return parsed;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
function intlDateTimeFormat(locale, options) {
|
|
31
|
+
try {
|
|
32
|
+
return new Intl.DateTimeFormat(locale, options);
|
|
33
|
+
} catch {
|
|
34
|
+
return new Intl.DateTimeFormat("en", options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { intlDateTimeFormat, parseDateText, timeInputFormats };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type DateTimeInputProps } from './Base.js';
|
|
3
|
+
export type { DateInputCommonProps, DateInputVariant, DateTimeInputProps, SelectableDays, } from './Base.js';
|
|
4
|
+
/**
|
|
5
|
+
* An input for a date and a time, with a calendar and a time zone menu. The
|
|
6
|
+
* user types the date and the time in the format of their settings, in
|
|
7
|
+
* their time zone, or picks the day in the calendar. The value has the
|
|
8
|
+
* offset of the time zone of the project.
|
|
9
|
+
*/
|
|
10
|
+
export default function DateTimeInput(props: DateTimeInputProps): React.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import DateTimeInputBase from "./Base.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region ../ui-public/src/form/DateTimeInput/index.tsx
|
|
5
|
+
/**
|
|
6
|
+
* An input for a date and a time, with a calendar and a time zone menu. The
|
|
7
|
+
* user types the date and the time in the format of their settings, in
|
|
8
|
+
* their time zone, or picks the day in the calendar. The value has the
|
|
9
|
+
* offset of the time zone of the project.
|
|
10
|
+
*/
|
|
11
|
+
function DateTimeInput(props) {
|
|
12
|
+
return /* @__PURE__ */ jsx(DateTimeInputBase, {
|
|
13
|
+
...props,
|
|
14
|
+
withTime: true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { DateTimeInput as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TZDate } from "@date-fns/tz";
|
|
2
|
+
import { format } from "date-fns";
|
|
3
|
+
//#region ../ui-public/src/form/DateTimeInput/value.ts
|
|
4
|
+
/** The date-fns pattern of the value of `DateInput` */
|
|
5
|
+
var DATE_VALUE_FORMAT = "yyyy-MM-dd";
|
|
6
|
+
/**
|
|
7
|
+
* The date-fns pattern of the value of `DateTimeInput` and of the ends of
|
|
8
|
+
* `DateTimeRangeInput`: an ISO 8601 date and time with an offset, as the API
|
|
9
|
+
* gives it
|
|
10
|
+
*/
|
|
11
|
+
var DATE_TIME_VALUE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssXXX";
|
|
12
|
+
/**
|
|
13
|
+
* Formats an instant (a Date or epoch milliseconds) as the wall clock of
|
|
14
|
+
* the target time zone.
|
|
15
|
+
*
|
|
16
|
+
* Example: an instant, "Europe/London" and DATE_TIME_VALUE_FORMAT give the
|
|
17
|
+
* ISO string of that instant with the offset of London.
|
|
18
|
+
*/
|
|
19
|
+
function formatInstantInTimezone(instant, targetTimezone, formatString) {
|
|
20
|
+
const epochMillis = typeof instant === "number" ? instant : instant.getTime();
|
|
21
|
+
return format(new TZDate(epochMillis, targetTimezone), formatString);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The value of an instant for `DateTimeInput` and `DateTimeRangeInput`:
|
|
25
|
+
* the ISO string with the offset of the time zone
|
|
26
|
+
*/
|
|
27
|
+
function formatDateTimeValue(instant, timezone) {
|
|
28
|
+
return formatInstantInTimezone(instant, timezone, DATE_TIME_VALUE_FORMAT);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { DATE_TIME_VALUE_FORMAT, DATE_VALUE_FORMAT, formatDateTimeValue, formatInstantInTimezone };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { useTranslation } from "../../i18n.js";
|
|
2
|
+
import { useDateSettings } from "../../content/DateSettings.js";
|
|
3
|
+
import Button from "../../actions/Button.js";
|
|
4
|
+
import { useAutoincrementIntegerId } from "../../hooks/useAutoincrementIntegerId.js";
|
|
5
|
+
import { timezoneOptions } from "../../utils/timezones.js";
|
|
6
|
+
import SelectInput from "../SelectInput/index.js";
|
|
7
|
+
import { parseDateText, timeInputFormats } from "../DateTimeInput/dateText.js";
|
|
8
|
+
import CalendarGrid from "../DateTimeInput/CalendarGrid.js";
|
|
9
|
+
import { formatDateTimeValue } from "../DateTimeInput/value.js";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import classNames from "classnames";
|
|
12
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { TZDate } from "@date-fns/tz";
|
|
14
|
+
import { format } from "date-fns";
|
|
15
|
+
//#region ../ui-public/src/form/DateTimeRangeInput/Panel.tsx
|
|
16
|
+
/** An end that the user picks as a day gets this time */
|
|
17
|
+
var DAY_EDGE_TIME = {
|
|
18
|
+
start: [0, 0],
|
|
19
|
+
end: [23, 59]
|
|
20
|
+
};
|
|
21
|
+
/** The instant of a wall clock: the day and the time in the time zone */
|
|
22
|
+
function atTime(day, [hours, minutes], tz) {
|
|
23
|
+
const wallClock = new TZDate(day.getFullYear(), day.getMonth(), day.getDate(), hours, minutes, 0, tz);
|
|
24
|
+
return new Date(wallClock.getTime());
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The date text and the time text of one end. A text is read when the user
|
|
28
|
+
* leaves it, and a text that is not a date or a time goes back to the value.
|
|
29
|
+
*/
|
|
30
|
+
function EdgeInputs({ edge, value, timezone, valueTimezone, active, onActivate, onChange }) {
|
|
31
|
+
const { t } = useTranslation();
|
|
32
|
+
const { dateFormat, twentyFourHour } = useDateSettings();
|
|
33
|
+
const timeFormats = timeInputFormats(twentyFourHour, false);
|
|
34
|
+
const dateInputId = `DateTimeRangeInput-${edge}-${useAutoincrementIntegerId()}`;
|
|
35
|
+
const local = value ? new TZDate(value, timezone) : null;
|
|
36
|
+
const dateText = local ? format(local, dateFormat) : "";
|
|
37
|
+
const timeText = local ? format(local, timeFormats[0]) : "";
|
|
38
|
+
const [dateInput, setDateInput] = useState(dateText);
|
|
39
|
+
const [timeInput, setTimeInput] = useState(timeText);
|
|
40
|
+
useEffect(() => setDateInput(dateText), [dateText]);
|
|
41
|
+
useEffect(() => setTimeInput(timeText), [timeText]);
|
|
42
|
+
const handleDateBlur = () => {
|
|
43
|
+
const day = parseDateText(dateInput, [dateFormat]);
|
|
44
|
+
if (!day) {
|
|
45
|
+
setDateInput(dateText);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const time = local ? [local.getHours(), local.getMinutes()] : DAY_EDGE_TIME[edge];
|
|
49
|
+
onChange(formatDateTimeValue(atTime(day, time, timezone), valueTimezone));
|
|
50
|
+
};
|
|
51
|
+
const handleTimeBlur = () => {
|
|
52
|
+
const time = parseDateText(timeInput, timeFormats);
|
|
53
|
+
if (!time || !local) {
|
|
54
|
+
setTimeInput(timeText);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
onChange(formatDateTimeValue(atTime(local, [time.getHours(), time.getMinutes()], timezone), valueTimezone));
|
|
58
|
+
};
|
|
59
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
60
|
+
className: "DateTimeRangeInput__edge",
|
|
61
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
62
|
+
htmlFor: dateInputId,
|
|
63
|
+
className: "DateTimeRangeInput__edge-label",
|
|
64
|
+
children: t(edge === "start" ? "dateTimeRangeInput.start" : "dateTimeRangeInput.end")
|
|
65
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
66
|
+
className: "DateTimeRangeInput__edge-inputs",
|
|
67
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
68
|
+
id: dateInputId,
|
|
69
|
+
type: "text",
|
|
70
|
+
className: classNames("DateTimeRangeInput__edge-date", { "is-active": active }),
|
|
71
|
+
placeholder: dateFormat,
|
|
72
|
+
value: dateInput,
|
|
73
|
+
onChange: (event) => setDateInput(event.target.value),
|
|
74
|
+
onFocus: onActivate,
|
|
75
|
+
onBlur: handleDateBlur,
|
|
76
|
+
spellCheck: false,
|
|
77
|
+
autoComplete: "off"
|
|
78
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
79
|
+
type: "text",
|
|
80
|
+
"aria-label": t(edge === "start" ? "dateTimeRangeInput.startTime" : "dateTimeRangeInput.endTime"),
|
|
81
|
+
className: "DateTimeRangeInput__edge-time",
|
|
82
|
+
placeholder: timeFormats[0],
|
|
83
|
+
value: timeInput,
|
|
84
|
+
onChange: (event) => setTimeInput(event.target.value),
|
|
85
|
+
onBlur: handleTimeBlur,
|
|
86
|
+
spellCheck: false,
|
|
87
|
+
autoComplete: "off"
|
|
88
|
+
})]
|
|
89
|
+
})]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The custom range: a calendar, the texts of the two ends, the time zone and
|
|
94
|
+
* the Apply button. The range changes only on Apply.
|
|
95
|
+
*/
|
|
96
|
+
function Panel({ initial, timezone, valueTimezone, showsTimezone, onTimezoneChange, selectableDays, onApply }) {
|
|
97
|
+
const { t } = useTranslation();
|
|
98
|
+
const [range, setRange] = useState(initial);
|
|
99
|
+
const [activeEdge, setActiveEdge] = useState("start");
|
|
100
|
+
const toValue = (instant) => formatDateTimeValue(instant, valueTimezone);
|
|
101
|
+
const dayOf = (value) => value ? format(new TZDate(value, timezone), "yyyy-MM-dd") : null;
|
|
102
|
+
const handlePickDay = (day) => {
|
|
103
|
+
if (activeEdge === "start") {
|
|
104
|
+
setRange((current) => ({
|
|
105
|
+
...current,
|
|
106
|
+
start: toValue(atTime(day, DAY_EDGE_TIME.start, timezone))
|
|
107
|
+
}));
|
|
108
|
+
setActiveEdge("end");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const end = atTime(day, DAY_EDGE_TIME.end, timezone);
|
|
112
|
+
const start = range.start ? new TZDate(range.start, timezone) : null;
|
|
113
|
+
if (start && end.getTime() < start.getTime()) setRange({
|
|
114
|
+
start: toValue(atTime(day, DAY_EDGE_TIME.start, timezone)),
|
|
115
|
+
end: toValue(atTime(start, DAY_EDGE_TIME.end, timezone))
|
|
116
|
+
});
|
|
117
|
+
else setRange((current) => ({
|
|
118
|
+
...current,
|
|
119
|
+
end: toValue(end)
|
|
120
|
+
}));
|
|
121
|
+
setActiveEdge("start");
|
|
122
|
+
};
|
|
123
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
124
|
+
className: "DateTimeRangeInput__panel",
|
|
125
|
+
children: [/* @__PURE__ */ jsx(CalendarGrid, {
|
|
126
|
+
selection: {
|
|
127
|
+
start: dayOf(range.start),
|
|
128
|
+
end: dayOf(range.end)
|
|
129
|
+
},
|
|
130
|
+
selectableDays,
|
|
131
|
+
onChange: handlePickDay
|
|
132
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
133
|
+
className: "DateTimeRangeInput__edges",
|
|
134
|
+
children: [
|
|
135
|
+
["start", "end"].map((edge) => /* @__PURE__ */ jsx(EdgeInputs, {
|
|
136
|
+
edge,
|
|
137
|
+
value: range[edge],
|
|
138
|
+
timezone,
|
|
139
|
+
valueTimezone,
|
|
140
|
+
active: activeEdge === edge,
|
|
141
|
+
onActivate: () => setActiveEdge(edge),
|
|
142
|
+
onChange: (value) => setRange((current) => ({
|
|
143
|
+
...current,
|
|
144
|
+
[edge]: value
|
|
145
|
+
}))
|
|
146
|
+
}, edge)),
|
|
147
|
+
/* @__PURE__ */ jsx(Button, {
|
|
148
|
+
tone: "primary",
|
|
149
|
+
size: "small",
|
|
150
|
+
expand: true,
|
|
151
|
+
label: t("dateTimeRangeInput.apply"),
|
|
152
|
+
className: "DateTimeRangeInput__apply",
|
|
153
|
+
onClick: () => onApply(range)
|
|
154
|
+
}),
|
|
155
|
+
showsTimezone && /* @__PURE__ */ jsx(SelectInput, {
|
|
156
|
+
"aria-label": t("dateTimeInput.timezone"),
|
|
157
|
+
className: "DateTimeRangeInput__timezone",
|
|
158
|
+
options: timezoneOptions,
|
|
159
|
+
value: timezone,
|
|
160
|
+
onChange: (value) => value && onTimezoneChange(value)
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
})]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
export { Panel as default };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TextMessage } from '../../Message.js';
|
|
3
|
+
import { type PopoverProps } from '../../overlays/Popover.js';
|
|
4
|
+
import { type SelectableDays } from '../DateTimeInput/CalendarGrid.js';
|
|
5
|
+
import { type FieldInputProps } from '../FieldWrapper.js';
|
|
6
|
+
import { type BaseInputComponentPropsFieldWithReadOnly } from '../inputProps.js';
|
|
7
|
+
export type { SelectableDays } from '../DateTimeInput/CalendarGrid.js';
|
|
8
|
+
/** An option of the menu: a range that your code computes, for example "Last 7 days" */
|
|
9
|
+
export type DateTimeRangePreset = {
|
|
10
|
+
/** The key of the preset. It goes in the `preset` of the value. */
|
|
11
|
+
value: string;
|
|
12
|
+
/** The text of the option, and of the trigger when the preset is the value */
|
|
13
|
+
label: TextMessage;
|
|
14
|
+
};
|
|
15
|
+
/** The presets of the menu, and the preset that the clear button sets */
|
|
16
|
+
export type DateTimeRangePresets = {
|
|
17
|
+
/**
|
|
18
|
+
* The ranges of the menu, in their order. "Custom range" comes after
|
|
19
|
+
* them.
|
|
20
|
+
*/
|
|
21
|
+
options: DateTimeRangePreset[];
|
|
22
|
+
/**
|
|
23
|
+
* The `value` of the preset that the clear button of a custom range sets.
|
|
24
|
+
* Without it, the clear button sets the first option.
|
|
25
|
+
*/
|
|
26
|
+
default?: string;
|
|
27
|
+
};
|
|
28
|
+
/** The value of `DateTimeRangeInput`: a preset, or a custom range */
|
|
29
|
+
export type DateTimeRangeValue =
|
|
30
|
+
/** A preset of the menu, as its `value` */
|
|
31
|
+
{
|
|
32
|
+
preset: string;
|
|
33
|
+
start?: never;
|
|
34
|
+
end?: never;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A custom range. Each end is an ISO 8601 date and time with the offset
|
|
38
|
+
* of the time zone of the project, for example
|
|
39
|
+
* `"2026-11-03T00:00:00+01:00"`, or `null` for no limit on that side. The
|
|
40
|
+
* input accepts any ISO 8601 string as an end.
|
|
41
|
+
*/
|
|
42
|
+
| {
|
|
43
|
+
preset?: never;
|
|
44
|
+
start: string | null;
|
|
45
|
+
end: string | null;
|
|
46
|
+
};
|
|
47
|
+
/** The look of the input, and the props that only one look has */
|
|
48
|
+
export type DateTimeRangeInputVariant =
|
|
49
|
+
/** A trigger with the look of a field */
|
|
50
|
+
{
|
|
51
|
+
/**
|
|
52
|
+
* The look of the trigger. "default" has the look of a field. "filter"
|
|
53
|
+
* has no border and a small text, for the value of a filter.
|
|
54
|
+
* @default 'default'
|
|
55
|
+
*/
|
|
56
|
+
variant?: 'default';
|
|
57
|
+
/**
|
|
58
|
+
* Shows a button that sets the value back to the default preset (see
|
|
59
|
+
* `presets`), or to an empty range when there are no presets.
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
clearable?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The trigger is as wide as its text, not as wide as its container.
|
|
65
|
+
* @default false
|
|
66
|
+
*/
|
|
67
|
+
autosize?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The value of a filter: no border, no clear button, a small text. The
|
|
71
|
+
* trigger is as wide as its text.
|
|
72
|
+
*/
|
|
73
|
+
| {
|
|
74
|
+
variant: 'filter';
|
|
75
|
+
clearable?: never;
|
|
76
|
+
autosize?: never;
|
|
77
|
+
};
|
|
78
|
+
/** The props of `DateTimeRangeInput` */
|
|
79
|
+
export type DateTimeRangeInputProps = BaseInputComponentPropsFieldWithReadOnly<DateTimeRangeValue> & Omit<FieldInputProps, 'id'> & DateTimeRangeInputVariant & {
|
|
80
|
+
/**
|
|
81
|
+
* The ranges of the menu, and the preset that the clear button sets.
|
|
82
|
+
* Without presets, the trigger opens the custom range directly.
|
|
83
|
+
*/
|
|
84
|
+
presets?: DateTimeRangePresets;
|
|
85
|
+
/**
|
|
86
|
+
* The text of the trigger when the custom range has no ends.
|
|
87
|
+
* @default "Custom range"
|
|
88
|
+
*/
|
|
89
|
+
placeholder?: TextMessage;
|
|
90
|
+
/**
|
|
91
|
+
* The accessible name of the input. Give it when the input is not in a
|
|
92
|
+
* `FieldWrapper` with a `label`.
|
|
93
|
+
*/
|
|
94
|
+
ariaLabel?: TextMessage;
|
|
95
|
+
/**
|
|
96
|
+
* When the custom range shows the time zone menu. "always" shows it.
|
|
97
|
+
* "whenDifferent" shows it only when the time zone of the user is not
|
|
98
|
+
* the time zone of the project.
|
|
99
|
+
* @default 'always'
|
|
100
|
+
*/
|
|
101
|
+
timezoneSelect?: 'always' | 'whenDifferent';
|
|
102
|
+
/**
|
|
103
|
+
* The side of the input where the custom range opens. It moves to the
|
|
104
|
+
* other side when there is no space.
|
|
105
|
+
* @default 'bottom-start'
|
|
106
|
+
*/
|
|
107
|
+
calendarPlacement?: PopoverProps['placement'];
|
|
108
|
+
/**
|
|
109
|
+
* The days that the user can pick in the calendar. "future" is today
|
|
110
|
+
* and the days after it. "past" is today and the days before it, for
|
|
111
|
+
* a range of past events. The calendar disables the other days. The
|
|
112
|
+
* user can still type a date out of the limit: check the value in your
|
|
113
|
+
* code.
|
|
114
|
+
* @default 'all'
|
|
115
|
+
*/
|
|
116
|
+
selectableDays?: SelectableDays;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* An input for a range of dates and times, for example the time range of a
|
|
120
|
+
* log. The trigger opens a menu with your presets and "Custom range", which
|
|
121
|
+
* opens a calendar with the two ends of the range.
|
|
122
|
+
*/
|
|
123
|
+
export default function DateTimeRangeInput({ value, onChange, onBlur, disabled: disabledProp, readOnly, presets: presetsProp, placeholder, ariaLabel, timezoneSelect, variant, clearable, calendarPlacement, selectableDays, autosize, id, name, ...ariaProps }: DateTimeRangeInputProps): React.JSX.Element;
|