@thecb/components 5.11.4 → 6.0.0-beta.10
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/index.cjs.js +138 -78
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +138 -78
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/country-dropdown/CountryDropdown.js +1 -0
- package/src/components/atoms/dropdown/Dropdown.js +158 -123
- package/src/components/atoms/form-select/FormSelect.js +4 -2
- package/src/components/atoms/state-province-dropdown/StateProvinceDropdown.js +1 -0
package/dist/index.cjs.js
CHANGED
|
@@ -19443,32 +19443,30 @@ var DropdownItemWrapper = styled__default.div.withConfig({
|
|
|
19443
19443
|
themeValues = _ref7.themeValues;
|
|
19444
19444
|
return selected ? themeValues.selectedColor : disabled ? WHITE : themeValues.hoverColor;
|
|
19445
19445
|
});
|
|
19446
|
-
var SearchInput = styled__default.input.withConfig({
|
|
19447
|
-
displayName: "Dropdown__SearchInput",
|
|
19448
|
-
componentId: "sc-pn6m0h-3"
|
|
19449
|
-
})(["border:none;background-color:", ";font-size:16px;height:24px;"], function (_ref8) {
|
|
19450
|
-
var themeValues = _ref8.themeValues;
|
|
19451
|
-
return themeValues.hoverColor && themeValues.hoverColor;
|
|
19452
|
-
});
|
|
19453
19446
|
|
|
19454
|
-
var Dropdown = function Dropdown(
|
|
19455
|
-
var placeholder =
|
|
19456
|
-
options =
|
|
19457
|
-
value =
|
|
19458
|
-
isOpen =
|
|
19459
|
-
isError =
|
|
19460
|
-
onSelect =
|
|
19461
|
-
|
|
19462
|
-
disabledValues =
|
|
19463
|
-
|
|
19464
|
-
onClick =
|
|
19465
|
-
themeValues =
|
|
19466
|
-
maxHeight =
|
|
19467
|
-
|
|
19468
|
-
widthFitOptions =
|
|
19469
|
-
disabled =
|
|
19470
|
-
|
|
19471
|
-
hasTitles =
|
|
19447
|
+
var Dropdown = function Dropdown(_ref8) {
|
|
19448
|
+
var placeholder = _ref8.placeholder,
|
|
19449
|
+
options = _ref8.options,
|
|
19450
|
+
value = _ref8.value,
|
|
19451
|
+
isOpen = _ref8.isOpen,
|
|
19452
|
+
isError = _ref8.isError,
|
|
19453
|
+
onSelect = _ref8.onSelect,
|
|
19454
|
+
_ref8$disabledValues = _ref8.disabledValues,
|
|
19455
|
+
disabledValues = _ref8$disabledValues === void 0 ? [] : _ref8$disabledValues,
|
|
19456
|
+
_ref8$onClick = _ref8.onClick,
|
|
19457
|
+
onClick = _ref8$onClick === void 0 ? noop : _ref8$onClick,
|
|
19458
|
+
themeValues = _ref8.themeValues,
|
|
19459
|
+
maxHeight = _ref8.maxHeight,
|
|
19460
|
+
_ref8$widthFitOptions = _ref8.widthFitOptions,
|
|
19461
|
+
widthFitOptions = _ref8$widthFitOptions === void 0 ? false : _ref8$widthFitOptions,
|
|
19462
|
+
disabled = _ref8.disabled,
|
|
19463
|
+
_ref8$hasTitles = _ref8.hasTitles,
|
|
19464
|
+
hasTitles = _ref8$hasTitles === void 0 ? false : _ref8$hasTitles,
|
|
19465
|
+
_ref8$autoEraseTypeAh = _ref8.autoEraseTypeAhead,
|
|
19466
|
+
autoEraseTypeAhead = _ref8$autoEraseTypeAh === void 0 ? true : _ref8$autoEraseTypeAh,
|
|
19467
|
+
ariaLabelledby = _ref8.ariaLabelledby,
|
|
19468
|
+
_ref8$autocompleteVal = _ref8.autocompleteValue,
|
|
19469
|
+
autocompleteValue = _ref8$autocompleteVal === void 0 ? "" : _ref8$autocompleteVal;
|
|
19472
19470
|
|
|
19473
19471
|
var _useState = React.useState(""),
|
|
19474
19472
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -19490,6 +19488,16 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19490
19488
|
optionsChanged = _useState8[0],
|
|
19491
19489
|
setOptionsChanged = _useState8[1];
|
|
19492
19490
|
|
|
19491
|
+
var _useState9 = React.useState(undefined),
|
|
19492
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
19493
|
+
selectedRef = _useState10[0],
|
|
19494
|
+
setSelectedRef = _useState10[1];
|
|
19495
|
+
|
|
19496
|
+
var _useState11 = React.useState(undefined),
|
|
19497
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
19498
|
+
focusedRef = _useState12[0],
|
|
19499
|
+
setFocusedRef = _useState12[1];
|
|
19500
|
+
|
|
19493
19501
|
if (optionsState !== options) {
|
|
19494
19502
|
setOptionsState(options);
|
|
19495
19503
|
setOptionsChanged(true);
|
|
@@ -19500,10 +19508,10 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19500
19508
|
setOptionsChanged(false);
|
|
19501
19509
|
}
|
|
19502
19510
|
|
|
19503
|
-
var
|
|
19504
|
-
|
|
19505
|
-
timer =
|
|
19506
|
-
setTimer =
|
|
19511
|
+
var _useState13 = React.useState(null),
|
|
19512
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
19513
|
+
timer = _useState14[0],
|
|
19514
|
+
setTimer = _useState14[1];
|
|
19507
19515
|
|
|
19508
19516
|
var optionRefs = React.useRef(_toConsumableArray(Array(options.length)).map(function () {
|
|
19509
19517
|
return /*#__PURE__*/React.createRef();
|
|
@@ -19519,12 +19527,20 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19519
19527
|
};
|
|
19520
19528
|
|
|
19521
19529
|
var onKeyDown = function onKeyDown(e) {
|
|
19530
|
+
var _optionRefs$current$l, _optionRefs$current;
|
|
19531
|
+
|
|
19532
|
+
console.log("key down event is", e.target);
|
|
19533
|
+
console.log("key down event value is", e.target.value);
|
|
19522
19534
|
var key = e.key,
|
|
19523
19535
|
keyCode = e.keyCode;
|
|
19524
19536
|
var focus = document.activeElement;
|
|
19537
|
+
console.log("dropdown value is", value);
|
|
19538
|
+
console.log("focus is", focus);
|
|
19539
|
+
console.log("option refs are", optionRefs.current);
|
|
19525
19540
|
var optionEl = optionRefs.current.find(function (ref) {
|
|
19526
19541
|
return ref.current === focus;
|
|
19527
19542
|
});
|
|
19543
|
+
console.log("option el is", optionEl);
|
|
19528
19544
|
|
|
19529
19545
|
switch (key) {
|
|
19530
19546
|
case "ArrowDown":
|
|
@@ -19570,16 +19586,30 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19570
19586
|
e.preventDefault();
|
|
19571
19587
|
setInputValue(inputValue.slice(0, -1));
|
|
19572
19588
|
break;
|
|
19573
|
-
}
|
|
19574
19589
|
|
|
19575
|
-
|
|
19576
|
-
|
|
19577
|
-
|
|
19590
|
+
case "Home":
|
|
19591
|
+
e.preventDefault();
|
|
19592
|
+
optionRefs.current[0].current.focus();
|
|
19593
|
+
break;
|
|
19594
|
+
|
|
19595
|
+
case "End":
|
|
19596
|
+
e.preventDefault();
|
|
19597
|
+
optionRefs.current[(_optionRefs$current$l = optionRefs === null || optionRefs === void 0 ? void 0 : (_optionRefs$current = optionRefs.current) === null || _optionRefs$current === void 0 ? void 0 : _optionRefs$current.length) !== null && _optionRefs$current$l !== void 0 ? _optionRefs$current$l : 0 - 1].current.focus();
|
|
19598
|
+
break;
|
|
19578
19599
|
}
|
|
19579
19600
|
};
|
|
19580
19601
|
|
|
19581
19602
|
React.useEffect(function () {
|
|
19582
|
-
|
|
19603
|
+
console.log("option refs in isopen useffect", optionRefs);
|
|
19604
|
+
console.log("option ref current in isopen useffect", optionRefs.current[0].current);
|
|
19605
|
+
console.log("selected refs in isopen useffect", selectedRef);
|
|
19606
|
+
console.log("value in isopen useffect", value);
|
|
19607
|
+
|
|
19608
|
+
if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
|
|
19609
|
+
// WAI-ARIA requires the selected option to receive focus
|
|
19610
|
+
selectedRef.current.focus();
|
|
19611
|
+
} else if (isOpen && optionRefs.current[0].current) {
|
|
19612
|
+
// If no selected option, first option receives focus
|
|
19583
19613
|
optionRefs.current[0].current.focus();
|
|
19584
19614
|
}
|
|
19585
19615
|
|
|
@@ -19587,16 +19617,21 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19587
19617
|
setInputValue("");
|
|
19588
19618
|
}, [isOpen]);
|
|
19589
19619
|
React.useEffect(function () {
|
|
19590
|
-
|
|
19591
|
-
|
|
19592
|
-
|
|
19593
|
-
|
|
19620
|
+
if (autoEraseTypeAhead) {
|
|
19621
|
+
clearTimeout(timer);
|
|
19622
|
+
setTimer(setTimeout(function () {
|
|
19623
|
+
return setInputValue("");
|
|
19624
|
+
}, 3000));
|
|
19625
|
+
}
|
|
19626
|
+
|
|
19594
19627
|
setFilteredOptions(options.filter(function (option) {
|
|
19595
19628
|
return option.value.toLowerCase().startsWith(inputValue.toLowerCase()) || option.text.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
19596
19629
|
}));
|
|
19597
19630
|
}, [inputValue]);
|
|
19598
19631
|
React.useEffect(function () {
|
|
19599
19632
|
if (!isOpen && filteredOptions[0] && !disabledValues.includes(filteredOptions[0].value) && filteredOptions[0].text != placeholder) {
|
|
19633
|
+
console.log("filtered options are", filteredOptions);
|
|
19634
|
+
console.log("option refs are", optionRefs);
|
|
19600
19635
|
onSelect(filteredOptions[0].value);
|
|
19601
19636
|
}
|
|
19602
19637
|
|
|
@@ -19606,70 +19641,91 @@ var Dropdown = function Dropdown(_ref9) {
|
|
|
19606
19641
|
dropdownRef.current.focus();
|
|
19607
19642
|
}
|
|
19608
19643
|
}, [filteredOptions]);
|
|
19609
|
-
return /*#__PURE__*/React__default.createElement(
|
|
19610
|
-
|
|
19611
|
-
|
|
19612
|
-
|
|
19613
|
-
width: "100%",
|
|
19614
|
-
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
19615
|
-
"aria-expanded": isOpen,
|
|
19616
|
-
extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
|
|
19617
|
-
title: hasTitles ? getSelection() : null
|
|
19644
|
+
return /*#__PURE__*/React__default.createElement(React.Fragment, null, /*#__PURE__*/React__default.createElement(Stack, {
|
|
19645
|
+
direction: "row",
|
|
19646
|
+
bottomItem: 2,
|
|
19647
|
+
extraStyles: "position: relative;"
|
|
19618
19648
|
}, /*#__PURE__*/React__default.createElement(Box, {
|
|
19619
|
-
as: "
|
|
19649
|
+
as: "input",
|
|
19650
|
+
"aria-multiline": "false",
|
|
19651
|
+
"aria-autocomplete": "list",
|
|
19652
|
+
"aria-controls": "".concat(ariaLabelledby, "_listbox"),
|
|
19653
|
+
"aria-activedescendant": "focused_option",
|
|
19654
|
+
"aria-owns": "".concat(ariaLabelledby, "_listbox"),
|
|
19655
|
+
"aria-haspopup": "listbox",
|
|
19656
|
+
"aria-labelledby": ariaLabelledby,
|
|
19657
|
+
"aria-expanded": isOpen,
|
|
19658
|
+
autocomplete: autocompleteValue,
|
|
19620
19659
|
background: isOpen ? themeValues.hoverColor : WHITE,
|
|
19621
|
-
|
|
19622
|
-
padding: "12px",
|
|
19623
|
-
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
19660
|
+
borderRadius: "2px",
|
|
19624
19661
|
borderSize: "1px",
|
|
19625
19662
|
borderColor: isError ? ERROR_COLOR : isOpen ? themeValues.selectedColor : GREY_CHATEAU,
|
|
19626
|
-
|
|
19627
|
-
|
|
19628
|
-
|
|
19629
|
-
|
|
19630
|
-
|
|
19631
|
-
|
|
19632
|
-
|
|
19633
|
-
|
|
19634
|
-
|
|
19663
|
+
extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;",
|
|
19664
|
+
hoverStyles: "background-color: ".concat(themeValues.hoverColor, ";"),
|
|
19665
|
+
isOpen: isOpen,
|
|
19666
|
+
name: autocompleteValue,
|
|
19667
|
+
onKeyDown: onKeyDown,
|
|
19668
|
+
onClick: onClick,
|
|
19669
|
+
onFocus: onClick,
|
|
19670
|
+
onChange: function onChange(e) {
|
|
19671
|
+
console.log("input change event", e.target);
|
|
19672
|
+
console.log("input change event value", e.target.value);
|
|
19673
|
+
setInputValue(e.target.value);
|
|
19674
|
+
},
|
|
19675
|
+
padding: "12px",
|
|
19676
|
+
placeholder: getSelection(),
|
|
19677
|
+
role: "combobox",
|
|
19678
|
+
themeValues: themeValues,
|
|
19679
|
+
title: hasTitles ? getSelection() : null,
|
|
19680
|
+
type: "text",
|
|
19681
|
+
tabIndex: -1,
|
|
19635
19682
|
value: inputValue,
|
|
19636
|
-
|
|
19637
|
-
|
|
19638
|
-
}
|
|
19639
|
-
variant: "p",
|
|
19640
|
-
extraStyles: disabled && "color: #6e727e;\n background-color: #f7f7f7;\n pointer-events: none;"
|
|
19641
|
-
}, getSelection()), /*#__PURE__*/React__default.createElement(IconWrapper, {
|
|
19642
|
-
open: isOpen
|
|
19643
|
-
}, /*#__PURE__*/React__default.createElement(DropdownIcon, null)))), isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
|
|
19683
|
+
width: "100%",
|
|
19684
|
+
dataQa: placeholder
|
|
19685
|
+
}, isOpen ? /*#__PURE__*/React__default.createElement(DropdownContentWrapper, {
|
|
19644
19686
|
maxHeight: maxHeight,
|
|
19645
19687
|
open: isOpen,
|
|
19646
19688
|
ref: dropdownRef,
|
|
19647
19689
|
widthFitOptions: widthFitOptions,
|
|
19648
|
-
tabIndex: 0
|
|
19690
|
+
tabIndex: 0,
|
|
19691
|
+
role: "listbox",
|
|
19692
|
+
id: "".concat(ariaLabelledby, "_listbox")
|
|
19649
19693
|
}, /*#__PURE__*/React__default.createElement(Stack, {
|
|
19650
19694
|
childGap: "0"
|
|
19651
19695
|
}, filteredOptions.map(function (choice, i) {
|
|
19696
|
+
if (choice.value === value && selectedRef !== optionRefs.current[i]) {
|
|
19697
|
+
setSelectedRef(optionRefs.current[i]);
|
|
19698
|
+
}
|
|
19699
|
+
|
|
19652
19700
|
return /*#__PURE__*/React__default.createElement(DropdownItemWrapper, {
|
|
19701
|
+
id: focusedRef === optionRefs.current[i] ? "focused_option" : choice.value,
|
|
19653
19702
|
key: choice.value,
|
|
19654
19703
|
ref: optionRefs.current[i],
|
|
19655
|
-
as: "button",
|
|
19656
19704
|
tabIndex: -1,
|
|
19657
19705
|
onClick: disabledValues.includes(choice.value) ? function (evt) {
|
|
19658
19706
|
return evt.preventDefault();
|
|
19659
19707
|
} : function () {
|
|
19660
|
-
|
|
19708
|
+
setSelectedRef(optionRefs.current[i]);
|
|
19709
|
+
onSelect(choice.value);
|
|
19661
19710
|
},
|
|
19662
19711
|
selected: choice.value === value,
|
|
19712
|
+
"aria-selected": choice.value === value,
|
|
19663
19713
|
disabled: disabledValues.includes(choice.value),
|
|
19664
19714
|
"data-qa": choice.text,
|
|
19665
19715
|
themeValues: themeValues,
|
|
19666
|
-
title: hasTitles ? choice.text : null
|
|
19716
|
+
title: hasTitles ? choice.text : null,
|
|
19717
|
+
role: "option",
|
|
19718
|
+
onFocus: function onFocus() {
|
|
19719
|
+
return setFocusedRef(optionRefs.current[i]);
|
|
19720
|
+
}
|
|
19667
19721
|
}, /*#__PURE__*/React__default.createElement(Text$1, {
|
|
19668
19722
|
variant: "p",
|
|
19669
19723
|
color: choice.value === value ? WHITE : disabledValues.includes(choice.value) ? STORM_GREY : MINESHAFT_GREY,
|
|
19670
19724
|
extraStyles: "padding-left: 16px; \n cursor: ".concat(disabledValues.includes(choice.value) ? "default" : "pointer", "; \n white-space: nowrap; \n overflow: hidden; \n text-overflow: ellipsis;")
|
|
19671
19725
|
}, choice.text));
|
|
19672
|
-
}))) : /*#__PURE__*/React__default.createElement(React.Fragment, null))
|
|
19726
|
+
}))) : /*#__PURE__*/React__default.createElement(React.Fragment, null)), /*#__PURE__*/React__default.createElement(IconWrapper, {
|
|
19727
|
+
open: isOpen
|
|
19728
|
+
}, /*#__PURE__*/React__default.createElement(DropdownIcon, null))));
|
|
19673
19729
|
};
|
|
19674
19730
|
|
|
19675
19731
|
var Dropdown$1 = themeComponent(Dropdown, "Dropdown", fallbackValues$e);
|
|
@@ -19770,7 +19826,8 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
19770
19826
|
disabled = _ref.disabled,
|
|
19771
19827
|
themeValues = _ref.themeValues,
|
|
19772
19828
|
_ref$hasTitles = _ref.hasTitles,
|
|
19773
|
-
hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles
|
|
19829
|
+
hasTitles = _ref$hasTitles === void 0 ? false : _ref$hasTitles,
|
|
19830
|
+
autocompleteValue = _ref.autocompleteValue;
|
|
19774
19831
|
|
|
19775
19832
|
var _useState = React.useState(false),
|
|
19776
19833
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -19808,7 +19865,7 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
19808
19865
|
extraStyles: "word-break: break-word;\n font-family: Public Sans;\n &::first-letter {\n text-transform: uppercase;\n }",
|
|
19809
19866
|
id: labelTextWhenNoError.replace(/\s+/g, "-")
|
|
19810
19867
|
}, labelTextWhenNoError))), /*#__PURE__*/React__default.createElement(Dropdown$1, {
|
|
19811
|
-
|
|
19868
|
+
ariaLabelledby: labelTextWhenNoError.replace(/\s+/g, "-"),
|
|
19812
19869
|
maxHeight: dropdownMaxHeight,
|
|
19813
19870
|
hasTitles: hasTitles,
|
|
19814
19871
|
placeholder: options[0] ? options[0].text : "",
|
|
@@ -19825,7 +19882,8 @@ var FormSelect = function FormSelect(_ref) {
|
|
|
19825
19882
|
onClick: function onClick() {
|
|
19826
19883
|
return setOpen(!open);
|
|
19827
19884
|
},
|
|
19828
|
-
disabled: disabled
|
|
19885
|
+
disabled: disabled,
|
|
19886
|
+
autocompleteValue: autocompleteValue
|
|
19829
19887
|
}), /*#__PURE__*/React__default.createElement(Stack, {
|
|
19830
19888
|
direction: "row",
|
|
19831
19889
|
justify: "space-between"
|
|
@@ -20598,7 +20656,8 @@ var CountryDropdown = function CountryDropdown(_ref) {
|
|
|
20598
20656
|
labelTextWhenNoError: labelTextWhenNoError,
|
|
20599
20657
|
errorMessages: errorMessages,
|
|
20600
20658
|
showErrors: showErrors,
|
|
20601
|
-
onChange: onChange
|
|
20659
|
+
onChange: onChange,
|
|
20660
|
+
autocompleteValue: "country-name"
|
|
20602
20661
|
});
|
|
20603
20662
|
};
|
|
20604
20663
|
|
|
@@ -33014,7 +33073,8 @@ var FormStateDropdown = function FormStateDropdown(_ref) {
|
|
|
33014
33073
|
fieldActions: fieldActions,
|
|
33015
33074
|
labelTextWhenNoError: labelTextWhenNoError,
|
|
33016
33075
|
errorMessages: errorMessages,
|
|
33017
|
-
showErrors: showErrors
|
|
33076
|
+
showErrors: showErrors,
|
|
33077
|
+
autocompleteValue: "address-level1"
|
|
33018
33078
|
});
|
|
33019
33079
|
};
|
|
33020
33080
|
|