@bolttech/molecules-dropdown 0.31.0 → 0.32.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/index.cjs +102 -56
- package/package.json +6 -6
- package/src/lib/molecules-dropdown.type.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -135,10 +135,10 @@ var SHARED = '__core-js_shared__';
|
|
|
135
135
|
var store$3 = sharedStore.exports = globalThis$e[SHARED] || defineGlobalProperty$2(SHARED, {});
|
|
136
136
|
|
|
137
137
|
(store$3.versions || (store$3.versions = [])).push({
|
|
138
|
-
version: '3.
|
|
138
|
+
version: '3.39.0',
|
|
139
139
|
mode: 'global',
|
|
140
140
|
copyright: '© 2014-2024 Denis Pushkarev (zloirock.ru)',
|
|
141
|
-
license: 'https://github.com/zloirock/core-js/blob/v3.
|
|
141
|
+
license: 'https://github.com/zloirock/core-js/blob/v3.39.0/LICENSE',
|
|
142
142
|
source: 'https://github.com/zloirock/core-js'
|
|
143
143
|
});
|
|
144
144
|
|
|
@@ -237,9 +237,9 @@ var symbolConstructorDetection = !!Object.getOwnPropertySymbols && !fails$e(func
|
|
|
237
237
|
/* eslint-disable es/no-symbol -- required for testing */
|
|
238
238
|
var NATIVE_SYMBOL$1 = symbolConstructorDetection;
|
|
239
239
|
|
|
240
|
-
var useSymbolAsUid = NATIVE_SYMBOL$1
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
var useSymbolAsUid = NATIVE_SYMBOL$1 &&
|
|
241
|
+
!Symbol.sham &&
|
|
242
|
+
typeof Symbol.iterator == 'symbol';
|
|
243
243
|
|
|
244
244
|
var globalThis$a = globalThis_1;
|
|
245
245
|
var shared$3 = shared$4;
|
|
@@ -2390,7 +2390,11 @@ const ContainerDropdown = /*#__PURE__*/styled__default["default"].section.withCo
|
|
|
2390
2390
|
const SectionContainer = /*#__PURE__*/styled__default["default"].section.withConfig({
|
|
2391
2391
|
displayName: "molecules-dropdownstyles__SectionContainer",
|
|
2392
2392
|
componentId: "sc-3wugi4-2"
|
|
2393
|
-
})(["position:relative;.errorMessage{padding-right:", ";padding-left:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}.helperMessage{padding-right:", ";padding-left:", ";margin-top:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}"], ({
|
|
2393
|
+
})(["position:relative;.top{top:-", ";transform:translateY(-100%);}.bottom{top:", ";}.errorMessage{padding-right:", ";padding-left:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}.helperMessage{padding-right:", ";padding-left:", ";margin-top:", ";label{color:", ";font-weight:", ";line-height:", ";font-size:", ";letter-spacing:", ";}}"], ({
|
|
2394
|
+
theme
|
|
2395
|
+
}) => theme.components.dropdown.borderWidth.default, ({
|
|
2396
|
+
theme
|
|
2397
|
+
}) => `calc(100% + ${theme.components.dropdown.borderWidth.default})`, ({
|
|
2394
2398
|
theme
|
|
2395
2399
|
}) => theme.components.dropdown.paddingHorizontal, ({
|
|
2396
2400
|
theme
|
|
@@ -2440,10 +2444,6 @@ const FieldLabelAndRequiredLabelDropdown = /*#__PURE__*/styled__default["default
|
|
|
2440
2444
|
})(["gap:", ";display:flex;"], ({
|
|
2441
2445
|
theme
|
|
2442
2446
|
}) => theme.components.dropdown.requiredGap);
|
|
2443
|
-
const DropdownOptionsContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
2444
|
-
displayName: "molecules-dropdownstyles__DropdownOptionsContainer",
|
|
2445
|
-
componentId: "sc-3wugi4-6"
|
|
2446
|
-
})(["position:absolute;inset:0;top:calc(100% + 1px);"]);
|
|
2447
2447
|
|
|
2448
2448
|
const ReusableDropdownComponent = _a => {
|
|
2449
2449
|
var {
|
|
@@ -2519,17 +2519,21 @@ const ReusableDropdownComponent = _a => {
|
|
|
2519
2519
|
var _a, _b;
|
|
2520
2520
|
onChangeInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || '');
|
|
2521
2521
|
onChangeInputLabel(((_b = e === null || e === void 0 ? void 0 : e.target) === null || _b === void 0 ? void 0 : _b.value) || '');
|
|
2522
|
-
setShowSelectComponent(true);
|
|
2523
2522
|
},
|
|
2524
2523
|
onFocus: event => {
|
|
2524
|
+
setShowSelectComponent(true);
|
|
2525
2525
|
onChangeInputValue('');
|
|
2526
2526
|
onChangeInputLabel('');
|
|
2527
|
-
setShowSelectComponent(true);
|
|
2528
2527
|
onFocus && onFocus(event);
|
|
2529
2528
|
},
|
|
2530
2529
|
onBlur: event => {
|
|
2531
|
-
|
|
2530
|
+
var _a, _b;
|
|
2531
|
+
if ((_a = event.relatedTarget) === null || _a === void 0 ? void 0 : _a.contains(event.currentTarget)) {
|
|
2532
|
+
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
2533
|
+
return;
|
|
2534
|
+
}
|
|
2532
2535
|
setShowSelectComponent(false);
|
|
2536
|
+
setSelectedOptionOnInputValue();
|
|
2533
2537
|
onBlur && onBlur(event);
|
|
2534
2538
|
},
|
|
2535
2539
|
onKeyUp: onKeyUp,
|
|
@@ -2714,7 +2718,17 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2714
2718
|
const [inputLabel, setInputLabel] = react.useState('');
|
|
2715
2719
|
const [internalSelectedOption, setInternalSelectedOption] = react.useState();
|
|
2716
2720
|
const inputRef = react.useRef(null);
|
|
2721
|
+
const selectRef = react.useRef(null);
|
|
2722
|
+
const containerRef = react.useRef(null);
|
|
2723
|
+
const {
|
|
2724
|
+
addOpenPositionClass,
|
|
2725
|
+
resetPositionClass
|
|
2726
|
+
} = uiUtils.useOpenPosition(selectRef, containerRef, ['top', 'bottom'], 'bottom');
|
|
2717
2727
|
react.useEffect(() => {
|
|
2728
|
+
if (!showSelectComponent) {
|
|
2729
|
+
setCurrentOptionList(optionList || []);
|
|
2730
|
+
return;
|
|
2731
|
+
}
|
|
2718
2732
|
if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
|
|
2719
2733
|
setCurrentOptionList([]);
|
|
2720
2734
|
} else {
|
|
@@ -2725,7 +2739,7 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2725
2739
|
setCurrentOptionList([...optionsResponse]);
|
|
2726
2740
|
}).catch(error => console.error('An error happens when trying to normalize options', error));
|
|
2727
2741
|
}
|
|
2728
|
-
}, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
|
|
2742
|
+
}, [showSelectComponent, filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
|
|
2729
2743
|
const setSelectedOptionOnInputValue = react.useCallback(() => {
|
|
2730
2744
|
if (!inputValue && internalSelectedOption) {
|
|
2731
2745
|
setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
|
|
@@ -2764,7 +2778,14 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2764
2778
|
style: {
|
|
2765
2779
|
maxWidth: (_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.style.width
|
|
2766
2780
|
},
|
|
2767
|
-
ref:
|
|
2781
|
+
ref: instance => {
|
|
2782
|
+
containerRef.current = instance;
|
|
2783
|
+
if (typeof ref === 'function') {
|
|
2784
|
+
ref(instance);
|
|
2785
|
+
} else if (typeof ref === 'object' && ref) {
|
|
2786
|
+
ref.current = instance;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2768
2789
|
}, uiUtils.applyDataAttributes(props), {
|
|
2769
2790
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
|
|
2770
2791
|
id: id,
|
|
@@ -2779,7 +2800,12 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2779
2800
|
showSelectComponent: showSelectComponent,
|
|
2780
2801
|
inputRef: inputRef,
|
|
2781
2802
|
placeholder: placeholder,
|
|
2782
|
-
setShowSelectComponent:
|
|
2803
|
+
setShowSelectComponent: show => {
|
|
2804
|
+
reactDom.flushSync(() => {
|
|
2805
|
+
setShowSelectComponent(show);
|
|
2806
|
+
});
|
|
2807
|
+
show ? addOpenPositionClass() : resetPositionClass();
|
|
2808
|
+
},
|
|
2783
2809
|
onChangeInputValue: setInputValue,
|
|
2784
2810
|
setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
|
|
2785
2811
|
onChangeInputLabel: setInputLabel,
|
|
@@ -2788,26 +2814,25 @@ const Dropdown = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2788
2814
|
onKeyUp: onKeyUp,
|
|
2789
2815
|
onKeyDown: onKeyDown,
|
|
2790
2816
|
disableSearch: disableSearch
|
|
2791
|
-
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
})]
|
|
2817
|
+
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(atomsSelect.Select, Object.assign({
|
|
2818
|
+
id: `${id}-select`,
|
|
2819
|
+
dataTestId: `${dataTestId}-select`,
|
|
2820
|
+
onChange: selectedValue => {
|
|
2821
|
+
var _a;
|
|
2822
|
+
if (!selectedValue.disabled) {
|
|
2823
|
+
setInputValue(selectedValue.value);
|
|
2824
|
+
setInputLabel(selectedValue.label);
|
|
2825
|
+
setInternalSelectedOption(Object.assign({}, selectedValue));
|
|
2826
|
+
reactDom.flushSync(() => {
|
|
2827
|
+
onChange(selectedValue);
|
|
2828
|
+
});
|
|
2829
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2830
|
+
}
|
|
2831
|
+
},
|
|
2832
|
+
ref: selectRef,
|
|
2833
|
+
active: internalSelectedOption,
|
|
2834
|
+
options: currentOptionList
|
|
2835
|
+
}, uiUtils.applyDataAttributes(props, 'select')))]
|
|
2811
2836
|
}));
|
|
2812
2837
|
});
|
|
2813
2838
|
|
|
@@ -2840,7 +2865,17 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2840
2865
|
const [inputLabel, setInputLabel] = react.useState('');
|
|
2841
2866
|
const [internalSelectedOption, setInternalSelectedOption] = react.useState();
|
|
2842
2867
|
const inputRef = react.useRef(null);
|
|
2868
|
+
const selectRef = react.useRef(null);
|
|
2869
|
+
const containerRef = react.useRef(null);
|
|
2870
|
+
const {
|
|
2871
|
+
addOpenPositionClass,
|
|
2872
|
+
resetPositionClass
|
|
2873
|
+
} = uiUtils.useOpenPosition(selectRef, containerRef, ['top', 'bottom'], 'bottom');
|
|
2843
2874
|
react.useEffect(() => {
|
|
2875
|
+
if (!showSelectComponent) {
|
|
2876
|
+
setCurrentOptionList(optionList || []);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2844
2879
|
if ((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) === inputValue) {
|
|
2845
2880
|
setCurrentOptionList([]);
|
|
2846
2881
|
} else {
|
|
@@ -2851,7 +2886,7 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2851
2886
|
setCurrentOptionList([...optionsResponse]);
|
|
2852
2887
|
}).catch(error => console.error('An error happens when trying to normalize options', error));
|
|
2853
2888
|
}
|
|
2854
|
-
}, [filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
|
|
2889
|
+
}, [showSelectComponent, filterOptionsParam, optionList, urlFilterOptions, inputValue, internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value]);
|
|
2855
2890
|
const setSelectedOptionOnInputValue = react.useCallback(() => {
|
|
2856
2891
|
if (!inputValue && internalSelectedOption) {
|
|
2857
2892
|
setInputValue((internalSelectedOption === null || internalSelectedOption === void 0 ? void 0 : internalSelectedOption.value) || '');
|
|
@@ -2895,7 +2930,14 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2895
2930
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2896
2931
|
"$variant": variant,
|
|
2897
2932
|
"data-testid": `${dataTestId}-container`,
|
|
2898
|
-
ref:
|
|
2933
|
+
ref: instance => {
|
|
2934
|
+
containerRef.current = instance;
|
|
2935
|
+
if (typeof ref === 'function') {
|
|
2936
|
+
ref(instance);
|
|
2937
|
+
} else if (typeof ref === 'object' && ref) {
|
|
2938
|
+
ref.current = instance;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2899
2941
|
}, uiUtils.applyDataAttributes(props), {
|
|
2900
2942
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, Object.assign({
|
|
2901
2943
|
label: label,
|
|
@@ -2909,7 +2951,12 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2909
2951
|
showSelectComponent: showSelectComponent,
|
|
2910
2952
|
inputRef: inputRef,
|
|
2911
2953
|
placeholder: placeholder,
|
|
2912
|
-
setShowSelectComponent:
|
|
2954
|
+
setShowSelectComponent: show => {
|
|
2955
|
+
reactDom.flushSync(() => {
|
|
2956
|
+
setShowSelectComponent(show);
|
|
2957
|
+
});
|
|
2958
|
+
show ? addOpenPositionClass() : resetPositionClass();
|
|
2959
|
+
},
|
|
2913
2960
|
onChangeInputValue: setInputValue,
|
|
2914
2961
|
onChangeInputLabel: setInputLabel,
|
|
2915
2962
|
setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
|
|
@@ -2918,23 +2965,22 @@ const DropdownWithHeaders = /*#__PURE__*/react.forwardRef((_a, ref) => {
|
|
|
2918
2965
|
onKeyUp: onKeyUp,
|
|
2919
2966
|
onKeyDown: onKeyDown,
|
|
2920
2967
|
disableSearch: disableSearch
|
|
2921
|
-
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
})]
|
|
2968
|
+
}, props)), showSelectComponent && !disabled && jsxRuntime.jsx(atomsSelect.SelectWithHeaders, Object.assign({
|
|
2969
|
+
dataTestId: `${dataTestId}-select`,
|
|
2970
|
+
onChange: selectedValue => {
|
|
2971
|
+
var _a;
|
|
2972
|
+
setInputLabel(selectedValue.label);
|
|
2973
|
+
setInputValue(selectedValue.value);
|
|
2974
|
+
setInternalSelectedOption(Object.assign({}, selectedValue));
|
|
2975
|
+
reactDom.flushSync(() => {
|
|
2976
|
+
onChange(selectedValue);
|
|
2977
|
+
});
|
|
2978
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2979
|
+
},
|
|
2980
|
+
active: internalSelectedOption,
|
|
2981
|
+
ref: selectRef,
|
|
2982
|
+
options: currentOptionList
|
|
2983
|
+
}, uiUtils.applyDataAttributes(props, 'select')))]
|
|
2938
2984
|
}));
|
|
2939
2985
|
});
|
|
2940
2986
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/molecules-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@bolttech/atoms-icon": "0.23.0",
|
|
9
|
-
"@bolttech/atoms-input": "0.26.
|
|
9
|
+
"@bolttech/atoms-input": "0.26.1",
|
|
10
10
|
"@bolttech/atoms-select": "0.22.0",
|
|
11
|
-
"@bolttech/default-theme": "0.
|
|
12
|
-
"@bolttech/form-engine": "3.0
|
|
13
|
-
"@bolttech/frontend-foundations": "0.
|
|
14
|
-
"@bolttech/ui-utils": "0.
|
|
11
|
+
"@bolttech/default-theme": "0.9.0",
|
|
12
|
+
"@bolttech/form-engine": "3.1.0-beta.13",
|
|
13
|
+
"@bolttech/frontend-foundations": "0.10.0",
|
|
14
|
+
"@bolttech/ui-utils": "0.5.0",
|
|
15
15
|
"react": "18.2.0",
|
|
16
16
|
"react-dom": "18.2.0",
|
|
17
17
|
"styled-components": "6.1.1"
|
|
@@ -183,7 +183,7 @@ export type DropdownWithHeadersProps = Pick<DOMAttributes<HTMLInputElement>, 'on
|
|
|
183
183
|
@property inputRef - A ref to the input element of the dropdown
|
|
184
184
|
*/
|
|
185
185
|
export type ReusableDropdownComponentProps = DefaultProps & Pick<DOMAttributes<HTMLInputElement>, 'onKeyUp' | 'onKeyDown'> & DefaultDropdownProps & {
|
|
186
|
-
setShowSelectComponent:
|
|
186
|
+
setShowSelectComponent: (show: boolean) => void;
|
|
187
187
|
showSelectComponent: boolean;
|
|
188
188
|
onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
189
189
|
onChangeInputLabel: React.Dispatch<React.SetStateAction<string>>;
|