@bolttech/molecules-dropdown 0.5.1 → 0.7.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 +26 -35
- package/package.json +5 -5
- package/src/index.d.ts +3 -3
- package/src/lib/molecules-dropdown-with-header-options.d.ts +3 -3
- package/src/lib/molecules-dropdown.d.ts +3 -3
- package/src/lib/molecules-dropdown.styles.d.ts +15 -15
- package/src/lib/molecules-dropdown.type.d.ts +179 -179
- package/src/lib/molecules-dropdown.utils.d.ts +3 -3
- package/src/lib/molecules-reusable-dropdown-component.d.ts +2 -3
package/index.cjs
CHANGED
|
@@ -2282,7 +2282,7 @@ const ContainerDropdown = /*#__PURE__*/styled__default["default"].section.withCo
|
|
|
2282
2282
|
shadow
|
|
2283
2283
|
}
|
|
2284
2284
|
}
|
|
2285
|
-
}) =>
|
|
2285
|
+
}) => shadow.lvl0, ({
|
|
2286
2286
|
theme,
|
|
2287
2287
|
variant,
|
|
2288
2288
|
hasValue
|
|
@@ -2438,32 +2438,28 @@ const ReusableDropdownComponent = ({
|
|
|
2438
2438
|
const theme = /*#__PURE__*/styled.useTheme();
|
|
2439
2439
|
const sizeIcon = Number(theme.components.dropdown.icon.size.replace(/[^\d.-]+/g, ''));
|
|
2440
2440
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2441
|
-
children: [jsxRuntime.jsxs(ContainerDropdown,
|
|
2441
|
+
children: [jsxRuntime.jsxs(ContainerDropdown, {
|
|
2442
2442
|
variant: _variant,
|
|
2443
2443
|
hasValue: inputValue,
|
|
2444
2444
|
hasError: hasError,
|
|
2445
2445
|
disabled: disabled,
|
|
2446
|
-
"data-testid": `${dataTestId}-dropdown-container
|
|
2447
|
-
}, {
|
|
2446
|
+
"data-testid": `${dataTestId}-dropdown-container`,
|
|
2448
2447
|
children: [jsxRuntime.jsxs(ContentDropdown, {
|
|
2449
|
-
children: [label && jsxRuntime.jsxs(FieldLabelAndRequiredLabelDropdown,
|
|
2448
|
+
children: [label && jsxRuntime.jsxs(FieldLabelAndRequiredLabelDropdown, {
|
|
2450
2449
|
onClick: () => {
|
|
2451
2450
|
setShowSelectComponent(disabled ? false : !showSelectComponent);
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
children: [jsxRuntime.jsx("label", Object.assign({
|
|
2451
|
+
},
|
|
2452
|
+
children: [jsxRuntime.jsx("label", {
|
|
2455
2453
|
htmlFor: `${id}-input`,
|
|
2456
2454
|
className: "fieldLabel",
|
|
2457
|
-
"data-testid": `${dataTestId}-label
|
|
2458
|
-
}, {
|
|
2455
|
+
"data-testid": `${dataTestId}-label`,
|
|
2459
2456
|
children: label
|
|
2460
|
-
})
|
|
2457
|
+
}), required && jsxRuntime.jsx("span", {
|
|
2461
2458
|
className: "requiredLabel",
|
|
2462
|
-
"data-testid": `${dataTestId}-label-required
|
|
2463
|
-
}, {
|
|
2459
|
+
"data-testid": `${dataTestId}-label-required`,
|
|
2464
2460
|
children: "*"
|
|
2465
|
-
})
|
|
2466
|
-
})
|
|
2461
|
+
})]
|
|
2462
|
+
}), jsxRuntime.jsx(InputAndIconDropdown, {
|
|
2467
2463
|
children: jsxRuntime.jsx(atomsInput.InputStyled, {
|
|
2468
2464
|
id: `${id}-input`,
|
|
2469
2465
|
"data-testid": `${dataTestId}-input`,
|
|
@@ -2491,26 +2487,23 @@ const ReusableDropdownComponent = ({
|
|
|
2491
2487
|
}
|
|
2492
2488
|
})
|
|
2493
2489
|
})]
|
|
2494
|
-
}), jsxRuntime.jsx(ClickableElement,
|
|
2490
|
+
}), jsxRuntime.jsx(ClickableElement, {
|
|
2495
2491
|
onClick: () => {
|
|
2496
2492
|
if (!disabled) setShowSelectComponent(!showSelectComponent);
|
|
2497
|
-
}
|
|
2498
|
-
}, {
|
|
2493
|
+
},
|
|
2499
2494
|
children: jsxRuntime.jsx(atomsIcon.Icon, {
|
|
2500
2495
|
dataTestId: `${dataTestId}-icon`,
|
|
2501
2496
|
size: sizeIcon,
|
|
2502
2497
|
icon: !showSelectComponent ? 'keyboard_arrow_down' : 'keyboard_arrow_up'
|
|
2503
2498
|
})
|
|
2504
|
-
})
|
|
2505
|
-
})
|
|
2506
|
-
className: "errorMessage"
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
"data-testid": `${dataTestId}-label-error-message`
|
|
2510
|
-
}, {
|
|
2499
|
+
})]
|
|
2500
|
+
}), !showSelectComponent && hasError && errorMessage && jsxRuntime.jsx("div", {
|
|
2501
|
+
className: "errorMessage",
|
|
2502
|
+
children: jsxRuntime.jsx("label", {
|
|
2503
|
+
"data-testid": `${dataTestId}-label-error-message`,
|
|
2511
2504
|
children: errorMessage
|
|
2512
|
-
})
|
|
2513
|
-
})
|
|
2505
|
+
})
|
|
2506
|
+
})]
|
|
2514
2507
|
});
|
|
2515
2508
|
};
|
|
2516
2509
|
|
|
@@ -2692,7 +2685,7 @@ const Dropdown = ({
|
|
|
2692
2685
|
setInternalSelectedOption(currentOptionList.find(option => option.id === value));
|
|
2693
2686
|
setIsFirstRender(false);
|
|
2694
2687
|
}, [currentOptionList, isFirstRender, setSelectedOptionOnInputValue, value]);
|
|
2695
|
-
return jsxRuntime.jsxs(SectionContainer,
|
|
2688
|
+
return jsxRuntime.jsxs(SectionContainer, {
|
|
2696
2689
|
onClick: () => {
|
|
2697
2690
|
var _a;
|
|
2698
2691
|
return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
@@ -2702,8 +2695,7 @@ const Dropdown = ({
|
|
|
2702
2695
|
"data-testid": `${_dataTestId}-container`,
|
|
2703
2696
|
style: {
|
|
2704
2697
|
maxWidth: (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.style.width
|
|
2705
|
-
}
|
|
2706
|
-
}, {
|
|
2698
|
+
},
|
|
2707
2699
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, {
|
|
2708
2700
|
id: _id,
|
|
2709
2701
|
dataTestId: _dataTestId,
|
|
@@ -2741,7 +2733,7 @@ const Dropdown = ({
|
|
|
2741
2733
|
options: currentOptionList
|
|
2742
2734
|
})
|
|
2743
2735
|
})]
|
|
2744
|
-
})
|
|
2736
|
+
});
|
|
2745
2737
|
};
|
|
2746
2738
|
|
|
2747
2739
|
const DropdownWithHeaders = ({
|
|
@@ -2802,14 +2794,13 @@ const DropdownWithHeaders = ({
|
|
|
2802
2794
|
})[0] || undefined);
|
|
2803
2795
|
setIsFirstRender(false);
|
|
2804
2796
|
}, [currentOptionList, isFirstRender, setSelectedOptionOnInputValue, value]);
|
|
2805
|
-
return jsxRuntime.jsxs(SectionContainer,
|
|
2797
|
+
return jsxRuntime.jsxs(SectionContainer, {
|
|
2806
2798
|
onClick: () => {
|
|
2807
2799
|
var _a;
|
|
2808
2800
|
return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
2809
2801
|
},
|
|
2810
2802
|
variant: _variant,
|
|
2811
|
-
"data-testid": `${dataTestId}-container
|
|
2812
|
-
}, {
|
|
2803
|
+
"data-testid": `${dataTestId}-container`,
|
|
2813
2804
|
children: [jsxRuntime.jsx(ReusableDropdownComponent, {
|
|
2814
2805
|
label: label,
|
|
2815
2806
|
variant: _variant,
|
|
@@ -2845,7 +2836,7 @@ const DropdownWithHeaders = ({
|
|
|
2845
2836
|
options: currentOptionList
|
|
2846
2837
|
})
|
|
2847
2838
|
})]
|
|
2848
|
-
})
|
|
2839
|
+
});
|
|
2849
2840
|
};
|
|
2850
2841
|
|
|
2851
2842
|
exports.Dropdown = Dropdown;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/molecules-dropdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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.
|
|
9
|
-
"@bolttech/atoms-input": "0.
|
|
10
|
-
"@bolttech/atoms-select": "0.
|
|
11
|
-
"@edirect/frontend-foundations": "0.0.
|
|
8
|
+
"@bolttech/atoms-icon": "0.1.0",
|
|
9
|
+
"@bolttech/atoms-input": "0.7.0",
|
|
10
|
+
"@bolttech/atoms-select": "0.7.0",
|
|
11
|
+
"@edirect/frontend-foundations": "0.0.56",
|
|
12
12
|
"jest-styled-components": "7.1.1",
|
|
13
13
|
"react": "18.2.0",
|
|
14
14
|
"react-dom": "18.2.0",
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Dropdown } from './lib/molecules-dropdown';
|
|
2
|
-
export { DropdownWithHeaders } from './lib/molecules-dropdown-with-header-options';
|
|
3
|
-
export type { DropdownProps, DropdownWithHeadersProps, } from './lib/molecules-dropdown.type';
|
|
1
|
+
export { Dropdown } from './lib/molecules-dropdown';
|
|
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
|
-
/// <reference types="react" />
|
|
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
|
+
/// <reference types="react" />
|
|
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
|
-
/// <reference types="react" />
|
|
2
|
-
import { DropdownProps } from './molecules-dropdown.type';
|
|
3
|
-
export declare const Dropdown: ({ label, variant, required, optionList, disabled, errorMessage, urlFilterOptions, id, dataTestId, filterOptionsParam, value, onChange, onBlur, onFocus, placeholder, }: DropdownProps) => JSX.Element;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DropdownProps } from './molecules-dropdown.type';
|
|
3
|
+
export declare const Dropdown: ({ label, variant, required, optionList, disabled, errorMessage, urlFilterOptions, id, dataTestId, filterOptionsParam, value, onChange, onBlur, onFocus, placeholder, }: DropdownProps) => JSX.Element;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { StyleVariants } from './molecules-dropdown.type';
|
|
2
|
-
type DropdownStyledProps = {
|
|
3
|
-
variant: StyleVariants;
|
|
4
|
-
hasValue: string;
|
|
5
|
-
hasError?: boolean;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare const ClickableElement: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
9
|
-
export declare const ContainerDropdown: import("styled-components").StyledComponent<"section", import("styled-components").DefaultTheme, DropdownStyledProps, never>;
|
|
10
|
-
export declare const SectionContainer: import("styled-components").StyledComponent<"section", import("styled-components").DefaultTheme, Omit<DropdownStyledProps, "hasValue">, never>;
|
|
11
|
-
export declare const InputAndIconDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
12
|
-
export declare const ContentDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
13
|
-
export declare const FieldLabelAndRequiredLabelDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
14
|
-
export declare const DropdownOptionsContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
15
|
-
export {};
|
|
1
|
+
import { StyleVariants } from './molecules-dropdown.type';
|
|
2
|
+
type DropdownStyledProps = {
|
|
3
|
+
variant: StyleVariants;
|
|
4
|
+
hasValue: string;
|
|
5
|
+
hasError?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const ClickableElement: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
9
|
+
export declare const ContainerDropdown: import("styled-components").StyledComponent<"section", import("styled-components").DefaultTheme, DropdownStyledProps, never>;
|
|
10
|
+
export declare const SectionContainer: import("styled-components").StyledComponent<"section", import("styled-components").DefaultTheme, Omit<DropdownStyledProps, "hasValue">, never>;
|
|
11
|
+
export declare const InputAndIconDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
12
|
+
export declare const ContentDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
13
|
+
export declare const FieldLabelAndRequiredLabelDropdown: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
14
|
+
export declare const DropdownOptionsContainer: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
15
|
+
export {};
|
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { OptionType, OptionWithHeaderType } from '@bolttech/atoms-select';
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {StyleVariants}
|
|
5
|
-
The string value possibilities to affect the theme
|
|
6
|
-
*/
|
|
7
|
-
export type StyleVariants = 'grey' | 'border';
|
|
8
|
-
/**
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionType, OptionWithHeaderType } from '@bolttech/atoms-select';
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {StyleVariants}
|
|
5
|
+
The string value possibilities to affect the theme
|
|
6
|
+
*/
|
|
7
|
+
export type StyleVariants = 'grey' | 'border';
|
|
8
|
+
/**
|
|
9
9
|
|
|
10
|
-
Default props for Dropdown component
|
|
11
|
-
@property label - A string to display as the label of the dropdown
|
|
12
|
-
@property placeholder - An optional string to display as the placeholder of the dropdown
|
|
13
|
-
@property disabled - An optional boolean to disable the dropdown
|
|
14
|
-
@property dataTestId - An optional string to use as the data-testid attribute for the dropdown
|
|
15
|
-
@property errorMessage - An optional string to display as an error message for the dropdown
|
|
16
|
-
@property required - An optional boolean to indicate if the dropdown is required
|
|
17
|
-
@property variant - An optional string to set the variant of the dropdown
|
|
18
|
-
*/
|
|
19
|
-
type DefaultProps = {
|
|
20
|
-
label: string;
|
|
21
|
-
placeholder?: string;
|
|
22
|
-
disabled?: boolean;
|
|
23
|
-
id?: string;
|
|
24
|
-
dataTestId?: string;
|
|
25
|
-
errorMessage?: string;
|
|
26
|
-
required?: boolean;
|
|
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);
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
Props for Dropdown component
|
|
33
|
-
@extends DefaultProps
|
|
34
|
-
@property optionList - An optional array of option objects to display in the dropdown
|
|
35
|
-
@property filterOptionsParam - An optional function that filters the option list based on input value
|
|
36
|
-
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
37
|
-
@property setSelectedOption - A function to set the selected option
|
|
38
|
-
@property selectedOption - An optional object representing the currently selected option
|
|
39
|
-
*/
|
|
40
|
-
export type DropdownProps = DefaultProps & {
|
|
41
|
-
optionList?: OptionType[];
|
|
42
|
-
/**
|
|
43
|
-
* An optional function that filters the option list based on input value
|
|
44
|
-
* The function can be get by the current optionList or can get by url from server side
|
|
45
|
-
* @example
|
|
46
|
-
* // Filter by current optionList
|
|
47
|
-
* function filterOptions(inputValue: string, optionList?: OptionType[]) {
|
|
48
|
-
* if (!optionList) return [];
|
|
49
|
-
* if (!inputValue) return optionList;
|
|
50
|
-
* return optionList.filter(
|
|
51
|
-
* (opt) =>
|
|
52
|
-
* opt.label.toLowerCase().search(inputValue.trim().toLowerCase()) !== -1
|
|
53
|
-
* );
|
|
54
|
-
* }
|
|
55
|
-
* @example
|
|
56
|
-
* // Filter by url
|
|
57
|
-
* function filterOptions(inputValue: string, optionList?: OptionType[], urlValue?: string) {
|
|
58
|
-
* if (!inputValue || !urlValue) return [];
|
|
59
|
-
* return fetch(`${urlValue}?valueSearch=${inputValue}`)
|
|
60
|
-
* .then(response => {
|
|
61
|
-
* if (!response.ok) {
|
|
62
|
-
* throw new Error('Network response was not ok');
|
|
63
|
-
* }
|
|
64
|
-
* return response.json();
|
|
65
|
-
* })
|
|
66
|
-
* .then(data => {
|
|
67
|
-
* const options: OptionType[] = data.map(option => ({
|
|
68
|
-
* label: option.name,
|
|
69
|
-
* value: option.id
|
|
70
|
-
* }));
|
|
71
|
-
* return options;
|
|
72
|
-
* });
|
|
73
|
-
* }
|
|
74
|
-
*/
|
|
75
|
-
filterOptionsParam?: (inputValue: string, optionList?: OptionType[], urlValue?: string) => OptionType[] | Promise<OptionType[]>;
|
|
76
|
-
urlFilterOptions?: string;
|
|
77
|
-
/**
|
|
78
|
-
* A function to set the selected option it's possible to use a void function or useStateFunction
|
|
79
|
-
* @example useStateFunction
|
|
80
|
-
* const [selectedOption, setSelectedOption] = useState<OptionType>();
|
|
81
|
-
* <Dropdown setSelectedOption={setSelectedOption} />
|
|
82
|
-
* @example void
|
|
83
|
-
* const manipulateData = (selectedOption?: OptionType) => {
|
|
84
|
-
* console.log(selectedOption);
|
|
85
|
-
* }
|
|
86
|
-
* <Dropdown setSelectedOption={manipulateData} />
|
|
87
|
-
*/
|
|
88
|
-
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
89
|
-
value?: string;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
Props for DropdownOptionsWithHeaders component
|
|
93
|
-
@extends DefaultProps
|
|
94
|
-
@property optionList - An optional array of option objects to display in the dropdown with headers
|
|
95
|
-
@property filterOptionsParam - An optional function that filters the option list based on input value
|
|
96
|
-
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
97
|
-
@property setSelectedOption - A function to set the selected option
|
|
98
|
-
@property selectedOption - An optional object representing the currently selected option
|
|
99
|
-
*/
|
|
100
|
-
export type DropdownWithHeadersProps = DefaultProps & {
|
|
101
|
-
optionList?: OptionWithHeaderType[];
|
|
102
|
-
/**
|
|
103
|
-
* An optional function that filters the option list based on input value
|
|
104
|
-
* The function can be get by the current optionList or can get by url from server side
|
|
105
|
-
* @example
|
|
106
|
-
* // Filter by current optionList
|
|
107
|
-
* function filterOptionsWithHeaders(
|
|
108
|
-
* inputValue: string,
|
|
109
|
-
* optionList?: OptionWithHeaderType[]
|
|
110
|
-
* ) {
|
|
111
|
-
* if (!optionList) return [];
|
|
112
|
-
* if (!inputValue) return optionList;
|
|
113
|
-
* return optionList.map((element) => {
|
|
114
|
-
* return {
|
|
115
|
-
* ...element,
|
|
116
|
-
* options: element.options.filter(
|
|
117
|
-
* (subElement) =>
|
|
118
|
-
* subElement.label
|
|
119
|
-
* .toLowerCase()
|
|
120
|
-
* .search(inputValue.trim().toLowerCase()) !== -1
|
|
121
|
-
* ),
|
|
122
|
-
* };
|
|
123
|
-
* });
|
|
124
|
-
* }
|
|
125
|
-
* @example
|
|
126
|
-
* // Filter by url
|
|
127
|
-
* function filterOptions(inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) {
|
|
128
|
-
* if (!inputValue || !urlValue) return [];
|
|
129
|
-
* return fetch(`${urlValue}?valueSearch=${inputValue}`)
|
|
130
|
-
* .then(response => {
|
|
131
|
-
* if (!response.ok) {
|
|
132
|
-
* throw new Error('Network response was not ok');
|
|
133
|
-
* }
|
|
134
|
-
* return response.json();
|
|
135
|
-
* })
|
|
136
|
-
* .then(data => {
|
|
137
|
-
* return options as OptionWithHeaderType[];
|
|
138
|
-
* });
|
|
139
|
-
* }
|
|
140
|
-
*/
|
|
141
|
-
filterOptionsParam?: (inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) => OptionWithHeaderType[] | Promise<OptionWithHeaderType[]>;
|
|
142
|
-
urlFilterOptions?: string;
|
|
143
|
-
/**
|
|
144
|
-
* A function to set the selected option it's possible to use a void function or useStateFunction
|
|
145
|
-
* @example useStateFunction
|
|
146
|
-
* const [selectedOption, setSelectedOption] = useState<OptionType>();
|
|
147
|
-
* <Dropdown setSelectedOption={setSelectedOption} />
|
|
148
|
-
* @example void
|
|
149
|
-
* const manipulateData = (selectedOption?: OptionType) => {
|
|
150
|
-
* console.log(selectedOption);
|
|
151
|
-
* }
|
|
152
|
-
* <Dropdown setSelectedOption={manipulateData} />
|
|
153
|
-
*/
|
|
154
|
-
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
155
|
-
value?: string;
|
|
156
|
-
};
|
|
157
|
-
/**
|
|
158
|
-
Props for ReusableDropdownComponent component
|
|
159
|
-
This type will be private, it will be use by only by our ReusableDropdownComponent
|
|
160
|
-
@extends DefaultProps
|
|
161
|
-
@property setShowSelectComponent - A function to set the visibility of the dropdown
|
|
162
|
-
@property showSelectComponent - A boolean indicating the visibility of the dropdown
|
|
163
|
-
@property onChangeInputValue - A function to set the input value of the dropdown
|
|
164
|
-
@property onChangeInputLabel - A function to set the input label of the dropdown
|
|
165
|
-
@property inputValue - A string representing the input value of the dropdown
|
|
166
|
-
@property inputLabel - A string representing the input value of the dropdown that will show on field
|
|
167
|
-
@property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
|
|
168
|
-
@property inputRef - A ref to the input element of the dropdown
|
|
169
|
-
*/
|
|
170
|
-
export type ReusableDropdownComponentProps = DefaultProps & {
|
|
171
|
-
setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
|
|
172
|
-
showSelectComponent: boolean;
|
|
173
|
-
onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
174
|
-
onChangeInputLabel: React.Dispatch<React.SetStateAction<string>>;
|
|
175
|
-
inputValue: string;
|
|
176
|
-
inputLabel: string;
|
|
177
|
-
setSelectedOptionOnInputValue: () => void;
|
|
178
|
-
inputRef: React.RefObject<HTMLInputElement>;
|
|
179
|
-
};
|
|
180
|
-
export {};
|
|
10
|
+
Default props for Dropdown component
|
|
11
|
+
@property label - A string to display as the label of the dropdown
|
|
12
|
+
@property placeholder - An optional string to display as the placeholder of the dropdown
|
|
13
|
+
@property disabled - An optional boolean to disable the dropdown
|
|
14
|
+
@property dataTestId - An optional string to use as the data-testid attribute for the dropdown
|
|
15
|
+
@property errorMessage - An optional string to display as an error message for the dropdown
|
|
16
|
+
@property required - An optional boolean to indicate if the dropdown is required
|
|
17
|
+
@property variant - An optional string to set the variant of the dropdown
|
|
18
|
+
*/
|
|
19
|
+
type DefaultProps = {
|
|
20
|
+
label: string;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
id?: string;
|
|
24
|
+
dataTestId?: string;
|
|
25
|
+
errorMessage?: string;
|
|
26
|
+
required?: boolean;
|
|
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);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
Props for Dropdown component
|
|
33
|
+
@extends DefaultProps
|
|
34
|
+
@property optionList - An optional array of option objects to display in the dropdown
|
|
35
|
+
@property filterOptionsParam - An optional function that filters the option list based on input value
|
|
36
|
+
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
37
|
+
@property setSelectedOption - A function to set the selected option
|
|
38
|
+
@property selectedOption - An optional object representing the currently selected option
|
|
39
|
+
*/
|
|
40
|
+
export type DropdownProps = DefaultProps & {
|
|
41
|
+
optionList?: OptionType[];
|
|
42
|
+
/**
|
|
43
|
+
* An optional function that filters the option list based on input value
|
|
44
|
+
* The function can be get by the current optionList or can get by url from server side
|
|
45
|
+
* @example
|
|
46
|
+
* // Filter by current optionList
|
|
47
|
+
* function filterOptions(inputValue: string, optionList?: OptionType[]) {
|
|
48
|
+
* if (!optionList) return [];
|
|
49
|
+
* if (!inputValue) return optionList;
|
|
50
|
+
* return optionList.filter(
|
|
51
|
+
* (opt) =>
|
|
52
|
+
* opt.label.toLowerCase().search(inputValue.trim().toLowerCase()) !== -1
|
|
53
|
+
* );
|
|
54
|
+
* }
|
|
55
|
+
* @example
|
|
56
|
+
* // Filter by url
|
|
57
|
+
* function filterOptions(inputValue: string, optionList?: OptionType[], urlValue?: string) {
|
|
58
|
+
* if (!inputValue || !urlValue) return [];
|
|
59
|
+
* return fetch(`${urlValue}?valueSearch=${inputValue}`)
|
|
60
|
+
* .then(response => {
|
|
61
|
+
* if (!response.ok) {
|
|
62
|
+
* throw new Error('Network response was not ok');
|
|
63
|
+
* }
|
|
64
|
+
* return response.json();
|
|
65
|
+
* })
|
|
66
|
+
* .then(data => {
|
|
67
|
+
* const options: OptionType[] = data.map(option => ({
|
|
68
|
+
* label: option.name,
|
|
69
|
+
* value: option.id
|
|
70
|
+
* }));
|
|
71
|
+
* return options;
|
|
72
|
+
* });
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
filterOptionsParam?: (inputValue: string, optionList?: OptionType[], urlValue?: string) => OptionType[] | Promise<OptionType[]>;
|
|
76
|
+
urlFilterOptions?: string;
|
|
77
|
+
/**
|
|
78
|
+
* A function to set the selected option it's possible to use a void function or useStateFunction
|
|
79
|
+
* @example useStateFunction
|
|
80
|
+
* const [selectedOption, setSelectedOption] = useState<OptionType>();
|
|
81
|
+
* <Dropdown setSelectedOption={setSelectedOption} />
|
|
82
|
+
* @example void
|
|
83
|
+
* const manipulateData = (selectedOption?: OptionType) => {
|
|
84
|
+
* console.log(selectedOption);
|
|
85
|
+
* }
|
|
86
|
+
* <Dropdown setSelectedOption={manipulateData} />
|
|
87
|
+
*/
|
|
88
|
+
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
89
|
+
value?: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
Props for DropdownOptionsWithHeaders component
|
|
93
|
+
@extends DefaultProps
|
|
94
|
+
@property optionList - An optional array of option objects to display in the dropdown with headers
|
|
95
|
+
@property filterOptionsParam - An optional function that filters the option list based on input value
|
|
96
|
+
@property urlFilterOptions - An optional string representing the url to fetch options
|
|
97
|
+
@property setSelectedOption - A function to set the selected option
|
|
98
|
+
@property selectedOption - An optional object representing the currently selected option
|
|
99
|
+
*/
|
|
100
|
+
export type DropdownWithHeadersProps = DefaultProps & {
|
|
101
|
+
optionList?: OptionWithHeaderType[];
|
|
102
|
+
/**
|
|
103
|
+
* An optional function that filters the option list based on input value
|
|
104
|
+
* The function can be get by the current optionList or can get by url from server side
|
|
105
|
+
* @example
|
|
106
|
+
* // Filter by current optionList
|
|
107
|
+
* function filterOptionsWithHeaders(
|
|
108
|
+
* inputValue: string,
|
|
109
|
+
* optionList?: OptionWithHeaderType[]
|
|
110
|
+
* ) {
|
|
111
|
+
* if (!optionList) return [];
|
|
112
|
+
* if (!inputValue) return optionList;
|
|
113
|
+
* return optionList.map((element) => {
|
|
114
|
+
* return {
|
|
115
|
+
* ...element,
|
|
116
|
+
* options: element.options.filter(
|
|
117
|
+
* (subElement) =>
|
|
118
|
+
* subElement.label
|
|
119
|
+
* .toLowerCase()
|
|
120
|
+
* .search(inputValue.trim().toLowerCase()) !== -1
|
|
121
|
+
* ),
|
|
122
|
+
* };
|
|
123
|
+
* });
|
|
124
|
+
* }
|
|
125
|
+
* @example
|
|
126
|
+
* // Filter by url
|
|
127
|
+
* function filterOptions(inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) {
|
|
128
|
+
* if (!inputValue || !urlValue) return [];
|
|
129
|
+
* return fetch(`${urlValue}?valueSearch=${inputValue}`)
|
|
130
|
+
* .then(response => {
|
|
131
|
+
* if (!response.ok) {
|
|
132
|
+
* throw new Error('Network response was not ok');
|
|
133
|
+
* }
|
|
134
|
+
* return response.json();
|
|
135
|
+
* })
|
|
136
|
+
* .then(data => {
|
|
137
|
+
* return options as OptionWithHeaderType[];
|
|
138
|
+
* });
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
filterOptionsParam?: (inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) => OptionWithHeaderType[] | Promise<OptionWithHeaderType[]>;
|
|
142
|
+
urlFilterOptions?: string;
|
|
143
|
+
/**
|
|
144
|
+
* A function to set the selected option it's possible to use a void function or useStateFunction
|
|
145
|
+
* @example useStateFunction
|
|
146
|
+
* const [selectedOption, setSelectedOption] = useState<OptionType>();
|
|
147
|
+
* <Dropdown setSelectedOption={setSelectedOption} />
|
|
148
|
+
* @example void
|
|
149
|
+
* const manipulateData = (selectedOption?: OptionType) => {
|
|
150
|
+
* console.log(selectedOption);
|
|
151
|
+
* }
|
|
152
|
+
* <Dropdown setSelectedOption={manipulateData} />
|
|
153
|
+
*/
|
|
154
|
+
onChange: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
|
|
155
|
+
value?: string;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
Props for ReusableDropdownComponent component
|
|
159
|
+
This type will be private, it will be use by only by our ReusableDropdownComponent
|
|
160
|
+
@extends DefaultProps
|
|
161
|
+
@property setShowSelectComponent - A function to set the visibility of the dropdown
|
|
162
|
+
@property showSelectComponent - A boolean indicating the visibility of the dropdown
|
|
163
|
+
@property onChangeInputValue - A function to set the input value of the dropdown
|
|
164
|
+
@property onChangeInputLabel - A function to set the input label of the dropdown
|
|
165
|
+
@property inputValue - A string representing the input value of the dropdown
|
|
166
|
+
@property inputLabel - A string representing the input value of the dropdown that will show on field
|
|
167
|
+
@property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
|
|
168
|
+
@property inputRef - A ref to the input element of the dropdown
|
|
169
|
+
*/
|
|
170
|
+
export type ReusableDropdownComponentProps = DefaultProps & {
|
|
171
|
+
setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
|
|
172
|
+
showSelectComponent: boolean;
|
|
173
|
+
onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
|
|
174
|
+
onChangeInputLabel: React.Dispatch<React.SetStateAction<string>>;
|
|
175
|
+
inputValue: string;
|
|
176
|
+
inputLabel: string;
|
|
177
|
+
setSelectedOptionOnInputValue: () => void;
|
|
178
|
+
inputRef: React.RefObject<HTMLInputElement>;
|
|
179
|
+
};
|
|
180
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { OptionType, OptionWithHeaderType } from '@bolttech/atoms-select';
|
|
2
|
-
export declare function filterOptions(inputValue: string, optionList?: OptionType[]): OptionType[];
|
|
3
|
-
export declare function filterOptionsWithHeaders(inputValue: string, optionList?: OptionWithHeaderType[]): OptionWithHeaderType[];
|
|
1
|
+
import { OptionType, OptionWithHeaderType } from '@bolttech/atoms-select';
|
|
2
|
+
export declare function filterOptions(inputValue: string, optionList?: OptionType[]): OptionType[];
|
|
3
|
+
export declare function filterOptionsWithHeaders(inputValue: string, optionList?: OptionWithHeaderType[]): OptionWithHeaderType[];
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
1
|
+
import { ReusableDropdownComponentProps } from './molecules-dropdown.type';
|
|
2
|
+
export declare const ReusableDropdownComponent: ({ id, dataTestId, label, variant, required, inputValue, inputLabel, disabled, errorMessage, onChangeInputValue, onChangeInputLabel, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, placeholder, onBlur, onFocus, }: ReusableDropdownComponentProps) => import("react/jsx-runtime").JSX.Element;
|