@kne/react-filter 0.1.21 → 0.1.24

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/README.md CHANGED
@@ -38,7 +38,6 @@ const {default: antdMessage} = message;
38
38
 
39
39
  const {City, List, Range, Text, Selector, Check, DateTime} = Filter.type;
40
40
 
41
- console.log(Text.Number);
42
41
  const {isNumber} = _;
43
42
 
44
43
  const BaseExample = () => {
@@ -196,6 +195,107 @@ render(<Example/>);
196
195
 
197
196
  ```
198
197
 
198
+ - 扩展示例
199
+ - 展示扩展筛选项,自定义筛选项
200
+ - reactFilter(@kne/react-filter),modal(antd/lib/modal),input(antd/lib/input),space(antd/lib/space),datePicker(antd/lib/date-picker),monment(moment),_(lodash),(@kne/react-filter/dist/index.css)
201
+
202
+ ```jsx
203
+ const {default: ReactFilter, useFilterContext, FilterItem, withFilterItem, SearchButton} = reactFilter;
204
+ const {default: Modal} = modal;
205
+ const {default: Input} = input;
206
+ const {default: Space} = space;
207
+ const {default: DatePicker} = datePicker;
208
+ const {useRef, useState} = React;
209
+ const {get} = _;
210
+
211
+ const MyFilter = (props) => {
212
+ const ref = useRef();
213
+ const {value, onChange} = useFilterContext();
214
+ return <FilterItem {...props} onClick={() => {
215
+ Modal.confirm({
216
+ icon: null,
217
+ content: <Input ref={ref} defaultValue={get(value[props.name], 'value')}/>,
218
+ onOk: () => {
219
+ const value = ref.current.input.value;
220
+ onChange(props.name, {
221
+ label: value,
222
+ value
223
+ });
224
+ }
225
+ });
226
+ console.log(value);
227
+ }}/>;
228
+ };
229
+
230
+ const DateRange = withFilterItem(({
231
+ name,
232
+ size,
233
+ isMore,
234
+ defaultActive,
235
+ onBlur,
236
+ onSearch,
237
+ onBeforeSearch,
238
+ startProps,
239
+ endProps,
240
+ placeholder
241
+ }) => {
242
+ const ref = useRef();
243
+
244
+ const sort = (a, b) => {
245
+ if (a && b) {
246
+ return new Date(a) - new Date(b);
247
+ }
248
+ return 0;
249
+ };
250
+
251
+ return <SearchButton size={size} template={(value) => {
252
+ if (!value[0] && value[1]) {
253
+ return `${value[1]}之前`;
254
+ }
255
+ if (!value[1] && value[0]) {
256
+ return `${value[0]}之后`;
257
+ }
258
+ return value.join('~');
259
+ }} isMore={isMore} onBlur={onBlur} defaultActive={defaultActive}
260
+ name={name}
261
+ onSearch={onSearch}
262
+ onBeforeSearch={onBeforeSearch}>
263
+ {({value, setValue, setActive}) => {
264
+ return <div ref={ref}>
265
+ <Space>
266
+ <DatePicker size="small" {...startProps} getPopupContainer={() => ref.current}
267
+ value={get(value, 0) && monment(get(value, 0))}
268
+ onChange={(inputValue) => {
269
+ const target = [inputValue && inputValue.format('YYYY-MM-DD HH:mm:ss'), get(value, 1)];
270
+ setValue(target.sort(sort));
271
+ }} onFocus={() => {
272
+ setActive(true);
273
+ }} placeholder={Array.isArray(placeholder) ? placeholder[0] : (placeholder || "请输入")}/>
274
+ ~
275
+ <DatePicker size="small" {...endProps} getPopupContainer={() => ref.current}
276
+ value={get(value, 1) && monment(get(value, 1))}
277
+ onChange={(inputValue) => {
278
+ const target = [get(value, 0), inputValue && inputValue.format('YYYY-MM-DD HH:mm:ss')];
279
+ setValue(target.sort(sort));
280
+ }} onFocus={() => {
281
+ setActive(true);
282
+ }} placeholder={Array.isArray(placeholder) ? placeholder[0] : (placeholder || "请输入")}/>
283
+ </Space>
284
+ </div>
285
+ }}
286
+ </SearchButton>
287
+ });
288
+
289
+ const Example = () => {
290
+ const [value, setValue] = useState({});
291
+ return <ReactFilter value={value} onChange={setValue} moreTrigger="click"
292
+ more={[<MyFilter name="test1" label="测试"/>, <DateRange name="test2" label="测试2"/>]}/>
293
+ };
294
+
295
+ render(<Example/>);
296
+
297
+ ```
298
+
199
299
 
200
300
  ### API
201
301