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

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.6
4
+
5
+ ### Patch Changes
6
+
7
+ - export helper functions
8
+
3
9
  ## 2.0.0-beta.5
4
10
 
5
11
  ### Minor Changes
@@ -14,6 +14,10 @@ const DEFAULT_QUICK_RANGES = [
14
14
  15 * 60,
15
15
  5 * 60
16
16
  ];
17
+ const DEFAULT_TIME_RANGE = {
18
+ type: "relative",
19
+ value: 30 * 60
20
+ };
17
21
  const formatDuration = (seconds, short = false) => {
18
22
  if (short) {
19
23
  return prettyMs(seconds * 1e3, { compact: true });
@@ -29,7 +33,30 @@ const toTimeRangeValue = (timeRange, offset = 0) => {
29
33
  return [now - timeRange.value + offset, now + offset];
30
34
  }
31
35
  };
36
+ function fromTimeRangeValue(v) {
37
+ return {
38
+ type: "absolute",
39
+ value: [...v]
40
+ };
41
+ }
42
+ const toURLTimeRange = (timeRange) => {
43
+ if (timeRange.type === "relative") {
44
+ return { from: `${timeRange.value}`, to: "now" };
45
+ }
46
+ const timeRangeValue = toTimeRangeValue(timeRange);
47
+ return { from: `${timeRangeValue[0]}`, to: `${timeRangeValue[1]}` };
48
+ };
49
+ const urlToTimeRange = (urlTimeRange) => {
50
+ if (urlTimeRange.to === "now") {
51
+ return { type: "relative", value: Number(urlTimeRange.from) };
52
+ }
53
+ return { type: "absolute", value: [Number(urlTimeRange.from), Number(urlTimeRange.to)] };
54
+ };
55
+ const urlToTimeRangeValue = (urlTimeRange) => {
56
+ return toTimeRangeValue(urlToTimeRange(urlTimeRange));
57
+ };
32
58
  const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
59
+ const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
33
60
  function addOffsetUTC(time, utcOffset) {
34
61
  const targetTime = new Date(time);
35
62
  const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
@@ -61,8 +88,14 @@ const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
61
88
  };
62
89
  exports.DEFAULT_QUICK_RANGES = DEFAULT_QUICK_RANGES;
63
90
  exports.DEFAULT_TIME_FORMAT = DEFAULT_TIME_FORMAT;
91
+ exports.DEFAULT_TIME_FORMAT_WITH_TIMEZONE = DEFAULT_TIME_FORMAT_WITH_TIMEZONE;
92
+ exports.DEFAULT_TIME_RANGE = DEFAULT_TIME_RANGE;
64
93
  exports.addOffsetUTC = addOffsetUTC;
65
94
  exports.formatDuration = formatDuration;
95
+ exports.fromTimeRangeValue = fromTimeRangeValue;
66
96
  exports.getUTCString = getUTCString;
67
97
  exports.timeFormatter = timeFormatter;
68
98
  exports.toTimeRangeValue = toTimeRangeValue;
99
+ exports.toURLTimeRange = toURLTimeRange;
100
+ exports.urlToTimeRange = urlToTimeRange;
101
+ exports.urlToTimeRangeValue = urlToTimeRangeValue;
@@ -12,6 +12,10 @@ const DEFAULT_QUICK_RANGES = [
12
12
  15 * 60,
13
13
  5 * 60
14
14
  ];
15
+ const DEFAULT_TIME_RANGE = {
16
+ type: "relative",
17
+ value: 30 * 60
18
+ };
15
19
  const formatDuration = (seconds, short = false) => {
16
20
  if (short) {
17
21
  return prettyMs(seconds * 1e3, { compact: true });
@@ -27,7 +31,30 @@ const toTimeRangeValue = (timeRange, offset = 0) => {
27
31
  return [now - timeRange.value + offset, now + offset];
28
32
  }
29
33
  };
34
+ function fromTimeRangeValue(v) {
35
+ return {
36
+ type: "absolute",
37
+ value: [...v]
38
+ };
39
+ }
40
+ const toURLTimeRange = (timeRange) => {
41
+ if (timeRange.type === "relative") {
42
+ return { from: `${timeRange.value}`, to: "now" };
43
+ }
44
+ const timeRangeValue = toTimeRangeValue(timeRange);
45
+ return { from: `${timeRangeValue[0]}`, to: `${timeRangeValue[1]}` };
46
+ };
47
+ const urlToTimeRange = (urlTimeRange) => {
48
+ if (urlTimeRange.to === "now") {
49
+ return { type: "relative", value: Number(urlTimeRange.from) };
50
+ }
51
+ return { type: "absolute", value: [Number(urlTimeRange.from), Number(urlTimeRange.to)] };
52
+ };
53
+ const urlToTimeRangeValue = (urlTimeRange) => {
54
+ return toTimeRangeValue(urlToTimeRange(urlTimeRange));
55
+ };
30
56
  const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
57
+ const DEFAULT_TIME_FORMAT_WITH_TIMEZONE = "YYYY-MM-DD HH:mm:ss Z";
31
58
  function addOffsetUTC(time, utcOffset) {
32
59
  const targetTime = new Date(time);
33
60
  const tzDifference = utcOffset * 60 + targetTime.getTimezoneOffset();
@@ -60,9 +87,15 @@ const timeFormatter = (timeValue, utcOffset, format = DEFAULT_TIME_FORMAT) => {
60
87
  export {
61
88
  DEFAULT_QUICK_RANGES,
62
89
  DEFAULT_TIME_FORMAT,
90
+ DEFAULT_TIME_FORMAT_WITH_TIMEZONE,
91
+ DEFAULT_TIME_RANGE,
63
92
  addOffsetUTC,
64
93
  formatDuration,
94
+ fromTimeRangeValue,
65
95
  getUTCString,
66
96
  timeFormatter,
67
- toTimeRangeValue
97
+ toTimeRangeValue,
98
+ toURLTimeRange,
99
+ urlToTimeRange,
100
+ urlToTimeRangeValue
68
101
  };
@@ -150,4 +150,17 @@ const DurationBadge = ({ children }) => {
150
150
  }
151
151
  );
152
152
  };
153
+ exports.DEFAULT_QUICK_RANGES = helpers.DEFAULT_QUICK_RANGES;
154
+ exports.DEFAULT_TIME_FORMAT = helpers.DEFAULT_TIME_FORMAT;
155
+ exports.DEFAULT_TIME_FORMAT_WITH_TIMEZONE = helpers.DEFAULT_TIME_FORMAT_WITH_TIMEZONE;
156
+ exports.DEFAULT_TIME_RANGE = helpers.DEFAULT_TIME_RANGE;
157
+ exports.addOffsetUTC = helpers.addOffsetUTC;
158
+ exports.formatDuration = helpers.formatDuration;
159
+ exports.fromTimeRangeValue = helpers.fromTimeRangeValue;
160
+ exports.getUTCString = helpers.getUTCString;
161
+ exports.timeFormatter = helpers.timeFormatter;
162
+ exports.toTimeRangeValue = helpers.toTimeRangeValue;
163
+ exports.toURLTimeRange = helpers.toURLTimeRange;
164
+ exports.urlToTimeRange = helpers.urlToTimeRange;
165
+ exports.urlToTimeRangeValue = helpers.urlToTimeRangeValue;
153
166
  exports.TimeRangePicker = TimeRangePicker;
@@ -12,3 +12,4 @@ export interface TimeRangePickerProps {
12
12
  timezone?: number;
13
13
  }
14
14
  export declare const TimeRangePicker: React.FC<React.PropsWithChildren<TimeRangePickerProps>>;
15
+ export * from './helpers.js';
@@ -12,3 +12,4 @@ export interface TimeRangePickerProps {
12
12
  timezone?: number;
13
13
  }
14
14
  export declare const TimeRangePicker: React.FC<React.PropsWithChildren<TimeRangePickerProps>>;
15
+ export * from './helpers.js';
@@ -4,6 +4,7 @@ import IconChevronRight from "../../icons/react/ChevronRight.js";
4
4
  import { Typography } from "../../primitive/Typography/index.js";
5
5
  import AbsoluteTimeRangePicker from "./AbsoluteTimeRangePicker.js";
6
6
  import { toTimeRangeValue, timeFormatter, formatDuration, DEFAULT_QUICK_RANGES } from "./helpers.js";
7
+ import { DEFAULT_TIME_FORMAT, DEFAULT_TIME_FORMAT_WITH_TIMEZONE, DEFAULT_TIME_RANGE, addOffsetUTC, fromTimeRangeValue, getUTCString, toURLTimeRange, urlToTimeRange, urlToTimeRangeValue } from "./helpers.js";
7
8
  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
9
  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
10
  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";
@@ -149,5 +150,18 @@ const DurationBadge = ({ children }) => {
149
150
  );
150
151
  };
151
152
  export {
152
- TimeRangePicker
153
+ DEFAULT_QUICK_RANGES,
154
+ DEFAULT_TIME_FORMAT,
155
+ DEFAULT_TIME_FORMAT_WITH_TIMEZONE,
156
+ DEFAULT_TIME_RANGE,
157
+ TimeRangePicker,
158
+ addOffsetUTC,
159
+ formatDuration,
160
+ fromTimeRangeValue,
161
+ getUTCString,
162
+ timeFormatter,
163
+ toTimeRangeValue,
164
+ toURLTimeRange,
165
+ urlToTimeRange,
166
+ urlToTimeRangeValue
153
167
  };
@@ -33,6 +33,7 @@ const TextArea = require("./Form/TextArea.cjs");
33
33
  const Rating = require("./Form/Rating.cjs");
34
34
  const context = require("./Form/context.cjs");
35
35
  const CopyText = require("./Form/CopyText.cjs");
36
+ const helpers = require("./TimeRangePicker/helpers.cjs");
36
37
  exports.Dot = index.Dot;
37
38
  exports.CodeBlock = index$1.CodeBlock;
38
39
  exports.CopyText = index$1.CopyText;
@@ -92,3 +93,16 @@ exports.HookFormContext = context.HookFormContext;
92
93
  exports.HookFormProvider = context.HookFormProvider;
93
94
  exports.useHookFormContext = context.useHookFormContext;
94
95
  exports.FormCopyText = CopyText.FormCopyText;
96
+ exports.DEFAULT_QUICK_RANGES = helpers.DEFAULT_QUICK_RANGES;
97
+ exports.DEFAULT_TIME_FORMAT = helpers.DEFAULT_TIME_FORMAT;
98
+ exports.DEFAULT_TIME_FORMAT_WITH_TIMEZONE = helpers.DEFAULT_TIME_FORMAT_WITH_TIMEZONE;
99
+ exports.DEFAULT_TIME_RANGE = helpers.DEFAULT_TIME_RANGE;
100
+ exports.addOffsetUTC = helpers.addOffsetUTC;
101
+ exports.formatDuration = helpers.formatDuration;
102
+ exports.fromTimeRangeValue = helpers.fromTimeRangeValue;
103
+ exports.getUTCString = helpers.getUTCString;
104
+ exports.timeFormatter = helpers.timeFormatter;
105
+ exports.toTimeRangeValue = helpers.toTimeRangeValue;
106
+ exports.toURLTimeRange = helpers.toURLTimeRange;
107
+ exports.urlToTimeRange = helpers.urlToTimeRange;
108
+ exports.urlToTimeRangeValue = helpers.urlToTimeRangeValue;
package/dist/biz/index.js CHANGED
@@ -31,10 +31,15 @@ import { FormTextareaInput } from "./Form/TextArea.js";
31
31
  import { FormRatingInput } from "./Form/Rating.js";
32
32
  import { HookFormContext, HookFormProvider, useHookFormContext } from "./Form/context.js";
33
33
  import { FormCopyText } from "./Form/CopyText.js";
34
+ import { DEFAULT_QUICK_RANGES, DEFAULT_TIME_FORMAT, DEFAULT_TIME_FORMAT_WITH_TIMEZONE, DEFAULT_TIME_RANGE, addOffsetUTC, formatDuration, fromTimeRangeValue, getUTCString, timeFormatter, toTimeRangeValue, toURLTimeRange, urlToTimeRange, urlToTimeRangeValue } from "./TimeRangePicker/helpers.js";
34
35
  export {
35
36
  BasicTable,
36
37
  CodeBlock,
37
38
  CopyText,
39
+ DEFAULT_QUICK_RANGES,
40
+ DEFAULT_TIME_FORMAT,
41
+ DEFAULT_TIME_FORMAT_WITH_TIMEZONE,
42
+ DEFAULT_TIME_RANGE,
38
43
  Dot,
39
44
  DotBadge,
40
45
  Form,
@@ -88,7 +93,16 @@ export {
88
93
  TimeRangePicker,
89
94
  TransferTree,
90
95
  Tree,
96
+ addOffsetUTC,
97
+ formatDuration,
98
+ fromTimeRangeValue,
99
+ getUTCString,
91
100
  renderExpandCell,
101
+ timeFormatter,
102
+ toTimeRangeValue,
103
+ toURLTimeRange,
104
+ urlToTimeRange,
105
+ urlToTimeRangeValue,
92
106
  useHookFormContext,
93
107
  validPhoneNumber
94
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidbcloud/uikit",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.6",
4
4
  "description": "tidbcloud uikit",
5
5
  "type": "module",
6
6
  "main": "dist/primitive/index.cjs",