dce-reactkit 3.8.4 → 3.8.5
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.
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A simple dropdown menu
|
|
3
3
|
* @author Alessandra De Lucas
|
|
4
|
-
* @author Gabe Abrams
|
|
5
4
|
* @author Yuen Ler Chow
|
|
5
|
+
* @author Gabe Abrams
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import Variant from '../types/Variant';
|
|
9
9
|
import DropdownItemType from '../types/DropdownItemType';
|
|
10
10
|
type Props = {
|
|
11
11
|
items: DropdownItem[];
|
|
12
|
-
variant?: Variant;
|
|
13
12
|
dropdownButton: {
|
|
14
13
|
ariaLabel: string;
|
|
15
14
|
id: string;
|
|
16
15
|
content?: React.ReactNode;
|
|
16
|
+
variant?: Variant;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
type DropdownItem = ({
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A simple dropdown menu
|
|
3
3
|
* @author Alessandra De Lucas
|
|
4
|
-
* @author Gabe Abrams
|
|
5
4
|
* @author Yuen Ler Chow
|
|
5
|
+
* @author Gabe Abrams
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import Variant from '../types/Variant';
|
|
9
9
|
import DropdownItemType from '../types/DropdownItemType';
|
|
10
10
|
type Props = {
|
|
11
11
|
items: DropdownItem[];
|
|
12
|
-
variant?: Variant;
|
|
13
12
|
dropdownButton: {
|
|
14
13
|
ariaLabel: string;
|
|
15
14
|
id: string;
|
|
16
15
|
content?: React.ReactNode;
|
|
16
|
+
variant?: Variant;
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
type DropdownItem = ({
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A simple dropdown menu
|
|
3
3
|
* @author Alessandra De Lucas
|
|
4
|
-
* @author Gabe Abrams
|
|
5
4
|
* @author Yuen Ler Chow
|
|
5
|
+
* @author Gabe Abrams
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// Import React
|
|
@@ -15,6 +15,9 @@ import combineClassNames from '../helpers/combineClassNames';
|
|
|
15
15
|
import Variant from '../types/Variant';
|
|
16
16
|
import DropdownItemType from '../types/DropdownItemType';
|
|
17
17
|
|
|
18
|
+
// Check dark mode
|
|
19
|
+
import { isDarkModeOn } from '../client/initClient';
|
|
20
|
+
|
|
18
21
|
/*------------------------------------------------------------------------*/
|
|
19
22
|
/* -------------------------------- Types ------------------------------- */
|
|
20
23
|
/*------------------------------------------------------------------------*/
|
|
@@ -23,8 +26,6 @@ import DropdownItemType from '../types/DropdownItemType';
|
|
|
23
26
|
type Props = {
|
|
24
27
|
// List of items in the dropdown menu
|
|
25
28
|
items: DropdownItem[],
|
|
26
|
-
// If true, dropdown variant is displayed
|
|
27
|
-
variant?: Variant,
|
|
28
29
|
// Information about the dropdown button
|
|
29
30
|
dropdownButton: {
|
|
30
31
|
// Aria label for accessibility
|
|
@@ -33,6 +34,8 @@ type Props = {
|
|
|
33
34
|
id: string,
|
|
34
35
|
// Button content
|
|
35
36
|
content?: React.ReactNode,
|
|
37
|
+
// Variant
|
|
38
|
+
variant?: Variant,
|
|
36
39
|
},
|
|
37
40
|
// If true, no arrow shows in dropdown
|
|
38
41
|
// noArrow?: boolean,
|
|
@@ -126,6 +129,7 @@ type Action = (
|
|
|
126
129
|
/**
|
|
127
130
|
* Reducer that executes actions
|
|
128
131
|
* @author Alessandra De Lucas
|
|
132
|
+
* @author Yuen Ler Chow
|
|
129
133
|
* @param state current state
|
|
130
134
|
* @param action action to execute
|
|
131
135
|
*/
|
|
@@ -164,7 +168,6 @@ const Dropdown: React.FC<Props> = (props) => {
|
|
|
164
168
|
const {
|
|
165
169
|
dropdownButton,
|
|
166
170
|
items,
|
|
167
|
-
variant = Variant.Secondary,
|
|
168
171
|
} = props;
|
|
169
172
|
|
|
170
173
|
/* -------------- State ------------- */
|
|
@@ -198,7 +201,10 @@ const Dropdown: React.FC<Props> = (props) => {
|
|
|
198
201
|
*/
|
|
199
202
|
const handleClickOutside = (event: MouseEvent) => {
|
|
200
203
|
if (
|
|
201
|
-
|
|
204
|
+
// Dropdown has been rendered
|
|
205
|
+
dropdownRef.current
|
|
206
|
+
// Click occurred outside the dropdown
|
|
207
|
+
&& !dropdownRef.current.contains(event.target as Element)
|
|
202
208
|
) {
|
|
203
209
|
dispatch({ type: ActionType.CloseDropdown });
|
|
204
210
|
}
|
|
@@ -227,14 +233,18 @@ const Dropdown: React.FC<Props> = (props) => {
|
|
|
227
233
|
/*----------------------------------------*/
|
|
228
234
|
|
|
229
235
|
return (
|
|
230
|
-
<div
|
|
236
|
+
<div
|
|
237
|
+
className="dropdown"
|
|
238
|
+
ref={dropdownRef}
|
|
239
|
+
data-bs-theme={isDarkModeOn() ? 'dark' : undefined}
|
|
240
|
+
>
|
|
231
241
|
<button
|
|
232
242
|
className={
|
|
233
243
|
combineClassNames([
|
|
234
244
|
'btn dropdown-toggle border',
|
|
235
245
|
isDropdownOpen && 'show',
|
|
236
|
-
`btn-${variant}`,
|
|
237
|
-
variant === Variant.Light && 'text-dark',
|
|
246
|
+
`btn-${dropdownButton.variant}`,
|
|
247
|
+
dropdownButton.variant === Variant.Light && 'text-dark',
|
|
238
248
|
])
|
|
239
249
|
}
|
|
240
250
|
type="button"
|
|
@@ -251,13 +261,14 @@ const Dropdown: React.FC<Props> = (props) => {
|
|
|
251
261
|
dropdownButton.content
|
|
252
262
|
}
|
|
253
263
|
</button>
|
|
254
|
-
<ul
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
264
|
+
<ul
|
|
265
|
+
className={
|
|
266
|
+
combineClassNames([
|
|
267
|
+
'dropdown-menu',
|
|
268
|
+
isDarkModeOn() && 'dropdown-menu-dark',
|
|
269
|
+
isDropdownOpen && 'show',
|
|
270
|
+
])
|
|
271
|
+
}
|
|
261
272
|
>
|
|
262
273
|
{Object.values(items).map((item) => {
|
|
263
274
|
if (item.type === DropdownItemType.Header) {
|
|
@@ -288,9 +299,7 @@ const Dropdown: React.FC<Props> = (props) => {
|
|
|
288
299
|
item.onClick();
|
|
289
300
|
}}
|
|
290
301
|
>
|
|
291
|
-
{
|
|
292
|
-
item.content
|
|
293
|
-
}
|
|
302
|
+
{item.content}
|
|
294
303
|
</button>
|
|
295
304
|
</li>
|
|
296
305
|
);
|