yootd 0.0.35 → 0.0.36

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.
@@ -46,24 +46,17 @@ export var DateInterval = function DateInterval(_ref) {
46
46
  type: e
47
47
  });
48
48
  };
49
- // 设置初始值
50
- useEffect(function () {
51
- if (value != null) {
52
- setType(value.type);
53
- setDate(value.date);
54
- }
55
- }, [value]);
56
49
  var datePickerMap = useMemo(function () {
57
50
  return {
58
51
  time: /*#__PURE__*/React.createElement(AntdDatePicker.TimePicker, _extends({}, props, {
59
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
52
+ defaultValue: date,
60
53
  style: {
61
54
  width: 180
62
55
  },
63
56
  onChange: onChangeTime
64
57
  })),
65
58
  date: /*#__PURE__*/React.createElement(AntdDatePicker, _extends({}, props, {
66
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
59
+ defaultValue: date,
67
60
  style: {
68
61
  width: 180
69
62
  },
@@ -72,7 +65,7 @@ export var DateInterval = function DateInterval(_ref) {
72
65
  week: /*#__PURE__*/React.createElement(AntdDatePicker, _extends({
73
66
  picker: "week"
74
67
  }, props, {
75
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
68
+ defaultValue: date,
76
69
  style: {
77
70
  width: 180
78
71
  },
@@ -81,7 +74,7 @@ export var DateInterval = function DateInterval(_ref) {
81
74
  month: /*#__PURE__*/React.createElement(AntdDatePicker, _extends({
82
75
  picker: "month"
83
76
  }, props, {
84
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
77
+ defaultValue: date,
85
78
  style: {
86
79
  width: 180
87
80
  },
@@ -90,7 +83,7 @@ export var DateInterval = function DateInterval(_ref) {
90
83
  quarter: /*#__PURE__*/React.createElement(AntdDatePicker, _extends({
91
84
  picker: "quarter"
92
85
  }, props, {
93
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
86
+ defaultValue: date,
94
87
  style: {
95
88
  width: 180
96
89
  },
@@ -99,7 +92,7 @@ export var DateInterval = function DateInterval(_ref) {
99
92
  year: /*#__PURE__*/React.createElement(AntdDatePicker, _extends({
100
93
  picker: "year"
101
94
  }, props, {
102
- defaultValue: value === null || value === void 0 ? void 0 : value.date,
95
+ defaultValue: date,
103
96
  style: {
104
97
  width: 180
105
98
  },
@@ -107,6 +100,20 @@ export var DateInterval = function DateInterval(_ref) {
107
100
  }))
108
101
  };
109
102
  }, [type]);
103
+ // 设置初始值
104
+ useEffect(function () {
105
+ if ((value === null || value === void 0 ? void 0 : value.type) != null) {
106
+ setType(value.type);
107
+ } else {
108
+ var _options$2;
109
+ setType((options === null || options === void 0 || (_options$2 = options[0]) === null || _options$2 === void 0 ? void 0 : _options$2.value) || 'time');
110
+ }
111
+ if ((value === null || value === void 0 ? void 0 : value.date) != null) {
112
+ setDate(value.date);
113
+ } else {
114
+ setDate(dayjs());
115
+ }
116
+ }, [value]);
110
117
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Select, {
111
118
  value: type,
112
119
  style: {
@@ -11,17 +11,37 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
11
11
  import { DatePicker, Select, TimePicker } from 'antd';
12
12
  import dayjs from 'dayjs';
13
13
  import React, { useEffect, useMemo, useState } from 'react';
14
+ var defaultOptions = [{
15
+ label: '时间',
16
+ value: 'time'
17
+ }, {
18
+ label: '日期',
19
+ value: 'date'
20
+ }, {
21
+ label: '周',
22
+ value: 'week'
23
+ }, {
24
+ label: '月份',
25
+ value: 'month'
26
+ }, {
27
+ label: '季度',
28
+ value: 'quarter'
29
+ }, {
30
+ label: '年份',
31
+ value: 'year'
32
+ }];
14
33
  export var DateRange = function DateRange(_ref) {
15
34
  var _options$;
16
- var options = _ref.options,
35
+ var _ref$options = _ref.options,
36
+ options = _ref$options === void 0 ? defaultOptions : _ref$options,
17
37
  value = _ref.value,
18
38
  onChange = _ref.onChange,
19
39
  props = _objectWithoutProperties(_ref, _excluded);
20
- var _useState = useState((options === null || options === void 0 || (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.value) || 'time'),
40
+ var _useState = useState(options === null || options === void 0 || (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.value),
21
41
  _useState2 = _slicedToArray(_useState, 2),
22
42
  type = _useState2[0],
23
43
  setType = _useState2[1];
24
- var _useState3 = useState((value === null || value === void 0 ? void 0 : value.dates) || [dayjs(), dayjs()]),
44
+ var _useState3 = useState([dayjs(), dayjs()]),
25
45
  _useState4 = _slicedToArray(_useState3, 2),
26
46
  dates = _useState4[0],
27
47
  setDates = _useState4[1];
@@ -35,14 +55,14 @@ export var DateRange = function DateRange(_ref) {
35
55
  var datePickerMap = useMemo(function () {
36
56
  return {
37
57
  time: /*#__PURE__*/React.createElement(TimePicker.RangePicker, _extends({}, props, {
38
- defaultValue: value === null || value === void 0 ? void 0 : value.dates,
58
+ defaultValue: dates,
39
59
  style: {
40
60
  width: 244
41
61
  },
42
62
  onChange: onChangeDate
43
63
  })),
44
64
  date: /*#__PURE__*/React.createElement(DatePicker.RangePicker, _extends({}, props, {
45
- defaultValue: value === null || value === void 0 ? void 0 : value.dates,
65
+ defaultValue: dates,
46
66
  style: {
47
67
  width: 244
48
68
  },
@@ -51,7 +71,7 @@ export var DateRange = function DateRange(_ref) {
51
71
  week: /*#__PURE__*/React.createElement(DatePicker.RangePicker, _extends({
52
72
  picker: "week"
53
73
  }, props, {
54
- defaultValue: value === null || value === void 0 ? void 0 : value.dates,
74
+ defaultValue: dates,
55
75
  style: {
56
76
  width: 244
57
77
  },
@@ -60,7 +80,7 @@ export var DateRange = function DateRange(_ref) {
60
80
  month: /*#__PURE__*/React.createElement(DatePicker.RangePicker, _extends({
61
81
  picker: "month"
62
82
  }, props, {
63
- defaultValue: value === null || value === void 0 ? void 0 : value.dates,
83
+ defaultValue: dates,
64
84
  style: {
65
85
  width: 244
66
86
  },
@@ -73,12 +93,12 @@ export var DateRange = function DateRange(_ref) {
73
93
  width: 244
74
94
  },
75
95
  onChange: onChangeDate,
76
- defaultValue: value === null || value === void 0 ? void 0 : value.dates
96
+ defaultValue: dates
77
97
  })),
78
98
  year: /*#__PURE__*/React.createElement(DatePicker.RangePicker, _extends({
79
99
  picker: "year"
80
100
  }, props, {
81
- defaultValue: value === null || value === void 0 ? void 0 : value.dates,
101
+ defaultValue: dates,
82
102
  style: {
83
103
  width: 244
84
104
  },
@@ -95,9 +115,16 @@ export var DateRange = function DateRange(_ref) {
95
115
  };
96
116
  // 设置初始值
97
117
  useEffect(function () {
98
- if (value != null) {
99
- setType(value.type);
100
- setDates(value.dates);
118
+ if ((value === null || value === void 0 ? void 0 : value.type) != null) {
119
+ setType(value === null || value === void 0 ? void 0 : value.type);
120
+ } else {
121
+ var _options$2;
122
+ setType(options === null || options === void 0 || (_options$2 = options[0]) === null || _options$2 === void 0 ? void 0 : _options$2.value);
123
+ }
124
+ if ((value === null || value === void 0 ? void 0 : value.dates) != null) {
125
+ setDates(value === null || value === void 0 ? void 0 : value.dates);
126
+ } else {
127
+ setDates([dayjs(), dayjs()]);
101
128
  }
102
129
  }, [value]);
103
130
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Select, {
@@ -105,25 +132,7 @@ export var DateRange = function DateRange(_ref) {
105
132
  style: {
106
133
  width: 92
107
134
  },
108
- options: options != null ? options : [{
109
- label: '时间',
110
- value: 'time'
111
- }, {
112
- label: '日期',
113
- value: 'date'
114
- }, {
115
- label: '周',
116
- value: 'week'
117
- }, {
118
- label: '月份',
119
- value: 'month'
120
- }, {
121
- label: '季度',
122
- value: 'quarter'
123
- }, {
124
- label: '年份',
125
- value: 'year'
126
- }],
135
+ options: options,
127
136
  onChange: handleSelectChange
128
137
  }), datePickerMap[type]);
129
138
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yootd",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",