@particle-network/ui-native 0.1.4-beta.3 → 0.1.4-beta.4

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.
@@ -13,10 +13,10 @@ import { DateWheelPicker } from "./date-wheel-picker.js";
13
13
  import { TimeWheelPicker } from "./time-wheel-picker.js";
14
14
  import useFormat from "./useFormat.js";
15
15
  import { hasTimeOnly } from "./utils.js";
16
- const UXDatePicker = ({ title, value, defaultValue, onConfirm = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, placeholder, isDisabled = false, isReadOnly = false, ...uxPressableProps })=>{
16
+ const UXDatePicker = ({ title, value, defaultValue, defaultInternalValue, onChange = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, placeholder, isDisabled = false, isReadOnly = false, ...uxPressableProps })=>{
17
17
  const [isOpen, setIsOpen] = useState(false);
18
18
  const [pickerType, setPickerType] = useState('date');
19
- const [internalValue, setInternalValue] = useState(value || defaultValue || new Date());
19
+ const [internalValue, setInternalValue] = useState(value || defaultValue || defaultInternalValue || new Date());
20
20
  const i18n = useI18n();
21
21
  const displayPlaceholder = placeholder ?? format;
22
22
  const { dateFormat, timeFormat, displayTitle } = useFormat({
@@ -24,7 +24,7 @@ const UXDatePicker = ({ title, value, defaultValue, onConfirm = ()=>null, format
24
24
  title
25
25
  });
26
26
  useEffect(()=>{
27
- if (void 0 !== value) setInternalValue(value);
27
+ value ? setInternalValue(value) : setInternalValue(defaultInternalValue || new Date());
28
28
  }, [
29
29
  value
30
30
  ]);
@@ -38,11 +38,11 @@ const UXDatePicker = ({ title, value, defaultValue, onConfirm = ()=>null, format
38
38
  format
39
39
  ]);
40
40
  const handleConfirm = useCallback(()=>{
41
- onConfirm(internalValue);
41
+ onChange(internalValue);
42
42
  setIsOpen(false);
43
43
  }, [
44
44
  internalValue,
45
- onConfirm
45
+ onChange
46
46
  ]);
47
47
  const handleClose = useCallback(()=>{
48
48
  setIsOpen(false);
@@ -61,7 +61,7 @@ const UXDatePicker = ({ title, value, defaultValue, onConfirm = ()=>null, format
61
61
  isReadOnly: isReadOnly,
62
62
  placeholder: displayPlaceholder,
63
63
  pointerEvents: "none",
64
- value: value ? dayjs(value).format(format) : void 0
64
+ value: value ? dayjs(value).format(format) : ''
65
65
  })
66
66
  }),
67
67
  /*#__PURE__*/ jsx(UXModal, {
@@ -15,12 +15,12 @@ import { DateWheelPicker } from "./date-wheel-picker.js";
15
15
  import { TimeWheelPicker } from "./time-wheel-picker.js";
16
16
  import useFormat from "./useFormat.js";
17
17
  import { hasTimeOnly } from "./utils.js";
18
- const UXDateRangePicker = ({ title, value, defaultValue, onConfirm = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, startPlaceholder, endPlaceholder, isDisabled = false, isReadOnly = false, ...hStackProps })=>{
18
+ const UXDateRangePicker = ({ title, value, defaultValue, defaultInternalValue, onConfirm = ()=>null, format = 'YYYY/MM/DD', minDate, maxDate, startPlaceholder, endPlaceholder, isDisabled = false, isReadOnly = false, ...hStackProps })=>{
19
19
  const [isOpen, setIsOpen] = useState(false);
20
20
  const [currentEditType, setCurrentEditType] = useState('start');
21
21
  const [pickerType, setPickerType] = useState('date');
22
- const [internalStart, setInternalStart] = useState(value?.start || defaultValue?.start || new Date());
23
- const [internalEnd, setInternalEnd] = useState(value?.end || defaultValue?.end || new Date());
22
+ const [internalStart, setInternalStart] = useState(value?.start || defaultValue?.start || defaultInternalValue?.start || new Date());
23
+ const [internalEnd, setInternalEnd] = useState(value?.end || defaultValue?.end || defaultInternalValue?.end || new Date());
24
24
  const [error, setError] = useState('');
25
25
  const i18n = useI18n();
26
26
  const displayStartPlaceholder = startPlaceholder ?? format;
@@ -31,8 +31,8 @@ const UXDateRangePicker = ({ title, value, defaultValue, onConfirm = ()=>null, f
31
31
  rangeMode: true
32
32
  });
33
33
  useEffect(()=>{
34
- if (value?.start !== void 0) setInternalStart(value?.start);
35
- if (value?.end !== void 0) setInternalEnd(value?.end);
34
+ value?.start ? setInternalStart(value?.start) : setInternalStart(defaultInternalValue?.start || new Date());
35
+ value?.end ? setInternalEnd(value?.end) : setInternalEnd(defaultInternalValue?.end || new Date());
36
36
  }, [
37
37
  value
38
38
  ]);
@@ -83,7 +83,7 @@ const UXDateRangePicker = ({ title, value, defaultValue, onConfirm = ()=>null, f
83
83
  isReadOnly: isReadOnly,
84
84
  placeholder: displayStartPlaceholder,
85
85
  pointerEvents: "none",
86
- value: value?.start ? dayjs(value?.start).format(format) : void 0
86
+ value: value?.start ? dayjs(value?.start).format(format) : ''
87
87
  })
88
88
  }),
89
89
  /*#__PURE__*/ jsx(Icon, {
@@ -103,7 +103,7 @@ const UXDateRangePicker = ({ title, value, defaultValue, onConfirm = ()=>null, f
103
103
  isReadOnly: isReadOnly,
104
104
  placeholder: displayEndPlaceholder,
105
105
  pointerEvents: "none",
106
- value: value?.end ? dayjs(value?.end).format(format) : void 0
106
+ value: value?.end ? dayjs(value?.end).format(format) : ''
107
107
  })
108
108
  })
109
109
  ]
@@ -10,9 +10,13 @@ export interface UXDatePickerProps extends Omit<UXPressableProps, 'children'> {
10
10
  */
11
11
  defaultValue?: Date;
12
12
  /**
13
- * 确认回调
13
+ * 默认内部值
14
+ */
15
+ defaultInternalValue?: Date;
16
+ /**
17
+ * 值改变回调
14
18
  */
15
- onConfirm?: (value: Date) => void;
19
+ onChange?: (value: Date) => void;
16
20
  /**
17
21
  * 日期格式
18
22
  */
@@ -51,6 +55,10 @@ export interface UXDateRangePickerProps extends Omit<HStackProps, 'children'> {
51
55
  * 默认值
52
56
  */
53
57
  defaultValue?: DateRangeValue;
58
+ /**
59
+ * 默认内部值
60
+ */
61
+ defaultInternalValue?: DateRangeValue;
54
62
  /**
55
63
  * 确认回调
56
64
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-native",
3
- "version": "0.1.4-beta.3",
3
+ "version": "0.1.4-beta.4",
4
4
  "main": "./entry.js",
5
5
  "react-native": "./dist/index.js",
6
6
  "module": "./dist/index.js",