@bolttech/molecules-dropdown 0.4.2 → 0.5.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 +59 -39
- package/package.json +6 -5
- package/src/index.d.ts +2 -2
- package/src/lib/molecules-dropdown-with-header-options.d.ts +2 -2
- package/src/lib/molecules-dropdown.d.ts +1 -1
- package/src/lib/molecules-dropdown.type.d.ts +8 -7
- package/src/lib/molecules-reusable-dropdown-component.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var atomsSelect = require('@bolttech/atoms-select');
|
|
|
8
8
|
var atomsIcon = require('@bolttech/atoms-icon');
|
|
9
9
|
var atomsInput = require('@bolttech/atoms-input');
|
|
10
10
|
var styled = require('styled-components');
|
|
11
|
+
var reactDom = require('react-dom');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
@@ -2413,12 +2414,13 @@ const DropdownOptionsContainer = /*#__PURE__*/styled__default["default"].div.wit
|
|
|
2413
2414
|
})(["position:absolute;inset:0;top:100%;"]);
|
|
2414
2415
|
|
|
2415
2416
|
const ReusableDropdownComponent = ({
|
|
2417
|
+
id,
|
|
2418
|
+
dataTestId,
|
|
2416
2419
|
label,
|
|
2417
2420
|
variant: _variant = 'grey',
|
|
2418
2421
|
required,
|
|
2419
2422
|
inputValue,
|
|
2420
2423
|
inputLabel,
|
|
2421
|
-
hasError,
|
|
2422
2424
|
disabled,
|
|
2423
2425
|
errorMessage,
|
|
2424
2426
|
onChangeInputValue,
|
|
@@ -2427,9 +2429,11 @@ const ReusableDropdownComponent = ({
|
|
|
2427
2429
|
showSelectComponent,
|
|
2428
2430
|
setSelectedOptionOnInputValue,
|
|
2429
2431
|
inputRef,
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
+
placeholder,
|
|
2433
|
+
onBlur,
|
|
2434
|
+
onFocus
|
|
2432
2435
|
}) => {
|
|
2436
|
+
const hasError = !!errorMessage;
|
|
2433
2437
|
// we have to type cast because of jest. when testing it sets the type of useTheme to DefaultTheme
|
|
2434
2438
|
const theme = /*#__PURE__*/styled.useTheme();
|
|
2435
2439
|
const sizeIcon = Number(theme.components.dropdown.icon.size.replace(/[^\d.-]+/g, ''));
|
|
@@ -2448,11 +2452,12 @@ const ReusableDropdownComponent = ({
|
|
|
2448
2452
|
}
|
|
2449
2453
|
}, {
|
|
2450
2454
|
children: [jsxRuntime.jsx("label", Object.assign({
|
|
2455
|
+
htmlFor: `${id}-input`,
|
|
2451
2456
|
className: "fieldLabel",
|
|
2452
2457
|
"data-testid": `${dataTestId}-label`
|
|
2453
2458
|
}, {
|
|
2454
2459
|
children: label
|
|
2455
|
-
})), required && jsxRuntime.jsx("
|
|
2460
|
+
})), required && jsxRuntime.jsx("span", Object.assign({
|
|
2456
2461
|
className: "requiredLabel",
|
|
2457
2462
|
"data-testid": `${dataTestId}-label-required`
|
|
2458
2463
|
}, {
|
|
@@ -2460,6 +2465,7 @@ const ReusableDropdownComponent = ({
|
|
|
2460
2465
|
}))]
|
|
2461
2466
|
})), jsxRuntime.jsx(InputAndIconDropdown, {
|
|
2462
2467
|
children: jsxRuntime.jsx(atomsInput.InputStyled, {
|
|
2468
|
+
id: `${id}-input`,
|
|
2463
2469
|
"data-testid": `${dataTestId}-input`,
|
|
2464
2470
|
ref: inputRef,
|
|
2465
2471
|
disabled: disabled,
|
|
@@ -2472,14 +2478,16 @@ const ReusableDropdownComponent = ({
|
|
|
2472
2478
|
onChangeInputLabel(((_b = e === null || e === void 0 ? void 0 : e.target) === null || _b === void 0 ? void 0 : _b.value) || '');
|
|
2473
2479
|
setShowSelectComponent(true);
|
|
2474
2480
|
},
|
|
2475
|
-
onFocus:
|
|
2481
|
+
onFocus: event => {
|
|
2476
2482
|
onChangeInputValue('');
|
|
2477
2483
|
onChangeInputLabel('');
|
|
2478
2484
|
setShowSelectComponent(true);
|
|
2485
|
+
onFocus && onFocus(event);
|
|
2479
2486
|
},
|
|
2480
|
-
onBlur:
|
|
2487
|
+
onBlur: event => {
|
|
2481
2488
|
setSelectedOptionOnInputValue();
|
|
2482
2489
|
setShowSelectComponent(false);
|
|
2490
|
+
onBlur && onBlur(event);
|
|
2483
2491
|
}
|
|
2484
2492
|
})
|
|
2485
2493
|
})]
|
|
@@ -2634,15 +2642,17 @@ const Dropdown = ({
|
|
|
2634
2642
|
label,
|
|
2635
2643
|
variant: _variant = 'grey',
|
|
2636
2644
|
required,
|
|
2637
|
-
hasError,
|
|
2638
2645
|
optionList,
|
|
2639
2646
|
disabled,
|
|
2640
2647
|
errorMessage,
|
|
2641
2648
|
urlFilterOptions,
|
|
2642
|
-
|
|
2649
|
+
id: _id = 'dropdown-id',
|
|
2650
|
+
dataTestId: _dataTestId = 'dropdown-data-testid',
|
|
2643
2651
|
filterOptionsParam: _filterOptionsParam = filterOptions,
|
|
2644
|
-
|
|
2645
|
-
|
|
2652
|
+
value,
|
|
2653
|
+
onChange,
|
|
2654
|
+
onBlur,
|
|
2655
|
+
onFocus,
|
|
2646
2656
|
placeholder
|
|
2647
2657
|
}) => {
|
|
2648
2658
|
var _a;
|
|
@@ -2650,15 +2660,8 @@ const Dropdown = ({
|
|
|
2650
2660
|
const [currentOptionList, setCurrentOptionList] = react.useState([]);
|
|
2651
2661
|
const [inputValue, setInputValue] = react.useState('');
|
|
2652
2662
|
const [inputLabel, setInputLabel] = react.useState('');
|
|
2653
|
-
const [internalSelectedOption, setInternalSelectedOption] = react.useState(
|
|
2663
|
+
const [internalSelectedOption, setInternalSelectedOption] = react.useState(value);
|
|
2654
2664
|
const inputRef = react.useRef(null);
|
|
2655
|
-
react.useEffect(() => {
|
|
2656
|
-
var _a;
|
|
2657
|
-
if (internalSelectedOption) {
|
|
2658
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2659
|
-
setSelectedOption(internalSelectedOption);
|
|
2660
|
-
}
|
|
2661
|
-
}, [internalSelectedOption, setSelectedOption]);
|
|
2662
2665
|
react.useEffect(() => {
|
|
2663
2666
|
const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
2664
2667
|
return yield _filterOptionsParam(inputValue, optionList, urlFilterOptions);
|
|
@@ -2679,41 +2682,54 @@ const Dropdown = ({
|
|
|
2679
2682
|
}
|
|
2680
2683
|
}
|
|
2681
2684
|
}, [currentOptionList, inputValue, internalSelectedOption]);
|
|
2685
|
+
react.useEffect(() => {
|
|
2686
|
+
setSelectedOptionOnInputValue();
|
|
2687
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2688
|
+
}, []);
|
|
2682
2689
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2683
2690
|
onClick: () => {
|
|
2684
2691
|
var _a;
|
|
2685
2692
|
return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
2686
2693
|
},
|
|
2687
2694
|
variant: _variant,
|
|
2688
|
-
|
|
2695
|
+
id: `${_id}-container`,
|
|
2696
|
+
"data-testid": `${_dataTestId}-container`,
|
|
2689
2697
|
style: {
|
|
2690
2698
|
maxWidth: (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.style.width
|
|
2691
2699
|
}
|
|
2692
2700
|
}, {
|
|
2693
2701
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, {
|
|
2702
|
+
id: _id,
|
|
2703
|
+
dataTestId: _dataTestId,
|
|
2694
2704
|
label: label,
|
|
2695
2705
|
variant: _variant,
|
|
2696
2706
|
required: required,
|
|
2697
2707
|
inputValue: inputValue,
|
|
2698
2708
|
inputLabel: inputLabel,
|
|
2699
|
-
dataTestId: dataTestId,
|
|
2700
2709
|
disabled: disabled,
|
|
2701
2710
|
errorMessage: errorMessage,
|
|
2702
|
-
hasError: hasError,
|
|
2703
2711
|
showSelectComponent: showSelectComponent,
|
|
2704
2712
|
inputRef: inputRef,
|
|
2705
2713
|
placeholder: placeholder,
|
|
2706
2714
|
setShowSelectComponent: setShowSelectComponent,
|
|
2707
2715
|
onChangeInputValue: setInputValue,
|
|
2708
2716
|
setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
|
|
2709
|
-
onChangeInputLabel: setInputLabel
|
|
2717
|
+
onChangeInputLabel: setInputLabel,
|
|
2718
|
+
onBlur: onBlur,
|
|
2719
|
+
onFocus: onFocus
|
|
2710
2720
|
}), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
|
|
2711
2721
|
children: jsxRuntime.jsx(atomsSelect.Select, {
|
|
2712
|
-
|
|
2722
|
+
id: `${_id}-select`,
|
|
2723
|
+
dataTestId: `${_dataTestId}-select`,
|
|
2713
2724
|
onChange: selectedValue => {
|
|
2725
|
+
var _a;
|
|
2714
2726
|
setInputValue(selectedValue.value);
|
|
2715
2727
|
setInputLabel(selectedValue.label);
|
|
2716
2728
|
setInternalSelectedOption(Object.assign({}, selectedValue));
|
|
2729
|
+
reactDom.flushSync(() => {
|
|
2730
|
+
onChange(selectedValue);
|
|
2731
|
+
});
|
|
2732
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2717
2733
|
},
|
|
2718
2734
|
active: internalSelectedOption,
|
|
2719
2735
|
options: currentOptionList
|
|
@@ -2722,34 +2738,28 @@ const Dropdown = ({
|
|
|
2722
2738
|
}));
|
|
2723
2739
|
};
|
|
2724
2740
|
|
|
2725
|
-
const
|
|
2741
|
+
const DropdownWithHeaders = ({
|
|
2726
2742
|
label,
|
|
2727
2743
|
variant: _variant = 'grey',
|
|
2728
2744
|
required,
|
|
2729
|
-
hasError,
|
|
2730
2745
|
optionList,
|
|
2731
2746
|
disabled,
|
|
2732
2747
|
errorMessage,
|
|
2733
2748
|
urlFilterOptions,
|
|
2734
2749
|
dataTestId,
|
|
2735
2750
|
filterOptionsParam: _filterOptionsParam = filterOptionsWithHeaders,
|
|
2736
|
-
|
|
2737
|
-
|
|
2751
|
+
value,
|
|
2752
|
+
onChange,
|
|
2753
|
+
onBlur,
|
|
2754
|
+
onFocus,
|
|
2738
2755
|
placeholder
|
|
2739
2756
|
}) => {
|
|
2740
2757
|
const [showSelectComponent, setShowSelectComponent] = react.useState(false);
|
|
2741
2758
|
const [currentOptionList, setCurrentOptionList] = react.useState([]);
|
|
2742
2759
|
const [inputValue, setInputValue] = react.useState('');
|
|
2743
2760
|
const [inputLabel, setInputLabel] = react.useState('');
|
|
2744
|
-
const [internalSelectedOption, setInternalSelectedOption] = react.useState(
|
|
2761
|
+
const [internalSelectedOption, setInternalSelectedOption] = react.useState(value);
|
|
2745
2762
|
const inputRef = react.useRef(null);
|
|
2746
|
-
react.useEffect(() => {
|
|
2747
|
-
var _a;
|
|
2748
|
-
if (internalSelectedOption) {
|
|
2749
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2750
|
-
setSelectedOption(internalSelectedOption);
|
|
2751
|
-
}
|
|
2752
|
-
}, [internalSelectedOption, setSelectedOption]);
|
|
2753
2763
|
react.useEffect(() => {
|
|
2754
2764
|
const normalizeOptionList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
2755
2765
|
return yield _filterOptionsParam(inputValue, optionList, urlFilterOptions);
|
|
@@ -2774,6 +2784,10 @@ const DropdownOptionsWithHeaders = ({
|
|
|
2774
2784
|
}
|
|
2775
2785
|
}
|
|
2776
2786
|
}, [currentOptionList, inputValue, internalSelectedOption]);
|
|
2787
|
+
react.useEffect(() => {
|
|
2788
|
+
setSelectedOptionOnInputValue();
|
|
2789
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2790
|
+
}, []);
|
|
2777
2791
|
return jsxRuntime.jsxs(SectionContainer, Object.assign({
|
|
2778
2792
|
onClick: () => {
|
|
2779
2793
|
var _a;
|
|
@@ -2791,23 +2805,29 @@ const DropdownOptionsWithHeaders = ({
|
|
|
2791
2805
|
dataTestId: dataTestId,
|
|
2792
2806
|
disabled: disabled,
|
|
2793
2807
|
errorMessage: errorMessage,
|
|
2794
|
-
hasError: hasError,
|
|
2795
2808
|
showSelectComponent: showSelectComponent,
|
|
2796
2809
|
inputRef: inputRef,
|
|
2797
2810
|
placeholder: placeholder,
|
|
2798
2811
|
setShowSelectComponent: setShowSelectComponent,
|
|
2799
2812
|
onChangeInputValue: setInputValue,
|
|
2800
2813
|
onChangeInputLabel: setInputLabel,
|
|
2801
|
-
setSelectedOptionOnInputValue: setSelectedOptionOnInputValue
|
|
2814
|
+
setSelectedOptionOnInputValue: setSelectedOptionOnInputValue,
|
|
2815
|
+
onBlur: onBlur,
|
|
2816
|
+
onFocus: onFocus
|
|
2802
2817
|
}), showSelectComponent && !disabled && jsxRuntime.jsx(DropdownOptionsContainer, {
|
|
2803
2818
|
children: jsxRuntime.jsx(atomsSelect.SelectWithHeaders, {
|
|
2804
2819
|
dataTestId: `${dataTestId}-select`,
|
|
2805
2820
|
onChange: selectedValue => {
|
|
2821
|
+
var _a;
|
|
2806
2822
|
setInputLabel(selectedValue.label);
|
|
2807
2823
|
setInputValue(selectedValue.value);
|
|
2808
2824
|
setInternalSelectedOption(Object.assign({}, selectedValue));
|
|
2825
|
+
reactDom.flushSync(() => {
|
|
2826
|
+
onChange(selectedValue);
|
|
2827
|
+
});
|
|
2828
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
2809
2829
|
},
|
|
2810
|
-
active:
|
|
2830
|
+
active: internalSelectedOption,
|
|
2811
2831
|
options: currentOptionList
|
|
2812
2832
|
})
|
|
2813
2833
|
})]
|
|
@@ -2815,4 +2835,4 @@ const DropdownOptionsWithHeaders = ({
|
|
|
2815
2835
|
};
|
|
2816
2836
|
|
|
2817
2837
|
exports.Dropdown = Dropdown;
|
|
2818
|
-
exports.
|
|
2838
|
+
exports.DropdownWithHeaders = DropdownWithHeaders;
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/molecules-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@bolttech/atoms-icon": "0.5.
|
|
9
|
-
"@bolttech/atoms-input": "0.
|
|
10
|
-
"@bolttech/atoms-select": "0.5.
|
|
11
|
-
"@edirect/frontend-foundations": "0.0.
|
|
8
|
+
"@bolttech/atoms-icon": "0.5.1",
|
|
9
|
+
"@bolttech/atoms-input": "0.5.0",
|
|
10
|
+
"@bolttech/atoms-select": "0.5.1",
|
|
11
|
+
"@edirect/frontend-foundations": "0.0.55",
|
|
12
12
|
"jest-styled-components": "7.1.1",
|
|
13
13
|
"react": "18.2.0",
|
|
14
|
+
"react-dom": "18.2.0",
|
|
14
15
|
"styled-components": "5.3.6"
|
|
15
16
|
},
|
|
16
17
|
"peerDependencies": {}
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Dropdown } from './lib/molecules-dropdown';
|
|
2
|
-
export {
|
|
3
|
-
export type { DropdownProps,
|
|
2
|
+
export { DropdownWithHeaders } from './lib/molecules-dropdown-with-header-options';
|
|
3
|
+
export type { DropdownProps, DropdownWithHeadersProps, } from './lib/molecules-dropdown.type';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const
|
|
2
|
+
import { DropdownWithHeadersProps } from './molecules-dropdown.type';
|
|
3
|
+
export declare const DropdownWithHeaders: ({ label, variant, required, optionList, disabled, errorMessage, urlFilterOptions, dataTestId, filterOptionsParam, value, onChange, onBlur, onFocus, placeholder, }: DropdownWithHeadersProps) => JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DropdownProps } from './molecules-dropdown.type';
|
|
3
|
-
export declare const Dropdown: ({ label, variant, required,
|
|
3
|
+
export declare const Dropdown: ({ label, variant, required, optionList, disabled, errorMessage, urlFilterOptions, id, dataTestId, filterOptionsParam, value, onChange, onBlur, onFocus, placeholder, }: DropdownProps) => JSX.Element;
|
|
@@ -13,7 +13,6 @@ Default props for Dropdown component
|
|
|
13
13
|
@property disabled - An optional boolean to disable the dropdown
|
|
14
14
|
@property dataTestId - An optional string to use as the data-testid attribute for the dropdown
|
|
15
15
|
@property errorMessage - An optional string to display as an error message for the dropdown
|
|
16
|
-
@property hasError - An optional boolean to indicate if the dropdown has an error
|
|
17
16
|
@property required - An optional boolean to indicate if the dropdown is required
|
|
18
17
|
@property variant - An optional string to set the variant of the dropdown
|
|
19
18
|
*/
|
|
@@ -21,11 +20,13 @@ type DefaultProps = {
|
|
|
21
20
|
label: string;
|
|
22
21
|
placeholder?: string;
|
|
23
22
|
disabled?: boolean;
|
|
23
|
+
id?: string;
|
|
24
24
|
dataTestId?: string;
|
|
25
25
|
errorMessage?: string;
|
|
26
|
-
hasError?: boolean;
|
|
27
26
|
required?: boolean;
|
|
28
27
|
variant?: StyleVariants;
|
|
28
|
+
onBlur?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
|
|
29
|
+
onFocus?: ((value?: unknown) => void) | ((evt: React.FocusEvent<HTMLElement, Element>) => void);
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
Props for Dropdown component
|
|
@@ -84,8 +85,8 @@ export type DropdownProps = DefaultProps & {
|
|
|
84
85
|
* }
|
|
85
86
|
* <Dropdown setSelectedOption={manipulateData} />
|
|
86
87
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
89
|
+
value?: OptionType;
|
|
89
90
|
};
|
|
90
91
|
/**
|
|
91
92
|
Props for DropdownOptionsWithHeaders component
|
|
@@ -96,7 +97,7 @@ export type DropdownProps = DefaultProps & {
|
|
|
96
97
|
@property setSelectedOption - A function to set the selected option
|
|
97
98
|
@property selectedOption - An optional object representing the currently selected option
|
|
98
99
|
*/
|
|
99
|
-
export type
|
|
100
|
+
export type DropdownWithHeadersProps = DefaultProps & {
|
|
100
101
|
optionList?: OptionWithHeaderType[];
|
|
101
102
|
/**
|
|
102
103
|
* An optional function that filters the option list based on input value
|
|
@@ -150,8 +151,8 @@ export type DropdownOptionsWithHeadersProps = DefaultProps & {
|
|
|
150
151
|
* }
|
|
151
152
|
* <Dropdown setSelectedOption={manipulateData} />
|
|
152
153
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
155
|
+
value?: OptionType;
|
|
155
156
|
};
|
|
156
157
|
/**
|
|
157
158
|
Props for ReusableDropdownComponent component
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ReusableDropdownComponentProps } from './molecules-dropdown.type';
|
|
3
|
-
export declare const ReusableDropdownComponent: ({ label, variant, required, inputValue, inputLabel,
|
|
3
|
+
export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, placeholder, onBlur, onFocus, }: ReusableDropdownComponentProps) => JSX.Element;
|