@tidbcloud/uikit 2.8.4 → 2.8.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.8.5
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(DateTimePicker): recover from invalid date values ([#657](https://github.com/tidbcloud/tidbcloud-uikit/pull/657))
8
+
3
9
  ## 2.8.4
4
10
 
5
11
  ### Patch Changes
@@ -24,6 +24,10 @@ const DatePicker = require("../../node_modules/.pnpm/@mantine_dates@7.17.8_@mant
24
24
  const Divider = require("../../node_modules/.pnpm/@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hooks@7.17.8_react@18.3.1_e5yvlgwhmeykc75dkphi7jou6q/node_modules/@mantine/core/esm/components/Divider/Divider.cjs");
25
25
  const TimeInput = require("../../node_modules/.pnpm/@mantine_dates@7.17.8_@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hoo_itsuscsie4edrhi6ero4lpb3hq/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.cjs");
26
26
  const Flex = require("../../node_modules/.pnpm/@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hooks@7.17.8_react@18.3.1_e5yvlgwhmeykc75dkphi7jou6q/node_modules/@mantine/core/esm/components/Flex/Flex.cjs");
27
+ const getValidDate = (value) => {
28
+ const date = value ? dayjs.dayjs(value) : void 0;
29
+ return (date == null ? void 0 : date.isValid()) ? date : void 0;
30
+ };
27
31
  const DateTimePicker = ({
28
32
  placeholder = "Select time",
29
33
  format = helpers$1.DEFAULT_TIME_FORMAT,
@@ -45,9 +49,11 @@ const DateTimePicker = ({
45
49
  const [opened, { close, open }] = useDisclosure.useDisclosure(false);
46
50
  const currentDay = dayjs.dayjs(today).startOf("day");
47
51
  const minimumDate = dayjs.dayjs(startDate);
52
+ const initialValue = getValidDate(defaultValue) ?? dayjs.dayjs();
53
+ const fallbackValue = initialValue.isBefore(minimumDate) ? minimumDate : initialValue.isAfter(endDate) ? dayjs.dayjs(endDate) : initialValue;
48
54
  const [currentValue, setCurrentValue] = useUncontrolled.useUncontrolled({
49
- value: value ? dayjs.dayjs(value) : void 0,
50
- defaultValue: defaultValue ? dayjs.dayjs(defaultValue) : dayjs.dayjs(),
55
+ value: getValidDate(value),
56
+ defaultValue: fallbackValue,
51
57
  onChange: (v) => {
52
58
  onChange == null ? void 0 : onChange(v.toDate());
53
59
  }
@@ -22,6 +22,10 @@ import { DatePicker } from "../../node_modules/.pnpm/@mantine_dates@7.17.8_@mant
22
22
  import { Divider } from "../../node_modules/.pnpm/@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hooks@7.17.8_react@18.3.1_e5yvlgwhmeykc75dkphi7jou6q/node_modules/@mantine/core/esm/components/Divider/Divider.mjs";
23
23
  import { TimeInput } from "../../node_modules/.pnpm/@mantine_dates@7.17.8_@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hoo_itsuscsie4edrhi6ero4lpb3hq/node_modules/@mantine/dates/esm/components/TimeInput/TimeInput.mjs";
24
24
  import { Flex } from "../../node_modules/.pnpm/@mantine_core@7.17.8_patch_hash_3qirwkgu3wxhvd6hnr2gb24yzq_@mantine_hooks@7.17.8_react@18.3.1_e5yvlgwhmeykc75dkphi7jou6q/node_modules/@mantine/core/esm/components/Flex/Flex.mjs";
25
+ const getValidDate = (value) => {
26
+ const date = value ? dayjs(value) : void 0;
27
+ return (date == null ? void 0 : date.isValid()) ? date : void 0;
28
+ };
25
29
  const DateTimePicker = ({
26
30
  placeholder = "Select time",
27
31
  format = DEFAULT_TIME_FORMAT,
@@ -43,9 +47,11 @@ const DateTimePicker = ({
43
47
  const [opened, { close, open }] = useDisclosure(false);
44
48
  const currentDay = dayjs(today).startOf("day");
45
49
  const minimumDate = dayjs(startDate);
50
+ const initialValue = getValidDate(defaultValue) ?? dayjs();
51
+ const fallbackValue = initialValue.isBefore(minimumDate) ? minimumDate : initialValue.isAfter(endDate) ? dayjs(endDate) : initialValue;
46
52
  const [currentValue, setCurrentValue] = useUncontrolled({
47
- value: value ? dayjs(value) : void 0,
48
- defaultValue: defaultValue ? dayjs(defaultValue) : dayjs(),
53
+ value: getValidDate(value),
54
+ defaultValue: fallbackValue,
49
55
  onChange: (v) => {
50
56
  onChange == null ? void 0 : onChange(v.toDate());
51
57
  }
@@ -50,7 +50,14 @@ export interface DateTimePickerProps extends Omit<TextInputProps, 'value' | 'onC
50
50
  * @deprecated
51
51
  */
52
52
  utcOffset?: number;
53
+ /**
54
+ * Initial date for an uncontrolled picker. Missing or invalid dates fall back
55
+ * to the current time within the selectable range.
56
+ */
53
57
  defaultValue?: Date;
58
+ /**
59
+ * Controlled date. Invalid dates are treated as missing values.
60
+ */
54
61
  value?: Date;
55
62
  /**
56
63
  * The current date used to highlight "today" in the calendar.
@@ -50,7 +50,14 @@ export interface DateTimePickerProps extends Omit<TextInputProps, 'value' | 'onC
50
50
  * @deprecated
51
51
  */
52
52
  utcOffset?: number;
53
+ /**
54
+ * Initial date for an uncontrolled picker. Missing or invalid dates fall back
55
+ * to the current time within the selectable range.
56
+ */
53
57
  defaultValue?: Date;
58
+ /**
59
+ * Controlled date. Invalid dates are treated as missing values.
60
+ */
54
61
  value?: Date;
55
62
  /**
56
63
  * The current date used to highlight "today" in the calendar.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidbcloud/uikit",
3
- "version": "2.8.4",
3
+ "version": "2.8.5",
4
4
  "description": "tidbcloud uikit",
5
5
  "type": "module",
6
6
  "main": "dist/primitive/index.cjs",