@canlooks/can-ui 0.0.140 → 0.0.142

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.
@@ -58,9 +58,14 @@ exports.Curd = (0, react_1.memo)((props) => {
58
58
  * -------------------------------------------------------------
59
59
  * 筛选部分
60
60
  */
61
+ const inlineFilterRef = (0, react_1.useRef)(null);
61
62
  const innerFilterRef = (0, react_1.useRef)(null);
62
- const filterHandler = (value) => {
63
- onFilter?.(value);
63
+ const getFilterValue = () => ({
64
+ ...inlineFilterRef.current.getFormValue(),
65
+ ...innerFilterRef.current.getFormValue()
66
+ });
67
+ const filterHandler = () => {
68
+ onFilter?.(getFilterValue());
64
69
  innerLoadRows().then();
65
70
  };
66
71
  const renderFilterableFn = () => {
@@ -139,7 +144,7 @@ exports.Curd = (0, react_1.memo)((props) => {
139
144
  page: innerPage.current,
140
145
  pageSize: innerPageSize.current
141
146
  }
142
- : void 0, innerFilterRef.current.getFormValue(), innerOrderColumn.current
147
+ : void 0, getFilterValue(), innerOrderColumn.current
143
148
  ? {
144
149
  field: innerOrderColumn.current,
145
150
  type: innerOrderType.current
@@ -207,7 +212,7 @@ exports.Curd = (0, react_1.memo)((props) => {
207
212
  }, filterProps, {
208
213
  ref: innerFilterRef,
209
214
  ...filterableProps?.showButton === false
210
- ? { onChange: (field, value, formValue) => filterHandler(formValue) }
215
+ ? { onChange: filterHandler }
211
216
  : { onFinish: filterHandler }
212
217
  }), children: renderFilterableFn() }), (creatable || toolbarLeft || toolbarRight || reloadable || resizable || columnConfigurable) &&
213
218
  (0, jsx_runtime_1.jsxs)("div", { className: curd_style_1.classes.toolbar, children: [(0, jsx_runtime_1.jsxs)("div", { className: curd_style_1.classes.toolbarLeft, children: [creatable &&
@@ -218,7 +223,7 @@ exports.Curd = (0, react_1.memo)((props) => {
218
223
  (0, jsx_runtime_1.jsx)(curdColumnConfig_1.CurdColumnConfig, { columns: orderedColumns, innerVisible: innerVisible.current, setInnerVisible: setInnerVisible, setInnerOrder: setInnerOrder })] })] }), (0, jsx_runtime_1.jsx)("div", { className: curd_style_1.classes.card, children: (0, jsx_runtime_1.jsx)(dataGrid_1.DataGrid, { ...dataGridProps, columns: actualColumns, tableProps: {
219
224
  ...props.tableProps,
220
225
  ...resizable && { size: innerSize.current }
221
- }, loading: innerLoading.current, rows: innerRows.current, paginatable: !loadRows && props.paginatable, renderPagination: loadRows && props.paginatable !== false
226
+ }, loading: innerLoading.current, rows: innerRows.current, filterProps: { ref: inlineFilterRef }, onFilter: filterHandler, paginatable: !loadRows && props.paginatable, renderPagination: loadRows && props.paginatable !== false
222
227
  ? () => (0, jsx_runtime_1.jsx)(pagination_1.Pagination, { ...props.paginationProps, total: innerTotal.current, page: innerPage.current, onPageChange: setInnerPage, pageSize: innerPageSize.current, onPageSizeChange: setInnerPageSize })
223
228
  : props.renderPagination, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler }) }), (creatable || updatable) &&
224
229
  (0, jsx_runtime_1.jsx)(curdDialog_1.CurdDialog, { ...dialogProps, ref: curdDialogRef, onFinish: finishHandler, curdProps: props })] }));
@@ -8,6 +8,8 @@ type FilterSharedProps = {
8
8
  export interface FilterOptionsProps extends FilterSharedProps, OptionsBaseProps<MenuOptionType> {
9
9
  /** 默认为`true` */
10
10
  multiple?: boolean;
11
+ /** 默认为`false` */
12
+ searchable?: boolean;
11
13
  }
12
14
  export interface FilterControlProps extends FilterSharedProps {
13
15
  control: FormItemChildren;
@@ -9,34 +9,43 @@ const button_1 = require("../button");
9
9
  const popper_1 = require("../popper");
10
10
  const react_1 = require("react");
11
11
  const form_1 = require("../form");
12
+ const filterBubbleContent_style_1 = require("./filterBubbleContent.style");
13
+ const input_1 = require("../input");
14
+ const icon_1 = require("../icon");
15
+ const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
16
+ const utils_1 = require("../../utils");
12
17
  exports.FilterBubbleContent = (0, react_1.memo)(({ columnKey, columnFilterProps }) => {
13
18
  const { formRef } = (0, form_1.useFormContext)();
14
- /**
15
- * ------------------------------------------------------------------------------------
16
- * 弹框关闭时触发筛选
17
- */
18
19
  const { open, setOpen } = (0, popper_1.usePopperContext)();
19
20
  (0, react_1.useEffect)(() => {
20
- !open && formRef.current.submit().then();
21
+ if (!open && 'multiple' in columnFilterProps && columnFilterProps.multiple) {
22
+ // 多选模式下,关闭弹框触发筛选
23
+ formRef.current.submit().then();
24
+ }
21
25
  }, [open]);
22
26
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(form_1.FormItem, { field: columnKey, children: 'control' in columnFilterProps
23
27
  ? columnFilterProps.control
24
- : (0, jsx_runtime_1.jsx)(FilterOptions, { ...columnFilterProps }) }), columnFilterProps.showButton !== false
25
- ? (0, jsx_runtime_1.jsx)(flex_1.Flex, { gap: 6, justifyContent: "center", marginTop: 6, children: (0, jsx_runtime_1.jsx)(button_1.Button, { variant: "text", onClick: () => {
28
+ : (0, jsx_runtime_1.jsx)(FilterOptions, { ...columnFilterProps }) }), columnFilterProps.showButton !== false &&
29
+ (0, jsx_runtime_1.jsx)(flex_1.Flex, { gap: 6, justifyContent: "center", marginTop: 6, children: (0, jsx_runtime_1.jsx)(button_1.Button, { variant: "text", onClick: () => {
26
30
  formRef.current.setFieldValue(columnKey, null);
27
31
  setOpen(false);
28
- }, children: "\u91CD\u7F6E" }) })
29
- : (0, jsx_runtime_1.jsx)(TriggerFilterOnChange, {})] }));
32
+ }, children: "\u91CD\u7F6E" }) }), 'multiple' in columnFilterProps && !columnFilterProps.multiple &&
33
+ // 单选模式,变化即触发筛选
34
+ (0, jsx_runtime_1.jsx)(TriggerFilterOnChange, { onSubmit: () => setOpen(false) })] }));
30
35
  });
31
- const FilterOptions = (0, react_1.memo)(({ multiple = true, showButton = true, value, onChange, ...props }) => {
36
+ const FilterOptions = (0, react_1.memo)(({ multiple = true, showButton = true, searchable = false, value, onChange, ...props }) => {
32
37
  const [selectedValue, toggleSelect] = (0, selectionContext_1.useFlatSelection)({ multiple, value, onChange });
33
- return ((0, jsx_runtime_1.jsx)(optionsBase_1.OptionsBase, { showCheckbox: multiple, ...props, selectedValue: selectedValue, onToggleSelected: toggleSelect }));
38
+ const [searchValue, setSearchValue] = (0, react_1.useState)('');
39
+ const deferredSearchValue = (0, react_1.useDeferredValue)(searchValue);
40
+ return ((0, jsx_runtime_1.jsxs)("div", { css: filterBubbleContent_style_1.style, children: [searchable &&
41
+ (0, jsx_runtime_1.jsx)(input_1.Input, { prefix: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: free_solid_svg_icons_1.faSearch }), placeholder: "\u641C\u7D22", value: searchValue, onChange: e => setSearchValue(e.target.value) }), (0, jsx_runtime_1.jsx)(optionsBase_1.OptionsBase, { showCheckbox: multiple, ...props, searchValue: deferredSearchValue, selectedValue: selectedValue, onToggleSelected: toggleSelect })] }));
34
42
  });
35
- const TriggerFilterOnChange = (0, react_1.memo)(() => {
43
+ function TriggerFilterOnChange(props) {
36
44
  const { formRef } = (0, form_1.useFormContext)();
37
45
  const { formValue } = (0, form_1.useFormValueContext)();
38
- (0, react_1.useEffect)(() => {
46
+ (0, utils_1.useUpdateEffect)(() => {
39
47
  formRef.current.submit().then();
48
+ props.onSubmit?.();
40
49
  }, [formValue]);
41
50
  return null;
42
- });
51
+ }
@@ -0,0 +1 @@
1
+ export declare const style: import("@emotion/react").SerializedStyles;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.style = void 0;
4
+ const react_1 = require("@emotion/react");
5
+ exports.style = (0, react_1.css) `
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 4px
9
+ `;
@@ -55,9 +55,14 @@ export const Curd = memo((props) => {
55
55
  * -------------------------------------------------------------
56
56
  * 筛选部分
57
57
  */
58
+ const inlineFilterRef = useRef(null);
58
59
  const innerFilterRef = useRef(null);
59
- const filterHandler = (value) => {
60
- onFilter?.(value);
60
+ const getFilterValue = () => ({
61
+ ...inlineFilterRef.current.getFormValue(),
62
+ ...innerFilterRef.current.getFormValue()
63
+ });
64
+ const filterHandler = () => {
65
+ onFilter?.(getFilterValue());
61
66
  innerLoadRows().then();
62
67
  };
63
68
  const renderFilterableFn = () => {
@@ -136,7 +141,7 @@ export const Curd = memo((props) => {
136
141
  page: innerPage.current,
137
142
  pageSize: innerPageSize.current
138
143
  }
139
- : void 0, innerFilterRef.current.getFormValue(), innerOrderColumn.current
144
+ : void 0, getFilterValue(), innerOrderColumn.current
140
145
  ? {
141
146
  field: innerOrderColumn.current,
142
147
  type: innerOrderType.current
@@ -204,7 +209,7 @@ export const Curd = memo((props) => {
204
209
  }, filterProps, {
205
210
  ref: innerFilterRef,
206
211
  ...filterableProps?.showButton === false
207
- ? { onChange: (field, value, formValue) => filterHandler(formValue) }
212
+ ? { onChange: filterHandler }
208
213
  : { onFinish: filterHandler }
209
214
  }), children: renderFilterableFn() }), (creatable || toolbarLeft || toolbarRight || reloadable || resizable || columnConfigurable) &&
210
215
  _jsxs("div", { className: classes.toolbar, children: [_jsxs("div", { className: classes.toolbarLeft, children: [creatable &&
@@ -215,7 +220,7 @@ export const Curd = memo((props) => {
215
220
  _jsx(CurdColumnConfig, { columns: orderedColumns, innerVisible: innerVisible.current, setInnerVisible: setInnerVisible, setInnerOrder: setInnerOrder })] })] }), _jsx("div", { className: classes.card, children: _jsx(DataGrid, { ...dataGridProps, columns: actualColumns, tableProps: {
216
221
  ...props.tableProps,
217
222
  ...resizable && { size: innerSize.current }
218
- }, loading: innerLoading.current, rows: innerRows.current, paginatable: !loadRows && props.paginatable, renderPagination: loadRows && props.paginatable !== false
223
+ }, loading: innerLoading.current, rows: innerRows.current, filterProps: { ref: inlineFilterRef }, onFilter: filterHandler, paginatable: !loadRows && props.paginatable, renderPagination: loadRows && props.paginatable !== false
219
224
  ? () => _jsx(Pagination, { ...props.paginationProps, total: innerTotal.current, page: innerPage.current, onPageChange: setInnerPage, pageSize: innerPageSize.current, onPageSizeChange: setInnerPageSize })
220
225
  : props.renderPagination, orderColumn: innerOrderColumn.current, orderType: innerOrderType.current, onOrderChange: orderChangeHandler }) }), (creatable || updatable) &&
221
226
  _jsx(CurdDialog, { ...dialogProps, ref: curdDialogRef, onFinish: finishHandler, curdProps: props })] }));
@@ -8,6 +8,8 @@ type FilterSharedProps = {
8
8
  export interface FilterOptionsProps extends FilterSharedProps, OptionsBaseProps<MenuOptionType> {
9
9
  /** 默认为`true` */
10
10
  multiple?: boolean;
11
+ /** 默认为`false` */
12
+ searchable?: boolean;
11
13
  }
12
14
  export interface FilterControlProps extends FilterSharedProps {
13
15
  control: FormItemChildren;
@@ -4,36 +4,45 @@ import { useFlatSelection } from '../selectionContext';
4
4
  import { Flex } from '../flex';
5
5
  import { Button } from '../button';
6
6
  import { usePopperContext } from '../popper';
7
- import { memo, useEffect } from 'react';
7
+ import { memo, useDeferredValue, useEffect, useState } from 'react';
8
8
  import { FormItem, useFormContext, useFormValueContext } from '../form';
9
+ import { style } from './filterBubbleContent.style';
10
+ import { Input } from '../input';
11
+ import { Icon } from '../icon';
12
+ import { faSearch } from '@fortawesome/free-solid-svg-icons';
13
+ import { useUpdateEffect } from '../../utils';
9
14
  export const FilterBubbleContent = memo(({ columnKey, columnFilterProps }) => {
10
15
  const { formRef } = useFormContext();
11
- /**
12
- * ------------------------------------------------------------------------------------
13
- * 弹框关闭时触发筛选
14
- */
15
16
  const { open, setOpen } = usePopperContext();
16
17
  useEffect(() => {
17
- !open && formRef.current.submit().then();
18
+ if (!open && 'multiple' in columnFilterProps && columnFilterProps.multiple) {
19
+ // 多选模式下,关闭弹框触发筛选
20
+ formRef.current.submit().then();
21
+ }
18
22
  }, [open]);
19
23
  return (_jsxs(_Fragment, { children: [_jsx(FormItem, { field: columnKey, children: 'control' in columnFilterProps
20
24
  ? columnFilterProps.control
21
- : _jsx(FilterOptions, { ...columnFilterProps }) }), columnFilterProps.showButton !== false
22
- ? _jsx(Flex, { gap: 6, justifyContent: "center", marginTop: 6, children: _jsx(Button, { variant: "text", onClick: () => {
25
+ : _jsx(FilterOptions, { ...columnFilterProps }) }), columnFilterProps.showButton !== false &&
26
+ _jsx(Flex, { gap: 6, justifyContent: "center", marginTop: 6, children: _jsx(Button, { variant: "text", onClick: () => {
23
27
  formRef.current.setFieldValue(columnKey, null);
24
28
  setOpen(false);
25
- }, children: "\u91CD\u7F6E" }) })
26
- : _jsx(TriggerFilterOnChange, {})] }));
29
+ }, children: "\u91CD\u7F6E" }) }), 'multiple' in columnFilterProps && !columnFilterProps.multiple &&
30
+ // 单选模式,变化即触发筛选
31
+ _jsx(TriggerFilterOnChange, { onSubmit: () => setOpen(false) })] }));
27
32
  });
28
- const FilterOptions = memo(({ multiple = true, showButton = true, value, onChange, ...props }) => {
33
+ const FilterOptions = memo(({ multiple = true, showButton = true, searchable = false, value, onChange, ...props }) => {
29
34
  const [selectedValue, toggleSelect] = useFlatSelection({ multiple, value, onChange });
30
- return (_jsx(OptionsBase, { showCheckbox: multiple, ...props, selectedValue: selectedValue, onToggleSelected: toggleSelect }));
35
+ const [searchValue, setSearchValue] = useState('');
36
+ const deferredSearchValue = useDeferredValue(searchValue);
37
+ return (_jsxs("div", { css: style, children: [searchable &&
38
+ _jsx(Input, { prefix: _jsx(Icon, { icon: faSearch }), placeholder: "\u641C\u7D22", value: searchValue, onChange: e => setSearchValue(e.target.value) }), _jsx(OptionsBase, { showCheckbox: multiple, ...props, searchValue: deferredSearchValue, selectedValue: selectedValue, onToggleSelected: toggleSelect })] }));
31
39
  });
32
- const TriggerFilterOnChange = memo(() => {
40
+ function TriggerFilterOnChange(props) {
33
41
  const { formRef } = useFormContext();
34
42
  const { formValue } = useFormValueContext();
35
- useEffect(() => {
43
+ useUpdateEffect(() => {
36
44
  formRef.current.submit().then();
45
+ props.onSubmit?.();
37
46
  }, [formValue]);
38
47
  return null;
39
- });
48
+ }
@@ -0,0 +1 @@
1
+ export declare const style: import("@emotion/react").SerializedStyles;
@@ -0,0 +1,6 @@
1
+ import { css } from '@emotion/react';
2
+ export const style = css `
3
+ display: flex;
4
+ flex-direction: column;
5
+ gap: 4px
6
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.140",
3
+ "version": "0.0.142",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",