funda-ui 4.2.375 → 4.2.445
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/MultilevelDropdownMenu/index.css +2 -2
- package/MultilevelDropdownMenu/index.js +54 -46
- package/MultipleSelect/index.css +35 -26
- package/MultipleSelect/index.d.ts +3 -0
- package/MultipleSelect/index.js +366 -134
- package/lib/cjs/MultilevelDropdownMenu/index.js +54 -46
- package/lib/cjs/MultipleSelect/index.d.ts +3 -0
- package/lib/cjs/MultipleSelect/index.js +366 -134
- package/lib/css/MultilevelDropdownMenu/index.css +2 -2
- package/lib/css/MultipleSelect/index.css +35 -26
- package/lib/esm/MultilevelDropdownMenu/{MenuList.tsx → ItemList.tsx} +52 -45
- package/lib/esm/MultilevelDropdownMenu/index.scss +2 -2
- package/lib/esm/MultilevelDropdownMenu/index.tsx +12 -4
- package/lib/esm/MultipleSelect/ItemList.tsx +300 -0
- package/lib/esm/MultipleSelect/index.scss +61 -30
- package/lib/esm/MultipleSelect/index.tsx +56 -87
- package/lib/esm/MultipleSelect/multiple-select-utils/func.ts +29 -0
- package/package.json +1 -1
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
border-radius: 0.35rem;
|
|
31
31
|
position: relative;
|
|
32
32
|
background: var(--m-select-body-bg);
|
|
33
|
+
/*-------- Multilevel --------*/
|
|
33
34
|
/*-------- List --------*/
|
|
34
35
|
}
|
|
35
36
|
.m-select__wrapper .m-select-diving-line {
|
|
@@ -74,8 +75,7 @@
|
|
|
74
75
|
cursor: default;
|
|
75
76
|
position: relative;
|
|
76
77
|
font-size: var(--m-select-body-font-size);
|
|
77
|
-
display:
|
|
78
|
-
justify-content: space-between;
|
|
78
|
+
display: block;
|
|
79
79
|
background: var(--m-select-options-item-bg);
|
|
80
80
|
border-bottom: 1px solid var(--m-select-options-item-dividingline-color);
|
|
81
81
|
}
|
|
@@ -99,37 +99,34 @@
|
|
|
99
99
|
.m-select__wrapper .m-select-inner li:last-child {
|
|
100
100
|
border-bottom: none;
|
|
101
101
|
}
|
|
102
|
-
.m-select__wrapper .m-select-inner li >
|
|
102
|
+
.m-select__wrapper .m-select-inner li > div {
|
|
103
103
|
padding: 0.35rem 0.75rem;
|
|
104
|
-
display:
|
|
105
|
-
|
|
104
|
+
display: flex;
|
|
105
|
+
justify-content: space-between;
|
|
106
|
+
width: 100%;
|
|
106
107
|
overflow: hidden;
|
|
107
108
|
text-overflow: ellipsis;
|
|
108
109
|
word-wrap: break-word;
|
|
109
110
|
word-break: break-word;
|
|
110
111
|
}
|
|
111
|
-
.m-select__wrapper .m-select-inner li > strong {
|
|
112
|
+
.m-select__wrapper .m-select-inner li > div > strong {
|
|
112
113
|
font-weight: normal;
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
113
116
|
}
|
|
114
|
-
.m-select__wrapper .m-select-inner li >
|
|
117
|
+
.m-select__wrapper .m-select-inner li > div > strong .arrow {
|
|
115
118
|
display: inline-block;
|
|
116
|
-
|
|
117
|
-
cursor: pointer;
|
|
119
|
+
margin-left: 0.2rem;
|
|
118
120
|
}
|
|
119
|
-
.m-select__wrapper .m-select-inner li >
|
|
120
|
-
|
|
121
|
+
.m-select__wrapper .m-select-inner li > div.active .arrow {
|
|
122
|
+
transform: rotate(90deg);
|
|
121
123
|
}
|
|
122
|
-
.m-select__wrapper .m-select-inner li
|
|
123
|
-
|
|
124
|
-
text-decoration: none;
|
|
125
|
-
padding: 0;
|
|
126
|
-
display: block;
|
|
124
|
+
.m-select__wrapper .m-select-inner li > div > i {
|
|
125
|
+
display: inline-block;
|
|
127
126
|
cursor: pointer;
|
|
128
127
|
}
|
|
129
|
-
.m-select__wrapper .m-select-inner li
|
|
130
|
-
|
|
131
|
-
right: 0.5rem;
|
|
132
|
-
top: 0.5rem;
|
|
128
|
+
.m-select__wrapper .m-select-inner li > div > i svg path {
|
|
129
|
+
fill: var(--m-select-options-item-icon-color);
|
|
133
130
|
}
|
|
134
131
|
.m-select__wrapper .m-select-inner div.m-select__selected__container .m-select__header {
|
|
135
132
|
border-radius: 0 0.35rem 0 0;
|
|
@@ -186,26 +183,38 @@
|
|
|
186
183
|
.m-select__wrapper .m-select-inner .m-select__search__container i svg {
|
|
187
184
|
fill: var(--m-select-search-icon-color);
|
|
188
185
|
}
|
|
189
|
-
.m-select__wrapper .m-select__options-contentlist {
|
|
186
|
+
.m-select__wrapper ul.m-select__options-contentlist > li ul {
|
|
187
|
+
transition: max-height 0.25s ease;
|
|
188
|
+
overflow: hidden;
|
|
189
|
+
position: relative;
|
|
190
|
+
padding-left: 1rem;
|
|
191
|
+
}
|
|
192
|
+
.m-select__wrapper ul.m-select__options-contentlist > li:not(.active) ul {
|
|
193
|
+
max-height: 0;
|
|
194
|
+
}
|
|
195
|
+
.m-select__wrapper ul.m-select__options-contentlist > li ul ul {
|
|
196
|
+
margin-top: auto;
|
|
197
|
+
}
|
|
198
|
+
.m-select__wrapper ul.m-select__options-contentlist {
|
|
190
199
|
position: relative;
|
|
191
200
|
width: 100%;
|
|
192
201
|
overflow: hidden;
|
|
193
202
|
overflow-y: auto;
|
|
194
203
|
max-height: calc(315px - 1.75rem);
|
|
195
204
|
}
|
|
196
|
-
.m-select__wrapper .m-select__options-contentlist::-webkit-scrollbar {
|
|
205
|
+
.m-select__wrapper ul.m-select__options-contentlist::-webkit-scrollbar {
|
|
197
206
|
width: var(--m-select-scrollbar-w);
|
|
198
207
|
}
|
|
199
|
-
.m-select__wrapper .m-select__options-contentlist::-webkit-scrollbar-thumb {
|
|
208
|
+
.m-select__wrapper ul.m-select__options-contentlist::-webkit-scrollbar-thumb {
|
|
200
209
|
background: var(--m-select-scrollbar-color);
|
|
201
210
|
}
|
|
202
|
-
.m-select__wrapper .m-select__options-contentlist::-webkit-scrollbar-track {
|
|
211
|
+
.m-select__wrapper ul.m-select__options-contentlist::-webkit-scrollbar-track {
|
|
203
212
|
background: var(--m-select-scrollbar-track);
|
|
204
213
|
}
|
|
205
|
-
.m-select__wrapper .m-select__options-contentlist.dragging {
|
|
214
|
+
.m-select__wrapper ul.m-select__options-contentlist.dragging {
|
|
206
215
|
cursor: grab;
|
|
207
216
|
}
|
|
208
|
-
.m-select__wrapper .m-select__options-contentlist--hide {
|
|
217
|
+
.m-select__wrapper ul.m-select__options-contentlist--hide {
|
|
209
218
|
overflow: hidden;
|
|
210
219
|
height: auto;
|
|
211
220
|
}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
|
|
9
9
|
/* Recursively nested components to traverse nodes
|
|
10
10
|
-------------------------------------------------*/
|
|
11
|
-
type
|
|
11
|
+
type ItemListProps = {
|
|
12
|
+
root: any;
|
|
12
13
|
alternateCollapse?: boolean;
|
|
13
14
|
first?: boolean;
|
|
14
15
|
arrow?: React.ReactNode;
|
|
@@ -18,9 +19,10 @@ type MenuListProps = {
|
|
|
18
19
|
onSelect?: (e: any, val: any) => void;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
export default function
|
|
22
|
+
export default function ItemList(props: ItemListProps) {
|
|
22
23
|
|
|
23
24
|
const {
|
|
25
|
+
root,
|
|
24
26
|
alternateCollapse,
|
|
25
27
|
first,
|
|
26
28
|
arrow,
|
|
@@ -89,6 +91,7 @@ export default function MenuList(props: MenuListProps) {
|
|
|
89
91
|
|
|
90
92
|
function handleClick(e: any) {
|
|
91
93
|
e.preventDefault();
|
|
94
|
+
e.stopPropagation();
|
|
92
95
|
const hyperlink = e.currentTarget;
|
|
93
96
|
const url = hyperlink.getAttribute('href');
|
|
94
97
|
const subElement = getNextSiblings(hyperlink, 'ul');
|
|
@@ -153,60 +156,63 @@ export default function MenuList(props: MenuListProps) {
|
|
|
153
156
|
|
|
154
157
|
useEffect(() => {
|
|
155
158
|
|
|
159
|
+
if (root !== null && data.length > 0) {
|
|
160
|
+
// Activate current item
|
|
161
|
+
//=====================
|
|
162
|
+
const allItems = rootRef.current ? [].slice.call(root.querySelectorAll(`.${childClassName} a`)).map( (item: any) => {
|
|
163
|
+
return {
|
|
164
|
+
href: item.getAttribute('href'),
|
|
165
|
+
el: item,
|
|
166
|
+
actived: item.parentNode.classList?.contains('active') ? true : false,
|
|
167
|
+
expandedLink: document.body.contains(item.parentNode.parentNode.previousSibling) ? item.parentNode.parentNode.previousSibling : false
|
|
168
|
+
}
|
|
169
|
+
} ) : [];
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const allItems = rootRef.current ? [].slice.call(document.querySelectorAll(`.${childClassName} a`)).map( (item: any) => {
|
|
160
|
-
return {
|
|
161
|
-
href: item.getAttribute('href'),
|
|
162
|
-
el: item,
|
|
163
|
-
actived: item.parentNode.classList?.contains('active') ? true : false,
|
|
164
|
-
expandedLink: document.body.contains(item.parentNode.parentNode.previousSibling) ? item.parentNode.parentNode.previousSibling : false
|
|
165
|
-
}
|
|
166
|
-
} ) : [];
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
allItems.forEach( (hyperlink: any) => {
|
|
171
|
+
|
|
172
|
+
allItems.forEach( (hyperlink: any) => {
|
|
170
173
|
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
// Expand the currently active item by default
|
|
175
|
+
if ( hyperlink.actived ) {
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
hyperlink.el.setAttribute('aria-expanded', 'true');
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
if ( hyperlink.expandedLink ) {
|
|
180
|
+
const expandedLink: any = hyperlink.expandedLink; // <a>
|
|
181
|
+
activeClass(expandedLink.parentNode, 'add');
|
|
182
|
+
expandedLink.setAttribute('aria-expanded', true);
|
|
183
|
+
}
|
|
181
184
|
|
|
182
185
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
// init <ul> height
|
|
187
|
+
const ul = getNextSiblings(hyperlink.el, 'ul');
|
|
188
|
+
|
|
189
|
+
[].slice.call(ul).forEach(function (_curUl: any) {
|
|
187
190
|
|
|
188
|
-
|
|
191
|
+
const allHeight = [].slice.call(_curUl.querySelectorAll('li')).map((_curLi: any) => _curLi.scrollHeight);
|
|
189
192
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
// Prevent missing height, causing the last element to be clipped
|
|
194
|
+
const maxHeight = Math.max(...allHeight);
|
|
195
|
+
allHeight.push(maxHeight * 3);
|
|
193
196
|
|
|
194
197
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
//
|
|
199
|
+
const totalHeight = allHeight.reduce(
|
|
200
|
+
(accumulator: number, currentValue: number) => accumulator + currentValue,
|
|
201
|
+
0,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
// Prevent the use of iframe or other situations where the height is 0
|
|
205
|
+
_curUl.style.maxHeight = `${totalHeight == 0 ? 999 : totalHeight}px`;
|
|
206
|
+
|
|
207
|
+
});
|
|
203
208
|
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
}
|
|
209
|
+
}
|
|
207
210
|
|
|
208
|
-
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
}
|
|
209
214
|
|
|
215
|
+
|
|
210
216
|
}, [data]);
|
|
211
217
|
|
|
212
218
|
|
|
@@ -232,9 +238,10 @@ export default function MenuList(props: MenuListProps) {
|
|
|
232
238
|
<li key={i} className={item.active ? `nav-item active` : (_matchPath ? `nav-item active` : 'nav-item')}>
|
|
233
239
|
<a tabIndex={-1} title={item.title} className={item.active ? `nav-link active` : (_matchPath ? `nav-link active` : 'nav-link')} href={item.link === '#' ? `${item.link}-${i}` : item.link} onClick={handleClick} data-router={item.link.indexOf('#') >= 0 || item.link.indexOf('http') >= 0 ? 'false' : 'true'} data-link={item.link} data-slug={item.slug}>
|
|
234
240
|
{item.icon ? item.icon.indexOf('</svg>') < 0 ? <><i className={item.icon}></i> </> : <var dangerouslySetInnerHTML={{ __html: `${item.icon}` }} /> : null}<i dangerouslySetInnerHTML={{ __html: `${item.title}` }}></i>
|
|
235
|
-
{item.children ? <span className="arrow">{arrowGenerator()}</span> : ''}
|
|
241
|
+
{item.children && item.children.length > 0 ? <span className="arrow">{arrowGenerator()}</span> : ''}
|
|
236
242
|
</a>
|
|
237
|
-
{item.children && <
|
|
243
|
+
{item.children && <ItemList
|
|
244
|
+
root={root}
|
|
238
245
|
data={item.children}
|
|
239
246
|
first={false}
|
|
240
247
|
arrow={arrow}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import React, { useState, useEffect, memo } from 'react';
|
|
1
|
+
import React, { useRef, useState, useEffect, memo } from 'react';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
useComId
|
|
5
5
|
} from 'funda-utils';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import ItemList from './ItemList';
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
type MultilevelDropdownMenuProps = {
|
|
@@ -38,6 +40,7 @@ const MultilevelDropdownMenu = (props: MultilevelDropdownMenuProps) => {
|
|
|
38
40
|
onSelect
|
|
39
41
|
} = props;
|
|
40
42
|
|
|
43
|
+
const rootRef = useRef<any>(null);
|
|
41
44
|
const uniqueID = useComId();
|
|
42
45
|
const idRes = id || uniqueID;
|
|
43
46
|
const [val, setVal] = useState<any>(null);
|
|
@@ -50,8 +53,13 @@ const MultilevelDropdownMenu = (props: MultilevelDropdownMenuProps) => {
|
|
|
50
53
|
return (
|
|
51
54
|
<>
|
|
52
55
|
|
|
53
|
-
<nav
|
|
54
|
-
|
|
56
|
+
<nav
|
|
57
|
+
id={idRes}
|
|
58
|
+
className={navbarClassName ? navbarClassName : "navbar"}
|
|
59
|
+
ref={rootRef}
|
|
60
|
+
>
|
|
61
|
+
<ItemList
|
|
62
|
+
root={rootRef.current}
|
|
55
63
|
alternateCollapse={alternateCollapse}
|
|
56
64
|
first={true}
|
|
57
65
|
arrow={arrow}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import React, { forwardRef, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getNextSiblings
|
|
5
|
+
} from 'funda-utils';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { formatIndentVal, multiSelControlOptionExist } from './multiple-select-utils/func';
|
|
9
|
+
|
|
10
|
+
/* Recursively nested components to traverse nodes
|
|
11
|
+
-------------------------------------------------*/
|
|
12
|
+
type ItemListProps = {
|
|
13
|
+
root: any;
|
|
14
|
+
listContainerClassName: string;
|
|
15
|
+
valSelected: any[];
|
|
16
|
+
indentStr: string;
|
|
17
|
+
iconAdd?: React.ReactNode | string;
|
|
18
|
+
iconRemove?: React.ReactNode | string;
|
|
19
|
+
selected?: boolean;
|
|
20
|
+
onSelect: (any) => void;
|
|
21
|
+
alternateCollapse?: boolean;
|
|
22
|
+
first?: boolean;
|
|
23
|
+
arrow?: React.ReactNode;
|
|
24
|
+
childClassName: string;
|
|
25
|
+
data: any[any];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ItemList = forwardRef((props: ItemListProps, externalRef: any) => {
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
root,
|
|
32
|
+
listContainerClassName,
|
|
33
|
+
valSelected,
|
|
34
|
+
indentStr,
|
|
35
|
+
iconAdd,
|
|
36
|
+
iconRemove,
|
|
37
|
+
selected,
|
|
38
|
+
onSelect,
|
|
39
|
+
alternateCollapse,
|
|
40
|
+
first,
|
|
41
|
+
arrow,
|
|
42
|
+
childClassName,
|
|
43
|
+
data,
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
const listContainerRef = useRef<any>(null);
|
|
47
|
+
|
|
48
|
+
const activeClass = (el: any, mode: string, classname: string = 'active') => {
|
|
49
|
+
if ( mode === 'add' ) {
|
|
50
|
+
el.classList.add(classname);
|
|
51
|
+
} else {
|
|
52
|
+
el.classList.remove(classname);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const closeChild = (hyperlink: HTMLElement, ul: HTMLAllCollection) => {
|
|
57
|
+
if ( ul.length === 0 ) return;
|
|
58
|
+
|
|
59
|
+
activeClass(hyperlink, 'remove');
|
|
60
|
+
hyperlink.setAttribute('aria-expanded', 'false');
|
|
61
|
+
activeClass(hyperlink.parentNode, 'remove');
|
|
62
|
+
|
|
63
|
+
//to close
|
|
64
|
+
[].slice.call(ul).forEach(function(element: any){
|
|
65
|
+
element.style.maxHeight = 0;
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const openChild = (hyperlink: HTMLElement, ul: HTMLAllCollection) => {
|
|
70
|
+
if ( ul.length === 0 ) return;
|
|
71
|
+
|
|
72
|
+
activeClass(hyperlink, 'add');
|
|
73
|
+
hyperlink.setAttribute('aria-expanded', 'true');
|
|
74
|
+
activeClass(hyperlink.parentNode, 'add');
|
|
75
|
+
|
|
76
|
+
// init <ul> height
|
|
77
|
+
[].slice.call(ul).forEach(function (_curUl: any) {
|
|
78
|
+
|
|
79
|
+
const allHeight = [].slice.call(_curUl.querySelectorAll('li')).map((_curLi: any) => _curLi.scrollHeight);
|
|
80
|
+
|
|
81
|
+
// Prevent missing height, causing the last element to be clipped
|
|
82
|
+
const maxHeight = Math.max(...allHeight);
|
|
83
|
+
allHeight.push(maxHeight*3);
|
|
84
|
+
|
|
85
|
+
//
|
|
86
|
+
const totalHeight = allHeight.reduce(
|
|
87
|
+
(accumulator: number, currentValue: number) => accumulator + currentValue,
|
|
88
|
+
0,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// Prevent the use of iframe or other situations where the height is 0
|
|
92
|
+
_curUl.style.maxHeight = `${totalHeight == 0 ? 999 : totalHeight}px`;
|
|
93
|
+
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
function handleClick(e: any) {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
e.stopPropagation();
|
|
103
|
+
const hyperlink = e.currentTarget.querySelector('div');
|
|
104
|
+
const subElement = getNextSiblings(hyperlink, 'ul');
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
// hide child if expandedLink doesn't exist, on the contrary
|
|
109
|
+
//=====================
|
|
110
|
+
if ( hyperlink.getAttribute('aria-expanded') === 'false' || hyperlink.getAttribute('aria-expanded') === null ) {
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//Hide all other siblings of the selected <ul>
|
|
114
|
+
if ( alternateCollapse ) {
|
|
115
|
+
[].slice.call(listContainerRef.current.children).forEach(function(li: any){
|
|
116
|
+
|
|
117
|
+
activeClass(li, 'remove');
|
|
118
|
+
|
|
119
|
+
const _li = li.firstChild;
|
|
120
|
+
activeClass(_li, 'remove');
|
|
121
|
+
_li.setAttribute('aria-expanded', false);
|
|
122
|
+
|
|
123
|
+
[].slice.call(getNextSiblings(_li, 'ul')).forEach(function(element: any){
|
|
124
|
+
element.style.maxHeight = 0;
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
//open current
|
|
131
|
+
openChild(hyperlink, subElement as never);
|
|
132
|
+
|
|
133
|
+
} else {
|
|
134
|
+
|
|
135
|
+
//close current
|
|
136
|
+
closeChild(hyperlink, subElement as never);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
function arrowGenerator() {
|
|
145
|
+
return arrow ? arrow : <svg viewBox="0 0 22 22" width="8px"><path d="m345.44 248.29l-194.29 194.28c-12.359 12.365-32.397 12.365-44.75 0-12.354-12.354-12.354-32.391 0-44.744l171.91-171.91-171.91-171.9c-12.354-12.359-12.354-32.394 0-44.748 12.354-12.359 32.391-12.359 44.75 0l194.29 194.28c6.177 6.18 9.262 14.271 9.262 22.366 0 8.099-3.091 16.196-9.267 22.373" transform="matrix(.03541-.00013.00013.03541 2.98 3.02)" fill="#a5a5a5" /></svg>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
|
|
150
|
+
if (root !== null && data.length > 0) {
|
|
151
|
+
// Activate current item
|
|
152
|
+
//=====================
|
|
153
|
+
const allItems = listContainerRef.current ? [].slice.call(root.querySelectorAll(`.${childClassName} div`)).map( (item: any) => {
|
|
154
|
+
return {
|
|
155
|
+
el: item,
|
|
156
|
+
actived: item.parentNode.classList?.contains('active') ? true : false,
|
|
157
|
+
expandedLink: document.body.contains(item.parentNode.parentNode.previousSibling) ? item.parentNode.parentNode.previousSibling : false
|
|
158
|
+
}
|
|
159
|
+
} ) : [];
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
allItems.forEach( (hyperlink: any) => {
|
|
163
|
+
|
|
164
|
+
// Expand the currently active item by default
|
|
165
|
+
if ( hyperlink.actived ) {
|
|
166
|
+
|
|
167
|
+
hyperlink.el.setAttribute('aria-expanded', 'true');
|
|
168
|
+
|
|
169
|
+
if ( hyperlink.expandedLink ) {
|
|
170
|
+
const expandedLink: any = hyperlink.expandedLink; // <a>
|
|
171
|
+
activeClass(expandedLink.parentNode, 'add');
|
|
172
|
+
expandedLink.setAttribute('aria-expanded', true);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
// init <ul> height
|
|
177
|
+
const ul = getNextSiblings(hyperlink.el, 'ul');
|
|
178
|
+
|
|
179
|
+
[].slice.call(ul).forEach(function (_curUl: any) {
|
|
180
|
+
|
|
181
|
+
const allHeight = [].slice.call(_curUl.querySelectorAll('li')).map((_curLi: any) => _curLi.scrollHeight);
|
|
182
|
+
|
|
183
|
+
// Prevent missing height, causing the last element to be clipped
|
|
184
|
+
const maxHeight = Math.max(...allHeight);
|
|
185
|
+
allHeight.push(maxHeight * 3);
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
//
|
|
189
|
+
const totalHeight = allHeight.reduce(
|
|
190
|
+
(accumulator: number, currentValue: number) => accumulator + currentValue,
|
|
191
|
+
0,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// Prevent the use of iframe or other situations where the height is 0
|
|
195
|
+
_curUl.style.maxHeight = `${totalHeight == 0 ? 999 : totalHeight}px`;
|
|
196
|
+
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
}, [data]);
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
if (data) {
|
|
211
|
+
|
|
212
|
+
return (
|
|
213
|
+
<>
|
|
214
|
+
<ul
|
|
215
|
+
className={`${listContainerClassName || ''} ${childClassName}`}
|
|
216
|
+
style={!first ? { maxHeight: '0px' } : {}}
|
|
217
|
+
ref={(node) => {
|
|
218
|
+
listContainerRef.current = node;
|
|
219
|
+
if (typeof externalRef === 'function') {
|
|
220
|
+
externalRef(node);
|
|
221
|
+
} else if (externalRef) {
|
|
222
|
+
externalRef.current = node;
|
|
223
|
+
}
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
{data ? data.map((item: any, i: number) => {
|
|
229
|
+
|
|
230
|
+
return <li
|
|
231
|
+
key={selected ? 'item-selected' + i : 'item' + i}
|
|
232
|
+
className={selected ? 'selected' : `${item.disabled ? 'disabled' : ''} ${multiSelControlOptionExist(valSelected, item.value) ? 'hide' : ''}`}
|
|
233
|
+
data-index={i}
|
|
234
|
+
data-value={`${item.value}`}
|
|
235
|
+
data-label={`${item.label}`}
|
|
236
|
+
data-list-item-label={`${typeof item.listItemLabel === 'undefined' ? '' : item.listItemLabel}`}
|
|
237
|
+
data-disabled={item.disabled || 'false'}
|
|
238
|
+
data-querystring={`${typeof item.queryString === 'undefined' ? '' : item.queryString}`}
|
|
239
|
+
data-itemdata={JSON.stringify(item)}
|
|
240
|
+
onClick={selected ? () => void(0) : handleClick}
|
|
241
|
+
>
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
<div>
|
|
245
|
+
<strong>
|
|
246
|
+
<span dangerouslySetInnerHTML={{
|
|
247
|
+
__html: selected ? (typeof item.listItemLabel === 'undefined' ? formatIndentVal(item.label, indentStr) : formatIndentVal(item.listItemLabel, indentStr)) : (typeof item.listItemLabel === 'undefined' ? item.label : item.listItemLabel)
|
|
248
|
+
}}></span>
|
|
249
|
+
{item.children && item.children.length > 0 && !selected ? <span className="arrow">{arrowGenerator()}</span> : ''}
|
|
250
|
+
</strong>
|
|
251
|
+
|
|
252
|
+
<i
|
|
253
|
+
onClick={(e: React.MouseEvent) => {
|
|
254
|
+
e.stopPropagation();
|
|
255
|
+
onSelect((e.target as any).closest('li'));
|
|
256
|
+
}}>
|
|
257
|
+
|
|
258
|
+
{selected ? <>
|
|
259
|
+
{iconRemove ? <>{iconRemove}</> : <><svg width="15px" height="15px" viewBox="0 0 24 24" fill="none"><path fillRule="evenodd" clipRule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10ZM8 11a1 1 0 1 0 0 2h8a1 1 0 1 0 0-2H8Z" fill="#000" /></svg></>}
|
|
260
|
+
</> : <>
|
|
261
|
+
{iconAdd ? <>{iconAdd}</> : <><svg width="15px" height="15px" viewBox="0 0 24 24" fill="none"><path d="M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2ZM16 12.75H12.75V16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16V12.75H8C7.59 12.75 7.25 12.41 7.25 12C7.25 11.59 7.59 11.25 8 11.25H11.25V8C11.25 7.59 11.59 7.25 12 7.25C12.41 7.25 12.75 7.59 12.75 8V11.25H16C16.41 11.25 16.75 11.59 16.75 12C16.75 12.41 16.41 12.75 16 12.75Z" fill="#000" /></svg></>}
|
|
262
|
+
</>}
|
|
263
|
+
</i>
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
{item.children && <ItemList
|
|
269
|
+
root={root}
|
|
270
|
+
listContainerClassName={listContainerClassName}
|
|
271
|
+
ref={externalRef}
|
|
272
|
+
indentStr={indentStr}
|
|
273
|
+
valSelected={valSelected}
|
|
274
|
+
iconAdd={iconAdd}
|
|
275
|
+
iconRemove={iconRemove}
|
|
276
|
+
onSelect={onSelect}
|
|
277
|
+
first={false}
|
|
278
|
+
arrow={arrow}
|
|
279
|
+
data={item.children}
|
|
280
|
+
childClassName={childClassName}
|
|
281
|
+
/>}
|
|
282
|
+
|
|
283
|
+
</li>;
|
|
284
|
+
}) : null}
|
|
285
|
+
|
|
286
|
+
</ul>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
</>
|
|
290
|
+
)
|
|
291
|
+
} else {
|
|
292
|
+
return (
|
|
293
|
+
<></>
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
export default ItemList;
|