@khanacademy/wonder-blocks-dropdown 9.0.0 → 9.1.0
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/CHANGELOG.md +924 -894
- package/LICENSE +21 -0
- package/dist/es/index.js +40 -38
- package/dist/index.js +82 -94
- package/package.json +18 -20
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
6
4
|
var React = require('react');
|
|
7
5
|
var aphrodite = require('aphrodite');
|
|
@@ -28,10 +26,7 @@ var wonderBlocksForm = require('@khanacademy/wonder-blocks-form');
|
|
|
28
26
|
var IconButton = require('@khanacademy/wonder-blocks-icon-button');
|
|
29
27
|
var Pill = require('@khanacademy/wonder-blocks-pill');
|
|
30
28
|
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
function _interopNamespace(e) {
|
|
34
|
-
if (e && e.__esModule) return e;
|
|
29
|
+
function _interopNamespaceDefault(e) {
|
|
35
30
|
var n = Object.create(null);
|
|
36
31
|
if (e) {
|
|
37
32
|
Object.keys(e).forEach(function (k) {
|
|
@@ -44,21 +39,12 @@ function _interopNamespace(e) {
|
|
|
44
39
|
}
|
|
45
40
|
});
|
|
46
41
|
}
|
|
47
|
-
n
|
|
42
|
+
n.default = e;
|
|
48
43
|
return Object.freeze(n);
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
54
|
-
var checkIcon__default = /*#__PURE__*/_interopDefaultLegacy(checkIcon);
|
|
55
|
-
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
|
56
|
-
var SearchField__default = /*#__PURE__*/_interopDefaultLegacy(SearchField);
|
|
57
|
-
var caretDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(caretDownIcon);
|
|
58
|
-
var caretDownIcon__default$1 = /*#__PURE__*/_interopDefaultLegacy(caretDownIcon$1);
|
|
59
|
-
var xIcon__default = /*#__PURE__*/_interopDefaultLegacy(xIcon);
|
|
60
|
-
var IconButton__default = /*#__PURE__*/_interopDefaultLegacy(IconButton);
|
|
61
|
-
var Pill__default = /*#__PURE__*/_interopDefaultLegacy(Pill);
|
|
46
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
47
|
+
var ReactDOM__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactDOM);
|
|
62
48
|
|
|
63
49
|
const selectDropdownStyle = {
|
|
64
50
|
marginTop: wonderBlocksTokens.spacing.xSmall_8,
|
|
@@ -131,10 +117,10 @@ class ActionItem extends React__namespace.Component {
|
|
|
131
117
|
const labelComponent = typeof label === "string" ? React__namespace.createElement(wonderBlocksTypography.LabelMedium, {
|
|
132
118
|
lang: lang,
|
|
133
119
|
style: styles$c.label
|
|
134
|
-
}, label) : React__namespace.cloneElement(label,
|
|
120
|
+
}, label) : (React__namespace.cloneElement(label, _extends({
|
|
135
121
|
lang,
|
|
136
122
|
style: styles$c.label
|
|
137
|
-
}, label.props));
|
|
123
|
+
}, label.props)));
|
|
138
124
|
return React__namespace.createElement(wonderBlocksCell.CompactCell, {
|
|
139
125
|
disabled: disabled,
|
|
140
126
|
horizontalRule: horizontalRule,
|
|
@@ -200,7 +186,7 @@ const Check = function Check(props) {
|
|
|
200
186
|
selected
|
|
201
187
|
} = props;
|
|
202
188
|
return React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
|
|
203
|
-
icon:
|
|
189
|
+
icon: checkIcon,
|
|
204
190
|
size: "small",
|
|
205
191
|
style: [styles$b.bounds, !selected && styles$b.hide]
|
|
206
192
|
});
|
|
@@ -231,7 +217,7 @@ const Checkbox = function Checkbox(props) {
|
|
|
231
217
|
className: "checkbox",
|
|
232
218
|
style: [styles$a.checkbox, selected && !disabled && styles$a.noBorder, disabled && styles$a.disabledCheckbox]
|
|
233
219
|
}, selected && React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
|
|
234
|
-
icon:
|
|
220
|
+
icon: checkIcon,
|
|
235
221
|
size: "small",
|
|
236
222
|
className: "check",
|
|
237
223
|
style: [{
|
|
@@ -267,7 +253,7 @@ const styles$a = aphrodite.StyleSheet.create({
|
|
|
267
253
|
});
|
|
268
254
|
|
|
269
255
|
const _excluded$5 = ["disabled", "label", "selected", "testId", "leftAccessory", "horizontalRule", "parentComponent", "rightAccessory", "style", "subtitle1", "subtitle2", "value", "onClick", "onToggle", "variant", "role"];
|
|
270
|
-
const
|
|
256
|
+
const StyledLi = wonderBlocksCore.addStyle("li");
|
|
271
257
|
class OptionItem extends React__namespace.Component {
|
|
272
258
|
constructor(...args) {
|
|
273
259
|
super(...args);
|
|
@@ -309,10 +295,10 @@ class OptionItem extends React__namespace.Component {
|
|
|
309
295
|
subtitle2,
|
|
310
296
|
role
|
|
311
297
|
} = _this$props,
|
|
312
|
-
sharedProps =
|
|
298
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$5);
|
|
313
299
|
const CheckComponent = this.getCheckComponent();
|
|
314
300
|
const defaultStyle = [styles$9.item, style];
|
|
315
|
-
return React__namespace.createElement(wonderBlocksCell.DetailCell,
|
|
301
|
+
return React__namespace.createElement(wonderBlocksCell.DetailCell, _extends({
|
|
316
302
|
disabled: disabled,
|
|
317
303
|
horizontalRule: horizontalRule,
|
|
318
304
|
rootStyle: parentComponent === "listbox" ? styles$9.listboxItem : defaultStyle,
|
|
@@ -355,7 +341,7 @@ class OptionItem extends React__namespace.Component {
|
|
|
355
341
|
selected
|
|
356
342
|
} = this.props;
|
|
357
343
|
if (parentComponent === "listbox") {
|
|
358
|
-
return React__namespace.createElement(
|
|
344
|
+
return React__namespace.createElement(StyledLi, {
|
|
359
345
|
onMouseDown: e => {
|
|
360
346
|
e.preventDefault();
|
|
361
347
|
},
|
|
@@ -375,7 +361,7 @@ OptionItem.defaultProps = {
|
|
|
375
361
|
disabled: false,
|
|
376
362
|
focused: false,
|
|
377
363
|
horizontalRule: "none",
|
|
378
|
-
onToggle: () =>
|
|
364
|
+
onToggle: () => undefined,
|
|
379
365
|
role: "option",
|
|
380
366
|
selected: false
|
|
381
367
|
};
|
|
@@ -490,10 +476,11 @@ class SeparatorItem extends React__namespace.Component {
|
|
|
490
476
|
return instance && instance.type && instance.type.__IS_SEPARATOR_ITEM__;
|
|
491
477
|
}
|
|
492
478
|
render() {
|
|
493
|
-
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
479
|
+
return (React__namespace.createElement(wonderBlocksCore.View, {
|
|
480
|
+
style: [styles$8.separator, this.props.style],
|
|
481
|
+
"aria-hidden": "true"
|
|
482
|
+
})
|
|
483
|
+
);
|
|
497
484
|
}
|
|
498
485
|
}
|
|
499
486
|
SeparatorItem.__IS_SEPARATOR_ITEM__ = true;
|
|
@@ -528,14 +515,14 @@ class DropdownOpener extends React__namespace.Component {
|
|
|
528
515
|
role,
|
|
529
516
|
onBlur
|
|
530
517
|
} = this.props;
|
|
531
|
-
const renderedChildren = this.props.children(
|
|
518
|
+
const renderedChildren = this.props.children(_extends({}, eventState, {
|
|
532
519
|
text,
|
|
533
520
|
opened
|
|
534
521
|
}));
|
|
535
522
|
const childrenProps = renderedChildren.props;
|
|
536
523
|
const childrenTestId = this.getTestIdFromProps(childrenProps);
|
|
537
524
|
const renderedAriaLabel = (_childrenProps$ariaL = childrenProps["aria-label"]) != null ? _childrenProps$ariaL : this.props["aria-label"];
|
|
538
|
-
return React__namespace.cloneElement(renderedChildren,
|
|
525
|
+
return React__namespace.cloneElement(renderedChildren, _extends({}, clickableChildrenProps, {
|
|
539
526
|
"aria-label": renderedAriaLabel != null ? renderedAriaLabel : undefined,
|
|
540
527
|
"aria-invalid": this.props.error,
|
|
541
528
|
disabled,
|
|
@@ -585,7 +572,7 @@ class DropdownVirtualizedItem extends React__namespace.Component {
|
|
|
585
572
|
role,
|
|
586
573
|
ref
|
|
587
574
|
} = item;
|
|
588
|
-
return React__namespace.cloneElement(component,
|
|
575
|
+
return React__namespace.cloneElement(component, _extends({
|
|
589
576
|
style
|
|
590
577
|
}, populatedProps, {
|
|
591
578
|
key: index,
|
|
@@ -645,7 +632,7 @@ class DropdownCoreVirtualized extends React__namespace.Component {
|
|
|
645
632
|
}
|
|
646
633
|
setWidth() {
|
|
647
634
|
const rootNode = ReactDOM__namespace.findDOMNode(this);
|
|
648
|
-
const parentNode = rootNode == null ?
|
|
635
|
+
const parentNode = rootNode == null ? undefined : rootNode.parentElement;
|
|
649
636
|
if (parentNode) {
|
|
650
637
|
const width = parentNode.getBoundingClientRect().width;
|
|
651
638
|
this.setState({
|
|
@@ -725,7 +712,7 @@ function modifyMaxHeight({
|
|
|
725
712
|
const [basePlacement] = state.placement.split("-");
|
|
726
713
|
const heightProp = basePlacement === "top" ? "top" : "bottom";
|
|
727
714
|
const maxHeight = height - overflow[heightProp] - y;
|
|
728
|
-
state.styles.popper =
|
|
715
|
+
state.styles.popper = _extends({}, state.styles.popper, {
|
|
729
716
|
maxHeight: `${maxHeight}px`,
|
|
730
717
|
["--popper-max-height"]: `${maxHeight}px`
|
|
731
718
|
});
|
|
@@ -862,10 +849,10 @@ class DropdownCore extends React__namespace.Component {
|
|
|
862
849
|
}
|
|
863
850
|
constructor(props) {
|
|
864
851
|
super(props);
|
|
865
|
-
this.popperElement =
|
|
866
|
-
this.virtualizedListRef =
|
|
867
|
-
this.handleKeyDownDebounced =
|
|
868
|
-
this.textSuggestion =
|
|
852
|
+
this.popperElement = undefined;
|
|
853
|
+
this.virtualizedListRef = undefined;
|
|
854
|
+
this.handleKeyDownDebounced = undefined;
|
|
855
|
+
this.textSuggestion = undefined;
|
|
869
856
|
this.focusedIndex = -1;
|
|
870
857
|
this.focusedOriginalIndex = -1;
|
|
871
858
|
this.itemsClicked = false;
|
|
@@ -1010,7 +997,7 @@ class DropdownCore extends React__namespace.Component {
|
|
|
1010
997
|
prevItems: this.props.items,
|
|
1011
998
|
itemRefs: [],
|
|
1012
999
|
sameItemsFocusable: false,
|
|
1013
|
-
labels:
|
|
1000
|
+
labels: _extends({
|
|
1014
1001
|
noResults: defaultLabels.noResults,
|
|
1015
1002
|
someResults: defaultLabels.someSelected
|
|
1016
1003
|
}, props.labels)
|
|
@@ -1050,7 +1037,7 @@ class DropdownCore extends React__namespace.Component {
|
|
|
1050
1037
|
}
|
|
1051
1038
|
if (this.props.labels !== prevProps.labels) {
|
|
1052
1039
|
this.setState({
|
|
1053
|
-
labels:
|
|
1040
|
+
labels: _extends({}, this.state.labels, this.props.labels)
|
|
1054
1041
|
});
|
|
1055
1042
|
}
|
|
1056
1043
|
}
|
|
@@ -1232,7 +1219,7 @@ class DropdownCore extends React__namespace.Component {
|
|
|
1232
1219
|
}
|
|
1233
1220
|
const focusIndex = focusCounter - 1;
|
|
1234
1221
|
const currentRef = this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null;
|
|
1235
|
-
return React__namespace.cloneElement(component,
|
|
1222
|
+
return React__namespace.cloneElement(component, _extends({}, populatedProps, {
|
|
1236
1223
|
key: index,
|
|
1237
1224
|
onClick: () => {
|
|
1238
1225
|
this.handleItemClick(focusIndex, item);
|
|
@@ -1253,7 +1240,7 @@ class DropdownCore extends React__namespace.Component {
|
|
|
1253
1240
|
focusCounter += 1;
|
|
1254
1241
|
}
|
|
1255
1242
|
const focusIndex = focusCounter - 1;
|
|
1256
|
-
return
|
|
1243
|
+
return _extends({}, item, {
|
|
1257
1244
|
role: populatedProps.role || itemRole,
|
|
1258
1245
|
ref: item.focusable && this.state.itemRefs[focusIndex] ? this.state.itemRefs[focusIndex].ref : null,
|
|
1259
1246
|
onClick: () => {
|
|
@@ -1276,7 +1263,7 @@ class DropdownCore extends React__namespace.Component {
|
|
|
1276
1263
|
const {
|
|
1277
1264
|
labels
|
|
1278
1265
|
} = this.state;
|
|
1279
|
-
return React__namespace.createElement(
|
|
1266
|
+
return React__namespace.createElement(SearchField, {
|
|
1280
1267
|
clearAriaLabel: labels.clearSearch,
|
|
1281
1268
|
onChange: this.handleSearchTextChanged,
|
|
1282
1269
|
placeholder: labels.filter,
|
|
@@ -1429,7 +1416,7 @@ class ActionMenuOpenerCore extends React__namespace.Component {
|
|
|
1429
1416
|
opened,
|
|
1430
1417
|
"aria-label": ariaLabel
|
|
1431
1418
|
} = _this$props,
|
|
1432
|
-
restProps =
|
|
1419
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$4);
|
|
1433
1420
|
const buttonColor = wonderBlocksTokens.color.blue;
|
|
1434
1421
|
const buttonStyles = _generateStyles$1(buttonColor);
|
|
1435
1422
|
const disabled = disabledProp;
|
|
@@ -1437,7 +1424,7 @@ class ActionMenuOpenerCore extends React__namespace.Component {
|
|
|
1437
1424
|
const label = React__namespace.createElement(wonderBlocksTypography.LabelLarge, {
|
|
1438
1425
|
style: sharedStyles.text
|
|
1439
1426
|
}, children);
|
|
1440
|
-
return React__namespace.createElement(StyledButton$1,
|
|
1427
|
+
return React__namespace.createElement(StyledButton$1, _extends({
|
|
1441
1428
|
"aria-expanded": opened ? "true" : "false",
|
|
1442
1429
|
"aria-haspopup": "menu",
|
|
1443
1430
|
"aria-label": ariaLabel,
|
|
@@ -1453,7 +1440,7 @@ class ActionMenuOpenerCore extends React__namespace.Component {
|
|
|
1453
1440
|
}), React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
|
|
1454
1441
|
size: "small",
|
|
1455
1442
|
color: "currentColor",
|
|
1456
|
-
icon:
|
|
1443
|
+
icon: caretDownIcon,
|
|
1457
1444
|
"aria-hidden": "true"
|
|
1458
1445
|
}));
|
|
1459
1446
|
}
|
|
@@ -1544,7 +1531,7 @@ const _excluded$3 = ["text", "opened"];
|
|
|
1544
1531
|
class ActionMenu extends React__namespace.Component {
|
|
1545
1532
|
constructor(...args) {
|
|
1546
1533
|
super(...args);
|
|
1547
|
-
this.openerElement =
|
|
1534
|
+
this.openerElement = undefined;
|
|
1548
1535
|
this.state = {
|
|
1549
1536
|
opened: false
|
|
1550
1537
|
};
|
|
@@ -1609,7 +1596,7 @@ class ActionMenu extends React__namespace.Component {
|
|
|
1609
1596
|
populatedProps: {}
|
|
1610
1597
|
};
|
|
1611
1598
|
if (ActionItem.isClassOf(item)) {
|
|
1612
|
-
return
|
|
1599
|
+
return _extends({}, itemObject, {
|
|
1613
1600
|
populatedProps: {
|
|
1614
1601
|
indent: isOptionItemIncluded,
|
|
1615
1602
|
onClick: this.handleItemSelected
|
|
@@ -1617,7 +1604,7 @@ class ActionMenu extends React__namespace.Component {
|
|
|
1617
1604
|
});
|
|
1618
1605
|
} else if (OptionItem.isClassOf(item)) {
|
|
1619
1606
|
const selected = selectedValues ? selectedValues.includes(value) : false;
|
|
1620
|
-
return
|
|
1607
|
+
return _extends({}, itemObject, {
|
|
1621
1608
|
populatedProps: {
|
|
1622
1609
|
onToggle: this.handleOptionSelected,
|
|
1623
1610
|
selected,
|
|
@@ -1657,8 +1644,8 @@ class ActionMenu extends React__namespace.Component {
|
|
|
1657
1644
|
const {
|
|
1658
1645
|
opened
|
|
1659
1646
|
} = openerProps,
|
|
1660
|
-
eventState =
|
|
1661
|
-
return React__namespace.createElement(ActionMenuOpenerCore,
|
|
1647
|
+
eventState = _objectWithoutPropertiesLoose(openerProps, _excluded$3);
|
|
1648
|
+
return React__namespace.createElement(ActionMenuOpenerCore, _extends({}, eventState, {
|
|
1662
1649
|
disabled: disabled,
|
|
1663
1650
|
opened: !!opened,
|
|
1664
1651
|
testId: testId
|
|
@@ -1757,11 +1744,11 @@ class SelectOpener extends React__namespace.Component {
|
|
|
1757
1744
|
"aria-required": ariaRequired,
|
|
1758
1745
|
onBlur
|
|
1759
1746
|
} = _this$props,
|
|
1760
|
-
sharedProps =
|
|
1747
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$2);
|
|
1761
1748
|
const stateStyles = _generateStyles(isPlaceholder, error);
|
|
1762
1749
|
const iconColor = disabled ? wonderBlocksTokens.semanticColor.action.disabled.default : wonderBlocksTokens.semanticColor.icon.primary;
|
|
1763
1750
|
const style = [styles$4.shared, stateStyles.default, disabled && stateStyles.disabled, !disabled && this.state.pressed && stateStyles.press];
|
|
1764
|
-
return React__namespace.createElement(StyledButton,
|
|
1751
|
+
return React__namespace.createElement(StyledButton, _extends({}, sharedProps, {
|
|
1765
1752
|
"aria-disabled": disabled,
|
|
1766
1753
|
"aria-expanded": open ? "true" : "false",
|
|
1767
1754
|
"aria-invalid": error,
|
|
@@ -1771,6 +1758,7 @@ class SelectOpener extends React__namespace.Component {
|
|
|
1771
1758
|
"data-testid": testId,
|
|
1772
1759
|
id: id,
|
|
1773
1760
|
role: "combobox",
|
|
1761
|
+
type: "button",
|
|
1774
1762
|
style: style,
|
|
1775
1763
|
onClick: !disabled ? this.handleClick : undefined,
|
|
1776
1764
|
onKeyDown: !disabled ? this.handleKeyDown : undefined,
|
|
@@ -1781,7 +1769,7 @@ class SelectOpener extends React__namespace.Component {
|
|
|
1781
1769
|
}, children || React__namespace.createElement("span", {
|
|
1782
1770
|
"aria-hidden": "true"
|
|
1783
1771
|
}, "\xA0")), React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
|
|
1784
|
-
icon:
|
|
1772
|
+
icon: caretDownIcon,
|
|
1785
1773
|
color: iconColor,
|
|
1786
1774
|
size: "small",
|
|
1787
1775
|
style: styles$4.caret,
|
|
@@ -1854,10 +1842,10 @@ const _generateStyles = (placeholder, error) => {
|
|
|
1854
1842
|
outlineStyle: "solid",
|
|
1855
1843
|
outlineWidth: wonderBlocksTokens.border.width.thin
|
|
1856
1844
|
};
|
|
1857
|
-
const focusHoverStyling =
|
|
1845
|
+
const focusHoverStyling = _extends({
|
|
1858
1846
|
outlineColor: action.hover.border
|
|
1859
1847
|
}, sharedOutlineStyling);
|
|
1860
|
-
const pressStyling =
|
|
1848
|
+
const pressStyling = _extends({
|
|
1861
1849
|
background: action.press.background,
|
|
1862
1850
|
color: placeholder ? error ? wonderBlocksTokens.semanticColor.text.secondary : wonderBlocksTokens.semanticColor.action.outlined.progressive.press.foreground : wonderBlocksTokens.semanticColor.text.primary,
|
|
1863
1851
|
outlineColor: action.press.border
|
|
@@ -1886,7 +1874,7 @@ const _generateStyles = (placeholder, error) => {
|
|
|
1886
1874
|
borderColor: states.disabled.border,
|
|
1887
1875
|
color: states.disabled.foreground,
|
|
1888
1876
|
cursor: "not-allowed",
|
|
1889
|
-
":focus-visible":
|
|
1877
|
+
":focus-visible": _extends({
|
|
1890
1878
|
outlineColor: wonderBlocksTokens.semanticColor.action.disabled.default
|
|
1891
1879
|
}, sharedOutlineStyling)
|
|
1892
1880
|
},
|
|
@@ -2002,7 +1990,7 @@ const SingleSelect = props => {
|
|
|
2002
1990
|
required,
|
|
2003
1991
|
showOpenerLabelAsText = true
|
|
2004
1992
|
} = props,
|
|
2005
|
-
sharedProps =
|
|
1993
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
2006
1994
|
const [open, setOpen] = React__namespace.useState(false);
|
|
2007
1995
|
const [searchText, setSearchText] = React__namespace.useState("");
|
|
2008
1996
|
const [openerElement, setOpenerElement] = React__namespace.useState();
|
|
@@ -2115,7 +2103,7 @@ const SingleSelect = props => {
|
|
|
2115
2103
|
opened: open,
|
|
2116
2104
|
error: hasError,
|
|
2117
2105
|
onBlur: onOpenerBlurValidation
|
|
2118
|
-
}, opener) : React__namespace.createElement(SelectOpener,
|
|
2106
|
+
}, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
|
|
2119
2107
|
"aria-label": ariaLabel,
|
|
2120
2108
|
"aria-controls": dropdownId,
|
|
2121
2109
|
disabled: isDisabled,
|
|
@@ -2193,8 +2181,8 @@ const MultiSelect = props => {
|
|
|
2193
2181
|
onValidate,
|
|
2194
2182
|
required
|
|
2195
2183
|
} = props,
|
|
2196
|
-
sharedProps =
|
|
2197
|
-
const labels =
|
|
2184
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
2185
|
+
const labels = _extends({}, defaultLabels, propLabels);
|
|
2198
2186
|
const [open, setOpen] = React__namespace.useState(false);
|
|
2199
2187
|
const [searchText, setSearchText] = React__namespace.useState("");
|
|
2200
2188
|
const [lastSelectedValues, setLastSelectedValues] = React__namespace.useState([]);
|
|
@@ -2270,7 +2258,7 @@ const MultiSelect = props => {
|
|
|
2270
2258
|
case 1:
|
|
2271
2259
|
const selectedItem = children.find(option => option.props.value === selectedValues[0]);
|
|
2272
2260
|
if (selectedItem) {
|
|
2273
|
-
const selectedLabel = getSelectOpenerLabel(showOpenerLabelAsText, selectedItem == null ?
|
|
2261
|
+
const selectedLabel = getSelectOpenerLabel(showOpenerLabelAsText, selectedItem == null ? undefined : selectedItem.props);
|
|
2274
2262
|
if (selectedLabel) {
|
|
2275
2263
|
return selectedLabel;
|
|
2276
2264
|
} else {
|
|
@@ -2399,7 +2387,7 @@ const MultiSelect = props => {
|
|
|
2399
2387
|
role: "combobox",
|
|
2400
2388
|
text: menuContent,
|
|
2401
2389
|
opened: open
|
|
2402
|
-
}, opener) : React__namespace.createElement(SelectOpener,
|
|
2390
|
+
}, opener) : React__namespace.createElement(SelectOpener, _extends({}, sharedProps, {
|
|
2403
2391
|
error: hasError,
|
|
2404
2392
|
disabled: isDisabled,
|
|
2405
2393
|
id: uniqueOpenerId,
|
|
@@ -2578,7 +2566,7 @@ function useListbox({
|
|
|
2578
2566
|
const renderList = React__namespace.useMemo(() => {
|
|
2579
2567
|
return options.map((component, index) => {
|
|
2580
2568
|
const isSingleSelection = selectionType === "single" && typeof selected === "string";
|
|
2581
|
-
const isSelected = (isSingleSelection ? selected === component.props.value : selected == null ?
|
|
2569
|
+
const isSelected = (isSingleSelection ? selected === component.props.value : selected == null ? undefined : selected.includes(component.props.value)) || false;
|
|
2582
2570
|
const optionId = id ? `${id}-option-${index}` : `option-${index}`;
|
|
2583
2571
|
return React__namespace.cloneElement(component, {
|
|
2584
2572
|
key: index,
|
|
@@ -2625,19 +2613,19 @@ function useMultipleSelection({
|
|
|
2625
2613
|
if (key === "ArrowLeft") {
|
|
2626
2614
|
setFocusedMultiSelectIndex(prev => {
|
|
2627
2615
|
const newIndex = prev - 1;
|
|
2628
|
-
return newIndex < 0 ? (selected == null ?
|
|
2616
|
+
return newIndex < 0 ? (selected == null ? undefined : selected.length) - 1 : newIndex;
|
|
2629
2617
|
});
|
|
2630
2618
|
}
|
|
2631
2619
|
if (key === "ArrowRight") {
|
|
2632
2620
|
setFocusedMultiSelectIndex(prev => {
|
|
2633
2621
|
const newIndex = prev + 1;
|
|
2634
|
-
return newIndex >= (selected == null ?
|
|
2622
|
+
return newIndex >= (selected == null ? undefined : selected.length) ? 0 : newIndex;
|
|
2635
2623
|
});
|
|
2636
2624
|
}
|
|
2637
2625
|
if (inputValue === "" && key === "Backspace") {
|
|
2638
2626
|
let newSelected = [];
|
|
2639
2627
|
if (focusedMultiSelectIndex < 0) {
|
|
2640
|
-
newSelected = selected == null ?
|
|
2628
|
+
newSelected = selected == null ? undefined : selected.slice(0, -1);
|
|
2641
2629
|
} else {
|
|
2642
2630
|
newSelected = selected.filter((_, index) => index !== focusedMultiSelectIndex);
|
|
2643
2631
|
}
|
|
@@ -2645,7 +2633,7 @@ function useMultipleSelection({
|
|
|
2645
2633
|
setFocusedMultiSelectIndex(-1);
|
|
2646
2634
|
}
|
|
2647
2635
|
if (focusedMultiSelectIndex >= 0 && key === "Enter") {
|
|
2648
|
-
const newSelected = selected == null ?
|
|
2636
|
+
const newSelected = selected == null ? undefined : selected.filter((_, index) => index !== focusedMultiSelectIndex);
|
|
2649
2637
|
setSelected(newSelected);
|
|
2650
2638
|
setFocusedMultiSelectIndex(-1);
|
|
2651
2639
|
}
|
|
@@ -2686,11 +2674,11 @@ function ComboboxLiveRegion({
|
|
|
2686
2674
|
const lastSelectedValue = React__namespace.useRef(null);
|
|
2687
2675
|
const [message, setMessage] = React__namespace.useState("");
|
|
2688
2676
|
React__namespace.useEffect(() => {
|
|
2689
|
-
if (selected && selected !== (lastSelectedValue == null ?
|
|
2677
|
+
if (selected && selected !== (lastSelectedValue == null ? undefined : lastSelectedValue.current)) {
|
|
2690
2678
|
var _lastSelectedValue$cu, _lastSelectedValue$cu2, _selected$length;
|
|
2691
2679
|
let newMessage = "";
|
|
2692
|
-
const lastSelectedLength = (_lastSelectedValue$cu = lastSelectedValue == null
|
|
2693
|
-
const selectedLength = (_selected$length = selected == null ?
|
|
2680
|
+
const lastSelectedLength = (_lastSelectedValue$cu = lastSelectedValue == null || (_lastSelectedValue$cu2 = lastSelectedValue.current) == null ? undefined : _lastSelectedValue$cu2.length) != null ? _lastSelectedValue$cu : 0;
|
|
2681
|
+
const selectedLength = (_selected$length = selected == null ? undefined : selected.length) != null ? _selected$length : 0;
|
|
2694
2682
|
if (Array.isArray(selected) && selected.length > 0) {
|
|
2695
2683
|
const currentLabels = selectedLabels.join(", ");
|
|
2696
2684
|
const selectedState = selectedLength > lastSelectedLength ? labels.selected(currentLabels) : labels.unselected(currentLabels);
|
|
@@ -2776,7 +2764,7 @@ const MultipleSelection = React__namespace.memo(function SelectedPills({
|
|
|
2776
2764
|
const label = labels[index];
|
|
2777
2765
|
const focused = index === focusedMultiSelectIndex;
|
|
2778
2766
|
const uniqueId = id + index;
|
|
2779
|
-
return React__namespace.createElement(
|
|
2767
|
+
return React__namespace.createElement(Pill, {
|
|
2780
2768
|
id: uniqueId,
|
|
2781
2769
|
key: uniqueId,
|
|
2782
2770
|
testId: testId ? `${testId}-pill-${index}` : undefined,
|
|
@@ -2787,7 +2775,7 @@ const MultipleSelection = React__namespace.memo(function SelectedPills({
|
|
|
2787
2775
|
tabIndex: -1,
|
|
2788
2776
|
onClick: () => onRemove(value)
|
|
2789
2777
|
}, React__namespace.createElement(React__namespace.Fragment, null, label, !disabled && React__namespace.createElement(wonderBlocksIcon.PhosphorIcon, {
|
|
2790
|
-
icon:
|
|
2778
|
+
icon: xIcon,
|
|
2791
2779
|
size: "small"
|
|
2792
2780
|
})));
|
|
2793
2781
|
}));
|
|
@@ -2844,7 +2832,7 @@ function StandaloneListbox(props) {
|
|
|
2844
2832
|
});
|
|
2845
2833
|
React__namespace.useEffect(() => {
|
|
2846
2834
|
if (selected && selected !== value) {
|
|
2847
|
-
onChange == null
|
|
2835
|
+
onChange == null || onChange(selected);
|
|
2848
2836
|
}
|
|
2849
2837
|
}, [onChange, selected, value]);
|
|
2850
2838
|
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
@@ -2916,7 +2904,7 @@ function Combobox({
|
|
|
2916
2904
|
testId,
|
|
2917
2905
|
value = ""
|
|
2918
2906
|
}) {
|
|
2919
|
-
var _renderList$find, _renderList$focusedIn
|
|
2907
|
+
var _renderList$find, _renderList$focusedIn;
|
|
2920
2908
|
const generatedUniqueId = React.useId();
|
|
2921
2909
|
const uniqueId = id != null ? id : generatedUniqueId;
|
|
2922
2910
|
const comboboxRef = React__namespace.useRef(null);
|
|
@@ -2947,7 +2935,7 @@ function Combobox({
|
|
|
2947
2935
|
disableSpaceSelection: true,
|
|
2948
2936
|
selectionType
|
|
2949
2937
|
});
|
|
2950
|
-
const itemFromSelected = (_renderList$find = renderList.find(item => item.props.value === selected)) == null ?
|
|
2938
|
+
const itemFromSelected = (_renderList$find = renderList.find(item => item.props.value === selected)) == null ? undefined : _renderList$find.props;
|
|
2951
2939
|
const labelFromSelected = itemFromSelected ? getLabel(itemFromSelected) : "";
|
|
2952
2940
|
const initialValue = typeof value === "string" ? labelFromSelected : "";
|
|
2953
2941
|
const [inputValue, setInputValue] = React__namespace.useState(initialValue);
|
|
@@ -2975,16 +2963,16 @@ function Combobox({
|
|
|
2975
2963
|
}
|
|
2976
2964
|
setCurrentOptions(children);
|
|
2977
2965
|
}
|
|
2978
|
-
onToggle == null
|
|
2966
|
+
onToggle == null || onToggle(newState);
|
|
2979
2967
|
}, [children, disabled, isControlled, labelFromSelected, onToggle, openState, selectionType, setFocusedIndex]);
|
|
2980
2968
|
const handleChange = React__namespace.useCallback(value => {
|
|
2981
2969
|
if (value !== valueState) {
|
|
2982
2970
|
setSelectedValue(value);
|
|
2983
|
-
onChange == null
|
|
2971
|
+
onChange == null || onChange(value);
|
|
2984
2972
|
}
|
|
2985
2973
|
if (selectionType === "single" && typeof value === "string") {
|
|
2986
2974
|
var _renderList$find2;
|
|
2987
|
-
const itemFromSelected = (_renderList$find2 = renderList.find(item => item.props.value === value)) == null ?
|
|
2975
|
+
const itemFromSelected = (_renderList$find2 = renderList.find(item => item.props.value === value)) == null ? undefined : _renderList$find2.props;
|
|
2988
2976
|
const labelFromSelected = itemFromSelected ? getLabel(itemFromSelected) : "";
|
|
2989
2977
|
updateOpenState(false, labelFromSelected);
|
|
2990
2978
|
} else if (Array.isArray(value)) {
|
|
@@ -3038,20 +3026,20 @@ function Combobox({
|
|
|
3038
3026
|
e.stopPropagation();
|
|
3039
3027
|
setInputValue("");
|
|
3040
3028
|
setSelected("");
|
|
3041
|
-
onChange == null
|
|
3042
|
-
(_comboboxRef$current = comboboxRef.current) == null
|
|
3029
|
+
onChange == null || onChange("");
|
|
3030
|
+
(_comboboxRef$current = comboboxRef.current) == null || _comboboxRef$current.focus();
|
|
3043
3031
|
}, [onChange, setSelected]);
|
|
3044
3032
|
React__namespace.useEffect(() => {
|
|
3045
3033
|
if (openState) {
|
|
3046
3034
|
var _comboboxRef$current2;
|
|
3047
|
-
(_comboboxRef$current2 = comboboxRef.current) == null
|
|
3035
|
+
(_comboboxRef$current2 = comboboxRef.current) == null || _comboboxRef$current2.focus();
|
|
3048
3036
|
}
|
|
3049
3037
|
}, [openState]);
|
|
3050
3038
|
const selectedLabels = React__namespace.useMemo(() => {
|
|
3051
3039
|
if (Array.isArray(selected)) {
|
|
3052
3040
|
return selected.map(value => {
|
|
3053
3041
|
const item = children.find(item => item.props.value === value);
|
|
3054
|
-
return item ? getLabel(item == null ?
|
|
3042
|
+
return item ? getLabel(item == null ? undefined : item.props) : "";
|
|
3055
3043
|
});
|
|
3056
3044
|
}
|
|
3057
3045
|
return [labelFromSelected];
|
|
@@ -3061,7 +3049,7 @@ function Combobox({
|
|
|
3061
3049
|
if (!startIcon) {
|
|
3062
3050
|
return null;
|
|
3063
3051
|
}
|
|
3064
|
-
const startIconElement = React__namespace.cloneElement(startIcon,
|
|
3052
|
+
const startIconElement = React__namespace.cloneElement(startIcon, _extends({
|
|
3065
3053
|
size: "small"
|
|
3066
3054
|
}, startIcon.props, {
|
|
3067
3055
|
color: disabled ? wonderBlocksTokens.color.offBlack32 : (_startIcon$props$colo = startIcon.props.color) != null ? _startIcon$props$colo : wonderBlocksTokens.semanticColor.icon.primary
|
|
@@ -3072,7 +3060,7 @@ function Combobox({
|
|
|
3072
3060
|
};
|
|
3073
3061
|
const pillIdPrefix = `${uniqueId}-pill-`;
|
|
3074
3062
|
const textFieldId = React.useId();
|
|
3075
|
-
const currentActiveDescendant = !openState ? undefined : focusedIndex >= 0 ? (_renderList$focusedIn = renderList[focusedIndex]) == null
|
|
3063
|
+
const currentActiveDescendant = !openState ? undefined : focusedIndex >= 0 ? (_renderList$focusedIn = renderList[focusedIndex]) == null || (_renderList$focusedIn = _renderList$focusedIn.props) == null ? undefined : _renderList$focusedIn.id : pillIdPrefix + focusedMultiSelectIndex;
|
|
3076
3064
|
const controlledWidget = !openState ? undefined : focusedIndex >= 0 ? uniqueId : pillIdPrefix;
|
|
3077
3065
|
return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(wonderBlocksCore.View, {
|
|
3078
3066
|
onClick: () => {
|
|
@@ -3124,17 +3112,17 @@ function Combobox({
|
|
|
3124
3112
|
ref: comboboxRef,
|
|
3125
3113
|
autoComplete: "off",
|
|
3126
3114
|
role: "combobox"
|
|
3127
|
-
}), inputValue && !disabled && React__namespace.createElement(
|
|
3128
|
-
icon:
|
|
3115
|
+
}), inputValue && !disabled && React__namespace.createElement(IconButton, {
|
|
3116
|
+
icon: xIcon,
|
|
3129
3117
|
onClick: handleClearClick,
|
|
3130
3118
|
kind: "tertiary",
|
|
3131
3119
|
size: "small",
|
|
3132
3120
|
style: [styles.button, styles.clearButton],
|
|
3133
3121
|
"aria-label": labels.clearSelection,
|
|
3134
3122
|
testId: testId ? `${testId}-clear` : undefined
|
|
3135
|
-
}), React__namespace.createElement(
|
|
3123
|
+
}), React__namespace.createElement(IconButton, {
|
|
3136
3124
|
disabled: disabled,
|
|
3137
|
-
icon:
|
|
3125
|
+
icon: caretDownIcon$1,
|
|
3138
3126
|
onClick: e => {
|
|
3139
3127
|
e.stopPropagation();
|
|
3140
3128
|
updateOpenState(!openState);
|
|
@@ -3151,13 +3139,13 @@ function Combobox({
|
|
|
3151
3139
|
"aria-label": labels.comboboxButton
|
|
3152
3140
|
})), openState && React__namespace.createElement(DropdownPopper, {
|
|
3153
3141
|
alignment: "left",
|
|
3154
|
-
referenceElement: rootNodeRef == null ?
|
|
3142
|
+
referenceElement: rootNodeRef == null ? undefined : rootNodeRef.current
|
|
3155
3143
|
}, isReferenceHidden => {
|
|
3156
3144
|
var _rootNodeRef$current, _rootNodeRef$current2;
|
|
3157
3145
|
return React__namespace.createElement(React__namespace.Fragment, null, renderList.length === 0 ? React__namespace.createElement(wonderBlocksCell.DetailCell, {
|
|
3158
3146
|
title: labels.noItems,
|
|
3159
3147
|
style: [styles.listbox, {
|
|
3160
|
-
minWidth: rootNodeRef == null
|
|
3148
|
+
minWidth: rootNodeRef == null || (_rootNodeRef$current = rootNodeRef.current) == null ? undefined : _rootNodeRef$current.offsetWidth
|
|
3161
3149
|
}],
|
|
3162
3150
|
horizontalRule: "none"
|
|
3163
3151
|
}) : React__namespace.createElement(Listbox, {
|
|
@@ -3165,7 +3153,7 @@ function Combobox({
|
|
|
3165
3153
|
tabIndex: -1,
|
|
3166
3154
|
selectionType: selectionType,
|
|
3167
3155
|
style: [styles.listbox, isReferenceHidden && styles.hidden, {
|
|
3168
|
-
minWidth: rootNodeRef == null
|
|
3156
|
+
minWidth: rootNodeRef == null || (_rootNodeRef$current2 = rootNodeRef.current) == null ? undefined : _rootNodeRef$current2.offsetWidth
|
|
3169
3157
|
}],
|
|
3170
3158
|
testId: testId ? `${testId}-listbox` : undefined,
|
|
3171
3159
|
"aria-label": labels.listbox,
|
package/package.json
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-dropdown",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Dropdown variants for Wonder Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/es/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
|
|
12
|
-
},
|
|
13
9
|
"author": "",
|
|
14
10
|
"license": "MIT",
|
|
15
11
|
"publishConfig": {
|
|
16
12
|
"access": "public"
|
|
17
13
|
},
|
|
18
14
|
"dependencies": {
|
|
19
|
-
"@babel/runtime": "^7.
|
|
20
|
-
"@khanacademy/wonder-blocks-cell": "
|
|
21
|
-
"@khanacademy/wonder-blocks-clickable": "
|
|
22
|
-
"@khanacademy/wonder-blocks-core": "
|
|
23
|
-
"@khanacademy/wonder-blocks-icon": "
|
|
24
|
-
"@khanacademy/wonder-blocks-layout": "
|
|
25
|
-
"@khanacademy/wonder-blocks-modal": "
|
|
26
|
-
"@khanacademy/wonder-blocks-pill": "
|
|
27
|
-
"@khanacademy/wonder-blocks-search-field": "
|
|
28
|
-
"@khanacademy/wonder-blocks-timing": "
|
|
29
|
-
"@khanacademy/wonder-blocks-tokens": "
|
|
30
|
-
"@khanacademy/wonder-blocks-typography": "
|
|
15
|
+
"@babel/runtime": "^7.24.5",
|
|
16
|
+
"@khanacademy/wonder-blocks-cell": "4.1.0",
|
|
17
|
+
"@khanacademy/wonder-blocks-clickable": "6.1.0",
|
|
18
|
+
"@khanacademy/wonder-blocks-core": "12.1.0",
|
|
19
|
+
"@khanacademy/wonder-blocks-icon": "5.1.0",
|
|
20
|
+
"@khanacademy/wonder-blocks-layout": "3.1.0",
|
|
21
|
+
"@khanacademy/wonder-blocks-modal": "7.1.0",
|
|
22
|
+
"@khanacademy/wonder-blocks-pill": "3.1.0",
|
|
23
|
+
"@khanacademy/wonder-blocks-search-field": "5.1.0",
|
|
24
|
+
"@khanacademy/wonder-blocks-timing": "7.0.0",
|
|
25
|
+
"@khanacademy/wonder-blocks-tokens": "4.2.0",
|
|
26
|
+
"@khanacademy/wonder-blocks-typography": "3.1.0"
|
|
31
27
|
},
|
|
32
28
|
"peerDependencies": {
|
|
33
29
|
"@phosphor-icons/core": "^2.0.2",
|
|
@@ -38,10 +34,12 @@
|
|
|
38
34
|
"react-popper": "^2.0.0",
|
|
39
35
|
"react-router": "5.3.4",
|
|
40
36
|
"react-router-dom": "5.3.4",
|
|
41
|
-
"react-window": "^1.8.
|
|
37
|
+
"react-window": "^1.8.11"
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
|
-
"@khanacademy/
|
|
45
|
-
|
|
40
|
+
"@khanacademy/wb-dev-build-settings": "2.1.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
46
44
|
}
|
|
47
45
|
}
|