@lemon-fe/components 0.1.7 → 0.1.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.
@@ -136,11 +136,6 @@ export default function DurationPicker(props) {
136
136
  value = _useState2[0],
137
137
  setValue = _useState2[1];
138
138
 
139
- useEffect(function () {
140
- if (value !== defaultValue && value !== valueProp && onChange) {
141
- onChange(value);
142
- }
143
- }, [value]);
144
139
  useEffect(function () {
145
140
  if (valueProp !== undefined) {
146
141
  setValue(valueProp);
@@ -164,40 +159,48 @@ export default function DurationPicker(props) {
164
159
  }, [value]);
165
160
 
166
161
  var handleChangeType = function handleChangeType(item) {
167
- setValue(function (prev) {
168
- if (item.value === prev.type) {
169
- return prev;
170
- }
171
-
172
- return _objectSpread(_objectSpread({}, prev), {}, {
162
+ if (value.type !== item.value) {
163
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
173
164
  type: item.value
174
165
  });
175
- });
176
- };
177
166
 
178
- var handleChangeOption = function handleChangeOption(item) {
179
- setValue(function (prev) {
180
- if (item.label === prev.option) {
181
- return prev;
167
+ setValue(newValue);
168
+
169
+ if (onChange) {
170
+ onChange(newValue);
182
171
  }
172
+ }
173
+ };
183
174
 
184
- return _objectSpread(_objectSpread({}, prev), {}, {
185
- option: item.label,
175
+ var handleChangeOption = function handleChangeOption(item) {
176
+ if (value.option !== item.label) {
177
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
186
178
  dates: item.value !== null ? item.value().map(function (date) {
187
179
  return date.format(dateFormat);
188
- }) : undefined
180
+ }) : undefined,
181
+ option: item.label
189
182
  });
190
- });
183
+
184
+ setValue(newValue);
185
+
186
+ if (onChange) {
187
+ onChange(newValue);
188
+ }
189
+ }
191
190
  };
192
191
 
193
192
  var handleChangeDates = function handleChangeDates(dates) {
194
- setValue(function (prev) {
195
- return _objectSpread(_objectSpread({}, prev), {}, {
196
- dates: dates ? dates.map(function (item) {
197
- return item.format(dateFormat);
198
- }) : undefined
199
- });
193
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
194
+ dates: dates ? dates.map(function (item) {
195
+ return item.format(dateFormat);
196
+ }) : undefined
200
197
  });
198
+
199
+ setValue(newValue);
200
+
201
+ if (onChange) {
202
+ onChange(newValue);
203
+ }
201
204
  };
202
205
 
203
206
  return /*#__PURE__*/React.createElement("div", {
@@ -23,7 +23,7 @@
23
23
  }
24
24
 
25
25
  &-type.ant-dropdown-trigger {
26
- flex: 0 0 124px;
26
+ flex: 0 0 auto;
27
27
  margin-right: 8px;
28
28
  border: 1px solid @select-border-color;
29
29
  border-radius: @border-radius-base;
@@ -2,5 +2,6 @@ import type { ComponentOption, FilterProps } from './typings';
2
2
  declare function Filter<T extends Record<string, any> = Record<string, any>>(props: FilterProps<T>): JSX.Element;
3
3
  declare namespace Filter {
4
4
  var setComponents: (items: ComponentOption[]) => void;
5
+ var setStorage: <T>(getData: (storageKey: string) => T | Promise<T>, setData: <T_1>(storageKey: string, data: T_1) => void | Promise<void>) => void;
5
6
  }
6
7
  export default Filter;
@@ -67,6 +67,21 @@ var components = [{
67
67
  }, item.extraProps));
68
68
  }
69
69
  }];
70
+
71
+ var getStorageData = function getData(storageKey) {
72
+ var data = localStorage.getItem("filter-storage-".concat(storageKey));
73
+
74
+ if (data) {
75
+ return JSON.parse(data);
76
+ }
77
+
78
+ return null;
79
+ };
80
+
81
+ var setStorageData = function setData(storageKey, data) {
82
+ localStorage.setItem("filter-storage-".concat(storageKey), JSON.stringify(data));
83
+ };
84
+
70
85
  var DEFAULT_TAB_TITLE = '默认';
71
86
 
72
87
  function setComponents(items) {
@@ -79,6 +94,11 @@ function setComponents(items) {
79
94
  components = _toConsumableArray(compMap.values());
80
95
  }
81
96
 
97
+ function setStorage(getData, setData) {
98
+ getStorageData = getData;
99
+ setStorageData = setData;
100
+ }
101
+
82
102
  function Filter(props) {
83
103
  var data = props.data,
84
104
  defaultValueProp = props.defaultValue,
@@ -144,7 +164,7 @@ function Filter(props) {
144
164
  form = _Form$useForm4[0];
145
165
 
146
166
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
147
- var tabsJson;
167
+ var tabsData;
148
168
  return regeneratorRuntime.wrap(function _callee$(_context) {
149
169
  while (1) {
150
170
  switch (_context.prev = _context.next) {
@@ -157,17 +177,12 @@ function Filter(props) {
157
177
  return _context.abrupt("return", null);
158
178
 
159
179
  case 2:
160
- tabsJson = localStorage.getItem("filter-storage-".concat(storageKey));
180
+ _context.next = 4;
181
+ return getStorageData(storageKey);
161
182
 
162
- if (!tabsJson) {
163
- _context.next = 5;
164
- break;
165
- }
166
-
167
- return _context.abrupt("return", JSON.parse(tabsJson));
168
-
169
- case 5:
170
- return _context.abrupt("return", null);
183
+ case 4:
184
+ tabsData = _context.sent;
185
+ return _context.abrupt("return", tabsData);
171
186
 
172
187
  case 6:
173
188
  case "end":
@@ -227,6 +242,10 @@ function Filter(props) {
227
242
  next.push(tab);
228
243
  }
229
244
 
245
+ if (!!storageKey) {
246
+ setStorageData(storageKey, next.slice(1));
247
+ }
248
+
230
249
  setTabs(next);
231
250
  setActive(index);
232
251
  setShowModal(false);
@@ -306,6 +325,12 @@ function Filter(props) {
306
325
  return next;
307
326
  });
308
327
  setActive(active - 1);
328
+
329
+ if (!!storageKey) {
330
+ setStorageData(storageKey, tabs.filter(function (item) {
331
+ return item.title !== tabs[active].title && item.title !== '默认';
332
+ }));
333
+ }
309
334
  }
310
335
  });
311
336
  };
@@ -525,4 +550,5 @@ function Filter(props) {
525
550
  }
526
551
 
527
552
  Filter.setComponents = setComponents;
553
+ Filter.setStorage = setStorage;
528
554
  export default Filter;
@@ -74,6 +74,7 @@
74
74
 
75
75
  &-item {
76
76
  margin-top: 16px;
77
+ overflow: hidden;
77
78
 
78
79
  .ant-checkbox-wrapper {
79
80
  color: #888;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -41,5 +41,5 @@
41
41
  "react": "^17.0.2",
42
42
  "react-dom": "^17.0.2"
43
43
  },
44
- "gitHead": "84f94d37e2938930fa2c32d2da6573dfc517b458"
44
+ "gitHead": "4ccc4baa581c66b4820373dffec12433c3ae7712"
45
45
  }