funda-ui 3.8.821 → 3.9.14
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/Checkbox/index.js +1 -1
- package/Table/index.css +3 -1
- package/Table/index.js +100 -459
- package/Tree/index.css +4 -1
- package/Tree/index.d.ts +5 -0
- package/Tree/index.js +226 -544
- package/lib/cjs/Checkbox/index.js +1 -1
- package/lib/cjs/Table/index.js +100 -459
- package/lib/cjs/Tree/index.d.ts +5 -0
- package/lib/cjs/Tree/index.js +226 -544
- package/lib/css/Table/index.css +3 -1
- package/lib/css/Tree/index.css +4 -1
- package/lib/esm/Checkbox/index.tsx +1 -1
- package/lib/esm/Table/TableFieldRow.tsx +52 -19
- package/lib/esm/Table/TableHeaders.tsx +24 -14
- package/lib/esm/Table/TableRow.tsx +3 -0
- package/lib/esm/Table/index.scss +4 -1
- package/lib/esm/Table/index.tsx +30 -1
- package/lib/esm/Table/table-utils.ts +8 -0
- package/lib/esm/Tree/TreeList.tsx +122 -108
- package/lib/esm/Tree/index.scss +5 -1
- package/lib/esm/Tree/index.tsx +90 -9
- package/lib/esm/Tree/tree-utils.ts +56 -0
- package/package.json +1 -1
package/lib/css/Table/index.css
CHANGED
|
@@ -79,9 +79,11 @@
|
|
|
79
79
|
min-height: auto;
|
|
80
80
|
margin-bottom: 0;
|
|
81
81
|
}
|
|
82
|
-
.table__wrapper .checkbox-trigger > div .form-check [type=checkbox]:indeterminate
|
|
82
|
+
.table__wrapper .checkbox-trigger > div .form-check [type=checkbox]:indeterminate,
|
|
83
|
+
.table__wrapper .checkbox-trigger > div .form-check [type=checkbox].indeterminate {
|
|
83
84
|
background-color: var(--table-checkbox-indeterminate-color);
|
|
84
85
|
border-color: var(--table-checkbox-indeterminate-color);
|
|
86
|
+
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e");
|
|
85
87
|
}
|
|
86
88
|
.table__wrapper .checkbox-trigger .radio-svg-btn svg,
|
|
87
89
|
.table__wrapper .checkbox-trigger .radio-svg-btn path,
|
package/lib/css/Tree/index.css
CHANGED
|
@@ -84,14 +84,17 @@
|
|
|
84
84
|
}
|
|
85
85
|
.tree-diagram-default .tree-diagram-default-nav .checkbox-trigger > div {
|
|
86
86
|
display: inline-block;
|
|
87
|
+
position: relative;
|
|
87
88
|
}
|
|
88
89
|
.tree-diagram-default .tree-diagram-default-nav .checkbox-trigger > div .form-check {
|
|
89
90
|
min-height: auto;
|
|
90
91
|
margin-bottom: 0;
|
|
91
92
|
}
|
|
92
|
-
.tree-diagram-default .tree-diagram-default-nav .checkbox-trigger > div .form-check [type=checkbox]:indeterminate
|
|
93
|
+
.tree-diagram-default .tree-diagram-default-nav .checkbox-trigger > div .form-check [type=checkbox]:indeterminate,
|
|
94
|
+
.tree-diagram-default .tree-diagram-default-nav .checkbox-trigger > div .form-check [type=checkbox].indeterminate {
|
|
93
95
|
background-color: var(--tree-checkbox-indeterminate-color);
|
|
94
96
|
border-color: var(--tree-checkbox-indeterminate-color);
|
|
97
|
+
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e");
|
|
95
98
|
}
|
|
96
99
|
.tree-diagram-default .tree-diagram-default-nav .arrow {
|
|
97
100
|
cursor: pointer;
|
|
@@ -112,7 +112,7 @@ const Checkbox = forwardRef((props: CheckboxProps, ref: any) => {
|
|
|
112
112
|
return (
|
|
113
113
|
<>
|
|
114
114
|
|
|
115
|
-
<div className={
|
|
115
|
+
<div className={`form-check__wrapper ${wrapperClassName || wrapperClassName === '' ? wrapperClassName : "mb-3 position-relative"} ${val ? (itemSelectedClassName || 'item-selected') : ''}`} ref={rootRef}>
|
|
116
116
|
<div className="form-check">
|
|
117
117
|
<input
|
|
118
118
|
ref={(node) => {
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import React, { useRef, useState, useImperativeHandle } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
// HAS CHECKBOX
|
|
8
4
|
|
|
9
5
|
import { getChildren } from './utils/dom';
|
|
10
|
-
import { removeItemOnce, formatCheckboxControlVal, setCheckboxCheckedData, formatRowControlVal } from './table-utils';
|
|
6
|
+
import { removeItemOnce, formatCheckboxControlVal, setCheckboxCheckedData, formatRowControlVal, getAllCheckboxInput } from './table-utils';
|
|
11
7
|
|
|
12
8
|
|
|
13
9
|
|
|
@@ -18,6 +14,7 @@ type TableFieldRowProps = {
|
|
|
18
14
|
tableCheckRef?: React.RefObject<any>;
|
|
19
15
|
rowActiveClassName?: string;
|
|
20
16
|
fieldsChecked?: boolean[] | boolean;
|
|
17
|
+
fieldsCheckedAct?: any[];
|
|
21
18
|
updateFirstInitCheckboxesClassName?: any;
|
|
22
19
|
draggable?: boolean;
|
|
23
20
|
useRadio?: boolean;
|
|
@@ -51,6 +48,7 @@ const TableFieldRow = (props: TableFieldRowProps) => {
|
|
|
51
48
|
tableCheckRef,
|
|
52
49
|
rowActiveClassName = 'active',
|
|
53
50
|
fieldsChecked,
|
|
51
|
+
fieldsCheckedAct,
|
|
54
52
|
updateFirstInitCheckboxesClassName,
|
|
55
53
|
draggable,
|
|
56
54
|
useRadio,
|
|
@@ -80,6 +78,9 @@ const TableFieldRow = (props: TableFieldRowProps) => {
|
|
|
80
78
|
const contentRef = useRef<any>(null);
|
|
81
79
|
const checkboxRef = useRef<any>(null);
|
|
82
80
|
const [firstInitCheckboxes, setFirstInitCheckboxes] = useState<boolean>(false);
|
|
81
|
+
|
|
82
|
+
//
|
|
83
|
+
const [fieldsCheckedUpdateDataPrint, setFieldsCheckedUpdateDataPrint] = fieldsCheckedAct || [null, null];
|
|
83
84
|
|
|
84
85
|
const rowIndex = rowKey?.replace('row-', '');
|
|
85
86
|
|
|
@@ -243,6 +244,27 @@ const TableFieldRow = (props: TableFieldRowProps) => {
|
|
|
243
244
|
|
|
244
245
|
let _res: any = getCheckedPrint;
|
|
245
246
|
|
|
247
|
+
|
|
248
|
+
// STEP 1:
|
|
249
|
+
// Update checked print from "fieldsChecked"
|
|
250
|
+
// !!! Only one time is allowed
|
|
251
|
+
//-----------
|
|
252
|
+
if (!fieldsCheckedUpdateDataPrint) {
|
|
253
|
+
if (Array.isArray(fieldsChecked)) {
|
|
254
|
+
const _checkboxes: any[] = getAllCheckboxInput(el);
|
|
255
|
+
_checkboxes.forEach((node: any, rowIndex: number) => {
|
|
256
|
+
if (fieldsChecked[Number(rowIndex)] === true) {
|
|
257
|
+
_res.push(formatCheckboxControlVal(node));
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//
|
|
263
|
+
setFieldsCheckedUpdateDataPrint(true);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
246
268
|
// STEP 1:
|
|
247
269
|
// Current checkbox
|
|
248
270
|
//-----------
|
|
@@ -293,6 +315,8 @@ const TableFieldRow = (props: TableFieldRowProps) => {
|
|
|
293
315
|
(e.target.closest('table') as any)?.querySelector('tbody').classList.add('drag-trigger-mousedown');
|
|
294
316
|
}
|
|
295
317
|
|
|
318
|
+
|
|
319
|
+
|
|
296
320
|
return (
|
|
297
321
|
<>
|
|
298
322
|
<th
|
|
@@ -398,19 +422,28 @@ const TableFieldRow = (props: TableFieldRowProps) => {
|
|
|
398
422
|
|
|
399
423
|
|
|
400
424
|
</> : <>
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
425
|
+
|
|
426
|
+
<div className="form-check__wrapper">
|
|
427
|
+
<div className="form-check d-inline-block">
|
|
428
|
+
<input
|
|
429
|
+
type="checkbox"
|
|
430
|
+
className="form-check-input"
|
|
431
|
+
name={`checkbox-${checkboxNamePrefix}-${rowIndex}`}
|
|
432
|
+
ref={checkboxRef}
|
|
433
|
+
tabIndex={-1}
|
|
434
|
+
data-index={`${rowIndex}`}
|
|
435
|
+
data-key={`${rowKey}`}
|
|
436
|
+
value={`${rowKey}`}
|
|
437
|
+
checked={latestCheckedData().filter((cur: any) => cur.key === rowKey)[0]?.checked}
|
|
438
|
+
onChange={(e: any) => {
|
|
439
|
+
checkedAct(e.target, !latestCheckedData().filter((cur: any) => cur.key === rowKey)[0]?.checked);
|
|
440
|
+
}}
|
|
441
|
+
/>
|
|
442
|
+
</div>
|
|
443
|
+
|
|
444
|
+
</div>
|
|
445
|
+
|
|
446
|
+
|
|
414
447
|
</>}
|
|
415
448
|
|
|
416
449
|
</span>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// HAS CHECKBOX
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
import { getChildren } from './utils/dom';
|
|
9
|
-
import { formatCheckboxControlVal, setCheckboxCheckedData } from './table-utils';
|
|
9
|
+
import { formatCheckboxControlVal, setCheckboxCheckedData, getAllCheckboxInput } from './table-utils';
|
|
10
10
|
|
|
11
11
|
/* Table Headers
|
|
12
12
|
-------------------------------------------------*/
|
|
@@ -78,8 +78,8 @@ const TableHeaders = (props: TableHeadersProps) => {
|
|
|
78
78
|
// STEP 2:
|
|
79
79
|
// All child checkboxes
|
|
80
80
|
//-----------
|
|
81
|
-
const _checkboxes =
|
|
82
|
-
|
|
81
|
+
const _checkboxes: any[] = getAllCheckboxInput(el);
|
|
82
|
+
_checkboxes.forEach((node: any) => {
|
|
83
83
|
if (val === true) {
|
|
84
84
|
setCheckboxCheckedData(_checkedData, node.dataset.key, true);
|
|
85
85
|
_res.push(formatCheckboxControlVal(node));
|
|
@@ -143,16 +143,26 @@ const TableHeaders = (props: TableHeadersProps) => {
|
|
|
143
143
|
}}
|
|
144
144
|
>
|
|
145
145
|
{i === 0 ? <span className="checkbox-trigger" style={{visibility: useRadio ? 'hidden' : 'visible'}}>
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
146
|
+
|
|
147
|
+
<div className="form-check__wrapper">
|
|
148
|
+
<div className="form-check d-inline-block">
|
|
149
|
+
<input
|
|
150
|
+
type="checkbox"
|
|
151
|
+
className="form-check-input"
|
|
152
|
+
name={`checkbox-${checkboxNamePrefix}-all`}
|
|
153
|
+
tabIndex={-1}
|
|
154
|
+
value={`row-all`}
|
|
155
|
+
checked={getCheckedRootData!.filter((cur: any) => cur.key === 'row-all')[0]?.checked}
|
|
156
|
+
onChange={(e: any) => {
|
|
157
|
+
checkedAct(e.target, !getCheckedRootData!.filter((cur: any) => cur.key === 'row-all')[0]?.checked);
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
|
|
156
166
|
</span> : null}
|
|
157
167
|
<span dangerouslySetInnerHTML={{ __html: `${item.content}` }}></span>
|
|
158
168
|
{sortable && itemSortable ? <span className="sort-trigger" onClick={evSort}><svg width="1em" height="1em" viewBox="0 0 18 18">
|
|
@@ -14,6 +14,7 @@ type TableRowProps = {
|
|
|
14
14
|
tableCheckRef?: React.RefObject<any>;
|
|
15
15
|
rowActiveClassName?: string;
|
|
16
16
|
fieldsChecked?: boolean[] | boolean;
|
|
17
|
+
fieldsCheckedAct?: any[];
|
|
17
18
|
index: React.Key;
|
|
18
19
|
data?: any[];
|
|
19
20
|
headerLabel?: any[];
|
|
@@ -46,6 +47,7 @@ const TableRow = (props: TableRowProps) => {
|
|
|
46
47
|
tableCheckRef,
|
|
47
48
|
rowActiveClassName = 'active',
|
|
48
49
|
fieldsChecked,
|
|
50
|
+
fieldsCheckedAct,
|
|
49
51
|
index,
|
|
50
52
|
data,
|
|
51
53
|
headerLabel,
|
|
@@ -128,6 +130,7 @@ const TableRow = (props: TableRowProps) => {
|
|
|
128
130
|
tableCheckRef={tableCheckRef}
|
|
129
131
|
rowActiveClassName={rowActiveClassName}
|
|
130
132
|
fieldsChecked={fieldsChecked}
|
|
133
|
+
fieldsCheckedAct={fieldsCheckedAct}
|
|
131
134
|
updateFirstInitCheckboxesClassName={setFirstInitCheckboxesClassName}
|
|
132
135
|
useRadio={useRadio}
|
|
133
136
|
columnHeader={typeof headerItem.content === 'string' ? headerItem.content.replace(/(<([^>]+)>)/ig, '') : headerItem.content}
|
package/lib/esm/Table/index.scss
CHANGED
|
@@ -101,9 +101,12 @@
|
|
|
101
101
|
min-height: auto;
|
|
102
102
|
margin-bottom: 0;
|
|
103
103
|
|
|
104
|
-
[type=checkbox]:indeterminate
|
|
104
|
+
[type=checkbox]:indeterminate,
|
|
105
|
+
[type=checkbox].indeterminate {
|
|
105
106
|
background-color: var(--table-checkbox-indeterminate-color);
|
|
106
107
|
border-color: var(--table-checkbox-indeterminate-color);
|
|
108
|
+
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10h8'/%3e%3c/svg%3e");
|
|
109
|
+
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
}
|
package/lib/esm/Table/index.tsx
CHANGED
|
@@ -95,6 +95,7 @@ const Table = (props: TableProps) => {
|
|
|
95
95
|
const [checkedRootData, setCheckedRootData] = useState<any[]>([]);
|
|
96
96
|
const [sortData, setSortData] = useState<any[] | undefined>([]);
|
|
97
97
|
const [mainUpdate, setMainUpdate] = useState<boolean>(false);
|
|
98
|
+
const [fieldsCheckedUpdateDataPrint, setFieldsCheckedUpdateDataPrint] = useState<boolean>(false);
|
|
98
99
|
|
|
99
100
|
const windowResizeUpdate = debounce(handleWindowUpdate, 50);
|
|
100
101
|
|
|
@@ -104,6 +105,8 @@ const Table = (props: TableProps) => {
|
|
|
104
105
|
let windowWidth = typeof window !== 'undefined' ? window.innerWidth : 0;
|
|
105
106
|
|
|
106
107
|
|
|
108
|
+
//
|
|
109
|
+
|
|
107
110
|
//Set the class names of different styles
|
|
108
111
|
//
|
|
109
112
|
let tableClasses = '';
|
|
@@ -208,11 +211,24 @@ const Table = (props: TableProps) => {
|
|
|
208
211
|
//get maxHeight of per row
|
|
209
212
|
for (let i = 0; i < tbodyRef.current.querySelector('tr').children.length; i++ ) {
|
|
210
213
|
const tbodyRows = rootRef.current.querySelectorAll(`tbody tr [data-table-col="${i}"]`);
|
|
214
|
+
const curColDisplay = window.getComputedStyle(tbodyRows, null).display;
|
|
215
|
+
|
|
216
|
+
// default display attribute
|
|
217
|
+
let curColDisplayVal = curColDisplay;
|
|
218
|
+
if (typeof tbodyRows.dataset.show === 'undefined') {
|
|
219
|
+
tbodyRows.dataset.show = curColDisplay;
|
|
220
|
+
} else {
|
|
221
|
+
curColDisplayVal = tbodyRows.dataset.show;
|
|
222
|
+
}
|
|
223
|
+
tbodyRows.style.display = curColDisplayVal;
|
|
224
|
+
|
|
225
|
+
//
|
|
211
226
|
const maxHeight = maxDimension(tbodyRows).height;
|
|
212
227
|
[].slice.call(tbodyRows).forEach((row: any) => {
|
|
213
228
|
row.style.height = maxHeight + 'px';
|
|
214
229
|
});
|
|
215
230
|
|
|
231
|
+
|
|
216
232
|
//
|
|
217
233
|
const theadRows = rootRef.current.querySelectorAll(`thead tr [data-table-col="${i}"]`);
|
|
218
234
|
[].slice.call(theadRows).forEach((row: any) => {
|
|
@@ -222,7 +238,19 @@ const Table = (props: TableProps) => {
|
|
|
222
238
|
|
|
223
239
|
} else {
|
|
224
240
|
[].slice.call(rootRef.current.querySelectorAll('tbody td, tbody th, thead th')).forEach((node: any, i: number) => {
|
|
225
|
-
|
|
241
|
+
const curColDisplay = window.getComputedStyle(node, null).display;
|
|
242
|
+
|
|
243
|
+
// default display attribute
|
|
244
|
+
let curColDisplayVal = curColDisplay;
|
|
245
|
+
if (typeof node.dataset.show === 'undefined') {
|
|
246
|
+
node.dataset.show = curColDisplay;
|
|
247
|
+
} else {
|
|
248
|
+
curColDisplayVal = node.dataset.show;
|
|
249
|
+
}
|
|
250
|
+
node.style.display = curColDisplayVal;
|
|
251
|
+
|
|
252
|
+
//
|
|
253
|
+
node.style.removeProperty('height');
|
|
226
254
|
});
|
|
227
255
|
}
|
|
228
256
|
|
|
@@ -582,6 +610,7 @@ const Table = (props: TableProps) => {
|
|
|
582
610
|
tableCheckRef={tableCheckRef}
|
|
583
611
|
rowActiveClassName={rowActiveClassName}
|
|
584
612
|
fieldsChecked={_fieldsChecked}
|
|
613
|
+
fieldsCheckedAct={[fieldsCheckedUpdateDataPrint, setFieldsCheckedUpdateDataPrint]}
|
|
585
614
|
rowKey={`row-${i}`}
|
|
586
615
|
headerLabel={_headers}
|
|
587
616
|
data={item}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getChildren } from './utils/dom';
|
|
1
2
|
|
|
2
3
|
export const removeItemOnce = (arr: any[], key: string) => {
|
|
3
4
|
return arr.filter((item: any) => {
|
|
@@ -63,3 +64,10 @@ export const setCheckboxCheckedData = (arr: any[], key: string, val: boolean) =>
|
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
66
|
|
|
67
|
+
|
|
68
|
+
export const getAllCheckboxInput = (el: any) => {
|
|
69
|
+
if (el === null) return [];
|
|
70
|
+
const _checkboxes = getChildren(el.closest('table').querySelector('tbody'), '[type="checkbox"]');
|
|
71
|
+
return [].slice.call(_checkboxes);
|
|
72
|
+
|
|
73
|
+
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useCallback } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// HAS CHECKBOX
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { getNextSiblings, getParents, getChildren } from './utils/dom';
|
|
6
|
+
import { getNextSiblings, getPreviousSiblings, getParents, getChildren } from './utils/dom';
|
|
9
7
|
|
|
10
8
|
import { initUlHeight } from './init-height';
|
|
9
|
+
import { removeItemOnce, activeClass } from './tree-utils';
|
|
11
10
|
|
|
12
11
|
interface fetchConfig {
|
|
13
12
|
fetchFuncAsync?: any | undefined;
|
|
@@ -71,13 +70,6 @@ export default function TreeList(props: TreeListProps) {
|
|
|
71
70
|
const loadingIcon: React.ReactNode = <var className="loading-icon"><svg width="1em" height="1em" viewBox="0 0 512 512"><g><path fill="currentColor" d="M256,0c-23.357,0-42.297,18.932-42.297,42.288c0,23.358,18.94,42.288,42.297,42.288c23.357,0,42.279-18.93,42.279-42.288C298.279,18.932,279.357,0,256,0z"/><path fill="currentColor" d="M256,427.424c-23.357,0-42.297,18.931-42.297,42.288C213.703,493.07,232.643,512,256,512c23.357,0,42.279-18.93,42.279-42.288C298.279,446.355,279.357,427.424,256,427.424z"/><path fill="currentColor" d="M74.974,74.983c-16.52,16.511-16.52,43.286,0,59.806c16.52,16.52,43.287,16.52,59.806,0c16.52-16.511,16.52-43.286,0-59.806C118.261,58.463,91.494,58.463,74.974,74.983z"/><path fill="currentColor" d="M377.203,377.211c-16.503,16.52-16.503,43.296,0,59.815c16.519,16.52,43.304,16.52,59.806,0c16.52-16.51,16.52-43.295,0-59.815C420.489,360.692,393.722,360.7,377.203,377.211z"/><path fill="currentColor" d="M84.567,256c0.018-23.348-18.922-42.279-42.279-42.279c-23.357-0.009-42.297,18.932-42.279,42.288c-0.018,23.348,18.904,42.279,42.279,42.279C65.645,298.288,84.567,279.358,84.567,256z"/><path fill="currentColor" d="M469.712,213.712c-23.357,0-42.279,18.941-42.297,42.288c0,23.358,18.94,42.288,42.297,42.297c23.357,0,42.297-18.94,42.279-42.297C512.009,232.652,493.069,213.712,469.712,213.712z"/><path fill="currentColor" d="M74.991,377.22c-16.519,16.511-16.519,43.296,0,59.806c16.503,16.52,43.27,16.52,59.789,0c16.52-16.519,16.52-43.295,0-59.815C118.278,360.692,91.511,360.692,74.991,377.22z"/><path fill="currentColor" d="M437.026,134.798c16.52-16.52,16.52-43.304,0-59.824c-16.519-16.511-43.304-16.52-59.823,0c-16.52,16.52-16.503,43.295,0,59.815C393.722,151.309,420.507,151.309,437.026,134.798z"/></g></svg></var>;
|
|
72
71
|
|
|
73
72
|
|
|
74
|
-
const removeItemOnce = (arr: any[], key: string) => {
|
|
75
|
-
return arr.filter((item: any) => {
|
|
76
|
-
return item.key !== key;
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
|
|
81
73
|
const formatCheckboxControlVal = (el: HTMLFormElement) => {
|
|
82
74
|
return {
|
|
83
75
|
name: el.dataset.name?.replace(/-label$/, ''),
|
|
@@ -115,7 +107,7 @@ export default function TreeList(props: TreeListProps) {
|
|
|
115
107
|
//---
|
|
116
108
|
_parentsLi.forEach((node: any) => {
|
|
117
109
|
const _checkboxes = getChildren(node, '[type="checkbox"]');
|
|
118
|
-
const parentKey = _checkboxes[0].dataset.key;
|
|
110
|
+
const parentKey = typeof _checkboxes[0] === 'undefined' ? '' : _checkboxes[0].dataset.key;
|
|
119
111
|
|
|
120
112
|
|
|
121
113
|
//
|
|
@@ -158,13 +150,6 @@ export default function TreeList(props: TreeListProps) {
|
|
|
158
150
|
|
|
159
151
|
};
|
|
160
152
|
|
|
161
|
-
const activeClass = (el: any, mode: string, classname: string = 'active') => {
|
|
162
|
-
if ( mode === 'add' ) {
|
|
163
|
-
el.classList.add(classname);
|
|
164
|
-
} else {
|
|
165
|
-
el.classList.remove(classname);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
153
|
|
|
169
154
|
const closeChild = (hyperlink: HTMLElement, ul: HTMLAllCollection) => {
|
|
170
155
|
if ( ul.length === 0 ) return;
|
|
@@ -295,6 +280,84 @@ export default function TreeList(props: TreeListProps) {
|
|
|
295
280
|
|
|
296
281
|
}
|
|
297
282
|
|
|
283
|
+
function checkedAct(el: any, val: any) {
|
|
284
|
+
|
|
285
|
+
if (el === null) return;
|
|
286
|
+
|
|
287
|
+
const _curKey: string = el.dataset.key;
|
|
288
|
+
const _checkedData: any = getCheckedData;
|
|
289
|
+
|
|
290
|
+
let _res: any = getCheckedPrint;
|
|
291
|
+
|
|
292
|
+
// STEP 1:
|
|
293
|
+
// Current checkbox
|
|
294
|
+
//-----------
|
|
295
|
+
if ( val === true ) {
|
|
296
|
+
_res.push(formatCheckboxControlVal(el));
|
|
297
|
+
setCheckboxIndeterminateData(_checkedData, _curKey, false);
|
|
298
|
+
setCheckboxCheckedData(_checkedData, _curKey, true);
|
|
299
|
+
|
|
300
|
+
} else {
|
|
301
|
+
setCheckboxCheckedData(_checkedData, _curKey, false);
|
|
302
|
+
_res = removeItemOnce(_res, _curKey);
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
// STEP 2:
|
|
308
|
+
// All child checkboxes
|
|
309
|
+
//-----------
|
|
310
|
+
[].slice.call(getChildren(el.closest('li'), '[type="checkbox"]')).forEach((node: any) => {
|
|
311
|
+
if ( val === true ) {
|
|
312
|
+
if ( node.dataset.key !== _curKey ) {
|
|
313
|
+
setCheckboxIndeterminateData(_checkedData, node.dataset.key, false);
|
|
314
|
+
setCheckboxCheckedData(_checkedData, node.dataset.key, true);
|
|
315
|
+
_res.push(formatCheckboxControlVal(node));
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
setCheckboxCheckedData(_checkedData, node.dataset.key, false);
|
|
319
|
+
_res = removeItemOnce(_res, node.dataset.key);
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
// STEP 3:
|
|
327
|
+
// ALl parent checkboxes
|
|
328
|
+
//-----------
|
|
329
|
+
const [updatedCheckedData, updatedPrintData] = setCheckboxIndeterminateStatus(_checkedData, _res, el);
|
|
330
|
+
let _updatedCheckedData: any[] = updatedCheckedData;
|
|
331
|
+
let _updatedPrintData: any[] = updatedPrintData;
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
// STEP 4:
|
|
335
|
+
// Update checked data
|
|
336
|
+
//-----------
|
|
337
|
+
updategetCheckedData(_updatedCheckedData);
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
// STEP 5:
|
|
341
|
+
// Array deduplication
|
|
342
|
+
//-----------
|
|
343
|
+
_updatedPrintData = _updatedPrintData.filter((item: any, index: number, self: any[]) => index === self.findIndex((t) => (t.key === item.key)))
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
// STEP 6:
|
|
347
|
+
// Update checked print
|
|
348
|
+
//-----------
|
|
349
|
+
updateCheckedPrint(_updatedPrintData);
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
// STEP 7:
|
|
353
|
+
// callback
|
|
354
|
+
//-----------
|
|
355
|
+
onCheck?.(_updatedPrintData);
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
298
361
|
|
|
299
362
|
useEffect(() => {
|
|
300
363
|
|
|
@@ -335,10 +398,11 @@ export default function TreeList(props: TreeListProps) {
|
|
|
335
398
|
// Initialize indeterminate status of all checkboxes
|
|
336
399
|
//=====================
|
|
337
400
|
setCheckboxIndeterminateStatus(getCheckedData as never, getCheckedPrint as never, null);
|
|
338
|
-
|
|
339
|
-
|
|
401
|
+
|
|
340
402
|
}, [data]);
|
|
341
403
|
|
|
404
|
+
|
|
405
|
+
|
|
342
406
|
|
|
343
407
|
if ( data ) {
|
|
344
408
|
|
|
@@ -353,8 +417,19 @@ export default function TreeList(props: TreeListProps) {
|
|
|
353
417
|
|
|
354
418
|
|
|
355
419
|
if ( item.heading ) return (
|
|
356
|
-
<li
|
|
357
|
-
|
|
420
|
+
<li
|
|
421
|
+
className={`nav-item ${first ? 'first' : ''}`}
|
|
422
|
+
key={item.key}
|
|
423
|
+
>
|
|
424
|
+
<a
|
|
425
|
+
tabIndex={-1}
|
|
426
|
+
className="nav-link disabled"
|
|
427
|
+
href="#"
|
|
428
|
+
aria-disabled="true"
|
|
429
|
+
data-link={item.link}
|
|
430
|
+
data-slug={item.slug}
|
|
431
|
+
data-key={item.key}
|
|
432
|
+
>
|
|
358
433
|
<span>{item.icon ? item.icon.indexOf('</svg>') < 0 ? <><i className={item.icon}></i> </> : <var dangerouslySetInnerHTML={{ __html: `${item.icon}` }} /> : null}<i dangerouslySetInnerHTML={{ __html: `${item.title}` }}></i></span>
|
|
359
434
|
</a>
|
|
360
435
|
</li>
|
|
@@ -370,94 +445,33 @@ export default function TreeList(props: TreeListProps) {
|
|
|
370
445
|
{(item.children && item.children.length) || item.childrenAsync ? <span aria-expanded={item.active ? 'true' : 'false'} className={item.active ? `arrow active ${_async} ${_cusIcons}` : `arrow ${_async} ${_cusIcons}`} onClick={handleCollapse} data-link={item.link} data-slug={item.slug} data-key={item.key}>{arrowGenerator()}</span> : ''}
|
|
371
446
|
|
|
372
447
|
<span className="checkbox-trigger">
|
|
373
|
-
<Checkbox
|
|
374
|
-
wrapperClassName=""
|
|
375
|
-
name={`checkbox-${checkboxNamePrefix}-${item.key}`}
|
|
376
|
-
tabIndex={-1}
|
|
377
|
-
data-key={item.key}
|
|
378
|
-
data-link={item.link}
|
|
379
|
-
value={item.slug}
|
|
380
|
-
indeterminate={getCheckedData!.filter((cur: any) => cur.key === item.key)[0]?.indeterminate}
|
|
381
|
-
checked={getCheckedData!.filter((cur: any) => cur.key === item.key)[0]?.checked}
|
|
382
|
-
onChange={(e: any, val: any) => {
|
|
383
|
-
|
|
384
|
-
const _curKey: string = e.target.dataset.key;
|
|
385
|
-
const _checkedData: any = getCheckedData;
|
|
386
|
-
|
|
387
|
-
let _res: any = getCheckedPrint;
|
|
388
|
-
|
|
389
|
-
// STEP 1:
|
|
390
|
-
// Current checkbox
|
|
391
|
-
//-----------
|
|
392
|
-
if ( val === true ) {
|
|
393
|
-
_res.push(formatCheckboxControlVal(e.target));
|
|
394
|
-
setCheckboxIndeterminateData(_checkedData, _curKey, false);
|
|
395
|
-
setCheckboxCheckedData(_checkedData, _curKey, true);
|
|
396
|
-
|
|
397
|
-
} else {
|
|
398
|
-
setCheckboxCheckedData(_checkedData, _curKey, false);
|
|
399
|
-
_res = removeItemOnce(_res, _curKey);
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
// STEP 2:
|
|
405
|
-
// All child checkboxes
|
|
406
|
-
//-----------
|
|
407
|
-
[].slice.call(getChildren(e.target.closest('li'), '[type="checkbox"]')).forEach((node: any) => {
|
|
408
|
-
if ( val === true ) {
|
|
409
|
-
if ( node.dataset.key !== _curKey ) {
|
|
410
|
-
setCheckboxIndeterminateData(_checkedData, node.dataset.key, false);
|
|
411
|
-
setCheckboxCheckedData(_checkedData, node.dataset.key, true);
|
|
412
|
-
_res.push(formatCheckboxControlVal(node));
|
|
413
|
-
}
|
|
414
|
-
} else {
|
|
415
|
-
setCheckboxCheckedData(_checkedData, node.dataset.key, false);
|
|
416
|
-
_res = removeItemOnce(_res, node.dataset.key);
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
// STEP 3:
|
|
424
|
-
// ALl parent checkboxes
|
|
425
|
-
//-----------
|
|
426
|
-
const [updatedCheckedData, updatedPrintData] = setCheckboxIndeterminateStatus(_checkedData, _res, e.target);
|
|
427
|
-
let _updatedCheckedData: any[] = updatedCheckedData;
|
|
428
|
-
let _updatedPrintData: any[] = updatedPrintData;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
// STEP 4:
|
|
432
|
-
// Update checked data
|
|
433
|
-
//-----------
|
|
434
|
-
updategetCheckedData(_updatedCheckedData);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
// STEP 5:
|
|
438
|
-
// Array deduplication
|
|
439
|
-
//-----------
|
|
440
|
-
_updatedPrintData = _updatedPrintData.filter((item: any, index: number, self: any[]) => index === self.findIndex((t) => (t.key === item.key)))
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
// STEP 6:
|
|
444
|
-
// Update checked print
|
|
445
|
-
//-----------
|
|
446
|
-
updateCheckedPrint(_updatedPrintData);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
// STEP 7:
|
|
450
|
-
// callback
|
|
451
|
-
//-----------
|
|
452
|
-
onCheck?.(_updatedPrintData);
|
|
453
|
-
}}
|
|
454
|
-
/>
|
|
455
|
-
</span>
|
|
456
448
|
|
|
457
|
-
|
|
449
|
+
<div className="form-check__wrapper">
|
|
450
|
+
<div className="form-check d-inline-block">
|
|
451
|
+
<input
|
|
452
|
+
type="checkbox"
|
|
453
|
+
className={`form-check-input ${getCheckedData!.filter((cur: any) => cur.key === item.key)[0]?.indeterminate ? 'indeterminate' : ''}`}
|
|
454
|
+
name={`checkbox-${checkboxNamePrefix}-${item.key}`}
|
|
455
|
+
tabIndex={-1}
|
|
456
|
+
data-name={`checkbox-${checkboxNamePrefix}-${item.key}`}
|
|
457
|
+
data-key={item.key}
|
|
458
|
+
data-link={item.link}
|
|
459
|
+
value={item.slug}
|
|
460
|
+
checked={getCheckedData!.filter((cur: any) => cur.key === item.key)[0]?.checked}
|
|
461
|
+
onChange={(e: any) => {
|
|
462
|
+
checkedAct(e.target, !getCheckedData!.filter((cur: any) => cur.key === item.key)[0]?.checked);
|
|
463
|
+
}}
|
|
464
|
+
/>
|
|
465
|
+
|
|
466
|
+
</div>
|
|
467
|
+
|
|
468
|
+
</div>
|
|
469
|
+
|
|
470
|
+
</span>
|
|
471
|
+
|
|
458
472
|
<a
|
|
459
473
|
tabIndex={-1}
|
|
460
|
-
className={
|
|
474
|
+
className={`nav-link ${_async} ${item.selected ? 'selected' : ''} ${item.active ? 'active': ''}`}
|
|
461
475
|
href={item.link === '#' ? `${item.link}-${i}` : item.link}
|
|
462
476
|
aria-expanded="false"
|
|
463
477
|
onClick={handleSelect}
|