dce-reactkit 5.0.5 → 5.0.7
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/dist/cjs/index.js +82 -73
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/CheckboxButton.d.ts +1 -0
- package/dist/cjs/types/components/ItemPicker/NestableItemList.d.ts +1 -0
- package/dist/cjs/types/components/ItemPicker/index.d.ts +1 -0
- package/dist/cjs/types/components/ItemPicker/types/PickableItem.d.ts +4 -1
- package/dist/esm/index.js +82 -73
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/CheckboxButton.d.ts +1 -0
- package/dist/esm/types/components/ItemPicker/NestableItemList.d.ts +1 -0
- package/dist/esm/types/components/ItemPicker/index.d.ts +1 -0
- package/dist/esm/types/components/ItemPicker/types/PickableItem.d.ts +4 -1
- package/dist/index.d.ts +5 -1
- package/package.json +1 -1
- package/src/components/CheckboxButton.tsx +25 -20
- package/src/components/ItemPicker/NestableItemList.tsx +42 -15
- package/src/components/ItemPicker/index.tsx +4 -0
- package/src/components/ItemPicker/types/PickableItem.tsx +7 -1
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
/**
|
|
2
3
|
* An item that can be chosen (for use within ItemPicker)
|
|
3
4
|
* @author Gabe Abrams
|
|
4
5
|
*/
|
|
5
6
|
type PickableItem = ({
|
|
6
7
|
id: number | string;
|
|
7
|
-
name:
|
|
8
|
+
name: React.ReactNode;
|
|
9
|
+
ariaLabel?: string;
|
|
8
10
|
link?: string;
|
|
11
|
+
tooltip?: string;
|
|
9
12
|
} & ({
|
|
10
13
|
isGroup: false;
|
|
11
14
|
checked: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -278,6 +278,7 @@ type Props$l = {
|
|
|
278
278
|
small?: boolean;
|
|
279
279
|
dashed?: boolean;
|
|
280
280
|
useComplexFormatting?: boolean;
|
|
281
|
+
minSizeToShowLabel?: 'sm' | 'md' | 'lg' | 'xl';
|
|
281
282
|
};
|
|
282
283
|
declare const CheckboxButton: React$1.FC<Props$l>;
|
|
283
284
|
|
|
@@ -441,8 +442,10 @@ declare const CopiableBox: React$1.FC<Props$c>;
|
|
|
441
442
|
*/
|
|
442
443
|
type PickableItem = ({
|
|
443
444
|
id: number | string;
|
|
444
|
-
name:
|
|
445
|
+
name: React.ReactNode;
|
|
446
|
+
ariaLabel?: string;
|
|
445
447
|
link?: string;
|
|
448
|
+
tooltip?: string;
|
|
446
449
|
} & ({
|
|
447
450
|
isGroup: false;
|
|
448
451
|
checked: boolean;
|
|
@@ -467,6 +470,7 @@ type Props$b = {
|
|
|
467
470
|
onChanged: (updatedItems: PickableItem[]) => void;
|
|
468
471
|
noBottomMargin?: boolean;
|
|
469
472
|
hideSelectAllOrNoneButtons?: boolean;
|
|
473
|
+
startWithGroupsExpanded?: boolean;
|
|
470
474
|
};
|
|
471
475
|
declare const ItemPicker: React$1.FC<Props$b>;
|
|
472
476
|
|
package/package.json
CHANGED
|
@@ -48,6 +48,8 @@ type Props = {
|
|
|
48
48
|
dashed?: boolean,
|
|
49
49
|
// If true, use complex formatting (tabs, newlines) in the text
|
|
50
50
|
useComplexFormatting?: boolean,
|
|
51
|
+
// Min bootstrap size to show the label
|
|
52
|
+
minSizeToShowLabel?: 'sm' | 'md' | 'lg' | 'xl',
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
/*------------------------------------------------------------------------*/
|
|
@@ -83,6 +85,7 @@ const CheckboxButton: React.FC<Props> = (props) => {
|
|
|
83
85
|
small,
|
|
84
86
|
dashed,
|
|
85
87
|
useComplexFormatting,
|
|
88
|
+
minSizeToShowLabel,
|
|
86
89
|
} = props;
|
|
87
90
|
|
|
88
91
|
/*------------------------------------------------------------------------*/
|
|
@@ -118,30 +121,32 @@ const CheckboxButton: React.FC<Props> = (props) => {
|
|
|
118
121
|
}}
|
|
119
122
|
>
|
|
120
123
|
<div className="d-flex align-items-center">
|
|
121
|
-
<div
|
|
124
|
+
<div>
|
|
122
125
|
<FontAwesomeIcon
|
|
123
126
|
icon={icon}
|
|
124
127
|
/>
|
|
125
128
|
</div>
|
|
126
|
-
{
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
129
|
+
<div className={`text-start flex-grow-1 ms-1 ${minSizeToShowLabel ? `d-none d-${minSizeToShowLabel}-block` : ''}`}>
|
|
130
|
+
{
|
|
131
|
+
useComplexFormatting
|
|
132
|
+
? (
|
|
133
|
+
<pre
|
|
134
|
+
className="ps-1 text-break m-0"
|
|
135
|
+
style={{
|
|
136
|
+
whiteSpace: 'pre-wrap',
|
|
137
|
+
tabSize: 2,
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
{text}
|
|
141
|
+
</pre>
|
|
142
|
+
)
|
|
143
|
+
: (
|
|
144
|
+
<div className="text-break">
|
|
145
|
+
{text}
|
|
146
|
+
</div>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
</div>
|
|
145
150
|
</div>
|
|
146
151
|
</button>
|
|
147
152
|
);
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
|
|
17
17
|
// Import shared components
|
|
18
18
|
import CheckboxButton from '../CheckboxButton';
|
|
19
|
+
import Tooltip from '../Tooltip';
|
|
19
20
|
import Variant from '../../types/Variant';
|
|
20
21
|
|
|
21
22
|
// Import types
|
|
@@ -35,6 +36,8 @@ type Props = {
|
|
|
35
36
|
* values updated
|
|
36
37
|
*/
|
|
37
38
|
onChanged: (updatedItems: PickableItem[]) => void,
|
|
39
|
+
// If true, groups start expanded instead of collapsed
|
|
40
|
+
startWithGroupsExpanded?: boolean,
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
/*------------------------------------------------------------------------*/
|
|
@@ -106,6 +109,7 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
106
109
|
const {
|
|
107
110
|
items,
|
|
108
111
|
onChanged,
|
|
112
|
+
startWithGroupsExpanded,
|
|
109
113
|
} = props;
|
|
110
114
|
|
|
111
115
|
/* -------------- State ------------- */
|
|
@@ -113,7 +117,7 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
113
117
|
// Create initial map of child expanded booleans
|
|
114
118
|
const initChildExpanded: { [k: string]: boolean } = {};
|
|
115
119
|
items.forEach((item) => {
|
|
116
|
-
initChildExpanded[String(item.id)] =
|
|
120
|
+
initChildExpanded[String(item.id)] = !!startWithGroupsExpanded;
|
|
117
121
|
});
|
|
118
122
|
|
|
119
123
|
// Initial state
|
|
@@ -229,6 +233,29 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
229
233
|
<div>
|
|
230
234
|
{
|
|
231
235
|
items.map((item) => {
|
|
236
|
+
// Human-readable label for accessibility. Prefer the explicit
|
|
237
|
+
// ariaLabel, then fall back to the name if it is a plain string
|
|
238
|
+
const accessibleName = (
|
|
239
|
+
item.ariaLabel
|
|
240
|
+
?? (typeof item.name === 'string' ? item.name : '')
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// Checkbox and Text
|
|
244
|
+
const checkbox = (
|
|
245
|
+
<CheckboxButton
|
|
246
|
+
className={`NestableItemList-CheckboxButton-${item.id}`}
|
|
247
|
+
text={item.name}
|
|
248
|
+
checked={item.isGroup ? allChecked(item.children) : item.checked}
|
|
249
|
+
dashed={item.isGroup ? !noneChecked(item.children) : false}
|
|
250
|
+
onChanged={(checked) => {
|
|
251
|
+
onChanged(changeChecked(item.id, checked, items));
|
|
252
|
+
}}
|
|
253
|
+
ariaLabel={`Select ${accessibleName}`}
|
|
254
|
+
checkedVariant={Variant.Light}
|
|
255
|
+
uncheckedVariant={Variant.Light}
|
|
256
|
+
/>
|
|
257
|
+
);
|
|
258
|
+
|
|
232
259
|
return (
|
|
233
260
|
<div key={item.id}>
|
|
234
261
|
{/* Dropdown Button */}
|
|
@@ -252,7 +279,7 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
252
279
|
id: item.id,
|
|
253
280
|
});
|
|
254
281
|
}}
|
|
255
|
-
aria-label={`${childExpanded[item.id] ? 'Hide' : 'Show'} items in ${
|
|
282
|
+
aria-label={`${childExpanded[item.id] ? 'Hide' : 'Show'} items in ${accessibleName}`}
|
|
256
283
|
>
|
|
257
284
|
<FontAwesomeIcon
|
|
258
285
|
icon={childExpanded[item.id] ? faChevronDown : faChevronRight}
|
|
@@ -261,19 +288,18 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
261
288
|
)}
|
|
262
289
|
</span>
|
|
263
290
|
|
|
264
|
-
{/* Checkbox and Text */}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
/>
|
|
291
|
+
{/* Checkbox and Text (optionally wrapped in a tooltip) */}
|
|
292
|
+
{
|
|
293
|
+
item.tooltip
|
|
294
|
+
? (
|
|
295
|
+
<Tooltip text={item.tooltip}>
|
|
296
|
+
<span className="d-inline-block">
|
|
297
|
+
{checkbox}
|
|
298
|
+
</span>
|
|
299
|
+
</Tooltip>
|
|
300
|
+
)
|
|
301
|
+
: checkbox
|
|
302
|
+
}
|
|
277
303
|
|
|
278
304
|
{/* Children */}
|
|
279
305
|
{(item.isGroup && childExpanded[item.id]) && (
|
|
@@ -288,6 +314,7 @@ const NestableItemList: React.FC<Props> = (props) => {
|
|
|
288
314
|
onChanged={(updatedItems) => {
|
|
289
315
|
onChanged(changeItems(item.id, updatedItems));
|
|
290
316
|
}}
|
|
317
|
+
startWithGroupsExpanded={startWithGroupsExpanded}
|
|
291
318
|
/>
|
|
292
319
|
</div>
|
|
293
320
|
)}
|
|
@@ -35,6 +35,8 @@ type Props = {
|
|
|
35
35
|
noBottomMargin?: boolean,
|
|
36
36
|
// If true, hide select all or none buttons
|
|
37
37
|
hideSelectAllOrNoneButtons?: boolean,
|
|
38
|
+
// If true, groups start expanded instead of collapsed
|
|
39
|
+
startWithGroupsExpanded?: boolean,
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
/*------------------------------------------------------------------------*/
|
|
@@ -55,6 +57,7 @@ const ItemPicker: React.FC<Props> = (props) => {
|
|
|
55
57
|
onChanged,
|
|
56
58
|
noBottomMargin,
|
|
57
59
|
hideSelectAllOrNoneButtons,
|
|
60
|
+
startWithGroupsExpanded,
|
|
58
61
|
} = props;
|
|
59
62
|
|
|
60
63
|
/*------------------------------------------------------------------------*/
|
|
@@ -171,6 +174,7 @@ const ItemPicker: React.FC<Props> = (props) => {
|
|
|
171
174
|
<NestableItemList
|
|
172
175
|
items={items}
|
|
173
176
|
onChanged={onChanged}
|
|
177
|
+
startWithGroupsExpanded={startWithGroupsExpanded}
|
|
174
178
|
/>
|
|
175
179
|
</div>
|
|
176
180
|
</TabBox>
|
|
@@ -7,9 +7,15 @@ type PickableItem = (
|
|
|
7
7
|
// Unique id of the item
|
|
8
8
|
id: number | string,
|
|
9
9
|
// Name of the item (human readable)
|
|
10
|
-
name:
|
|
10
|
+
name: React.ReactNode,
|
|
11
|
+
// Accessible label for the item, used for screen readers. Required when
|
|
12
|
+
// "name" is not a plain string (e.g. a custom ReactNode); when "name" is
|
|
13
|
+
// a string, it is used as the label if this is not provided
|
|
14
|
+
ariaLabel?: string,
|
|
11
15
|
// Link to view the item in the browser
|
|
12
16
|
link?: string,
|
|
17
|
+
// If included, show this text in a tooltip when hovering over the item
|
|
18
|
+
tooltip?: string,
|
|
13
19
|
}
|
|
14
20
|
& (
|
|
15
21
|
| {
|