@pisell/date-picker 1.0.7 → 1.0.8

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.
@@ -12,9 +12,9 @@ var ActionBar = function ActionBar(props) {
12
12
  var ownerState = props.ownerState,
13
13
  onCancel = props.onCancel,
14
14
  onOk = props.onOk,
15
+ onChange = props.onChange,
15
16
  showTime = props.showTime;
16
- var onChange = ownerState.onChange,
17
- value = ownerState.value,
17
+ var value = ownerState.value,
18
18
  slotProps = ownerState.slotProps;
19
19
  var _ref = (slotProps === null || slotProps === void 0 ? void 0 : slotProps.shortcuts) || {},
20
20
  items = _ref.items;
@@ -22,12 +22,12 @@ var ActionBar = function ActionBar(props) {
22
22
  var handleStartChange = function handleStartChange(val) {
23
23
  var newValue = _toConsumableArray(value);
24
24
  newValue[0] = newValue[0].set("hour", val.get("hour")).set("minute", val.get("minute")).set("second", val.get("second"));
25
- onChange(newValue);
25
+ onChange(newValue, "time");
26
26
  };
27
27
  var handleEndChange = function handleEndChange(val) {
28
28
  var newValue = _toConsumableArray(value);
29
29
  newValue[1] = newValue[1].set("hour", val.get("hour")).set("minute", val.get("minute")).set("second", val.get("second"));
30
- onChange(newValue);
30
+ onChange(newValue, "time");
31
31
  };
32
32
  return /*#__PURE__*/React.createElement("div", {
33
33
  className: classNames(props.className, "date-picker-action-bar")
@@ -7,7 +7,9 @@ export interface PisellDateRangePickerProps {
7
7
  defaultValue?: Dayjs[];
8
8
  presets?: PresetType[];
9
9
  className?: string;
10
- showTime?: boolean;
10
+ showTime?: boolean | {
11
+ defaultValue: [Dayjs, Dayjs];
12
+ };
11
13
  placeholder?: string;
12
14
  disableDate?: (day: Dayjs) => boolean;
13
15
  format?: string;
@@ -1,3 +1,4 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -72,11 +73,16 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
72
73
  };
73
74
  });
74
75
  }, [presets]);
75
- var handleChange = function handleChange(val) {
76
- setValue(val);
76
+ var handleChange = function handleChange(val, type) {
77
+ var newVal = val;
78
+ if (_typeof(showTime) === "object" && showTime !== null && showTime !== void 0 && showTime.defaultValue && type !== 'time') {
79
+ newVal = newVal.map(function (item, index) {
80
+ var _showTime$defaultValu, _showTime$defaultValu2, _showTime$defaultValu3, _showTime$defaultValu4, _showTime$defaultValu5, _showTime$defaultValu6;
81
+ return (item === null || item === void 0 ? void 0 : item.set("hour", showTime === null || showTime === void 0 ? void 0 : (_showTime$defaultValu = showTime.defaultValue) === null || _showTime$defaultValu === void 0 ? void 0 : (_showTime$defaultValu2 = _showTime$defaultValu[index]) === null || _showTime$defaultValu2 === void 0 ? void 0 : _showTime$defaultValu2.get("hour")).set("minute", showTime === null || showTime === void 0 ? void 0 : (_showTime$defaultValu3 = showTime.defaultValue) === null || _showTime$defaultValu3 === void 0 ? void 0 : (_showTime$defaultValu4 = _showTime$defaultValu3[index]) === null || _showTime$defaultValu4 === void 0 ? void 0 : _showTime$defaultValu4.get("minute")).set("second", showTime === null || showTime === void 0 ? void 0 : (_showTime$defaultValu5 = showTime.defaultValue) === null || _showTime$defaultValu5 === void 0 ? void 0 : (_showTime$defaultValu6 = _showTime$defaultValu5[index]) === null || _showTime$defaultValu6 === void 0 ? void 0 : _showTime$defaultValu6.get("second"))) || null;
82
+ });
83
+ }
84
+ setValue(newVal);
77
85
  };
78
-
79
- // console.log(_value,'_value');
80
86
  return /*#__PURE__*/React.createElement(DateRangePicker
81
87
  // defaultValue={defaultValue}
82
88
  , {
@@ -98,13 +104,14 @@ var PisellDateRangePicker = function PisellDateRangePicker(props) {
98
104
  slotProps: {
99
105
  shortcuts: {
100
106
  items: _presets,
101
- changeImportance: 'set',
107
+ changeImportance: "set",
102
108
  onChange: handleChange
103
109
  },
104
110
  actionBar: {
105
111
  onOk: handleOk,
106
112
  onCancel: handleClose,
107
- showTime: showTime
113
+ showTime: showTime,
114
+ onChange: handleChange
108
115
  },
109
116
  field: {
110
117
  size: "small"
@@ -37,19 +37,19 @@ var import_classnames = __toESM(require("classnames"));
37
37
  var import_antd = require("antd");
38
38
  var import_index = require("./index.less");
39
39
  var ActionBar = (props) => {
40
- const { ownerState, onCancel, onOk, showTime } = props;
41
- const { onChange, value, slotProps } = ownerState;
40
+ const { ownerState, onCancel, onOk, onChange, showTime } = props;
41
+ const { value, slotProps } = ownerState;
42
42
  const { items } = (slotProps == null ? void 0 : slotProps.shortcuts) || {};
43
43
  const hasShortcuts = !!items.length;
44
44
  const handleStartChange = (val) => {
45
45
  const newValue = [...value];
46
46
  newValue[0] = newValue[0].set("hour", val.get("hour")).set("minute", val.get("minute")).set("second", val.get("second"));
47
- onChange(newValue);
47
+ onChange(newValue, "time");
48
48
  };
49
49
  const handleEndChange = (val) => {
50
50
  const newValue = [...value];
51
51
  newValue[1] = newValue[1].set("hour", val.get("hour")).set("minute", val.get("minute")).set("second", val.get("second"));
52
- onChange(newValue);
52
+ onChange(newValue, "time");
53
53
  };
54
54
  return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(props.className, "date-picker-action-bar") }, hasShortcuts && /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-action-bar-left" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-action-bar-right" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { split: "-" }, showTime ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
55
55
  import_antd.TimePicker,
@@ -7,7 +7,9 @@ export interface PisellDateRangePickerProps {
7
7
  defaultValue?: Dayjs[];
8
8
  presets?: PresetType[];
9
9
  className?: string;
10
- showTime?: boolean;
10
+ showTime?: boolean | {
11
+ defaultValue: [Dayjs, Dayjs];
12
+ };
11
13
  placeholder?: string;
12
14
  disableDate?: (day: Dayjs) => boolean;
13
15
  format?: string;
@@ -61,7 +61,9 @@ var PisellDateRangePicker = (props) => {
61
61
  defaultValue
62
62
  } = props;
63
63
  const [open, setOpen] = (0, import_react.useState)(false);
64
- const [_value, setValue] = (0, import_react.useState)(() => transDayjsArr(propsValue, defaultValue));
64
+ const [_value, setValue] = (0, import_react.useState)(
65
+ () => transDayjsArr(propsValue, defaultValue)
66
+ );
65
67
  (0, import_react.useEffect)(() => {
66
68
  setValue(transDayjsArr(propsValue, defaultValue));
67
69
  }, [propsValue]);
@@ -90,8 +92,17 @@ var PisellDateRangePicker = (props) => {
90
92
  };
91
93
  });
92
94
  }, [presets]);
93
- const handleChange = (val) => {
94
- setValue(val);
95
+ const handleChange = (val, type) => {
96
+ let newVal = val;
97
+ if (typeof showTime === "object" && (showTime == null ? void 0 : showTime.defaultValue) && type !== "time") {
98
+ newVal = newVal.map(
99
+ (item, index) => {
100
+ var _a, _b, _c, _d, _e, _f;
101
+ return (item == null ? void 0 : item.set("hour", (_b = (_a = showTime == null ? void 0 : showTime.defaultValue) == null ? void 0 : _a[index]) == null ? void 0 : _b.get("hour")).set("minute", (_d = (_c = showTime == null ? void 0 : showTime.defaultValue) == null ? void 0 : _c[index]) == null ? void 0 : _d.get("minute")).set("second", (_f = (_e = showTime == null ? void 0 : showTime.defaultValue) == null ? void 0 : _e[index]) == null ? void 0 : _f.get("second"))) || null;
102
+ }
103
+ );
104
+ }
105
+ setValue(newVal);
95
106
  };
96
107
  return /* @__PURE__ */ React.createElement(
97
108
  import_DateRangePicker.DateRangePicker,
@@ -120,7 +131,8 @@ var PisellDateRangePicker = (props) => {
120
131
  actionBar: {
121
132
  onOk: handleOk,
122
133
  onCancel: handleClose,
123
- showTime
134
+ showTime,
135
+ onChange: handleChange
124
136
  },
125
137
  field: {
126
138
  size: "small"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/date-picker",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "sideEffects": [
5
5
  "*.less"
6
6
  ],