@tidbcloud/uikit 2.0.0-beta.4 → 2.0.0-beta.5

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tidbcloud/uikit
2
2
 
3
+ ## 2.0.0-beta.5
4
+
5
+ ### Minor Changes
6
+
7
+ - add TimeRangePicker component
8
+
3
9
  ## 2.0.0-beta.4
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ const jsxRuntime = require("../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs");
3
+ const dayjs = require("dayjs");
4
+ const React = require("react");
5
+ const AlertCircle = require("../../icons/react/AlertCircle.cjs");
6
+ const ChevronLeft = require("../../icons/react/ChevronLeft.cjs");
7
+ const index = require("../../primitive/Typography/index.cjs");
8
+ const helpers = require("./helpers.cjs");
9
+ const DatePicker = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/DatePicker/DatePicker.cjs");
10
+ const TimeInput = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.cjs");
11
+ const RangeCalendar = require("../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/RangeCalendar/RangeCalendar.cjs");
12
+ const Text = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.cjs");
13
+ const MantineProvider = require("../../node_modules/.pnpm/@mantine_styles@5.10.4_@emotion_react@11.11.0_react-dom@18.2.0_react@18.2.0/node_modules/@mantine/styles/esm/theme/MantineProvider.cjs");
14
+ const Box = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.cjs");
15
+ const Group = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.cjs");
16
+ const Flex = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Flex/Flex.cjs");
17
+ const Alert = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Alert/Alert.cjs");
18
+ const Button = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.cjs");
19
+ const AbsoluteTimeRangePicker = ({
20
+ value,
21
+ maxDateTime,
22
+ minDateTime,
23
+ maxDuration,
24
+ onChange,
25
+ onCancel,
26
+ onReturnClick
27
+ }) => {
28
+ const theme = MantineProvider.useMantineTheme();
29
+ const dayStyle = (_date, modifiers) => modifiers.weekend && !modifiers.disabled && !modifiers.selected && !modifiers.outside && !modifiers.selectedInRange ? { color: theme.colors.gray[7] } : null;
30
+ const [start, setStart] = React.useState(() => new Date(value[0] * 1e3));
31
+ const [end, setEnd] = React.useState(() => new Date(value[1] * 1e3));
32
+ const startAfterEnd = React.useMemo(() => {
33
+ return start.valueOf() > end.valueOf();
34
+ }, [start, end]);
35
+ const beyondMin = React.useMemo(() => {
36
+ return minDateTime && start.valueOf() < minDateTime.valueOf();
37
+ }, [minDateTime, start]);
38
+ const beyondMax = React.useMemo(() => {
39
+ return maxDateTime && end.valueOf() > maxDateTime.valueOf();
40
+ }, [maxDateTime, end]);
41
+ const beyondDuration = React.useMemo(() => {
42
+ if (maxDuration !== void 0) {
43
+ return end.valueOf() - start.valueOf() > maxDuration * 1e3;
44
+ }
45
+ return false;
46
+ }, [maxDuration, start, end]);
47
+ const updateDate = (dates) => {
48
+ const newStart = new Date(dates[0]);
49
+ newStart.setHours(start.getHours());
50
+ newStart.setMinutes(start.getMinutes());
51
+ newStart.setSeconds(start.getSeconds());
52
+ setStart(newStart);
53
+ let newEnd = new Date(dates[0]);
54
+ if (dates[1]) {
55
+ newEnd = new Date(dates[1]);
56
+ }
57
+ newEnd.setHours(end.getHours());
58
+ newEnd.setMinutes(end.getMinutes());
59
+ newEnd.setSeconds(end.getSeconds());
60
+ setEnd(newEnd);
61
+ };
62
+ const updateTime = (d, setter) => {
63
+ setter((old) => {
64
+ const newD = new Date(old);
65
+ newD.setHours(d.getHours());
66
+ newD.setMinutes(d.getMinutes());
67
+ newD.setSeconds(d.getSeconds());
68
+ return newD;
69
+ });
70
+ };
71
+ const apply = () => onChange == null ? void 0 : onChange({ type: "absolute", value: [dayjs(start).unix(), dayjs(end).unix()] });
72
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Box.Box, { p: 16, w: 280, m: -4, children: [
73
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { onClick: onReturnClick, sx: { cursor: "pointer" }, children: [
74
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(ChevronLeft, { size: 16 }),
75
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "body-lg", children: "Back" })
76
+ ] }),
77
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 0, pt: 8, position: "apart", children: [
78
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "label-sm", children: "Start" }),
79
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 8, children: [
80
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
81
+ DatePicker.DatePicker,
82
+ {
83
+ onClick: () => {
84
+ },
85
+ w: 116,
86
+ value: start,
87
+ inputFormat: "MMM D, YYYY",
88
+ clearable: false,
89
+ error: beyondMin || startAfterEnd || beyondDuration
90
+ }
91
+ ),
92
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
93
+ TimeInput.TimeInput,
94
+ {
95
+ format: "24",
96
+ w: 90,
97
+ styles: { input: { paddingLeft: 4, paddingRight: 4 } },
98
+ withSeconds: true,
99
+ value: start,
100
+ onChange: (d) => updateTime(d, setStart),
101
+ error: beyondMin || startAfterEnd || beyondDuration
102
+ }
103
+ )
104
+ ] })
105
+ ] }),
106
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 0, pt: 8, position: "apart", children: [
107
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "label-sm", children: "End" }),
108
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { spacing: 8, children: [
109
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
110
+ DatePicker.DatePicker,
111
+ {
112
+ onClick: () => {
113
+ },
114
+ w: 116,
115
+ value: end,
116
+ inputFormat: "MMM D, YYYY",
117
+ clearable: false,
118
+ error: beyondMax || startAfterEnd || beyondDuration
119
+ }
120
+ ),
121
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
122
+ TimeInput.TimeInput,
123
+ {
124
+ format: "24",
125
+ w: 90,
126
+ styles: { input: { paddingLeft: 4, paddingRight: 4 } },
127
+ withSeconds: true,
128
+ value: end,
129
+ onChange: (d) => updateTime(d, setEnd),
130
+ error: beyondMax || startAfterEnd || beyondDuration
131
+ }
132
+ )
133
+ ] })
134
+ ] }),
135
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Flex.Flex, { justify: "center", pt: 8, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
136
+ RangeCalendar.RangeCalendar,
137
+ {
138
+ value: [start, end],
139
+ onChange: updateDate,
140
+ maxDate: maxDateTime,
141
+ minDate: minDateTime,
142
+ dayStyle
143
+ }
144
+ ) }),
145
+ (startAfterEnd || beyondMin || beyondMax || beyondDuration) && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Alert.Alert, { icon: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(AlertCircle, { size: 16 }), color: "red", pt: 8, children: [
146
+ startAfterEnd && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Text.Text, { color: "red", children: "Please select an end time after the start time." }),
147
+ beyondMin && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
148
+ "Please select a start time after ",
149
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(jsxRuntime.jsxRuntimeExports.Fragment, { children: helpers.timeFormatter(minDateTime, null, "MMM D, YYYY HH:mm:ss") })
150
+ ] }),
151
+ beyondMax && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
152
+ "Please select an end time before ",
153
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(jsxRuntime.jsxRuntimeExports.Fragment, { children: helpers.timeFormatter(maxDateTime, null, "MMM D, YYYY HH:mm:ss") })
154
+ ] }),
155
+ beyondDuration && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { color: "red", children: [
156
+ "The selection exceeds the ",
157
+ helpers.formatDuration(maxDuration),
158
+ " limit, please select a shorter time range."
159
+ ] })
160
+ ] }),
161
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Flex.Flex, { pt: 8, gap: "xs", justify: "flex-end", align: "flex-start", direction: "row", wrap: "wrap", children: [
162
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Button.Button, { size: "xs", variant: "default", onClick: onCancel, children: "Cancel" }),
163
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Button.Button, { size: "xs", onClick: apply, disabled: startAfterEnd || beyondMin || beyondMax || beyondDuration, children: "Apply" })
164
+ ] })
165
+ ] });
166
+ };
167
+ const AbsoluteTimeRangePicker$1 = AbsoluteTimeRangePicker;
168
+ module.exports = AbsoluteTimeRangePicker$1;
@@ -0,0 +1,13 @@
1
+ import { MouseEventHandler } from 'react';
2
+ import { AbsoluteTimeRange, TimeRangeValue } from './helpers.js';
3
+ interface AbsoluteTimeRangePickerProps {
4
+ value: TimeRangeValue;
5
+ minDateTime?: Date;
6
+ maxDateTime?: Date;
7
+ maxDuration?: number;
8
+ onChange?: (v: AbsoluteTimeRange) => void;
9
+ onCancel?: () => void;
10
+ onReturnClick?: MouseEventHandler<HTMLElement>;
11
+ }
12
+ declare const AbsoluteTimeRangePicker: React.FC<React.PropsWithChildren<AbsoluteTimeRangePickerProps>>;
13
+ export default AbsoluteTimeRangePicker;
@@ -0,0 +1,13 @@
1
+ import { MouseEventHandler } from 'react';
2
+ import { AbsoluteTimeRange, TimeRangeValue } from './helpers.js';
3
+ interface AbsoluteTimeRangePickerProps {
4
+ value: TimeRangeValue;
5
+ minDateTime?: Date;
6
+ maxDateTime?: Date;
7
+ maxDuration?: number;
8
+ onChange?: (v: AbsoluteTimeRange) => void;
9
+ onCancel?: () => void;
10
+ onReturnClick?: MouseEventHandler<HTMLElement>;
11
+ }
12
+ declare const AbsoluteTimeRangePicker: React.FC<React.PropsWithChildren<AbsoluteTimeRangePickerProps>>;
13
+ export default AbsoluteTimeRangePicker;
@@ -0,0 +1,169 @@
1
+ import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js";
2
+ import dayjs from "dayjs";
3
+ import { useState, useMemo } from "react";
4
+ import IconAlertCircle from "../../icons/react/AlertCircle.js";
5
+ import IconChevronLeft from "../../icons/react/ChevronLeft.js";
6
+ import { Typography } from "../../primitive/Typography/index.js";
7
+ import { timeFormatter, formatDuration } from "./helpers.js";
8
+ import { DatePicker } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/DatePicker/DatePicker.js";
9
+ import { TimeInput } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.js";
10
+ import { RangeCalendar } from "../../node_modules/.pnpm/@mantine_dates@5.10.4_@mantine_core@5.10.4_@mantine_hooks@5.10.4_dayjs@1.11.7_react@18.2.0/node_modules/@mantine/dates/esm/components/RangeCalendar/RangeCalendar.js";
11
+ import { Text } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.js";
12
+ import { useMantineTheme } from "../../node_modules/.pnpm/@mantine_styles@5.10.4_@emotion_react@11.11.0_react-dom@18.2.0_react@18.2.0/node_modules/@mantine/styles/esm/theme/MantineProvider.js";
13
+ import { Box } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.js";
14
+ import { Group } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.js";
15
+ import { Flex } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Flex/Flex.js";
16
+ import { Alert } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Alert/Alert.js";
17
+ import { Button } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.js";
18
+ const AbsoluteTimeRangePicker = ({
19
+ value,
20
+ maxDateTime,
21
+ minDateTime,
22
+ maxDuration,
23
+ onChange,
24
+ onCancel,
25
+ onReturnClick
26
+ }) => {
27
+ const theme = useMantineTheme();
28
+ const dayStyle = (_date, modifiers) => modifiers.weekend && !modifiers.disabled && !modifiers.selected && !modifiers.outside && !modifiers.selectedInRange ? { color: theme.colors.gray[7] } : null;
29
+ const [start, setStart] = useState(() => new Date(value[0] * 1e3));
30
+ const [end, setEnd] = useState(() => new Date(value[1] * 1e3));
31
+ const startAfterEnd = useMemo(() => {
32
+ return start.valueOf() > end.valueOf();
33
+ }, [start, end]);
34
+ const beyondMin = useMemo(() => {
35
+ return minDateTime && start.valueOf() < minDateTime.valueOf();
36
+ }, [minDateTime, start]);
37
+ const beyondMax = useMemo(() => {
38
+ return maxDateTime && end.valueOf() > maxDateTime.valueOf();
39
+ }, [maxDateTime, end]);
40
+ const beyondDuration = useMemo(() => {
41
+ if (maxDuration !== void 0) {
42
+ return end.valueOf() - start.valueOf() > maxDuration * 1e3;
43
+ }
44
+ return false;
45
+ }, [maxDuration, start, end]);
46
+ const updateDate = (dates) => {
47
+ const newStart = new Date(dates[0]);
48
+ newStart.setHours(start.getHours());
49
+ newStart.setMinutes(start.getMinutes());
50
+ newStart.setSeconds(start.getSeconds());
51
+ setStart(newStart);
52
+ let newEnd = new Date(dates[0]);
53
+ if (dates[1]) {
54
+ newEnd = new Date(dates[1]);
55
+ }
56
+ newEnd.setHours(end.getHours());
57
+ newEnd.setMinutes(end.getMinutes());
58
+ newEnd.setSeconds(end.getSeconds());
59
+ setEnd(newEnd);
60
+ };
61
+ const updateTime = (d, setter) => {
62
+ setter((old) => {
63
+ const newD = new Date(old);
64
+ newD.setHours(d.getHours());
65
+ newD.setMinutes(d.getMinutes());
66
+ newD.setSeconds(d.getSeconds());
67
+ return newD;
68
+ });
69
+ };
70
+ const apply = () => onChange == null ? void 0 : onChange({ type: "absolute", value: [dayjs(start).unix(), dayjs(end).unix()] });
71
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { p: 16, w: 280, m: -4, children: [
72
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { onClick: onReturnClick, sx: { cursor: "pointer" }, children: [
73
+ /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronLeft, { size: 16 }),
74
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "body-lg", children: "Back" })
75
+ ] }),
76
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 0, pt: 8, position: "apart", children: [
77
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "label-sm", children: "Start" }),
78
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 8, children: [
79
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
80
+ DatePicker,
81
+ {
82
+ onClick: () => {
83
+ },
84
+ w: 116,
85
+ value: start,
86
+ inputFormat: "MMM D, YYYY",
87
+ clearable: false,
88
+ error: beyondMin || startAfterEnd || beyondDuration
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
92
+ TimeInput,
93
+ {
94
+ format: "24",
95
+ w: 90,
96
+ styles: { input: { paddingLeft: 4, paddingRight: 4 } },
97
+ withSeconds: true,
98
+ value: start,
99
+ onChange: (d) => updateTime(d, setStart),
100
+ error: beyondMin || startAfterEnd || beyondDuration
101
+ }
102
+ )
103
+ ] })
104
+ ] }),
105
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 0, pt: 8, position: "apart", children: [
106
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "label-sm", children: "End" }),
107
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { spacing: 8, children: [
108
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
109
+ DatePicker,
110
+ {
111
+ onClick: () => {
112
+ },
113
+ w: 116,
114
+ value: end,
115
+ inputFormat: "MMM D, YYYY",
116
+ clearable: false,
117
+ error: beyondMax || startAfterEnd || beyondDuration
118
+ }
119
+ ),
120
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
121
+ TimeInput,
122
+ {
123
+ format: "24",
124
+ w: 90,
125
+ styles: { input: { paddingLeft: 4, paddingRight: 4 } },
126
+ withSeconds: true,
127
+ value: end,
128
+ onChange: (d) => updateTime(d, setEnd),
129
+ error: beyondMax || startAfterEnd || beyondDuration
130
+ }
131
+ )
132
+ ] })
133
+ ] }),
134
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "center", pt: 8, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
135
+ RangeCalendar,
136
+ {
137
+ value: [start, end],
138
+ onChange: updateDate,
139
+ maxDate: maxDateTime,
140
+ minDate: minDateTime,
141
+ dayStyle
142
+ }
143
+ ) }),
144
+ (startAfterEnd || beyondMin || beyondMax || beyondDuration) && /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(IconAlertCircle, { size: 16 }), color: "red", pt: 8, children: [
145
+ startAfterEnd && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { color: "red", children: "Please select an end time after the start time." }),
146
+ beyondMin && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
147
+ "Please select a start time after ",
148
+ /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: timeFormatter(minDateTime, null, "MMM D, YYYY HH:mm:ss") })
149
+ ] }),
150
+ beyondMax && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
151
+ "Please select an end time before ",
152
+ /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: timeFormatter(maxDateTime, null, "MMM D, YYYY HH:mm:ss") })
153
+ ] }),
154
+ beyondDuration && /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { color: "red", children: [
155
+ "The selection exceeds the ",
156
+ formatDuration(maxDuration),
157
+ " limit, please select a shorter time range."
158
+ ] })
159
+ ] }),
160
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { pt: 8, gap: "xs", justify: "flex-end", align: "flex-start", direction: "row", wrap: "wrap", children: [
161
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "xs", variant: "default", onClick: onCancel, children: "Cancel" }),
162
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "xs", onClick: apply, disabled: startAfterEnd || beyondMin || beyondMax || beyondDuration, children: "Apply" })
163
+ ] })
164
+ ] });
165
+ };
166
+ const AbsoluteTimeRangePicker$1 = AbsoluteTimeRangePicker;
167
+ export {
168
+ AbsoluteTimeRangePicker$1 as default
169
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const dayjs = require("dayjs");
4
+ const lodashEs = require("lodash-es");
5
+ const prettyMs = require("pretty-ms");
6
+ const DEFAULT_QUICK_RANGES = [
7
+ 3 * 24 * 60 * 60,
8
+ 2 * 24 * 60 * 60,
9
+ 24 * 60 * 60,
10
+ 12 * 60 * 60,
11
+ 3 * 60 * 60,
12
+ 60 * 60,
13
+ 30 * 60,
14
+ 15 * 60,
15
+ 5 * 60
16
+ ];
17
+ const formatDuration = (seconds, short = false) => {
18
+ if (short) {
19
+ return prettyMs(seconds * 1e3, { compact: true });
20
+ } else {
21
+ return prettyMs(seconds * 1e3, { verbose: true });
22
+ }
23
+ };
24
+ const toTimeRangeValue = (timeRange, offset = 0) => {
25
+ if (timeRange.type === "absolute") {
26
+ return timeRange.value.map((t) => t + offset);
27
+ } else {
28
+ const now = dayjs().unix();
29
+ return [now - timeRange.value + offset, now + offset];
30
+ }
31
+ };
32
+ const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
33
+ function addOffsetUTC(time, utcOffset) {
34
+ const targetTime = new Date(time);
35
+ const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
36
+ return new Date(targetTime.getTime() + tzDifference * 60 * 1e3);
37
+ }
38
+ const getUTCString = (offset) => {
39
+ const offsetStrs = offset.toString().split(".");
40
+ let mm = "00";
41
+ let hh = "";
42
+ const offsetH = Number.parseInt(offsetStrs[0] || "0");
43
+ const offsetM = Number.parseFloat(`0.${offsetStrs[1]}` || "0") * 60;
44
+ hh = Math.abs(offsetH).toString().padStart(2, "0");
45
+ mm = offsetM === 0 ? "00" : offsetM.toString();
46
+ if (offset > 0) {
47
+ return `UTC+${hh}:${mm}`;
48
+ }
49
+ if (offset < 0) {
50
+ return `UTC-${hh}:${mm}`;
51
+ }
52
+ return "UTC±00:00";
53
+ };
54
+ const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
55
+ if (!timeValue)
56
+ return "-";
57
+ const time = timeValue instanceof Date || isNaN(Number(timeValue)) ? timeValue : Number(timeValue) * 1e3;
58
+ const currentTZOffsetInHours = utcOffset === void 0 || utcOffset === null ? -((/* @__PURE__ */ new Date()).getTimezoneOffset() / 60) : utcOffset;
59
+ const withUTC = format.indexOf("Z") >= 0;
60
+ return dayjs(addOffsetUTC(time, currentTZOffsetInHours)).format(withUTC ? lodashEs.trim(format, "Z") : format) + (withUTC ? getUTCString(currentTZOffsetInHours) : "");
61
+ };
62
+ exports.DEFAULT_QUICK_RANGES = DEFAULT_QUICK_RANGES;
63
+ exports.DEFAULT_TIME_FORMAT = DEFAULT_TIME_FORMAT;
64
+ exports.addOffsetUTC = addOffsetUTC;
65
+ exports.formatDuration = formatDuration;
66
+ exports.getUTCString = getUTCString;
67
+ exports.timeFormatter = timeFormatter;
68
+ exports.toTimeRangeValue = toTimeRangeValue;
@@ -0,0 +1,27 @@
1
+ export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
2
+ export interface RelativeTimeRange {
3
+ type: 'relative';
4
+ value: number;
5
+ }
6
+ export interface AbsoluteTimeRange {
7
+ type: 'absolute';
8
+ value: TimeRangeValue;
9
+ }
10
+ export type TimeRangeValue = [from: number, to: number];
11
+ export declare const DEFAULT_QUICK_RANGES: number[];
12
+ export declare const DEFAULT_TIME_RANGE: TimeRange;
13
+ export declare const formatDuration: (seconds: number, short?: boolean) => string;
14
+ export declare const toTimeRangeValue: (timeRange: TimeRange, offset?: number) => TimeRangeValue;
15
+ export declare function fromTimeRangeValue(v: TimeRangeValue): AbsoluteTimeRange;
16
+ export type URLTimeRange = {
17
+ from: string;
18
+ to: string;
19
+ };
20
+ export declare const toURLTimeRange: (timeRange: TimeRange) => URLTimeRange;
21
+ export declare const urlToTimeRange: (urlTimeRange: URLTimeRange) => TimeRange;
22
+ export declare const urlToTimeRangeValue: (urlTimeRange: URLTimeRange) => TimeRangeValue;
23
+ export declare const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
24
+ export declare const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
25
+ export declare function addOffsetUTC(time: string | number | Date, utcOffset: number): Date;
26
+ export declare const getUTCString: (offset: number) => string;
27
+ export declare const timeFormatter: (timeValue: number | string | Date, utcOffset?: number | null, format?: string) => string;
@@ -0,0 +1,27 @@
1
+ export type TimeRange = RelativeTimeRange | AbsoluteTimeRange;
2
+ export interface RelativeTimeRange {
3
+ type: 'relative';
4
+ value: number;
5
+ }
6
+ export interface AbsoluteTimeRange {
7
+ type: 'absolute';
8
+ value: TimeRangeValue;
9
+ }
10
+ export type TimeRangeValue = [from: number, to: number];
11
+ export declare const DEFAULT_QUICK_RANGES: number[];
12
+ export declare const DEFAULT_TIME_RANGE: TimeRange;
13
+ export declare const formatDuration: (seconds: number, short?: boolean) => string;
14
+ export declare const toTimeRangeValue: (timeRange: TimeRange, offset?: number) => TimeRangeValue;
15
+ export declare function fromTimeRangeValue(v: TimeRangeValue): AbsoluteTimeRange;
16
+ export type URLTimeRange = {
17
+ from: string;
18
+ to: string;
19
+ };
20
+ export declare const toURLTimeRange: (timeRange: TimeRange) => URLTimeRange;
21
+ export declare const urlToTimeRange: (urlTimeRange: URLTimeRange) => TimeRange;
22
+ export declare const urlToTimeRangeValue: (urlTimeRange: URLTimeRange) => TimeRangeValue;
23
+ export declare const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
24
+ export declare const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
25
+ export declare function addOffsetUTC(time: string | number | Date, utcOffset: number): Date;
26
+ export declare const getUTCString: (offset: number) => string;
27
+ export declare const timeFormatter: (timeValue: number | string | Date, utcOffset?: number | null, format?: string) => string;
@@ -0,0 +1,68 @@
1
+ import dayjs from "dayjs";
2
+ import { trim } from "lodash-es";
3
+ import prettyMs from "pretty-ms";
4
+ const DEFAULT_QUICK_RANGES = [
5
+ 3 * 24 * 60 * 60,
6
+ 2 * 24 * 60 * 60,
7
+ 24 * 60 * 60,
8
+ 12 * 60 * 60,
9
+ 3 * 60 * 60,
10
+ 60 * 60,
11
+ 30 * 60,
12
+ 15 * 60,
13
+ 5 * 60
14
+ ];
15
+ const formatDuration = (seconds, short = false) => {
16
+ if (short) {
17
+ return prettyMs(seconds * 1e3, { compact: true });
18
+ } else {
19
+ return prettyMs(seconds * 1e3, { verbose: true });
20
+ }
21
+ };
22
+ const toTimeRangeValue = (timeRange, offset = 0) => {
23
+ if (timeRange.type === "absolute") {
24
+ return timeRange.value.map((t) => t + offset);
25
+ } else {
26
+ const now = dayjs().unix();
27
+ return [now - timeRange.value + offset, now + offset];
28
+ }
29
+ };
30
+ const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
31
+ function addOffsetUTC(time, utcOffset) {
32
+ const targetTime = new Date(time);
33
+ const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
34
+ return new Date(targetTime.getTime() + tzDifference * 60 * 1e3);
35
+ }
36
+ const getUTCString = (offset) => {
37
+ const offsetStrs = offset.toString().split(".");
38
+ let mm = "00";
39
+ let hh = "";
40
+ const offsetH = Number.parseInt(offsetStrs[0] || "0");
41
+ const offsetM = Number.parseFloat(`0.${offsetStrs[1]}` || "0") * 60;
42
+ hh = Math.abs(offsetH).toString().padStart(2, "0");
43
+ mm = offsetM === 0 ? "00" : offsetM.toString();
44
+ if (offset > 0) {
45
+ return `UTC+${hh}:${mm}`;
46
+ }
47
+ if (offset < 0) {
48
+ return `UTC-${hh}:${mm}`;
49
+ }
50
+ return "UTC±00:00";
51
+ };
52
+ const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
53
+ if (!timeValue)
54
+ return "-";
55
+ const time = timeValue instanceof Date || isNaN(Number(timeValue)) ? timeValue : Number(timeValue) * 1e3;
56
+ const currentTZOffsetInHours = utcOffset === void 0 || utcOffset === null ? -((/* @__PURE__ */ new Date()).getTimezoneOffset() / 60) : utcOffset;
57
+ const withUTC = format.indexOf("Z") >= 0;
58
+ return dayjs(addOffsetUTC(time, currentTZOffsetInHours)).format(withUTC ? trim(format, "Z") : format) + (withUTC ? getUTCString(currentTZOffsetInHours) : "");
59
+ };
60
+ export {
61
+ DEFAULT_QUICK_RANGES,
62
+ DEFAULT_TIME_FORMAT,
63
+ addOffsetUTC,
64
+ formatDuration,
65
+ getUTCString,
66
+ timeFormatter,
67
+ toTimeRangeValue
68
+ };
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs");
4
+ const React = require("react");
5
+ const ChevronRight = require("../../icons/react/ChevronRight.cjs");
6
+ const index = require("../../primitive/Typography/index.cjs");
7
+ const AbsoluteTimeRangePicker = require("./AbsoluteTimeRangePicker.cjs");
8
+ const helpers = require("./helpers.cjs");
9
+ const Menu = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Menu/Menu.cjs");
10
+ const ChevronIcon = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Select/SelectRightSection/ChevronIcon.cjs");
11
+ const Tooltip = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Tooltip/Tooltip.cjs");
12
+ const Button = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.cjs");
13
+ const Group = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.cjs");
14
+ const Box = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.cjs");
15
+ const Text = require("../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.cjs");
16
+ const TimeRangePicker = ({
17
+ value,
18
+ minDateTime,
19
+ maxDateTime,
20
+ maxDuration,
21
+ disableAbsoluteRanges = false,
22
+ onChange,
23
+ quickRanges = helpers.DEFAULT_QUICK_RANGES,
24
+ loading,
25
+ timezone
26
+ }) => {
27
+ const [opened, setOpened] = React.useState(false);
28
+ const [customMode, setCustomMode] = React.useState(false);
29
+ const isRelativeRange = (value == null ? void 0 : value.type) === "relative";
30
+ const timeRangeValue = helpers.toTimeRangeValue(value);
31
+ const duration = timeRangeValue[1] - timeRangeValue[0];
32
+ const selectedRelativeItem = React.useMemo(() => {
33
+ if (value.type === "absolute") {
34
+ return;
35
+ }
36
+ return quickRanges.find((it) => it === value.value);
37
+ }, [quickRanges, value]);
38
+ const formattedAbsDateTime = React.useMemo(() => {
39
+ return `${helpers.timeFormatter(timeRangeValue[0], timezone || null, "MMM D, YYYY HH:mm")} - ${helpers.timeFormatter(
40
+ timeRangeValue[1],
41
+ timezone || null,
42
+ "MMM D, YYYY HH:mm"
43
+ )}`;
44
+ }, [timeRangeValue]);
45
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(
46
+ Menu.Menu,
47
+ {
48
+ shadow: "md",
49
+ width: customMode ? "auto" : disableAbsoluteRanges ? 200 : 280,
50
+ position: "bottom-end",
51
+ opened,
52
+ onOpen: () => {
53
+ setOpened(true);
54
+ setCustomMode(false);
55
+ },
56
+ onClose: () => setOpened(false),
57
+ children: [
58
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Menu.Menu.Target, { children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Tooltip.Tooltip, { label: formattedAbsDateTime, disabled: isRelativeRange, withArrow: true, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
59
+ Button.Button,
60
+ {
61
+ variant: "default",
62
+ styles: (theme) => ({
63
+ root: {
64
+ paddingLeft: "12px",
65
+ paddingRight: "12px",
66
+ borderColor: opened ? theme.colors.blue[7] : "",
67
+ "&:hover": {
68
+ background: "transparent"
69
+ }
70
+ },
71
+ inner: {
72
+ width: "100%"
73
+ },
74
+ label: {
75
+ display: "flex",
76
+ justifyContent: "space-between",
77
+ width: "100%"
78
+ }
79
+ }),
80
+ w: disableAbsoluteRanges ? 200 : 280,
81
+ fw: "normal",
82
+ ...loading ? { "data-loading": true } : {},
83
+ children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Group.Group, { w: "100%", spacing: 0, children: [
84
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Box.Box, { sx: { flex: "none" }, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(DurationBadge, { children: helpers.formatDuration(duration, true) }) }),
85
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Text.Text, { px: 8, sx: { flex: "1 1", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis" }, children: isRelativeRange ? `Past ${helpers.formatDuration(duration)}` : formattedAbsDateTime }),
86
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Box.Box, { sx: { flex: "none" }, children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(ChevronIcon.ChevronIcon, { size: "md", error: false }) })
87
+ ] })
88
+ }
89
+ ) }) }),
90
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Menu.Menu.Dropdown, { children: customMode ? /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
91
+ AbsoluteTimeRangePicker,
92
+ {
93
+ value: timeRangeValue,
94
+ minDateTime: minDateTime == null ? void 0 : minDateTime(),
95
+ maxDateTime: maxDateTime == null ? void 0 : maxDateTime(),
96
+ maxDuration,
97
+ onChange: (v) => {
98
+ onChange == null ? void 0 : onChange(v);
99
+ setOpened(false);
100
+ },
101
+ onCancel: () => setOpened(false),
102
+ onReturnClick: () => setCustomMode(false)
103
+ }
104
+ ) : /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(jsxRuntime.jsxRuntimeExports.Fragment, { children: [
105
+ !disableAbsoluteRanges && /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(jsxRuntime.jsxRuntimeExports.Fragment, { children: [
106
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
107
+ Menu.Menu.Item,
108
+ {
109
+ rightSection: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(ChevronRight, { size: 16 }),
110
+ closeMenuOnClick: false,
111
+ onClick: () => setCustomMode(true),
112
+ children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index.Typography, { variant: "body-lg", children: "Custom" })
113
+ }
114
+ ),
115
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(Menu.Menu.Divider, {})
116
+ ] }),
117
+ /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(jsxRuntime.jsxRuntimeExports.Fragment, { children: quickRanges.map((seconds) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
118
+ Menu.Menu.Item,
119
+ {
120
+ sx: (theme) => ({
121
+ background: seconds === selectedRelativeItem ? theme.colors.gray[2] : ""
122
+ }),
123
+ onClick: () => onChange == null ? void 0 : onChange({ type: "relative", value: seconds }),
124
+ children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsxs(Text.Text, { children: [
125
+ "Past ",
126
+ helpers.formatDuration(seconds)
127
+ ] })
128
+ },
129
+ seconds
130
+ )) })
131
+ ] }) })
132
+ ]
133
+ }
134
+ );
135
+ };
136
+ const DurationBadge = ({ children }) => {
137
+ return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
138
+ Box.Box,
139
+ {
140
+ display: "inline-block",
141
+ w: 35,
142
+ py: 3,
143
+ bg: "gray.4",
144
+ c: "gray.7",
145
+ fz: 10,
146
+ lh: "14px",
147
+ ta: "center",
148
+ sx: { borderRadius: 8 },
149
+ children
150
+ }
151
+ );
152
+ };
153
+ exports.TimeRangePicker = TimeRangePicker;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { TimeRange } from './helpers.js';
3
+ export interface TimeRangePickerProps {
4
+ value: TimeRange;
5
+ onChange?: (value: TimeRange) => void;
6
+ loading?: boolean;
7
+ minDateTime?: () => Date;
8
+ maxDateTime?: () => Date;
9
+ maxDuration?: number;
10
+ quickRanges?: number[];
11
+ disableAbsoluteRanges?: boolean;
12
+ timezone?: number;
13
+ }
14
+ export declare const TimeRangePicker: React.FC<React.PropsWithChildren<TimeRangePickerProps>>;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { TimeRange } from './helpers.js';
3
+ export interface TimeRangePickerProps {
4
+ value: TimeRange;
5
+ onChange?: (value: TimeRange) => void;
6
+ loading?: boolean;
7
+ minDateTime?: () => Date;
8
+ maxDateTime?: () => Date;
9
+ maxDuration?: number;
10
+ quickRanges?: number[];
11
+ disableAbsoluteRanges?: boolean;
12
+ timezone?: number;
13
+ }
14
+ export declare const TimeRangePicker: React.FC<React.PropsWithChildren<TimeRangePickerProps>>;
@@ -0,0 +1,153 @@
1
+ import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.js";
2
+ import { useState, useMemo } from "react";
3
+ import IconChevronRight from "../../icons/react/ChevronRight.js";
4
+ import { Typography } from "../../primitive/Typography/index.js";
5
+ import AbsoluteTimeRangePicker from "./AbsoluteTimeRangePicker.js";
6
+ import { toTimeRangeValue, timeFormatter, formatDuration, DEFAULT_QUICK_RANGES } from "./helpers.js";
7
+ import { Menu } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Menu/Menu.js";
8
+ import { ChevronIcon } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Select/SelectRightSection/ChevronIcon.js";
9
+ import { Tooltip } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Tooltip/Tooltip.js";
10
+ import { Button } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Button/Button.js";
11
+ import { Group } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Group/Group.js";
12
+ import { Box } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Box/Box.js";
13
+ import { Text } from "../../node_modules/.pnpm/@mantine_core@5.10.4_patch_hash_k3wzpm5n4esvq7igbvcsgyfoja_@emotion_react@11.11.0_@mantine_ho_pge4mijgvpte4ejkiygju76xvm/node_modules/@mantine/core/esm/Text/Text.js";
14
+ const TimeRangePicker = ({
15
+ value,
16
+ minDateTime,
17
+ maxDateTime,
18
+ maxDuration,
19
+ disableAbsoluteRanges = false,
20
+ onChange,
21
+ quickRanges = DEFAULT_QUICK_RANGES,
22
+ loading,
23
+ timezone
24
+ }) => {
25
+ const [opened, setOpened] = useState(false);
26
+ const [customMode, setCustomMode] = useState(false);
27
+ const isRelativeRange = (value == null ? void 0 : value.type) === "relative";
28
+ const timeRangeValue = toTimeRangeValue(value);
29
+ const duration = timeRangeValue[1] - timeRangeValue[0];
30
+ const selectedRelativeItem = useMemo(() => {
31
+ if (value.type === "absolute") {
32
+ return;
33
+ }
34
+ return quickRanges.find((it) => it === value.value);
35
+ }, [quickRanges, value]);
36
+ const formattedAbsDateTime = useMemo(() => {
37
+ return `${timeFormatter(timeRangeValue[0], timezone || null, "MMM D, YYYY HH:mm")} - ${timeFormatter(
38
+ timeRangeValue[1],
39
+ timezone || null,
40
+ "MMM D, YYYY HH:mm"
41
+ )}`;
42
+ }, [timeRangeValue]);
43
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
44
+ Menu,
45
+ {
46
+ shadow: "md",
47
+ width: customMode ? "auto" : disableAbsoluteRanges ? 200 : 280,
48
+ position: "bottom-end",
49
+ opened,
50
+ onOpen: () => {
51
+ setOpened(true);
52
+ setCustomMode(false);
53
+ },
54
+ onClose: () => setOpened(false),
55
+ children: [
56
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Target, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { label: formattedAbsDateTime, disabled: isRelativeRange, withArrow: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
57
+ Button,
58
+ {
59
+ variant: "default",
60
+ styles: (theme) => ({
61
+ root: {
62
+ paddingLeft: "12px",
63
+ paddingRight: "12px",
64
+ borderColor: opened ? theme.colors.blue[7] : "",
65
+ "&:hover": {
66
+ background: "transparent"
67
+ }
68
+ },
69
+ inner: {
70
+ width: "100%"
71
+ },
72
+ label: {
73
+ display: "flex",
74
+ justifyContent: "space-between",
75
+ width: "100%"
76
+ }
77
+ }),
78
+ w: disableAbsoluteRanges ? 200 : 280,
79
+ fw: "normal",
80
+ ...loading ? { "data-loading": true } : {},
81
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { w: "100%", spacing: 0, children: [
82
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { sx: { flex: "none" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DurationBadge, { children: formatDuration(duration, true) }) }),
83
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { px: 8, sx: { flex: "1 1", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis" }, children: isRelativeRange ? `Past ${formatDuration(duration)}` : formattedAbsDateTime }),
84
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { sx: { flex: "none" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronIcon, { size: "md", error: false }) })
85
+ ] })
86
+ }
87
+ ) }) }),
88
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Dropdown, { children: customMode ? /* @__PURE__ */ jsxRuntimeExports.jsx(
89
+ AbsoluteTimeRangePicker,
90
+ {
91
+ value: timeRangeValue,
92
+ minDateTime: minDateTime == null ? void 0 : minDateTime(),
93
+ maxDateTime: maxDateTime == null ? void 0 : maxDateTime(),
94
+ maxDuration,
95
+ onChange: (v) => {
96
+ onChange == null ? void 0 : onChange(v);
97
+ setOpened(false);
98
+ },
99
+ onCancel: () => setOpened(false),
100
+ onReturnClick: () => setCustomMode(false)
101
+ }
102
+ ) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
103
+ !disableAbsoluteRanges && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
104
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
105
+ Menu.Item,
106
+ {
107
+ rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconChevronRight, { size: 16 }),
108
+ closeMenuOnClick: false,
109
+ onClick: () => setCustomMode(true),
110
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Typography, { variant: "body-lg", children: "Custom" })
111
+ }
112
+ ),
113
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Divider, {})
114
+ ] }),
115
+ /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: quickRanges.map((seconds) => /* @__PURE__ */ jsxRuntimeExports.jsx(
116
+ Menu.Item,
117
+ {
118
+ sx: (theme) => ({
119
+ background: seconds === selectedRelativeItem ? theme.colors.gray[2] : ""
120
+ }),
121
+ onClick: () => onChange == null ? void 0 : onChange({ type: "relative", value: seconds }),
122
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { children: [
123
+ "Past ",
124
+ formatDuration(seconds)
125
+ ] })
126
+ },
127
+ seconds
128
+ )) })
129
+ ] }) })
130
+ ]
131
+ }
132
+ );
133
+ };
134
+ const DurationBadge = ({ children }) => {
135
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
136
+ Box,
137
+ {
138
+ display: "inline-block",
139
+ w: 35,
140
+ py: 3,
141
+ bg: "gray.4",
142
+ c: "gray.7",
143
+ fz: 10,
144
+ lh: "14px",
145
+ ta: "center",
146
+ sx: { borderRadius: 8 },
147
+ children
148
+ }
149
+ );
150
+ };
151
+ export {
152
+ TimeRangePicker
153
+ };
@@ -10,6 +10,7 @@ const index$7 = require("./Tree/index.cjs");
10
10
  const index$8 = require("./TransferTree/index.cjs");
11
11
  const index$9 = require("./PropertyCard/index.cjs");
12
12
  const index$a = require("./PageShell/index.cjs");
13
+ const index$b = require("./TimeRangePicker/index.cjs");
13
14
  const helper = require("./PhoneInput/helper.cjs");
14
15
  const BasicTable = require("./Table/BasicTable/BasicTable.cjs");
15
16
  const mantineReactTable_esm = require("../node_modules/.pnpm/mantine-react-table@0.9.5_@emotion_react@11.11.0_@mantine_core@5.10.4_@mantine_dates@5.10.4_@_wgj3awrrave5mmlv3z2e7ky62q/node_modules/mantine-react-table/dist/esm/mantine-react-table.esm.cjs");
@@ -44,6 +45,7 @@ exports.TransferTree = index$8.TransferTree;
44
45
  exports.PropertyCard = index$9.PropertyCard;
45
46
  exports.PageHeader = index$a.PageHeader;
46
47
  exports.PageShell = index$a.PageShell;
48
+ exports.TimeRangePicker = index$b.TimeRangePicker;
47
49
  exports.validPhoneNumber = helper.validPhoneNumber;
48
50
  exports.BasicTable = BasicTable.BasicTable;
49
51
  exports.TableNoticeRow = BasicTable.TableNoticeRow;
@@ -10,3 +10,4 @@ export * from './Tree/index.js';
10
10
  export * from './TransferTree/index.js';
11
11
  export * from './PropertyCard/index.js';
12
12
  export * from './PageShell/index.js';
13
+ export * from './TimeRangePicker/index.js';
@@ -10,3 +10,4 @@ export * from './Tree/index.js';
10
10
  export * from './TransferTree/index.js';
11
11
  export * from './PropertyCard/index.js';
12
12
  export * from './PageShell/index.js';
13
+ export * from './TimeRangePicker/index.js';
package/dist/biz/index.js CHANGED
@@ -8,6 +8,7 @@ import { Tree } from "./Tree/index.js";
8
8
  import { TransferTree } from "./TransferTree/index.js";
9
9
  import { PropertyCard } from "./PropertyCard/index.js";
10
10
  import { PageHeader, PageShell } from "./PageShell/index.js";
11
+ import { TimeRangePicker } from "./TimeRangePicker/index.js";
11
12
  import { validPhoneNumber } from "./PhoneInput/helper.js";
12
13
  import { BasicTable, TableNoticeRow } from "./Table/BasicTable/BasicTable.js";
13
14
  import { MRT_AggregationFns, MRT_BottomToolbar, MRT_CopyButton, MRT_FilterFns, MRT_FilterOptionMenu, MRT_GlobalFilterTextInput, MRT_ProgressBar, MRT_ShowHideColumnsButton, MRT_SortingFns, MRT_TablePagination, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleFullScreenButton, MRT_ToggleGlobalFilterButton, MRT_ToggleRowActionMenuButton, MRT_ToolbarAlertBanner, MRT_ToolbarDropZone, MRT_ToolbarInternalButtons, MRT_TopToolbar, MantineReactTable } from "../node_modules/.pnpm/mantine-react-table@0.9.5_@emotion_react@11.11.0_@mantine_core@5.10.4_@mantine_dates@5.10.4_@_wgj3awrrave5mmlv3z2e7ky62q/node_modules/mantine-react-table/dist/esm/mantine-react-table.esm.js";
@@ -84,6 +85,7 @@ export {
84
85
  PropertyCard,
85
86
  SearchArea,
86
87
  TableNoticeRow,
88
+ TimeRangePicker,
87
89
  TransferTree,
88
90
  Tree,
89
91
  renderExpandCell,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidbcloud/uikit",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "tidbcloud uikit",
5
5
  "type": "module",
6
6
  "main": "dist/primitive/index.cjs",
@@ -61,6 +61,7 @@
61
61
  "google-libphonenumber": "^3.2.30",
62
62
  "lodash-es": "^4.17.21",
63
63
  "mantine-react-table": "0.9.5",
64
+ "pretty-ms": "^9.1.0",
64
65
  "rc-tree": "^5.8.2",
65
66
  "react-hook-form": "^7.51.5",
66
67
  "react-phone-input-2": "^2.15.1",