@tidbcloud/uikit 2.0.0-beta.44 → 2.0.0-beta.46
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/CHANGELOG.md +12 -0
- package/dist/biz/DateTimePicker/constant.cjs +11 -0
- package/dist/biz/DateTimePicker/constant.d.cts +7 -0
- package/dist/biz/DateTimePicker/constant.d.ts +7 -0
- package/dist/biz/DateTimePicker/constant.js +11 -0
- package/dist/biz/DateTimePicker/index.cjs +219 -0
- package/dist/biz/DateTimePicker/index.d.cts +18 -0
- package/dist/biz/DateTimePicker/index.d.ts +18 -0
- package/dist/biz/DateTimePicker/index.js +219 -0
- package/dist/biz/DateTimePicker/usePickerScroll.cjs +255 -0
- package/dist/biz/DateTimePicker/usePickerScroll.d.cts +30 -0
- package/dist/biz/DateTimePicker/usePickerScroll.d.ts +30 -0
- package/dist/biz/DateTimePicker/usePickerScroll.js +255 -0
- package/dist/biz/index.cjs +2 -0
- package/dist/biz/index.d.cts +1 -0
- package/dist/biz/index.d.ts +1 -0
- package/dist/biz/index.js +2 -0
- package/dist/icons/index.cjs +4 -4
- package/dist/icons/index.d.cts +3719 -2
- package/dist/icons/index.d.ts +3719 -2
- package/dist/icons/index.js +4 -4
- package/dist/theme/theme.cjs +57 -9
- package/dist/theme/theme.js +57 -9
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @tidbcloud/uikit
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.46
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add DateTimePicker and update Calendar styles
|
|
8
|
+
|
|
9
|
+
## 2.0.0-beta.45
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- Update ActionIcon styles and added jsdoc preview for icon component
|
|
14
|
+
|
|
3
15
|
## 2.0.0-beta.44
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const CellHeight = 32;
|
|
4
|
+
const CellStyle = {
|
|
5
|
+
height: CellHeight,
|
|
6
|
+
width: CellHeight,
|
|
7
|
+
lineHeight: `${CellHeight}px`,
|
|
8
|
+
borderRadius: 8
|
|
9
|
+
};
|
|
10
|
+
exports.CellHeight = CellHeight;
|
|
11
|
+
exports.CellStyle = CellStyle;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.cjs");
|
|
4
|
+
const ahooks = require("ahooks");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const index = require("../../icons/index.cjs");
|
|
7
|
+
const index$1 = require("../../primitive/Typography/index.cjs");
|
|
8
|
+
const dayjs = require("dayjs");
|
|
9
|
+
const helpers = require("../TimeRangePicker/helpers.cjs");
|
|
10
|
+
const usePickerScroll = require("./usePickerScroll.cjs");
|
|
11
|
+
const useDisclosure = require("../../node_modules/.pnpm/@mantine_hooks@5.10.4_react@18.3.1/node_modules/@mantine/hooks/esm/use-disclosure/use-disclosure.cjs");
|
|
12
|
+
const Popover = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Popover/Popover.cjs");
|
|
13
|
+
const TextInput = require("../../primitive/TextInput/TextInput.cjs");
|
|
14
|
+
const Calendar = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.12_react@18.3.1/node_modules/@mantine/dates/esm/components/Calendar/Calendar.cjs");
|
|
15
|
+
const TimeInput = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.12_react@18.3.1/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.cjs");
|
|
16
|
+
const Loader = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Loader/Loader.cjs");
|
|
17
|
+
const Box = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Box/Box.cjs");
|
|
18
|
+
const Stack = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Stack/Stack.cjs");
|
|
19
|
+
const Group = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Group/Group.cjs");
|
|
20
|
+
const Divider = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Divider/Divider.cjs");
|
|
21
|
+
const Flex = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Flex/Flex.cjs");
|
|
22
|
+
const DateTimePicker = ({
|
|
23
|
+
placeholder = "Select time",
|
|
24
|
+
format = helpers.DEFAULT_TIME_FORMAT,
|
|
25
|
+
defaultValue,
|
|
26
|
+
value,
|
|
27
|
+
startDate = dayjs().subtract(10, "year").toDate(),
|
|
28
|
+
endDate = dayjs().add(10, "year").toDate(),
|
|
29
|
+
onChange,
|
|
30
|
+
disable = false,
|
|
31
|
+
utcOffset = dayjs().utcOffset(),
|
|
32
|
+
withinPortal = true,
|
|
33
|
+
sx,
|
|
34
|
+
loading = false,
|
|
35
|
+
size
|
|
36
|
+
}) => {
|
|
37
|
+
const [opened, { close, open }] = useDisclosure.useDisclosure(false);
|
|
38
|
+
const [currentValue, setCurrentValue] = React.useState(
|
|
39
|
+
defaultValue ? dayjs(defaultValue) : value ? dayjs(value) : dayjs()
|
|
40
|
+
);
|
|
41
|
+
const updateCurrentValue = ahooks.useMemoizedFn((val) => {
|
|
42
|
+
setCurrentValue(val);
|
|
43
|
+
onChange == null ? void 0 : onChange(val.toDate());
|
|
44
|
+
});
|
|
45
|
+
const inputStr = currentValue.format(format);
|
|
46
|
+
const utcStr = React.useMemo(() => {
|
|
47
|
+
const h = Math.floor(utcOffset / 60);
|
|
48
|
+
const m = utcOffset % 60;
|
|
49
|
+
return `UTC${h >= 0 ? "+" : "-"}${Math.abs(h)}:${m < 10 ? "0" : ""}${m}`;
|
|
50
|
+
}, [utcOffset]);
|
|
51
|
+
const scroll = usePickerScroll.useTimePickerScroll(currentValue, opened, startDate, endDate, utcOffset);
|
|
52
|
+
const calendarChange = ahooks.useMemoizedFn((v) => {
|
|
53
|
+
let next = currentValue;
|
|
54
|
+
next = next.utcOffset(utcOffset).year(v.getFullYear()).month(v.getMonth()).date(v.getDate());
|
|
55
|
+
if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
56
|
+
updateCurrentValue(next);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const timeInputChange = ahooks.useMemoizedFn((v) => {
|
|
60
|
+
let next = currentValue;
|
|
61
|
+
next = next.utcOffset(utcOffset).hour(v.getHours()).minute(v.getMinutes()).second(v.getSeconds());
|
|
62
|
+
if (startDate && next.valueOf() < startDate.valueOf()) {
|
|
63
|
+
updateCurrentValue(dayjs(startDate));
|
|
64
|
+
} else if (endDate && next.valueOf() > endDate.valueOf()) {
|
|
65
|
+
updateCurrentValue(dayjs(endDate));
|
|
66
|
+
} else if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
67
|
+
updateCurrentValue(next);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
ahooks.useUpdateEffect(() => {
|
|
71
|
+
let next = currentValue;
|
|
72
|
+
const [h, m, s] = scroll.value;
|
|
73
|
+
next = next.utcOffset(utcOffset).hour(h).minute(m).second(s);
|
|
74
|
+
if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
75
|
+
updateCurrentValue(next);
|
|
76
|
+
}
|
|
77
|
+
}, [scroll.value]);
|
|
78
|
+
ahooks.useUpdateEffect(() => {
|
|
79
|
+
if (value && dayjs(value).unix() !== currentValue.unix()) {
|
|
80
|
+
updateCurrentValue(dayjs(value));
|
|
81
|
+
}
|
|
82
|
+
}, [value]);
|
|
83
|
+
return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Popover.Popover, { position: "bottom-end", opened, withinPortal, shadow: "md", onClose: close, children: [
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Popover.Popover.Target, { children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
85
|
+
TextInput.TextInput,
|
|
86
|
+
{
|
|
87
|
+
readOnly: true,
|
|
88
|
+
disabled: disable,
|
|
89
|
+
placeholder,
|
|
90
|
+
value: inputStr,
|
|
91
|
+
rightSection: loading ? /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Loader.Loader, { size: "xs" }) : /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Box.Box, { component: index.IconClock, size: 18, c: "carbon.6" }),
|
|
92
|
+
onClick: open,
|
|
93
|
+
sx,
|
|
94
|
+
size
|
|
95
|
+
}
|
|
96
|
+
) }),
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Popover.Popover.Dropdown, { children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Stack.Stack, { children: [
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { align: "flex-start", children: [
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
100
|
+
Calendar.Calendar,
|
|
101
|
+
{
|
|
102
|
+
minDate: startDate,
|
|
103
|
+
maxDate: endDate,
|
|
104
|
+
value: currentValue.toDate(),
|
|
105
|
+
onChange: calendarChange,
|
|
106
|
+
size: "sm",
|
|
107
|
+
styles: () => ({
|
|
108
|
+
calendarHeaderLevel: {
|
|
109
|
+
height: 32
|
|
110
|
+
},
|
|
111
|
+
calendarHeaderControl: {
|
|
112
|
+
height: 32,
|
|
113
|
+
width: 32
|
|
114
|
+
},
|
|
115
|
+
weekdayCell: {
|
|
116
|
+
height: 32,
|
|
117
|
+
width: 32,
|
|
118
|
+
lineHeight: "32px"
|
|
119
|
+
},
|
|
120
|
+
month: {
|
|
121
|
+
"& thead tr": {
|
|
122
|
+
display: "flex",
|
|
123
|
+
gap: 8
|
|
124
|
+
},
|
|
125
|
+
"& tbody tr": {
|
|
126
|
+
display: "flex",
|
|
127
|
+
gap: 8
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
day: {
|
|
131
|
+
height: 32,
|
|
132
|
+
width: 32,
|
|
133
|
+
lineHeight: "32px"
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Divider.Divider, { orientation: "vertical", mt: -12, mb: -16 }),
|
|
139
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Stack.Stack, { justify: "flex-start", children: [
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
141
|
+
TimeInput.TimeInput,
|
|
142
|
+
{
|
|
143
|
+
w: 112,
|
|
144
|
+
withSeconds: true,
|
|
145
|
+
value: currentValue.toDate(),
|
|
146
|
+
onChange: timeInputChange,
|
|
147
|
+
size: "sm",
|
|
148
|
+
styles: {
|
|
149
|
+
controls: {
|
|
150
|
+
height: 30
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
|
|
156
|
+
Box.Box,
|
|
157
|
+
{
|
|
158
|
+
pos: "relative",
|
|
159
|
+
fz: 14,
|
|
160
|
+
fw: 400,
|
|
161
|
+
h: 224,
|
|
162
|
+
sx: (theme) => ({ color: theme.colors.carbon[8], overflow: "hidden", zIndex: 9999 }),
|
|
163
|
+
children: [
|
|
164
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Flex.Flex, { mah: "100%", gap: 8, children: [
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
166
|
+
Box.Box,
|
|
167
|
+
{
|
|
168
|
+
bg: "carbon.3",
|
|
169
|
+
pos: "absolute",
|
|
170
|
+
top: 0,
|
|
171
|
+
left: 0,
|
|
172
|
+
h: 32,
|
|
173
|
+
w: 32,
|
|
174
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
178
|
+
Box.Box,
|
|
179
|
+
{
|
|
180
|
+
bg: "carbon.3",
|
|
181
|
+
pos: "absolute",
|
|
182
|
+
top: 0,
|
|
183
|
+
left: 40,
|
|
184
|
+
h: 32,
|
|
185
|
+
w: 32,
|
|
186
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
187
|
+
}
|
|
188
|
+
),
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
|
|
190
|
+
Box.Box,
|
|
191
|
+
{
|
|
192
|
+
bg: "carbon.3",
|
|
193
|
+
pos: "absolute",
|
|
194
|
+
top: 0,
|
|
195
|
+
left: 80,
|
|
196
|
+
h: 32,
|
|
197
|
+
w: 32,
|
|
198
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
] }),
|
|
202
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Flex.Flex, { mah: "100%", gap: 8, children: scroll.content })
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
)
|
|
206
|
+
] })
|
|
207
|
+
] }),
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Divider.Divider, { mx: -16 }),
|
|
209
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Group.Group, { children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(index$1.Typography, { size: "sm", children: [
|
|
210
|
+
"Use",
|
|
211
|
+
" ",
|
|
212
|
+
/* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index$1.Typography, { fw: 600, component: "span", children: utcStr }),
|
|
213
|
+
" ",
|
|
214
|
+
"from your local time zone"
|
|
215
|
+
] }) })
|
|
216
|
+
] }) })
|
|
217
|
+
] });
|
|
218
|
+
};
|
|
219
|
+
exports.DateTimePicker = DateTimePicker;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Sx, MantineSize } from '../../primitive/index.js';
|
|
2
|
+
|
|
3
|
+
export interface DateTimePickerProps {
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
format?: string;
|
|
6
|
+
utcOffset?: number;
|
|
7
|
+
defaultValue?: Date;
|
|
8
|
+
value?: Date;
|
|
9
|
+
startDate?: Date;
|
|
10
|
+
endDate?: Date;
|
|
11
|
+
onChange?: (val: Date) => void;
|
|
12
|
+
disable?: boolean;
|
|
13
|
+
withinPortal?: boolean;
|
|
14
|
+
sx?: Sx;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
size?: MantineSize;
|
|
17
|
+
}
|
|
18
|
+
export declare const DateTimePicker: React.FC<React.PropsWithChildren<DateTimePickerProps>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Sx, MantineSize } from '../../primitive/index.js';
|
|
2
|
+
|
|
3
|
+
export interface DateTimePickerProps {
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
format?: string;
|
|
6
|
+
utcOffset?: number;
|
|
7
|
+
defaultValue?: Date;
|
|
8
|
+
value?: Date;
|
|
9
|
+
startDate?: Date;
|
|
10
|
+
endDate?: Date;
|
|
11
|
+
onChange?: (val: Date) => void;
|
|
12
|
+
disable?: boolean;
|
|
13
|
+
withinPortal?: boolean;
|
|
14
|
+
sx?: Sx;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
size?: MantineSize;
|
|
17
|
+
}
|
|
18
|
+
export declare const DateTimePicker: React.FC<React.PropsWithChildren<DateTimePickerProps>>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
|
|
2
|
+
import { useMemoizedFn, useUpdateEffect } from "ahooks";
|
|
3
|
+
import { useState, useMemo } from "react";
|
|
4
|
+
import { IconClock } from "../../icons/index.js";
|
|
5
|
+
import { Typography } from "../../primitive/Typography/index.js";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
import { DEFAULT_TIME_FORMAT } from "../TimeRangePicker/helpers.js";
|
|
8
|
+
import { useTimePickerScroll } from "./usePickerScroll.js";
|
|
9
|
+
import { useDisclosure } from "../../node_modules/.pnpm/@mantine_hooks@5.10.4_react@18.3.1/node_modules/@mantine/hooks/esm/use-disclosure/use-disclosure.js";
|
|
10
|
+
import { Popover } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Popover/Popover.js";
|
|
11
|
+
import { TextInput } from "../../primitive/TextInput/TextInput.js";
|
|
12
|
+
import { Calendar } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.12_react@18.3.1/node_modules/@mantine/dates/esm/components/Calendar/Calendar.js";
|
|
13
|
+
import { TimeInput } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.12_react@18.3.1/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.js";
|
|
14
|
+
import { Loader } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Loader/Loader.js";
|
|
15
|
+
import { Box } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Box/Box.js";
|
|
16
|
+
import { Stack } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Stack/Stack.js";
|
|
17
|
+
import { Group } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Group/Group.js";
|
|
18
|
+
import { Divider } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Divider/Divider.js";
|
|
19
|
+
import { Flex } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.13.0_@mantine_ho_u2jurujayhgo5kjqawpkatsdsi/node_modules/@mantine/core/esm/Flex/Flex.js";
|
|
20
|
+
const DateTimePicker = ({
|
|
21
|
+
placeholder = "Select time",
|
|
22
|
+
format = DEFAULT_TIME_FORMAT,
|
|
23
|
+
defaultValue,
|
|
24
|
+
value,
|
|
25
|
+
startDate = dayjs().subtract(10, "year").toDate(),
|
|
26
|
+
endDate = dayjs().add(10, "year").toDate(),
|
|
27
|
+
onChange,
|
|
28
|
+
disable = false,
|
|
29
|
+
utcOffset = dayjs().utcOffset(),
|
|
30
|
+
withinPortal = true,
|
|
31
|
+
sx,
|
|
32
|
+
loading = false,
|
|
33
|
+
size
|
|
34
|
+
}) => {
|
|
35
|
+
const [opened, { close, open }] = useDisclosure(false);
|
|
36
|
+
const [currentValue, setCurrentValue] = useState(
|
|
37
|
+
defaultValue ? dayjs(defaultValue) : value ? dayjs(value) : dayjs()
|
|
38
|
+
);
|
|
39
|
+
const updateCurrentValue = useMemoizedFn((val) => {
|
|
40
|
+
setCurrentValue(val);
|
|
41
|
+
onChange == null ? void 0 : onChange(val.toDate());
|
|
42
|
+
});
|
|
43
|
+
const inputStr = currentValue.format(format);
|
|
44
|
+
const utcStr = useMemo(() => {
|
|
45
|
+
const h = Math.floor(utcOffset / 60);
|
|
46
|
+
const m = utcOffset % 60;
|
|
47
|
+
return `UTC${h >= 0 ? "+" : "-"}${Math.abs(h)}:${m < 10 ? "0" : ""}${m}`;
|
|
48
|
+
}, [utcOffset]);
|
|
49
|
+
const scroll = useTimePickerScroll(currentValue, opened, startDate, endDate, utcOffset);
|
|
50
|
+
const calendarChange = useMemoizedFn((v) => {
|
|
51
|
+
let next = currentValue;
|
|
52
|
+
next = next.utcOffset(utcOffset).year(v.getFullYear()).month(v.getMonth()).date(v.getDate());
|
|
53
|
+
if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
54
|
+
updateCurrentValue(next);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const timeInputChange = useMemoizedFn((v) => {
|
|
58
|
+
let next = currentValue;
|
|
59
|
+
next = next.utcOffset(utcOffset).hour(v.getHours()).minute(v.getMinutes()).second(v.getSeconds());
|
|
60
|
+
if (startDate && next.valueOf() < startDate.valueOf()) {
|
|
61
|
+
updateCurrentValue(dayjs(startDate));
|
|
62
|
+
} else if (endDate && next.valueOf() > endDate.valueOf()) {
|
|
63
|
+
updateCurrentValue(dayjs(endDate));
|
|
64
|
+
} else if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
65
|
+
updateCurrentValue(next);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
useUpdateEffect(() => {
|
|
69
|
+
let next = currentValue;
|
|
70
|
+
const [h, m, s] = scroll.value;
|
|
71
|
+
next = next.utcOffset(utcOffset).hour(h).minute(m).second(s);
|
|
72
|
+
if ((currentValue == null ? void 0 : currentValue.unix()) !== next.unix()) {
|
|
73
|
+
updateCurrentValue(next);
|
|
74
|
+
}
|
|
75
|
+
}, [scroll.value]);
|
|
76
|
+
useUpdateEffect(() => {
|
|
77
|
+
if (value && dayjs(value).unix() !== currentValue.unix()) {
|
|
78
|
+
updateCurrentValue(dayjs(value));
|
|
79
|
+
}
|
|
80
|
+
}, [value]);
|
|
81
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs(Popover, { position: "bottom-end", opened, withinPortal, shadow: "md", onClose: close, children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Target, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
83
|
+
TextInput,
|
|
84
|
+
{
|
|
85
|
+
readOnly: true,
|
|
86
|
+
disabled: disable,
|
|
87
|
+
placeholder,
|
|
88
|
+
value: inputStr,
|
|
89
|
+
rightSection: loading ? /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "xs" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { component: IconClock, size: 18, c: "carbon.6" }),
|
|
90
|
+
onClick: open,
|
|
91
|
+
sx,
|
|
92
|
+
size
|
|
93
|
+
}
|
|
94
|
+
) }),
|
|
95
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Dropdown, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { children: [
|
|
96
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { align: "flex-start", children: [
|
|
97
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
98
|
+
Calendar,
|
|
99
|
+
{
|
|
100
|
+
minDate: startDate,
|
|
101
|
+
maxDate: endDate,
|
|
102
|
+
value: currentValue.toDate(),
|
|
103
|
+
onChange: calendarChange,
|
|
104
|
+
size: "sm",
|
|
105
|
+
styles: () => ({
|
|
106
|
+
calendarHeaderLevel: {
|
|
107
|
+
height: 32
|
|
108
|
+
},
|
|
109
|
+
calendarHeaderControl: {
|
|
110
|
+
height: 32,
|
|
111
|
+
width: 32
|
|
112
|
+
},
|
|
113
|
+
weekdayCell: {
|
|
114
|
+
height: 32,
|
|
115
|
+
width: 32,
|
|
116
|
+
lineHeight: "32px"
|
|
117
|
+
},
|
|
118
|
+
month: {
|
|
119
|
+
"& thead tr": {
|
|
120
|
+
display: "flex",
|
|
121
|
+
gap: 8
|
|
122
|
+
},
|
|
123
|
+
"& tbody tr": {
|
|
124
|
+
display: "flex",
|
|
125
|
+
gap: 8
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
day: {
|
|
129
|
+
height: 32,
|
|
130
|
+
width: 32,
|
|
131
|
+
lineHeight: "32px"
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { orientation: "vertical", mt: -12, mb: -16 }),
|
|
137
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { justify: "flex-start", children: [
|
|
138
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
139
|
+
TimeInput,
|
|
140
|
+
{
|
|
141
|
+
w: 112,
|
|
142
|
+
withSeconds: true,
|
|
143
|
+
value: currentValue.toDate(),
|
|
144
|
+
onChange: timeInputChange,
|
|
145
|
+
size: "sm",
|
|
146
|
+
styles: {
|
|
147
|
+
controls: {
|
|
148
|
+
height: 30
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
),
|
|
153
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
154
|
+
Box,
|
|
155
|
+
{
|
|
156
|
+
pos: "relative",
|
|
157
|
+
fz: 14,
|
|
158
|
+
fw: 400,
|
|
159
|
+
h: 224,
|
|
160
|
+
sx: (theme) => ({ color: theme.colors.carbon[8], overflow: "hidden", zIndex: 9999 }),
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { mah: "100%", gap: 8, children: [
|
|
163
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
164
|
+
Box,
|
|
165
|
+
{
|
|
166
|
+
bg: "carbon.3",
|
|
167
|
+
pos: "absolute",
|
|
168
|
+
top: 0,
|
|
169
|
+
left: 0,
|
|
170
|
+
h: 32,
|
|
171
|
+
w: 32,
|
|
172
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
176
|
+
Box,
|
|
177
|
+
{
|
|
178
|
+
bg: "carbon.3",
|
|
179
|
+
pos: "absolute",
|
|
180
|
+
top: 0,
|
|
181
|
+
left: 40,
|
|
182
|
+
h: 32,
|
|
183
|
+
w: 32,
|
|
184
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
188
|
+
Box,
|
|
189
|
+
{
|
|
190
|
+
bg: "carbon.3",
|
|
191
|
+
pos: "absolute",
|
|
192
|
+
top: 0,
|
|
193
|
+
left: 80,
|
|
194
|
+
h: 32,
|
|
195
|
+
w: 32,
|
|
196
|
+
sx: (theme) => ({ zIndex: -1, borderRadius: theme.defaultRadius, pointerEvents: "none" })
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
] }),
|
|
200
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { mah: "100%", gap: 8, children: scroll.content })
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
)
|
|
204
|
+
] })
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { mx: -16 }),
|
|
207
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Group, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Typography, { size: "sm", children: [
|
|
208
|
+
"Use",
|
|
209
|
+
" ",
|
|
210
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { fw: 600, component: "span", children: utcStr }),
|
|
211
|
+
" ",
|
|
212
|
+
"from your local time zone"
|
|
213
|
+
] }) })
|
|
214
|
+
] }) })
|
|
215
|
+
] });
|
|
216
|
+
};
|
|
217
|
+
export {
|
|
218
|
+
DateTimePicker
|
|
219
|
+
};
|