@rainbow-oh/yee-c 0.8.10 → 0.8.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-oh/yee-c",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "description": "yee basic components",
5
5
  "keywords": [
6
6
  "react",
@@ -1,15 +1,24 @@
1
1
  import { useMemo, useState } from 'react';
2
2
 
3
+ type FilterValue = string | number;
4
+ type FilterInput = FilterValue | FilterValue[];
5
+
3
6
  type FilterOptions = {
4
7
  dataIndex: string;
5
- value: string;
8
+ value: FilterInput;
6
9
  };
7
10
 
8
11
  type FilterRecord = {
9
- value: string;
12
+ value: FilterInput;
10
13
  dataIndex: string;
11
14
  };
12
15
 
16
+ const isEmptyFilterValue = (value: FilterInput) =>
17
+ value === '' || (Array.isArray(value) && value.length === 0);
18
+
19
+ const normalizeValue = (value: unknown) =>
20
+ value === null || value === undefined ? '' : String(value).toLowerCase();
21
+
13
22
  export default function useFilter({
14
23
  data,
15
24
  }: {
@@ -18,7 +27,7 @@ export default function useFilter({
18
27
  const [filterRecords, setFilterRecords] = useState<Array<FilterRecord>>([]);
19
28
  const onFilter = ({ value, dataIndex }: FilterOptions) => {
20
29
  let newFilterMap = [...filterRecords];
21
- if (!value || (Array.isArray(value) && !value.length)) {
30
+ if (isEmptyFilterValue(value)) {
22
31
  newFilterMap = newFilterMap.filter(
23
32
  (item) => item.dataIndex !== dataIndex,
24
33
  );
@@ -40,23 +49,23 @@ export default function useFilter({
40
49
 
41
50
  const filtered = useMemo(() => {
42
51
  const handled = filterRecords.filter(
43
- (item) => item.dataIndex && item.value,
52
+ ({ dataIndex, value }) =>
53
+ Boolean(dataIndex) && !isEmptyFilterValue(value),
44
54
  );
45
55
  if (!handled.length) {
46
56
  return data;
47
57
  }
48
58
  return data.filter((item) => {
49
- return handled.find((o) => {
50
- if (Array.isArray(o.value)) {
51
- return o.value.some((v) => {
52
- const t = item[o.dataIndex] || '';
53
- return (t as string).toLowerCase() === v.toLowerCase();
54
- });
55
- } else {
56
- const v = o.value.toLowerCase();
57
- const t = item[o.dataIndex] || '';
58
- return (t as string).toLowerCase().includes(v);
59
+ return handled.some(({ dataIndex, value }) => {
60
+ const targetValue = normalizeValue(item[dataIndex]);
61
+
62
+ if (Array.isArray(value)) {
63
+ return value.some(
64
+ (filterValue) => targetValue === normalizeValue(filterValue),
65
+ );
59
66
  }
67
+
68
+ return targetValue.includes(normalizeValue(value));
60
69
  });
61
70
  });
62
71
  }, [data, filterRecords]);
@@ -72,14 +72,13 @@
72
72
  }
73
73
 
74
74
  &-filter {
75
+ max-height: var(--yee-table-filter-popup-height);
76
+ background-color: var(--yee-table-filter-list-bg-color);
77
+
75
78
  &-trigger {
76
79
  display: inline-flex;
77
80
  cursor: pointer;
78
81
  }
79
-
80
- &-popup {
81
- background-color: var(--yee-table-filter-list-bg-color);
82
- }
83
82
  }
84
83
 
85
84
  &-content {
@@ -189,7 +189,7 @@ const HeaderFilter = React.memo((props: any) => {
189
189
  <Popover
190
190
  trigger="click"
191
191
  placement="bottomRight"
192
- popupClassName={clsx(`${prefixCls}-filter`)}
192
+ className={`${prefixCls}-filter`}
193
193
  content={popup}
194
194
  arrow
195
195
  open={open}
@@ -403,6 +403,7 @@
403
403
  --yee-popover-header-line-height: 24px;
404
404
  --yee-popover-arrow-width: var(--yee-popup-arrow-width);
405
405
  --yee-popover-arrow-height: var(--yee-popup-arrow-height);
406
+ --yee-table-filter-popup-height: 400px;
406
407
 
407
408
  /* --Progress-- */
408
409
  --yee-progress-text-width: 48px;
package/src/version.ts CHANGED
@@ -4,7 +4,7 @@ declare global {
4
4
  }
5
5
  }
6
6
 
7
- export const version = "0.8.10";
7
+ export const version = "0.8.12";
8
8
 
9
9
  if (typeof window !== 'undefined') {
10
10
  window.__yee_c_version__ = version;