@dmsi/wedgekit-react 0.0.2
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 +35 -0
- package/dist/chunk-27KIIUAR.js +59 -0
- package/dist/chunk-2G2E2JMA.js +123 -0
- package/dist/chunk-4C66DLIJ.js +51 -0
- package/dist/chunk-4RD5ZF2V.js +55 -0
- package/dist/chunk-4RJKB7LC.js +14 -0
- package/dist/chunk-4T7F5BZZ.js +26 -0
- package/dist/chunk-5GOBP2JS.js +53 -0
- package/dist/chunk-6ZY524ID.js +42 -0
- package/dist/chunk-AWQSSKCK.js +32 -0
- package/dist/chunk-BNHSAFMP.js +93 -0
- package/dist/chunk-BWRHL2AG.js +439 -0
- package/dist/chunk-DKKYR6DS.js +132 -0
- package/dist/chunk-E5ALT5W7.js +182 -0
- package/dist/chunk-FY7PTP6E.js +322 -0
- package/dist/chunk-GTCSRHPF.js +119 -0
- package/dist/chunk-I2UVVKQI.js +12 -0
- package/dist/chunk-IGQVA7SC.js +41 -0
- package/dist/chunk-K3IKUSZW.js +59 -0
- package/dist/chunk-KENSVWOY.js +151 -0
- package/dist/chunk-KX3O6GJ6.js +138 -0
- package/dist/chunk-L4UM372R.js +253 -0
- package/dist/chunk-ORMEWXMH.js +37 -0
- package/dist/chunk-Q3FKEKIN.js +23 -0
- package/dist/chunk-SEKKGFM6.js +28 -0
- package/dist/chunk-SY3HT54E.js +91 -0
- package/dist/chunk-TAW5ZZ4Z.js +346 -0
- package/dist/chunk-TRUPPHBQ.js +109 -0
- package/dist/chunk-TU55CHXU.js +30 -0
- package/dist/chunk-TWZZB4WO.js +114 -0
- package/dist/chunk-TYI74BSP.js +62 -0
- package/dist/chunk-U42SKNR6.js +104 -0
- package/dist/chunk-UU3FA6LV.js +72 -0
- package/dist/chunk-WVUIIBRR.js +51 -0
- package/dist/chunk-XUIPGYP5.js +39 -0
- package/dist/chunk-Z4UCFUF7.js +299 -0
- package/dist/components/Breadcrumbs.cjs +376 -0
- package/dist/components/Breadcrumbs.js +90 -0
- package/dist/components/Button.cjs +319 -0
- package/dist/components/Button.js +8 -0
- package/dist/components/CalendarRange.cjs +520 -0
- package/dist/components/CalendarRange.js +13 -0
- package/dist/components/Caption.cjs +283 -0
- package/dist/components/Caption.js +80 -0
- package/dist/components/Checkbox.cjs +378 -0
- package/dist/components/Checkbox.js +11 -0
- package/dist/components/ContentTab.cjs +382 -0
- package/dist/components/ContentTab.js +10 -0
- package/dist/components/ContentTabs.cjs +472 -0
- package/dist/components/ContentTabs.js +98 -0
- package/dist/components/DMSiLogo.cjs +79 -0
- package/dist/components/DMSiLogo.js +56 -0
- package/dist/components/DataGrid.cjs +3113 -0
- package/dist/components/DataGrid.js +758 -0
- package/dist/components/DataGridCell.cjs +1907 -0
- package/dist/components/DataGridCell.js +24 -0
- package/dist/components/DataTable.cjs +791 -0
- package/dist/components/DataTable.js +720 -0
- package/dist/components/DateInput.cjs +1130 -0
- package/dist/components/DateInput.js +170 -0
- package/dist/components/DateRangeInput.cjs +1131 -0
- package/dist/components/DateRangeInput.js +171 -0
- package/dist/components/DebugJson.cjs +50 -0
- package/dist/components/DebugJson.js +27 -0
- package/dist/components/Display.cjs +234 -0
- package/dist/components/Display.js +12 -0
- package/dist/components/EditingContext.cjs +73 -0
- package/dist/components/EditingContext.js +35 -0
- package/dist/components/FilterGroup.cjs +1431 -0
- package/dist/components/FilterGroup.js +231 -0
- package/dist/components/FullViewportBox.cjs +35 -0
- package/dist/components/FullViewportBox.js +12 -0
- package/dist/components/Grid.cjs +69 -0
- package/dist/components/Grid.js +36 -0
- package/dist/components/GridContainer.cjs +125 -0
- package/dist/components/GridContainer.js +92 -0
- package/dist/components/Heading.cjs +238 -0
- package/dist/components/Heading.js +14 -0
- package/dist/components/HorizontalDivider.cjs +33 -0
- package/dist/components/HorizontalDivider.js +10 -0
- package/dist/components/Icon.cjs +98 -0
- package/dist/components/Icon.js +7 -0
- package/dist/components/Input.cjs +672 -0
- package/dist/components/Input.js +21 -0
- package/dist/components/InputGroup.cjs +270 -0
- package/dist/components/InputGroup.js +60 -0
- package/dist/components/Label.cjs +223 -0
- package/dist/components/Label.js +8 -0
- package/dist/components/Link.cjs +262 -0
- package/dist/components/Link.js +8 -0
- package/dist/components/List.cjs +37 -0
- package/dist/components/List.js +14 -0
- package/dist/components/LiveChatComponent.cjs +63 -0
- package/dist/components/LiveChatComponent.js +40 -0
- package/dist/components/LogoAgilityTopBar.cjs +115 -0
- package/dist/components/LogoAgilityTopBar.js +92 -0
- package/dist/components/LogoDMSiTopBar.cjs +79 -0
- package/dist/components/LogoDMSiTopBar.js +7 -0
- package/dist/components/LogoMillworkTopBar.cjs +221 -0
- package/dist/components/LogoMillworkTopBar.js +198 -0
- package/dist/components/MainBar.cjs +211 -0
- package/dist/components/MainBar.js +65 -0
- package/dist/components/Menu.cjs +437 -0
- package/dist/components/Menu.js +11 -0
- package/dist/components/MenuOption.cjs +483 -0
- package/dist/components/MenuOption.js +13 -0
- package/dist/components/MobileDataGrid.cjs +658 -0
- package/dist/components/MobileDataGrid.js +125 -0
- package/dist/components/Modal.cjs +783 -0
- package/dist/components/Modal.js +245 -0
- package/dist/components/ModalButtons.cjs +385 -0
- package/dist/components/ModalButtons.js +10 -0
- package/dist/components/ModalContent.cjs +57 -0
- package/dist/components/ModalContent.js +7 -0
- package/dist/components/ModalHeader.cjs +426 -0
- package/dist/components/ModalHeader.js +11 -0
- package/dist/components/ModalScrim.cjs +64 -0
- package/dist/components/ModalScrim.js +7 -0
- package/dist/components/NavigationTab.cjs +431 -0
- package/dist/components/NavigationTab.js +10 -0
- package/dist/components/NavigationTabs.cjs +477 -0
- package/dist/components/NavigationTabs.js +56 -0
- package/dist/components/Notification.cjs +640 -0
- package/dist/components/Notification.js +117 -0
- package/dist/components/OptionPill.cjs +478 -0
- package/dist/components/OptionPill.js +11 -0
- package/dist/components/Paragraph.cjs +231 -0
- package/dist/components/Paragraph.js +8 -0
- package/dist/components/Password.cjs +700 -0
- package/dist/components/Password.js +53 -0
- package/dist/components/ProjectBar.cjs +242 -0
- package/dist/components/ProjectBar.js +63 -0
- package/dist/components/Radio.cjs +349 -0
- package/dist/components/Radio.js +131 -0
- package/dist/components/Search.cjs +767 -0
- package/dist/components/Search.js +12 -0
- package/dist/components/Select.cjs +758 -0
- package/dist/components/Select.js +12 -0
- package/dist/components/SideMenu.cjs +54 -0
- package/dist/components/SideMenu.js +21 -0
- package/dist/components/SideMenuGroup.cjs +422 -0
- package/dist/components/SideMenuGroup.js +83 -0
- package/dist/components/SideMenuItem.cjs +388 -0
- package/dist/components/SideMenuItem.js +70 -0
- package/dist/components/Stack.cjs +138 -0
- package/dist/components/Stack.js +7 -0
- package/dist/components/StatusPill.cjs +265 -0
- package/dist/components/StatusPill.js +52 -0
- package/dist/components/Stepper.cjs +885 -0
- package/dist/components/Stepper.js +105 -0
- package/dist/components/Subheader.cjs +226 -0
- package/dist/components/Subheader.js +8 -0
- package/dist/components/Surface.cjs +98 -0
- package/dist/components/Surface.js +40 -0
- package/dist/components/Swatch.cjs +1728 -0
- package/dist/components/Swatch.js +1319 -0
- package/dist/components/Textarea.cjs +269 -0
- package/dist/components/Textarea.js +96 -0
- package/dist/components/Theme.cjs +36 -0
- package/dist/components/Theme.js +7 -0
- package/dist/components/Time.cjs +1118 -0
- package/dist/components/Time.js +353 -0
- package/dist/components/Toast.cjs +644 -0
- package/dist/components/Toast.js +218 -0
- package/dist/components/Tooltip.cjs +273 -0
- package/dist/components/Tooltip.js +9 -0
- package/dist/components/TopBar.cjs +352 -0
- package/dist/components/TopBar.js +132 -0
- package/dist/components/useInfiniteScroll.cjs +57 -0
- package/dist/components/useInfiniteScroll.js +8 -0
- package/dist/components/useMatchesMedia.cjs +53 -0
- package/dist/components/useMatchesMedia.js +9 -0
- package/dist/components/useMenuSystem.cjs +358 -0
- package/dist/components/useMenuSystem.js +11 -0
- package/dist/components/useMounted.cjs +39 -0
- package/dist/components/useMounted.js +8 -0
- package/dist/fonts.css +21 -0
- package/dist/icons-light[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/icons-normal[FILL]-PPZXOLWS.woff2 +0 -0
- package/dist/index.css +4401 -0
- package/dist/open-sans-55T6A4JE.woff2 +0 -0
- package/dist/types.cjs +18 -0
- package/dist/types.js +0 -0
- package/package.json +66 -0
- package/src/brand.css +125 -0
- package/src/classNames.ts +144 -0
- package/src/components/Breadcrumbs.tsx +116 -0
- package/src/components/Button.tsx +210 -0
- package/src/components/CalendarRange.tsx +429 -0
- package/src/components/Caption.tsx +101 -0
- package/src/components/Checkbox.tsx +196 -0
- package/src/components/ContentTab.tsx +66 -0
- package/src/components/ContentTabs.tsx +103 -0
- package/src/components/DMSiLogo.tsx +32 -0
- package/src/components/DataGrid.tsx +948 -0
- package/src/components/DataGridCell.tsx +384 -0
- package/src/components/DataTable.tsx +835 -0
- package/src/components/DateInput.tsx +188 -0
- package/src/components/DateRangeInput.tsx +179 -0
- package/src/components/DebugJson.tsx +24 -0
- package/src/components/Display.tsx +60 -0
- package/src/components/EditingContext.tsx +40 -0
- package/src/components/FilterGroup.tsx +234 -0
- package/src/components/FullViewportBox.tsx +11 -0
- package/src/components/Grid.tsx +75 -0
- package/src/components/GridContainer.tsx +124 -0
- package/src/components/Heading.tsx +66 -0
- package/src/components/HorizontalDivider.tsx +3 -0
- package/src/components/Icon.tsx +36 -0
- package/src/components/Input.tsx +511 -0
- package/src/components/InputGroup.tsx +51 -0
- package/src/components/Label.tsx +40 -0
- package/src/components/Link.tsx +106 -0
- package/src/components/List.tsx +10 -0
- package/src/components/LiveChatComponent.tsx +56 -0
- package/src/components/LogoAgilityTopBar.tsx +53 -0
- package/src/components/LogoDMSiTopBar.tsx +32 -0
- package/src/components/LogoMillworkTopBar.tsx +118 -0
- package/src/components/MainBar.tsx +83 -0
- package/src/components/Menu.tsx +286 -0
- package/src/components/MenuOption.tsx +275 -0
- package/src/components/MobileDataGrid.tsx +135 -0
- package/src/components/Modal.tsx +271 -0
- package/src/components/ModalButtons.tsx +44 -0
- package/src/components/ModalContent.tsx +23 -0
- package/src/components/ModalHeader.tsx +41 -0
- package/src/components/ModalScrim.tsx +35 -0
- package/src/components/NavigationTab.tsx +89 -0
- package/src/components/NavigationTabs.tsx +63 -0
- package/src/components/Notification.tsx +120 -0
- package/src/components/OptionPill.tsx +114 -0
- package/src/components/Paragraph.tsx +49 -0
- package/src/components/Password.tsx +46 -0
- package/src/components/ProjectBar.tsx +76 -0
- package/src/components/Radio.tsx +140 -0
- package/src/components/Search.tsx +129 -0
- package/src/components/Select.tsx +104 -0
- package/src/components/SideMenu.tsx +21 -0
- package/src/components/SideMenuGroup.tsx +81 -0
- package/src/components/SideMenuItem.tsx +90 -0
- package/src/components/Stack.tsx +179 -0
- package/src/components/StatusPill.tsx +51 -0
- package/src/components/Stepper.tsx +91 -0
- package/src/components/Subheader.tsx +44 -0
- package/src/components/Surface.tsx +34 -0
- package/src/components/Swatch.tsx +1066 -0
- package/src/components/Textarea.tsx +101 -0
- package/src/components/Theme.tsx +13 -0
- package/src/components/Time.tsx +438 -0
- package/src/components/Toast.tsx +244 -0
- package/src/components/Tooltip.tsx +137 -0
- package/src/components/TopBar.tsx +124 -0
- package/src/components/useInfiniteScroll.tsx +40 -0
- package/src/components/useMatchesMedia.tsx +28 -0
- package/src/components/useMenuSystem.tsx +367 -0
- package/src/components/useMounted.tsx +14 -0
- package/src/darkmode.css +140 -0
- package/src/fonts.css +23 -0
- package/src/index.css +509 -0
- package/src/index.tsx +2 -0
- package/src/types.ts +149 -0
- package/src/utils/formatting.tsx +81 -0
- package/src/utils.ts +23 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { ComponentProps, ReactNode } from "react";
|
|
4
|
+
import { baseTransition, typography } from "../classNames";
|
|
5
|
+
|
|
6
|
+
interface TextareaProps
|
|
7
|
+
extends Omit<
|
|
8
|
+
ComponentProps<"textarea">,
|
|
9
|
+
"children" | "dangerouslySetInnerHTML"
|
|
10
|
+
> {
|
|
11
|
+
label?: string;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
caption?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const textareaComponentPaddingMinusBorder = clsx(
|
|
17
|
+
"p-[calc(var(--spacing-mobile-component-padding)_+_var(--spacing-mobile-component-gap)_-_1px)]",
|
|
18
|
+
"desktop:p-[calc(var(--spacing-desktop-component-padding)_+_var(--spacing-desktop-component-gap)_-_1px)]",
|
|
19
|
+
"compact:p-[calc(var(--spacing-desktop-compact-component-padding)_+_var(--spacing-desktop-compact-component-gap)_-_1px)]",
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const textareaBaseClass = clsx(
|
|
23
|
+
"w-full min-h-19",
|
|
24
|
+
"rounded-base border border-border-primary-normal bg-background-primary-normal caret-text-action-normal",
|
|
25
|
+
"outline-transparent outline-2",
|
|
26
|
+
textareaComponentPaddingMinusBorder,
|
|
27
|
+
baseTransition,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const textareaInvalidClass = clsx(
|
|
31
|
+
"data-error:not-disabled:border-transparent data-error:not-focus:outline-border-primary-error data-error:not-focus:outline-1",
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const textareaFocusClass = clsx(
|
|
35
|
+
"focus:border-transparent focus:outline-border-primary-focus",
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const textareaDisabledClass = clsx(
|
|
39
|
+
"disabled:bg-background-action-secondary-disabled disabled:border-border-primary-normal",
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const textareaReadOnlyClass = clsx(
|
|
43
|
+
"read-only:outline-none read-only:bg-transparent read-only:border-transparent read-only:appearance-none read-only:resize-none read-only:not-disabled:pl-0",
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export const Textarea = ({
|
|
47
|
+
label,
|
|
48
|
+
error,
|
|
49
|
+
caption,
|
|
50
|
+
...props
|
|
51
|
+
}: TextareaProps) => {
|
|
52
|
+
const attributes = {
|
|
53
|
+
"data-error": error || null,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<label
|
|
58
|
+
className={clsx(
|
|
59
|
+
"block w-full space-y-desktop-component-gap",
|
|
60
|
+
"text-text-primary-normal has-disabled:text-text-primary-disabled",
|
|
61
|
+
!props.disabled &&
|
|
62
|
+
!props.readOnly &&
|
|
63
|
+
"has-[[data-error]]:text-text-primary-error",
|
|
64
|
+
)}
|
|
65
|
+
>
|
|
66
|
+
{label && (
|
|
67
|
+
<span
|
|
68
|
+
className={clsx(
|
|
69
|
+
typography.label,
|
|
70
|
+
"text-inherit",
|
|
71
|
+
props.disabled || props.readOnly
|
|
72
|
+
? "cursor-default"
|
|
73
|
+
: "cursor-pointer",
|
|
74
|
+
"inline-block",
|
|
75
|
+
)}
|
|
76
|
+
>
|
|
77
|
+
{label}
|
|
78
|
+
</span>
|
|
79
|
+
)}
|
|
80
|
+
|
|
81
|
+
<textarea
|
|
82
|
+
{...props}
|
|
83
|
+
{...attributes}
|
|
84
|
+
id={props.id}
|
|
85
|
+
className={clsx(
|
|
86
|
+
"disabled:text-text-primary-disabled",
|
|
87
|
+
typography.paragraph,
|
|
88
|
+
textareaBaseClass,
|
|
89
|
+
textareaInvalidClass,
|
|
90
|
+
textareaFocusClass,
|
|
91
|
+
textareaDisabledClass,
|
|
92
|
+
textareaReadOnlyClass,
|
|
93
|
+
)}
|
|
94
|
+
></textarea>
|
|
95
|
+
|
|
96
|
+
{caption}
|
|
97
|
+
</label>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
Textarea.displayName = "Textarea";
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { InputBase } from "./Input";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { typography } from "../classNames";
|
|
6
|
+
import { Icon } from "./Icon";
|
|
7
|
+
import { findDocumentRoot } from "../utils";
|
|
8
|
+
import { Stack } from "./Stack";
|
|
9
|
+
|
|
10
|
+
type TimeProps = {
|
|
11
|
+
label?: string;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
readOnly?: boolean;
|
|
14
|
+
caption?: ReactNode;
|
|
15
|
+
format?: "12h" | "24h";
|
|
16
|
+
} & Omit<ComponentProps<"input">, "type" | "children" | "dangerouslySetInnerHTML">;
|
|
17
|
+
|
|
18
|
+
const timePickerScrollableStyle = "overflow-auto max-h-full py-4 no-scrollbar";
|
|
19
|
+
|
|
20
|
+
export const Time = ({ onChange, format = "12h", ...props }: TimeProps) => {
|
|
21
|
+
const [showTimePicker, setShowTimePicker] = useState(false);
|
|
22
|
+
const [hasInteracted, setHasInteracted] = useState(false);
|
|
23
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
24
|
+
const inputContainerRef = useRef<HTMLLabelElement>(null);
|
|
25
|
+
const timeRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
const [timePosition, setTimePosition] = useState({
|
|
27
|
+
top: 0,
|
|
28
|
+
left: 0,
|
|
29
|
+
width: 0,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const [hour, setHour] = useState<string | null>(null);
|
|
33
|
+
const [minute, setMinute] = useState<string | null>(null);
|
|
34
|
+
const [meridiem, setMeridiem] = useState<"AM" | "PM" | null>(null);
|
|
35
|
+
const [inputValue, setInputValue] = useState("");
|
|
36
|
+
|
|
37
|
+
const is12HourFormat = format === "12h";
|
|
38
|
+
|
|
39
|
+
const formattedTime =
|
|
40
|
+
hour && minute
|
|
41
|
+
? is12HourFormat
|
|
42
|
+
? meridiem
|
|
43
|
+
? `${hour}:${minute} ${meridiem}`
|
|
44
|
+
: `${hour}:${minute}`
|
|
45
|
+
: `${hour}:${minute}`
|
|
46
|
+
: "";
|
|
47
|
+
|
|
48
|
+
const updatePosition = () => {
|
|
49
|
+
if (inputContainerRef.current) {
|
|
50
|
+
const rect = inputContainerRef.current.getBoundingClientRect();
|
|
51
|
+
setTimePosition({
|
|
52
|
+
top: rect.bottom + window.scrollY + 6,
|
|
53
|
+
left: rect.left + window.scrollX,
|
|
54
|
+
width: rect.width,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (showTimePicker) {
|
|
61
|
+
updatePosition();
|
|
62
|
+
}
|
|
63
|
+
}, [showTimePicker, is12HourFormat]);
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
67
|
+
if (
|
|
68
|
+
inputRef.current &&
|
|
69
|
+
timeRef.current &&
|
|
70
|
+
!inputRef.current.contains(event.target as Node) &&
|
|
71
|
+
!timeRef.current.contains(event.target as Node)
|
|
72
|
+
) {
|
|
73
|
+
setShowTimePicker(false);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (showTimePicker) {
|
|
78
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return () => {
|
|
82
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
83
|
+
};
|
|
84
|
+
}, [showTimePicker, is12HourFormat]);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (formattedTime && hasInteracted) {
|
|
88
|
+
setInputValue(formattedTime);
|
|
89
|
+
|
|
90
|
+
onChange?.({
|
|
91
|
+
target: { value: formattedTime },
|
|
92
|
+
} as unknown as React.ChangeEvent<HTMLInputElement>);
|
|
93
|
+
}
|
|
94
|
+
}, [formattedTime, hasInteracted, onChange]);
|
|
95
|
+
|
|
96
|
+
const handleFocus = () => {
|
|
97
|
+
if (!props.disabled && !props.readOnly) {
|
|
98
|
+
setHasInteracted(true);
|
|
99
|
+
setShowTimePicker(true);
|
|
100
|
+
|
|
101
|
+
// Initialize meridiem to AM if not set and using 12-hour format
|
|
102
|
+
if (is12HourFormat && meridiem === null) {
|
|
103
|
+
setMeridiem("AM");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const handleSelect = (
|
|
109
|
+
type: "hour" | "minute" | "meridiem",
|
|
110
|
+
value: string,
|
|
111
|
+
) => {
|
|
112
|
+
if (type === "hour") setHour(value);
|
|
113
|
+
if (type === "minute") setMinute(value);
|
|
114
|
+
if (type === "meridiem") setMeridiem(value as "AM" | "PM");
|
|
115
|
+
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
const allSet =
|
|
118
|
+
(type === "hour" ? value : hour) &&
|
|
119
|
+
(type === "minute" ? value : minute) &&
|
|
120
|
+
(is12HourFormat ? (type === "meridiem" ? value : meridiem) : true);
|
|
121
|
+
|
|
122
|
+
if (allSet) {
|
|
123
|
+
setShowTimePicker(false);
|
|
124
|
+
}
|
|
125
|
+
}, 100);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (!showTimePicker && formattedTime) {
|
|
130
|
+
setInputValue(formattedTime);
|
|
131
|
+
}
|
|
132
|
+
}, [showTimePicker, formattedTime]);
|
|
133
|
+
|
|
134
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
135
|
+
const value = e.target.value
|
|
136
|
+
.toUpperCase()
|
|
137
|
+
.replace(/[^0-9:APM ]/gi, "")
|
|
138
|
+
.trim();
|
|
139
|
+
setInputValue(value);
|
|
140
|
+
|
|
141
|
+
// Check if input is cleared
|
|
142
|
+
if (value === "") {
|
|
143
|
+
setHour(null);
|
|
144
|
+
setMinute(null);
|
|
145
|
+
setMeridiem(null);
|
|
146
|
+
setShowTimePicker(true); // Keep dropdown open
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const match = value.match(
|
|
150
|
+
is12HourFormat
|
|
151
|
+
? /^(\d{1,2}):(\d{2})(?:\s*(AM|PM))?$/
|
|
152
|
+
: /^(\d{1,2}):(\d{2})$/,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (match) {
|
|
156
|
+
const [, hRaw, mRaw, mer] = match;
|
|
157
|
+
const h = parseInt(hRaw, 10);
|
|
158
|
+
const m = parseInt(mRaw, 10);
|
|
159
|
+
|
|
160
|
+
if (h >= 0 && h <= 23 && m >= 0 && m <= 59) {
|
|
161
|
+
let hStr: string;
|
|
162
|
+
const mStr = m.toString().padStart(2, "0");
|
|
163
|
+
let meridiemValue = mer as "AM" | "PM" | undefined;
|
|
164
|
+
|
|
165
|
+
if (is12HourFormat) {
|
|
166
|
+
hStr = (h % 12 || 12).toString().padStart(2, "0");
|
|
167
|
+
if (h > 12) {
|
|
168
|
+
meridiemValue = "PM";
|
|
169
|
+
}
|
|
170
|
+
setHour(hStr);
|
|
171
|
+
setMinute(mStr);
|
|
172
|
+
if (meridiemValue) {
|
|
173
|
+
setMeridiem(meridiemValue);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
hStr = h.toString().padStart(2, "0");
|
|
177
|
+
setHour(hStr);
|
|
178
|
+
setMinute(mStr);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
onChange?.(e);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const selectedRefs = {
|
|
187
|
+
hour: useRef<HTMLButtonElement | null>(null),
|
|
188
|
+
minute: useRef<HTMLButtonElement | null>(null),
|
|
189
|
+
meridiem: useRef<HTMLButtonElement | null>(null),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
193
|
+
if (e.key === "Enter") {
|
|
194
|
+
setShowTimePicker(false);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
|
199
|
+
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
|
|
202
|
+
let h: number;
|
|
203
|
+
let m: number;
|
|
204
|
+
let mer: "AM" | "PM";
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
hour === null ||
|
|
208
|
+
minute === null ||
|
|
209
|
+
(is12HourFormat && meridiem === null)
|
|
210
|
+
) {
|
|
211
|
+
const now = new Date();
|
|
212
|
+
h = now.getHours();
|
|
213
|
+
m = Math.round(now.getMinutes() / 5) * 5;
|
|
214
|
+
if (m === 60) {
|
|
215
|
+
m = 0;
|
|
216
|
+
h += 1;
|
|
217
|
+
}
|
|
218
|
+
if (is12HourFormat) {
|
|
219
|
+
mer = h >= 12 ? "PM" : "AM";
|
|
220
|
+
h = h % 12 || 12;
|
|
221
|
+
} else {
|
|
222
|
+
mer = "AM";
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
h = parseInt(hour, 10);
|
|
226
|
+
m = parseInt(minute, 10);
|
|
227
|
+
mer = (meridiem as "AM" | "PM") || "AM";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const step = 5;
|
|
231
|
+
const remainder = m % step;
|
|
232
|
+
m +=
|
|
233
|
+
e.key === "ArrowDown"
|
|
234
|
+
? remainder === 0
|
|
235
|
+
? step
|
|
236
|
+
: step - remainder
|
|
237
|
+
: -(remainder === 0 ? step : remainder);
|
|
238
|
+
|
|
239
|
+
if (m >= 60) {
|
|
240
|
+
m -= 60;
|
|
241
|
+
h += 1;
|
|
242
|
+
} else if (m < 0) {
|
|
243
|
+
m += 60;
|
|
244
|
+
h -= 1;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (is12HourFormat) {
|
|
248
|
+
if (h > 12) {
|
|
249
|
+
h = 1;
|
|
250
|
+
mer = mer === "AM" ? "PM" : "AM";
|
|
251
|
+
} else if (h <= 0) {
|
|
252
|
+
h = 12;
|
|
253
|
+
mer = mer === "AM" ? "PM" : "AM";
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
h = (h + 24) % 24;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
setHour(h.toString().padStart(2, "0"));
|
|
260
|
+
setMinute(m.toString().padStart(2, "0"));
|
|
261
|
+
if (is12HourFormat) setMeridiem(mer);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (showTimePicker) {
|
|
266
|
+
// Use a slight delay to ensure DOM is updated
|
|
267
|
+
setTimeout(() => {
|
|
268
|
+
selectedRefs.hour.current?.scrollIntoView({
|
|
269
|
+
block: "nearest",
|
|
270
|
+
behavior: "instant",
|
|
271
|
+
});
|
|
272
|
+
selectedRefs.minute.current?.scrollIntoView({
|
|
273
|
+
block: "nearest",
|
|
274
|
+
behavior: "instant",
|
|
275
|
+
});
|
|
276
|
+
if (is12HourFormat) {
|
|
277
|
+
selectedRefs.meridiem.current?.scrollIntoView({
|
|
278
|
+
block: "nearest",
|
|
279
|
+
behavior: "instant",
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}, 0);
|
|
283
|
+
}
|
|
284
|
+
}, [showTimePicker, is12HourFormat, selectedRefs.hour, selectedRefs.minute, selectedRefs.meridiem]);
|
|
285
|
+
const renderOptions = (
|
|
286
|
+
items: string[],
|
|
287
|
+
type: "hour" | "minute" | "meridiem",
|
|
288
|
+
) =>
|
|
289
|
+
items.map((val) => {
|
|
290
|
+
const isSelected =
|
|
291
|
+
(type === "hour" && val === hour) ||
|
|
292
|
+
(type === "minute" && val === minute) ||
|
|
293
|
+
(type === "meridiem" && val === meridiem);
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<TimeCell
|
|
297
|
+
key={val}
|
|
298
|
+
selected={isSelected}
|
|
299
|
+
ref={
|
|
300
|
+
isSelected
|
|
301
|
+
? (el) => {
|
|
302
|
+
selectedRefs[type].current = el;
|
|
303
|
+
}
|
|
304
|
+
: null
|
|
305
|
+
}
|
|
306
|
+
onClick={() => handleSelect(type, val)}
|
|
307
|
+
className={clsx("!size-10 cursor-pointer", typography.caption)}
|
|
308
|
+
>
|
|
309
|
+
{val}
|
|
310
|
+
</TimeCell>
|
|
311
|
+
);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
<div className="relative max-w-38">
|
|
316
|
+
<InputBase
|
|
317
|
+
{...props}
|
|
318
|
+
ref={inputRef}
|
|
319
|
+
inputContainerRef={inputContainerRef}
|
|
320
|
+
value={inputValue}
|
|
321
|
+
placeholder={is12HourFormat ? "hh:mm am" : "hh:mm"}
|
|
322
|
+
after={
|
|
323
|
+
<span className="text-icon-primary-normal contents">
|
|
324
|
+
<Icon name="schedule" />
|
|
325
|
+
</span>
|
|
326
|
+
}
|
|
327
|
+
onFocus={handleFocus}
|
|
328
|
+
caption={props.caption}
|
|
329
|
+
onChange={handleInputChange}
|
|
330
|
+
onKeyDown={handleKeyDown}
|
|
331
|
+
type="text"
|
|
332
|
+
/>
|
|
333
|
+
{showTimePicker &&
|
|
334
|
+
createPortal(
|
|
335
|
+
<Stack
|
|
336
|
+
elevation={4}
|
|
337
|
+
height={240}
|
|
338
|
+
position="absolute"
|
|
339
|
+
backgroundColor="background-grouped-primary-normal"
|
|
340
|
+
overflowX="hidden"
|
|
341
|
+
overflowY="hidden"
|
|
342
|
+
zIndex={50}
|
|
343
|
+
top={timePosition.top}
|
|
344
|
+
left={timePosition.left}
|
|
345
|
+
minWidth={timePosition.width}
|
|
346
|
+
maxWidth={0}
|
|
347
|
+
rounded
|
|
348
|
+
>
|
|
349
|
+
<div ref={timeRef} className="px-4 flex h-60">
|
|
350
|
+
<div className={clsx(timePickerScrollableStyle)}>
|
|
351
|
+
{renderOptions(
|
|
352
|
+
Array.from({ length: is12HourFormat ? 12 : 24 }, (_, i) =>
|
|
353
|
+
(i + 1).toString().padStart(2, "0"),
|
|
354
|
+
),
|
|
355
|
+
"hour",
|
|
356
|
+
)}
|
|
357
|
+
</div>
|
|
358
|
+
<div className={clsx(timePickerScrollableStyle)}>
|
|
359
|
+
{renderOptions(
|
|
360
|
+
Array.from({ length: 12 }, (_, i) =>
|
|
361
|
+
(i * 5).toString().padStart(2, "0"),
|
|
362
|
+
),
|
|
363
|
+
"minute",
|
|
364
|
+
)}
|
|
365
|
+
</div>
|
|
366
|
+
{is12HourFormat && (
|
|
367
|
+
<div className="py-4">
|
|
368
|
+
{renderOptions(["AM", "PM"], "meridiem")}
|
|
369
|
+
</div>
|
|
370
|
+
)}
|
|
371
|
+
</div>
|
|
372
|
+
</Stack>,
|
|
373
|
+
findDocumentRoot(timeRef.current),
|
|
374
|
+
)}
|
|
375
|
+
</div>
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
type TimeCellProps = {
|
|
380
|
+
selected?: boolean;
|
|
381
|
+
children?: React.ReactNode;
|
|
382
|
+
start?: boolean;
|
|
383
|
+
intermediate?: boolean;
|
|
384
|
+
end?: boolean;
|
|
385
|
+
disabled?: boolean;
|
|
386
|
+
today?: boolean;
|
|
387
|
+
onClick?: () => void;
|
|
388
|
+
onHover?: () => void;
|
|
389
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLButtonElement>) => void;
|
|
390
|
+
className?: string;
|
|
391
|
+
ref?: React.Ref<HTMLButtonElement> | undefined;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
function TimeCell({
|
|
395
|
+
selected = false,
|
|
396
|
+
start = false,
|
|
397
|
+
intermediate = false,
|
|
398
|
+
end = false,
|
|
399
|
+
today = false,
|
|
400
|
+
disabled = false,
|
|
401
|
+
onClick,
|
|
402
|
+
onHover,
|
|
403
|
+
onKeyDown,
|
|
404
|
+
children,
|
|
405
|
+
className,
|
|
406
|
+
ref,
|
|
407
|
+
...props
|
|
408
|
+
}: TimeCellProps) {
|
|
409
|
+
const isDefault = !selected && !start && !intermediate && !end && !today;
|
|
410
|
+
const isToday = today && !selected && !start && !intermediate && !end;
|
|
411
|
+
return (
|
|
412
|
+
<button
|
|
413
|
+
onPointerOver={onHover}
|
|
414
|
+
onClick={onClick}
|
|
415
|
+
onKeyDown={onKeyDown}
|
|
416
|
+
disabled={disabled}
|
|
417
|
+
ref={ref}
|
|
418
|
+
className={clsx(
|
|
419
|
+
"w-full h-full aspect-square flex items-center justify-center ",
|
|
420
|
+
isDefault &&
|
|
421
|
+
"text-neutral-500 hover:bg-action-100 hover:text-action-500 active:text-action-300 disabled:text-neutral-300 disabled:pointer-events-none rounded",
|
|
422
|
+
isToday &&
|
|
423
|
+
"rounded-full border border-neutral-300 hover:bg-action-100 hover:text-action-500 active:text-action-300 disabled:text-neutral-300 ",
|
|
424
|
+
selected &&
|
|
425
|
+
"text-white bg-action-400 hover:bg-action-500 active:bg-action-300 disabled:text-neutral-400 disabled:bg-neutral-200 rounded",
|
|
426
|
+
start &&
|
|
427
|
+
"bg-action-400 hover:bg-action-500 active:bg-action-300 disabled:text-neutral-400 disabled:bg-neutral-200 rounded-l",
|
|
428
|
+
end &&
|
|
429
|
+
"bg-action-400 hover:bg-action-500 active:bg-action-300 disabled:text-neutral-400 disabled:bg-neutral-200 rounded-r",
|
|
430
|
+
intermediate && "bg-action-100 border-y border-action-400",
|
|
431
|
+
className,
|
|
432
|
+
)}
|
|
433
|
+
{...props}
|
|
434
|
+
>
|
|
435
|
+
{children}
|
|
436
|
+
</button>
|
|
437
|
+
);
|
|
438
|
+
}
|