@plexui/ui 0.28.1 → 0.30.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/dist/es/components/Alert/Alert.js +2 -2
- package/dist/es/components/Alert/Alert.js.map +1 -1
- package/dist/es/components/Avatar/Avatar.js +3 -1
- package/dist/es/components/Avatar/Avatar.js.map +1 -1
- package/dist/es/components/Badge/index.js +1 -1
- package/dist/es/components/Badge/index.js.map +1 -1
- package/dist/es/components/Button/Button.js +4 -3
- package/dist/es/components/Button/Button.js.map +1 -1
- package/dist/es/components/Button/NavigationButton.js +10 -0
- package/dist/es/components/Button/NavigationButton.js.map +1 -0
- package/dist/es/components/Button/NavigationGlyph.js +19 -0
- package/dist/es/components/Button/NavigationGlyph.js.map +1 -0
- package/dist/es/components/Button/index.js +1 -0
- package/dist/es/components/Button/index.js.map +1 -1
- package/dist/es/components/Checkbox/Checkbox.js +2 -1
- package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/es/components/ColorPicker/ColorPicker.js +227 -0
- package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/es/components/ColorPicker/ColorWell.js +58 -0
- package/dist/es/components/ColorPicker/ColorWell.js.map +1 -0
- package/dist/es/components/ColorPicker/index.js +3 -0
- package/dist/es/components/ColorPicker/index.js.map +1 -0
- package/dist/es/components/ColorPicker/shared.js +132 -0
- package/dist/es/components/ColorPicker/shared.js.map +1 -0
- package/dist/es/components/ContextMenu/ContextMenu.js +164 -0
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/es/components/ContextMenu/index.js +2 -0
- package/dist/es/components/ContextMenu/index.js.map +1 -0
- package/dist/es/components/ContextMenu/shared.js +56 -0
- package/dist/es/components/ContextMenu/shared.js.map +1 -0
- package/dist/es/components/DateInput/DateInput.js +4 -2
- package/dist/es/components/DateInput/DateInput.js.map +1 -1
- package/dist/es/components/DatePicker/Calendar.js +89 -55
- package/dist/es/components/DatePicker/Calendar.js.map +1 -1
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js +13 -0
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js.map +1 -0
- package/dist/es/components/DatePicker/DatePicker.js +9 -2
- package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/es/components/DatePicker/useCalendarGutter.js +8 -0
- package/dist/es/components/DatePicker/useCalendarGutter.js.map +1 -0
- package/dist/es/components/DateRangePicker/Calendar.js +66 -49
- package/dist/es/components/DateRangePicker/Calendar.js.map +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js +6 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +136 -20
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +77 -24
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +51 -4
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +4 -2
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
- package/dist/es/components/FileUpload/FileUpload.js +43 -3
- package/dist/es/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +18 -16
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js +11 -6
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js.map +1 -1
- package/dist/es/components/Icon/index.js +2 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/Disclosure.js +5 -0
- package/dist/es/components/Icon/svg/Disclosure.js.map +1 -0
- package/dist/es/components/Icon/svg/Eyedropper.js +6 -0
- package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +1 -1
- package/dist/es/components/Indicator/LoadingIndicator.js.map +1 -1
- package/dist/es/components/Input/Input.js +3 -3
- package/dist/es/components/Input/Input.js.map +1 -1
- package/dist/es/components/InputGroup/InputGroup.js +3 -1
- package/dist/es/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +95 -93
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +306 -34
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/OTPInput/OTPInput.js +4 -1
- package/dist/es/components/OTPInput/OTPInput.js.map +1 -1
- package/dist/es/components/Page/Page.js +147 -19
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/Page/index.js.map +1 -1
- package/dist/es/components/PageControl/PageControl.js +146 -0
- package/dist/es/components/PageControl/PageControl.js.map +1 -0
- package/dist/es/components/PageControl/index.js +2 -0
- package/dist/es/components/PageControl/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +75 -33
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredOutsidePress.js +90 -0
- package/dist/es/components/Popover/deferredOutsidePress.js.map +1 -0
- package/dist/es/components/Popover/usePopoverContext.js.map +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es/components/Select/Select.js +98 -32
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/SelectControl/SelectControl.js +48 -29
- package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
- package/dist/es/components/SelectControl/index.js +1 -1
- package/dist/es/components/SelectControl/index.js.map +1 -1
- package/dist/es/components/ShimmerText/ShimmerText.js +17 -7
- package/dist/es/components/ShimmerText/ShimmerText.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +21 -8
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +61 -15
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Sortable/Sortable.js +16 -6
- package/dist/es/components/Sortable/Sortable.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +114 -0
- package/dist/es/components/Stepper/Stepper.js.map +1 -0
- package/dist/es/components/Stepper/index.js +2 -0
- package/dist/es/components/Stepper/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +2 -2
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +128 -0
- package/dist/es/components/TabBar/TabBar.js.map +1 -0
- package/dist/es/components/TabBar/index.js +2 -0
- package/dist/es/components/TabBar/index.js.map +1 -0
- package/dist/es/components/Tabs/Tabs.js +27 -11
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +40 -4
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +7 -1
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Toast/ToastRenderer.js +86 -0
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -0
- package/dist/es/components/Toast/Toaster.js +31 -16
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +283 -0
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -0
- package/dist/es/components/Toolbar/Toolbar.js +92 -0
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -0
- package/dist/es/components/Toolbar/index.js +2 -0
- package/dist/es/components/Toolbar/index.js.map +1 -0
- package/dist/es/components/Tooltip/CopyTooltip.js +37 -11
- package/dist/es/components/Tooltip/CopyTooltip.js.map +1 -1
- package/dist/es/components/Tooltip/Tooltip.js +61 -9
- package/dist/es/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/es/hooks/useFloatingBoundary.js +35 -0
- package/dist/es/hooks/useFloatingBoundary.js.map +1 -0
- package/dist/es/hooks/usePhoneSubmenu.js +22 -0
- package/dist/es/hooks/usePhoneSubmenu.js.map +1 -0
- package/dist/es/lib/copyToClipboard.js +16 -7
- package/dist/es/lib/copyToClipboard.js.map +1 -1
- package/dist/es/lib/fieldRow.js +7 -1
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +90 -0
- package/dist/es/lib/floatingBoundary.js.map +1 -0
- package/dist/es/lib/focusRestore.js +56 -0
- package/dist/es/lib/focusRestore.js.map +1 -0
- package/dist/es/lib/helpers.js +0 -18
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/inputMode.js +9 -0
- package/dist/es/lib/inputMode.js.map +1 -0
- package/dist/es/lib/menuInitialFocus.js +100 -0
- package/dist/es/lib/menuInitialFocus.js.map +1 -0
- package/dist/es/lib/menuSubmenuPlacement.js +264 -0
- package/dist/es/lib/menuSubmenuPlacement.js.map +1 -0
- package/dist/es/lib/menuTriggerCover.js +70 -0
- package/dist/es/lib/menuTriggerCover.js.map +1 -0
- package/dist/es/lib/observeTextareaWidth.js +49 -0
- package/dist/es/lib/observeTextareaWidth.js.map +1 -0
- package/dist/es/lib/scrollEdges.js +34 -0
- package/dist/es/lib/scrollEdges.js.map +1 -0
- package/dist/es/lib/selectPress.js +34 -0
- package/dist/es/lib/selectPress.js.map +1 -0
- package/dist/es/lib/sortable.js +74 -20
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/es/styles/mobile-materials.css +1 -0
- package/dist/es/styles/mobile-surfaces.css +1 -0
- package/dist/types/components/Button/Button.d.ts +2 -0
- package/dist/types/components/Button/NavigationButton.d.ts +8 -0
- package/dist/types/components/Button/NavigationGlyph.d.ts +7 -0
- package/dist/types/components/Button/index.d.ts +1 -0
- package/dist/types/components/ColorPicker/ColorPicker.d.ts +34 -0
- package/dist/types/components/ColorPicker/ColorWell.d.ts +32 -0
- package/dist/types/components/ColorPicker/index.d.ts +3 -0
- package/dist/types/components/ColorPicker/shared.d.ts +69 -0
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +78 -0
- package/dist/types/components/ContextMenu/index.d.ts +1 -0
- package/dist/types/components/ContextMenu/shared.d.ts +50 -0
- package/dist/types/components/DatePicker/CalendarNavigationIcon.d.ts +5 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +7 -1
- package/dist/types/components/DatePicker/useCalendarGutter.d.ts +1 -0
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +2 -0
- package/dist/types/components/Dialog/Dialog.d.ts +17 -6
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts +12 -2
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +11 -2
- package/dist/types/components/Icon/index.d.ts +2 -0
- package/dist/types/components/Icon/svg/Disclosure.d.ts +6 -0
- package/dist/types/components/Icon/svg/Eyedropper.d.ts +6 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +1 -1
- package/dist/types/components/Menu/Menu.d.ts +74 -9
- package/dist/types/components/Page/Page.d.ts +24 -9
- package/dist/types/components/Page/index.d.ts +1 -1
- package/dist/types/components/PageControl/PageControl.d.ts +52 -0
- package/dist/types/components/PageControl/index.d.ts +1 -0
- package/dist/types/components/Popover/Popover.d.ts +11 -6
- package/dist/types/components/Popover/deferredOutsidePress.d.ts +14 -0
- package/dist/types/components/Popover/usePopoverContext.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +3 -3
- package/dist/types/components/SelectControl/SelectControl.d.ts +2 -2
- package/dist/types/components/SelectControl/index.d.ts +1 -1
- package/dist/types/components/Sortable/Sortable.d.ts +1 -1
- package/dist/types/components/Stepper/Stepper.d.ts +56 -0
- package/dist/types/components/Stepper/index.d.ts +1 -0
- package/dist/types/components/Switch/Switch.d.ts +3 -1
- package/dist/types/components/TabBar/TabBar.d.ts +74 -0
- package/dist/types/components/TabBar/index.d.ts +1 -0
- package/dist/types/components/Toast/ToastRenderer.d.ts +3 -0
- package/dist/types/components/Toast/Toaster.d.ts +4 -2
- package/dist/types/components/Toast/toastLifecycle.d.ts +90 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +93 -0
- package/dist/types/components/Toolbar/index.d.ts +1 -0
- package/dist/types/components/Tooltip/Tooltip.d.ts +2 -2
- package/dist/types/hooks/useFloatingBoundary.d.ts +24 -0
- package/dist/types/hooks/usePhoneSubmenu.d.ts +3 -0
- package/dist/types/lib/fieldRow.d.ts +6 -0
- package/dist/types/lib/floatingBoundary.d.ts +9 -0
- package/dist/types/lib/focusRestore.d.ts +5 -0
- package/dist/types/lib/helpers.d.ts +1 -5
- package/dist/types/lib/inputMode.d.ts +7 -0
- package/dist/types/lib/menuInitialFocus.d.ts +9 -0
- package/dist/types/lib/menuSubmenuPlacement.d.ts +57 -0
- package/dist/types/lib/menuTriggerCover.d.ts +23 -0
- package/dist/types/lib/observeTextareaWidth.d.ts +2 -0
- package/dist/types/lib/scrollEdges.d.ts +16 -0
- package/dist/types/lib/selectPress.d.ts +23 -0
- package/dist/types/lib/sortable.d.ts +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Portal, Slot } from "radix-ui";
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
5
|
+
import s from "@plexui/styles/components/ContextMenu/ContextMenu.module.css";
|
|
6
|
+
import { Menu, useMenuContext } from "../Menu/Menu.js";
|
|
7
|
+
import { TransitionGroup } from "../Transition/index.js";
|
|
8
|
+
import { overlayTiming } from "../Transition/shared.js";
|
|
9
|
+
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuHoleMask, contextMenuPlacement, contextMenuPreview, } from "./shared.js";
|
|
10
|
+
const ContextMenuContext = createContext(null);
|
|
11
|
+
function useContextMenuContext(part) {
|
|
12
|
+
const context = useContext(ContextMenuContext);
|
|
13
|
+
if (!context)
|
|
14
|
+
throw new Error(`${part} must be used within ContextMenu`);
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at
|
|
19
|
+
* the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as
|
|
20
|
+
* iOS lifts the preview. The items are the ones of `Menu`.
|
|
21
|
+
*/
|
|
22
|
+
function ContextMenuRoot({ children, onOpen, onClose }) {
|
|
23
|
+
const [presentation, setPresentation] = useState(null);
|
|
24
|
+
const regionRef = useRef(null);
|
|
25
|
+
const value = useMemo(() => ({ presentation, setPresentation, regionRef }), [presentation]);
|
|
26
|
+
return (_jsx(ContextMenuContext.Provider, { value: value, children: _jsx(Menu, { onOpen: onOpen, onClose: onClose, children: children }) }));
|
|
27
|
+
}
|
|
28
|
+
ContextMenuRoot.displayName = "ContextMenu";
|
|
29
|
+
/**
|
|
30
|
+
* Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown
|
|
31
|
+
* would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose
|
|
32
|
+
* content takes the press), and the click would activate the element.
|
|
33
|
+
*/
|
|
34
|
+
const suppressNextClick = (doc) => {
|
|
35
|
+
const hold = (event) => {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
};
|
|
39
|
+
const swallow = (event) => {
|
|
40
|
+
hold(event);
|
|
41
|
+
stop();
|
|
42
|
+
};
|
|
43
|
+
const stop = () => {
|
|
44
|
+
doc.removeEventListener("mousedown", hold, true);
|
|
45
|
+
doc.removeEventListener("click", swallow, true);
|
|
46
|
+
doc.removeEventListener("pointerdown", stop, true);
|
|
47
|
+
window.clearTimeout(timer);
|
|
48
|
+
};
|
|
49
|
+
// A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.
|
|
50
|
+
const timer = window.setTimeout(stop, 600);
|
|
51
|
+
doc.addEventListener("mousedown", hold, true);
|
|
52
|
+
doc.addEventListener("click", swallow, true);
|
|
53
|
+
doc.addEventListener("pointerdown", stop, true);
|
|
54
|
+
};
|
|
55
|
+
function ContextMenuTrigger({ children, disabled = false }) {
|
|
56
|
+
const menu = useMenuContext();
|
|
57
|
+
const { setPresentation, regionRef } = useContextMenuContext("ContextMenu.Trigger");
|
|
58
|
+
const press = useRef(null);
|
|
59
|
+
const cancel = () => {
|
|
60
|
+
if (press.current)
|
|
61
|
+
window.clearTimeout(press.current.timer);
|
|
62
|
+
press.current = null;
|
|
63
|
+
};
|
|
64
|
+
useEffect(() => () => {
|
|
65
|
+
if (press.current)
|
|
66
|
+
window.clearTimeout(press.current.timer);
|
|
67
|
+
}, []);
|
|
68
|
+
const open = (presentation) => {
|
|
69
|
+
setPresentation(presentation);
|
|
70
|
+
menu.setOpen(true);
|
|
71
|
+
};
|
|
72
|
+
const openPreview = (element, x) => {
|
|
73
|
+
regionRef.current = element;
|
|
74
|
+
open(contextMenuPreview(element, x));
|
|
75
|
+
};
|
|
76
|
+
const handlers = {
|
|
77
|
+
onPointerDown: (event) => {
|
|
78
|
+
if (event.defaultPrevented || disabled || event.pointerType !== "touch" || !event.isPrimary)
|
|
79
|
+
return;
|
|
80
|
+
cancel();
|
|
81
|
+
const element = event.currentTarget;
|
|
82
|
+
const x = event.clientX;
|
|
83
|
+
const timer = window.setTimeout(() => {
|
|
84
|
+
const current = press.current;
|
|
85
|
+
if (!current || current.timer !== timer)
|
|
86
|
+
return;
|
|
87
|
+
current.opened = true;
|
|
88
|
+
openPreview(element, x);
|
|
89
|
+
}, CONTEXT_MENU_LONG_PRESS);
|
|
90
|
+
press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false };
|
|
91
|
+
},
|
|
92
|
+
onPointerMove: (event) => {
|
|
93
|
+
const current = press.current;
|
|
94
|
+
if (!current || current.id !== event.pointerId || current.opened)
|
|
95
|
+
return;
|
|
96
|
+
if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP)
|
|
97
|
+
cancel();
|
|
98
|
+
},
|
|
99
|
+
onPointerUp: (event) => {
|
|
100
|
+
const current = press.current;
|
|
101
|
+
if (!current || current.id !== event.pointerId)
|
|
102
|
+
return;
|
|
103
|
+
if (current.opened)
|
|
104
|
+
suppressNextClick(event.currentTarget.ownerDocument);
|
|
105
|
+
cancel();
|
|
106
|
+
},
|
|
107
|
+
onPointerCancel: (event) => {
|
|
108
|
+
if (press.current?.id === event.pointerId)
|
|
109
|
+
cancel();
|
|
110
|
+
},
|
|
111
|
+
onContextMenu: (event) => {
|
|
112
|
+
if (event.defaultPrevented || disabled)
|
|
113
|
+
return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
const element = event.currentTarget;
|
|
116
|
+
regionRef.current = element;
|
|
117
|
+
// A touch and hold that the browser reports as a context menu (Android) opens the preview once.
|
|
118
|
+
const current = press.current;
|
|
119
|
+
if (current) {
|
|
120
|
+
if (current.opened)
|
|
121
|
+
return;
|
|
122
|
+
window.clearTimeout(current.timer);
|
|
123
|
+
current.opened = true;
|
|
124
|
+
return openPreview(element, current.x);
|
|
125
|
+
}
|
|
126
|
+
if (menu.isUsingKeyboard.current)
|
|
127
|
+
return open({ kind: "keyboard", rect: element.getBoundingClientRect() });
|
|
128
|
+
open({ kind: "pointer", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } });
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
return _jsx(Slot.Root, { className: s.Trigger, ...handlers, children: children });
|
|
132
|
+
}
|
|
133
|
+
ContextMenuTrigger.displayName = "ContextMenu.Trigger";
|
|
134
|
+
function ContextMenuContent(props) {
|
|
135
|
+
const { open } = useMenuContext();
|
|
136
|
+
const { presentation, regionRef } = useContextMenuContext("ContextMenu.Content");
|
|
137
|
+
const rect = presentation?.rect;
|
|
138
|
+
const placement = contextMenuPlacement(presentation);
|
|
139
|
+
const preview = presentation?.kind === "preview" ? presentation : null;
|
|
140
|
+
const dimmed = open && preview !== null;
|
|
141
|
+
return (_jsxs(_Fragment, { children: [_jsx(Portal.Root, { asChild: true, children: _jsx(Menu.Trigger, { children: _jsx("span", { "aria-hidden": "true", tabIndex: -1, className: s.Anchor, style: rect ? { left: rect.x, top: rect.y, width: rect.width, height: rect.height } : undefined }) }) }), _jsx(Portal.Root, { asChild: true, children: _jsx(TransitionGroup, { className: s.Dimming, ...overlayTiming, children: dimmed && (_jsx("div", { "data-context-menu-dimming": "", className: s.Overlay, style: contextMenuHoleMask(preview), children: _jsx("div", { className: s.Preview, style: { left: preview.rect.x, top: preview.rect.y, width: preview.rect.width, height: preview.rect.height, borderRadius: preview.radius } }) }, "dimming")) }) }), _jsx(Menu.Content, { ...props, ...placement, onCloseAutoFocus: (event) => {
|
|
142
|
+
// Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
if (presentation?.kind === "keyboard")
|
|
145
|
+
regionRef.current?.focus({ preventScroll: true });
|
|
146
|
+
} })] }));
|
|
147
|
+
}
|
|
148
|
+
ContextMenuContent.displayName = "ContextMenu.Content";
|
|
149
|
+
export const ContextMenu = Object.assign(ContextMenuRoot, {
|
|
150
|
+
Trigger: ContextMenuTrigger,
|
|
151
|
+
Content: ContextMenuContent,
|
|
152
|
+
Item: Menu.Item,
|
|
153
|
+
Link: Menu.Link,
|
|
154
|
+
Separator: Menu.Separator,
|
|
155
|
+
Label: Menu.Label,
|
|
156
|
+
Group: Menu.Group,
|
|
157
|
+
Sub: Menu.Sub,
|
|
158
|
+
SubTrigger: Menu.SubTrigger,
|
|
159
|
+
SubContent: Menu.SubContent,
|
|
160
|
+
CheckboxItem: Menu.CheckboxItem,
|
|
161
|
+
RadioGroup: Menu.RadioGroup,
|
|
162
|
+
RadioItem: Menu.RadioItem,
|
|
163
|
+
});
|
|
164
|
+
//# sourceMappingURL=ContextM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Memo,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactElement,\n type ReactNode,\n type RefObject,\n} from \"react\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { Menu, useMenuContext, type MenuContentProps } from \"../Menu/Menu\"\nimport { TransitionGroup } from \"../Transition\"\nimport { overlayTiming } from \"../Transition/shared\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuHoleMask,\n contextMenuPlacement,\n contextMenuPreview,\n type ContextMenuPresentation,\n} from \"./shared\"\n\ntype ContextMenuContextValue = {\n presentation: ContextMenuPresentation | null\n setPresentation: (presentation: ContextMenuPresentation) => void\n regionRef: RefObject<HTMLElement | null>\n}\n\nconst ContextMenuContext = createContext<ContextMenuContextValue | null>(null)\n\nfunction useContextMenuContext(part: string) {\n const context = useContext(ContextMenuContext)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nexport type ContextMenuProps = {\n /** `ContextMenu.Trigger` and `ContextMenu.Content`. */\n children: ReactNode\n /** Called when the menu opens. */\n onOpen?: () => void\n /** Called when the menu closes. */\n onClose?: () => void\n}\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nfunction ContextMenuRoot({ children, onOpen, onClose }: ContextMenuProps) {\n const [presentation, setPresentation] = useState<ContextMenuPresentation | null>(null)\n const regionRef = useRef<HTMLElement | null>(null)\n const value = useMemo(() => ({ presentation, setPresentation, regionRef }), [presentation])\n return (\n <ContextMenuContext.Provider value={value}>\n <Menu onOpen={onOpen} onClose={onClose}>{children}</Menu>\n </ContextMenuContext.Provider>\n )\n}\nContextMenuRoot.displayName = \"ContextMenu\"\n\nexport type ContextMenuTriggerProps = {\n /** The element the menu is for; it receives the handlers, so it keeps its own role and focus. */\n children: ReactElement\n /** When `true`, the element keeps the browser's own context menu. */\n disabled?: boolean\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\nfunction ContextMenuTrigger({ children, disabled = false }: ContextMenuTriggerProps) {\n const menu = useMenuContext()\n const { setPresentation, regionRef } = useContextMenuContext(\"ContextMenu.Trigger\")\n const press = useRef<Press | null>(null)\n\n const cancel = () => {\n if (press.current) window.clearTimeout(press.current.timer)\n press.current = null\n }\n useEffect(() => () => {\n if (press.current) window.clearTimeout(press.current.timer)\n }, [])\n\n const open = (presentation: ContextMenuPresentation) => {\n setPresentation(presentation)\n menu.setOpen(true)\n }\n const openPreview = (element: HTMLElement, x: number) => {\n regionRef.current = element\n open(contextMenuPreview(element, x))\n }\n\n const handlers = {\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n cancel()\n const element = event.currentTarget\n const x = event.clientX\n const timer = window.setTimeout(() => {\n const current = press.current\n if (!current || current.timer !== timer) return\n current.opened = true\n openPreview(element, x)\n }, CONTEXT_MENU_LONG_PRESS)\n press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId || current.opened) return\n if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId) return\n if (current.opened) suppressNextClick(event.currentTarget.ownerDocument)\n cancel()\n },\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => {\n if (press.current?.id === event.pointerId) cancel()\n },\n onContextMenu: (event: ReactMouseEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled) return\n event.preventDefault()\n const element = event.currentTarget\n regionRef.current = element\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n const current = press.current\n if (current) {\n if (current.opened) return\n window.clearTimeout(current.timer)\n current.opened = true\n return openPreview(element, current.x)\n }\n if (menu.isUsingKeyboard.current) return open({ kind: \"keyboard\", rect: element.getBoundingClientRect() })\n open({ kind: \"pointer\", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } })\n },\n }\n\n return <Slot.Root className={s.Trigger} {...handlers}>{children}</Slot.Root>\n}\nContextMenuTrigger.displayName = \"ContextMenu.Trigger\"\n\n/** The props of `Menu.Content` but its placement, which follows how the menu opened. */\nexport type ContextMenuContentProps = Omit<MenuContentProps, \"side\" | \"sideOffset\" | \"align\" | \"alignOffset\" | \"onCloseAutoFocus\" | \"layout\" | \"size\">\n\nfunction ContextMenuContent(props: ContextMenuContentProps) {\n const { open } = useMenuContext()\n const { presentation, regionRef } = useContextMenuContext(\"ContextMenu.Content\")\n const rect = presentation?.rect\n const placement = contextMenuPlacement(presentation)\n const preview = presentation?.kind === \"preview\" ? presentation : null\n const dimmed = open && preview !== null\n\n return (\n <>\n {/* The menu is placed against this invisible box: the pointer, or the element. */}\n <Portal.Root asChild>\n <Menu.Trigger>\n <span\n aria-hidden=\"true\"\n tabIndex={-1}\n className={s.Anchor}\n style={rect ? { left: rect.x, top: rect.y, width: rect.width, height: rect.height } : undefined}\n />\n </Menu.Trigger>\n </Portal.Root>\n <Portal.Root asChild>\n <TransitionGroup className={s.Dimming} {...overlayTiming}>\n {dimmed && (\n <div key=\"dimming\" data-context-menu-dimming=\"\" className={s.Overlay} style={contextMenuHoleMask(preview) as CSSProperties}>\n <div\n className={s.Preview}\n style={{ left: preview.rect.x, top: preview.rect.y, width: preview.rect.width, height: preview.rect.height, borderRadius: preview.radius }}\n />\n </div>\n )}\n </TransitionGroup>\n </Portal.Root>\n <Menu.Content\n {...props}\n {...placement}\n onCloseAutoFocus={(event) => {\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n event.preventDefault()\n if (presentation?.kind === \"keyboard\") regionRef.current?.focus({ preventScroll: true })\n }}\n />\n </>\n )\n}\nContextMenuContent.displayName = \"ContextMenu.Content\"\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Trigger: ContextMenuTrigger,\n Content: ContextMenuContent,\n Item: Menu.Item,\n Link: Menu.Link,\n Separator: Menu.Separator,\n Label: Menu.Label,\n Group: Menu.Group,\n Sub: Menu.Sub,\n SubTrigger: Menu.SubTrigger,\n SubContent: Menu.SubContent,\n CheckboxItem: Menu.CheckboxItem,\n RadioGroup: Menu.RadioGroup,\n RadioItem: Menu.RadioItem,\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqF,MAAM,eAAe,CAAA","sourcesContent":["export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps, type ContextMenuTriggerProps } from \"./ContextMenu\"\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** A touch held this long opens the menu, as a UIKit long press (0.5 s). */
|
|
2
|
+
export const CONTEXT_MENU_LONG_PRESS = 500;
|
|
3
|
+
/** A touch that moves farther than this before then scrolls or drags instead. */
|
|
4
|
+
export const CONTEXT_MENU_LONG_PRESS_SLOP = 10;
|
|
5
|
+
/** The kit's gap between the preview and the menu (Context Menu, Alignment=Vertical: 160 + 18 = 178). */
|
|
6
|
+
export const CONTEXT_MENU_PREVIEW_GAP = 18;
|
|
7
|
+
/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */
|
|
8
|
+
const PREVIEW_RADIUS = 30;
|
|
9
|
+
const px = (value, base) => {
|
|
10
|
+
const number = Number.parseFloat(value);
|
|
11
|
+
if (!Number.isFinite(number))
|
|
12
|
+
return 0;
|
|
13
|
+
return value.trim().endsWith("%") ? (number / 100) * base : number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and
|
|
17
|
+
* the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.
|
|
18
|
+
*/
|
|
19
|
+
export function contextMenuPreview(element, touchX) {
|
|
20
|
+
const box = element.getBoundingClientRect();
|
|
21
|
+
const rect = { x: box.left, y: box.top, width: box.width, height: box.height };
|
|
22
|
+
const style = getComputedStyle(element);
|
|
23
|
+
const short = Math.min(rect.width, rect.height);
|
|
24
|
+
const own = px(style.borderTopLeftRadius, short);
|
|
25
|
+
const fallback = px(style.getPropertyValue("--context-menu-preview-radius"), short) || PREVIEW_RADIUS;
|
|
26
|
+
const radius = Math.min(own > 0 ? own : fallback, short / 2);
|
|
27
|
+
const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width;
|
|
28
|
+
return { kind: "preview", rect, radius, align: touchX < width / 2 ? "start" : "end" };
|
|
29
|
+
}
|
|
30
|
+
/** The menu's side, alignment and offsets for a presentation. */
|
|
31
|
+
export function contextMenuPlacement(presentation) {
|
|
32
|
+
if (presentation?.kind === "preview")
|
|
33
|
+
return { side: "bottom", align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 };
|
|
34
|
+
if (presentation?.kind === "keyboard")
|
|
35
|
+
return { side: "bottom", align: "start", sideOffset: 5, alignOffset: 0 };
|
|
36
|
+
// As a desktop context menu, its corner at the pointer.
|
|
37
|
+
return { side: "bottom", align: "start", sideOffset: 2, alignOffset: 0 };
|
|
38
|
+
}
|
|
39
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
40
|
+
/**
|
|
41
|
+
* The dimming covers the page but the element: an SVG mask with the element's rounded box cut out, written to
|
|
42
|
+
* `--context-menu-hole`, so the element stays clear above the dimmed, blurred page.
|
|
43
|
+
*/
|
|
44
|
+
export function contextMenuHoleMask(preview, viewport) {
|
|
45
|
+
const width = round(viewport?.width ?? window.innerWidth);
|
|
46
|
+
const height = round(viewport?.height ?? window.innerHeight);
|
|
47
|
+
const x = round(preview.rect.x);
|
|
48
|
+
const y = round(preview.rect.y);
|
|
49
|
+
const w = round(preview.rect.width);
|
|
50
|
+
const h = round(preview.rect.height);
|
|
51
|
+
const r = round(preview.radius);
|
|
52
|
+
const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`;
|
|
53
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='M0 0H${width}V${height}H0Z${hole}'/></svg>`;
|
|
54
|
+
return { "--context-menu-hole": `url("data:image/svg+xml,${encodeURIComponent(svg)}")` };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ContextM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,CAAC,GAAG,CAAA;IACjR,MAAM,GAAG,GAAG,kDAAkD,KAAK,aAAa,MAAM,kBAAkB,KAAK,IAAI,MAAM,uCAAuC,KAAK,IAAI,MAAM,MAAM,IAAI,WAAW,CAAA;IAClM,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;AAC1F,CAAC","sourcesContent":["/** A touch held this long opens the menu, as a UIKit long press (0.5 s). */\nexport const CONTEXT_MENU_LONG_PRESS = 500\n/** A touch that moves farther than this before then scrolls or drags instead. */\nexport const CONTEXT_MENU_LONG_PRESS_SLOP = 10\n/** The kit's gap between the preview and the menu (Context Menu, Alignment=Vertical: 160 + 18 = 178). */\nexport const CONTEXT_MENU_PREVIEW_GAP = 18\n/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */\nconst PREVIEW_RADIUS = 30\n\ntype Rect = { x: number; y: number; width: number; height: number }\n\n/** Where the menu opens: at the pointer, under the element for the keyboard, or beside a touch-and-hold preview. */\nexport type ContextMenuPresentation =\n | { kind: \"pointer\"; rect: Rect }\n | { kind: \"keyboard\"; rect: Rect }\n | { kind: \"preview\"; rect: Rect; radius: number; align: \"start\" | \"end\" }\n\nconst px = (value: string, base: number) => {\n const number = Number.parseFloat(value)\n if (!Number.isFinite(number)) return 0\n return value.trim().endsWith(\"%\") ? (number / 100) * base : number\n}\n\n/**\n * The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and\n * the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.\n */\nexport function contextMenuPreview(element: HTMLElement, touchX: number): ContextMenuPresentation {\n const box = element.getBoundingClientRect()\n const rect = { x: box.left, y: box.top, width: box.width, height: box.height }\n const style = getComputedStyle(element)\n const short = Math.min(rect.width, rect.height)\n const own = px(style.borderTopLeftRadius, short)\n const fallback = px(style.getPropertyValue(\"--context-menu-preview-radius\"), short) || PREVIEW_RADIUS\n const radius = Math.min(own > 0 ? own : fallback, short / 2)\n const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width\n return { kind: \"preview\", rect, radius, align: touchX < width / 2 ? \"start\" : \"end\" }\n}\n\n/** The menu's side, alignment and offsets for a presentation. */\nexport function contextMenuPlacement(presentation: ContextMenuPresentation | null) {\n if (presentation?.kind === \"preview\")\n return { side: \"bottom\" as const, align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 }\n if (presentation?.kind === \"keyboard\") return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 5, alignOffset: 0 }\n // As a desktop context menu, its corner at the pointer.\n return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 2, alignOffset: 0 }\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\n\n/**\n * The dimming covers the page but the element: an SVG mask with the element's rounded box cut out, written to\n * `--context-menu-hole`, so the element stays clear above the dimmed, blurred page.\n */\nexport function contextMenuHoleMask(preview: Extract<ContextMenuPresentation, { kind: \"preview\" }>, viewport?: { width: number; height: number }) {\n const width = round(viewport?.width ?? window.innerWidth)\n const height = round(viewport?.height ?? window.innerHeight)\n const x = round(preview.rect.x)\n const y = round(preview.rect.y)\n const w = round(preview.rect.width)\n const h = round(preview.rect.height)\n const r = round(preview.radius)\n const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`\n const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='M0 0H${width}V${height}H0Z${hole}'/></svg>`\n return { \"--context-menu-hole\": `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\")` }\n}\n"]}
|
|
@@ -7,7 +7,7 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
7
7
|
import { mergeRefs } from "react-merge-refs";
|
|
8
8
|
import { Input } from "../Input/index.js";
|
|
9
9
|
export const DateInput = (props) => {
|
|
10
|
-
const { value, onChange, mode = "dd/mm/yyyy", separator = ".", timeMode, dateTimeSeparator = ", ", timeStep = 0, min, max, clearable = false, placeholder, onBlur, ref, ...inputProps } = props;
|
|
10
|
+
const { value, onChange, mode = "dd/mm/yyyy", separator = ".", timeMode, dateTimeSeparator = ", ", timeStep = 0, min, max, clearable = false, placeholder, inputMode, onBlur, ref, ...inputProps } = props;
|
|
11
11
|
const hasTime = !!timeMode;
|
|
12
12
|
const dateParams = useMemo(() => ({
|
|
13
13
|
mode,
|
|
@@ -76,6 +76,8 @@ export const DateInput = (props) => {
|
|
|
76
76
|
return datePart;
|
|
77
77
|
return `${datePart}${dateTimeSeparator}${timeMode}`;
|
|
78
78
|
}, [mode, separator, hasTime, timeMode, dateTimeSeparator]);
|
|
79
|
-
return (_jsx(Input, { ...inputProps,
|
|
79
|
+
return (_jsx(Input, { ...inputProps,
|
|
80
|
+
// Maskito inserts separators; only the AM/PM segment needs letters.
|
|
81
|
+
inputMode: inputMode ?? (timeMode?.includes("AA") ? "text" : "numeric"), ref: mergeRefs([maskRef, ref]), value: inputValue, onInput: handleInput, onBlur: handleBlur, placeholder: placeholder ?? defaultPlaceholder, onClear: clearable ? handleClear : undefined }));
|
|
80
82
|
};
|
|
81
83
|
//# sourceMappingURL=DateInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../../../src/components/DateInput/DateInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,GAKzB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,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AAE,UAAU,EACjB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,IAAI,kBAAkB,EAC9C,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,GAC5C,CACH,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport {\n maskitoDateOptionsGenerator,\n maskitoDateTimeOptionsGenerator,\n maskitoParseDate,\n maskitoParseDateTime,\n maskitoStringifyDate,\n maskitoStringifyDateTime,\n type MaskitoDateMode,\n type MaskitoDateParams,\n type MaskitoDateTimeParams,\n type MaskitoTimeMode,\n} from \"@maskito/kit\"\nimport { useMaskito } from \"@maskito/react\"\nimport { DateTime } from \"luxon\"\nimport { useEffect, useMemo, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\nimport { Input, type InputProps } from \"../Input\"\n\nexport type DateInputProps = {\n value: DateTime | null\n onChange: (value: DateTime | null) => void\n mode?: MaskitoDateMode\n separator?: string\n timeMode?: MaskitoTimeMode\n dateTimeSeparator?: string\n timeStep?: number\n min?: DateTime\n max?: DateTime\n clearable?: boolean\n ref?: React.Ref<HTMLInputElement | null>\n} & Omit<\n InputProps,\n \"value\" | \"defaultValue\" | \"onChange\" | \"onInput\" | \"onClear\" | \"ref\" | \"type\" | \"min\" | \"max\"\n>\n\nexport const DateInput = (props: DateInputProps) => {\n const {\n value,\n onChange,\n mode = \"dd/mm/yyyy\",\n separator = \".\",\n timeMode,\n dateTimeSeparator = \", \",\n timeStep = 0,\n min,\n max,\n clearable = false,\n placeholder,\n inputMode,\n onBlur,\n ref,\n ...inputProps\n } = props\n\n const hasTime = !!timeMode\n\n const dateParams = useMemo<MaskitoDateParams>(\n () => ({\n mode,\n separator,\n ...(min ? { min: min.toJSDate() } : undefined),\n ...(max ? { max: max.toJSDate() } : undefined),\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [mode, separator, min?.toMillis(), max?.toMillis()],\n )\n\n const dateTimeParams = useMemo<MaskitoDateTimeParams>(\n () => ({\n dateMode: mode,\n dateSeparator: separator,\n timeMode: timeMode ?? \"HH:MM\",\n dateTimeSeparator,\n ...(timeStep ? { timeStep } : undefined),\n ...(min ? { min: min.toJSDate() } : undefined),\n ...(max ? { max: max.toJSDate() } : undefined),\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [mode, separator, timeMode, dateTimeSeparator, timeStep, min?.toMillis(), max?.toMillis()],\n )\n\n const maskOptions = useMemo(\n () =>\n hasTime\n ? maskitoDateTimeOptionsGenerator(dateTimeParams)\n : maskitoDateOptionsGenerator(dateParams),\n [hasTime, dateParams, dateTimeParams],\n )\n\n const maskRef = useMaskito({ options: maskOptions })\n\n const [inputValue, setInputValue] = useState(\"\")\n\n const format = (date: DateTime | null) => {\n if (!date) return \"\"\n return hasTime\n ? maskitoStringifyDateTime(date.toJSDate(), dateTimeParams)\n : maskitoStringifyDate(date.toJSDate(), dateParams)\n }\n\n const parse = (str: string) =>\n hasTime ? maskitoParseDateTime(str, dateTimeParams) : maskitoParseDate(str, dateParams)\n\n const valueMsKey = value?.toMillis() ?? null\n useEffect(() => {\n setInputValue(format(value))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [valueMsKey, hasTime, dateParams, dateTimeParams])\n\n const handleInput = (evt: React.FormEvent<HTMLInputElement>) => {\n const str = evt.currentTarget.value\n setInputValue(str)\n\n if (!str) {\n onChange(null)\n return\n }\n\n const parsed = parse(str)\n\n if (parsed) {\n onChange(DateTime.fromJSDate(parsed))\n }\n }\n\n // Text that is not a complete date never reaches onChange, so leaving the\n // field shows the value again instead of a date the value does not hold\n const handleBlur = (evt: React.FocusEvent<HTMLInputElement>) => {\n onBlur?.(evt)\n if (inputValue && !parse(inputValue)) {\n setInputValue(format(value))\n }\n }\n\n const handleClear = () => {\n setInputValue(\"\")\n onChange(null)\n }\n\n const defaultPlaceholder = useMemo(() => {\n const datePart = mode.replace(/\\//g, separator).toUpperCase()\n if (!hasTime) return datePart\n return `${datePart}${dateTimeSeparator}${timeMode}`\n }, [mode, separator, hasTime, timeMode, dateTimeSeparator])\n\n return (\n <Input\n {...inputProps}\n // Maskito inserts separators; only the AM/PM segment needs letters.\n inputMode={inputMode ?? (timeMode?.includes(\"AA\") ? \"text\" : \"numeric\")}\n ref={mergeRefs([maskRef as unknown as React.Ref<HTMLInputElement>, ref])}\n value={inputValue}\n onInput={handleInput}\n onBlur={handleBlur}\n placeholder={placeholder ?? defaultPlaceholder}\n onClear={clearable ? handleClear : undefined}\n />\n )\n}\n"]}
|