@bolttech/molecules-dropdown 0.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/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@bolttech/molecules-dropdown",
3
+ "version": "0.1.0",
4
+ "dependencies": {
5
+ "@bolttech/atoms-icon": "0.0.1",
6
+ "@bolttech/atoms-input": "0.0.1"
7
+ },
8
+ "module": "./index.js",
9
+ "main": "./index.js",
10
+ "type": "module",
11
+ "types": "./src/index.d.ts",
12
+ "peerDependencies": {
13
+ "@bolttech/atoms-select": "0.1.0",
14
+ "@edirect/frontend-foundations": "0.0.21",
15
+ "jest-styled-components": "7.1.1",
16
+ "react": "18.2.0",
17
+ "styled-components": "5.3.6"
18
+ }
19
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { Dropdown } from './lib/molecules-dropdown';
2
+ export { DropdownOptionsWithHeaders } from './lib/molecules-dropdown-with-header-options';
3
+ export type { DropdownProps, DropdownOptionsWithHeadersProps } from './lib/molecules-dropdown.type';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { DropdownOptionsWithHeadersProps } from './molecules-dropdown.type';
3
+ export declare const DropdownOptionsWithHeaders: ({ label, variant, required, hasError, optionList, disabled, errorMessage, urlFilterOptions, dataTestId, filterOptionsParam, selectedOption, setSelectedOption, placeholder }: DropdownOptionsWithHeadersProps) => JSX.Element;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { DropdownProps } from './molecules-dropdown.type';
3
+ export declare const Dropdown: ({ label, variant, required, hasError, optionList, disabled, errorMessage, urlFilterOptions, dataTestId, filterOptionsParam, selectedOption, setSelectedOption, placeholder }: DropdownProps) => JSX.Element;
@@ -0,0 +1,14 @@
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 {};
@@ -0,0 +1,175 @@
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
+
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 hasError - An optional boolean to indicate if the dropdown has an error
17
+ @property required - An optional boolean to indicate if the dropdown is required
18
+ @property variant - An optional string to set the variant of the dropdown
19
+ */
20
+ type DefaultProps = {
21
+ label: string;
22
+ placeholder?: string;
23
+ disabled?: boolean;
24
+ dataTestId?: string;
25
+ errorMessage?: string;
26
+ hasError?: boolean;
27
+ required?: boolean;
28
+ variant?: StyleVariants;
29
+ };
30
+ /**
31
+ Props for Dropdown component
32
+ @extends DefaultProps
33
+ @property optionList - An optional array of option objects to display in the dropdown
34
+ @property filterOptionsParam - An optional function that filters the option list based on input value
35
+ @property urlFilterOptions - An optional string representing the url to fetch options
36
+ @property setSelectedOption - A function to set the selected option
37
+ @property selectedOption - An optional object representing the currently selected option
38
+ */
39
+ export type DropdownProps = DefaultProps & {
40
+ optionList?: OptionType[];
41
+ /**
42
+ * An optional function that filters the option list based on input value
43
+ * The function can be get by the current optionList or can get by url from server side
44
+ * @example
45
+ * // Filter by current optionList
46
+ * function filterOptions(inputValue: string, optionList?: OptionType[]) {
47
+ * if (!optionList) return [];
48
+ * if (!inputValue) return optionList;
49
+ * return optionList.filter(
50
+ * (opt) =>
51
+ * opt.label.toLowerCase().search(inputValue.trim().toLowerCase()) !== -1
52
+ * );
53
+ * }
54
+ * @example
55
+ * // Filter by url
56
+ * function filterOptions(inputValue: string, optionList?: OptionType[], urlValue?: string) {
57
+ * if (!inputValue || !urlValue) return [];
58
+ * return fetch(`${urlValue}?valueSearch=${inputValue}`)
59
+ * .then(response => {
60
+ * if (!response.ok) {
61
+ * throw new Error('Network response was not ok');
62
+ * }
63
+ * return response.json();
64
+ * })
65
+ * .then(data => {
66
+ * const options: OptionType[] = data.map(option => ({
67
+ * label: option.name,
68
+ * value: option.id
69
+ * }));
70
+ * return options;
71
+ * });
72
+ * }
73
+ */
74
+ filterOptionsParam?: (inputValue: string, optionList?: OptionType[], urlValue?: string) => OptionType[] | Promise<OptionType[]>;
75
+ urlFilterOptions?: string;
76
+ /**
77
+ * A function to set the selected option it's possible to use a void function or useStateFunction
78
+ * @example useStateFunction
79
+ * const [selectedOption, setSelectedOption] = useState<OptionType>();
80
+ * <Dropdown setSelectedOption={setSelectedOption} />
81
+ * @example void
82
+ * const manipulateData = (selectedOption?: OptionType) => {
83
+ * console.log(selectedOption);
84
+ * }
85
+ * <Dropdown setSelectedOption={manipulateData} />
86
+ */
87
+ setSelectedOption: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
88
+ selectedOption?: OptionType;
89
+ };
90
+ /**
91
+ Props for DropdownOptionsWithHeaders component
92
+ @extends DefaultProps
93
+ @property optionList - An optional array of option objects to display in the dropdown with headers
94
+ @property filterOptionsParam - An optional function that filters the option list based on input value
95
+ @property urlFilterOptions - An optional string representing the url to fetch options
96
+ @property setSelectedOption - A function to set the selected option
97
+ @property selectedOption - An optional object representing the currently selected option
98
+ */
99
+ export type DropdownOptionsWithHeadersProps = DefaultProps & {
100
+ optionList?: OptionWithHeaderType[];
101
+ /**
102
+ * An optional function that filters the option list based on input value
103
+ * The function can be get by the current optionList or can get by url from server side
104
+ * @example
105
+ * // Filter by current optionList
106
+ * function filterOptionsWithHeaders(
107
+ * inputValue: string,
108
+ * optionList?: OptionWithHeaderType[]
109
+ * ) {
110
+ * if (!optionList) return [];
111
+ * if (!inputValue) return optionList;
112
+ * return optionList.map((element) => {
113
+ * return {
114
+ * ...element,
115
+ * options: element.options.filter(
116
+ * (subElement) =>
117
+ * subElement.label
118
+ * .toLowerCase()
119
+ * .search(inputValue.trim().toLowerCase()) !== -1
120
+ * ),
121
+ * };
122
+ * });
123
+ * }
124
+ * @example
125
+ * // Filter by url
126
+ * function filterOptions(inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) {
127
+ * if (!inputValue || !urlValue) return [];
128
+ * return fetch(`${urlValue}?valueSearch=${inputValue}`)
129
+ * .then(response => {
130
+ * if (!response.ok) {
131
+ * throw new Error('Network response was not ok');
132
+ * }
133
+ * return response.json();
134
+ * })
135
+ * .then(data => {
136
+ * return options as OptionWithHeaderType[];
137
+ * });
138
+ * }
139
+ */
140
+ filterOptionsParam?: (inputValue: string, optionList?: OptionWithHeaderType[], urlValue?: string) => OptionWithHeaderType[] | Promise<OptionWithHeaderType[]>;
141
+ urlFilterOptions?: string;
142
+ /**
143
+ * A function to set the selected option it's possible to use a void function or useStateFunction
144
+ * @example useStateFunction
145
+ * const [selectedOption, setSelectedOption] = useState<OptionType>();
146
+ * <Dropdown setSelectedOption={setSelectedOption} />
147
+ * @example void
148
+ * const manipulateData = (selectedOption?: OptionType) => {
149
+ * console.log(selectedOption);
150
+ * }
151
+ * <Dropdown setSelectedOption={manipulateData} />
152
+ */
153
+ setSelectedOption: (selectedOption?: OptionType) => void | React.Dispatch<React.SetStateAction<OptionType>>;
154
+ selectedOption?: OptionType;
155
+ };
156
+ /**
157
+ Props for ReusableDropdownComponent component
158
+ This type will be private, it will be use by only by our ReusableDropdownComponent
159
+ @extends DefaultProps
160
+ @property setShowSelectComponent - A function to set the visibility of the dropdown
161
+ @property showSelectComponent - A boolean indicating the visibility of the dropdown
162
+ @property onChangeInputValue - A function to set the input value of the dropdown
163
+ @property inputValue - A string representing the input value of the dropdown
164
+ @property setSelectedOptionOnInputValue - A function to set the selected option based on the input value
165
+ @property inputRef - A ref to the input element of the dropdown
166
+ */
167
+ export type ReusableDropdownComponentProps = DefaultProps & {
168
+ setShowSelectComponent: React.Dispatch<React.SetStateAction<boolean>>;
169
+ showSelectComponent: boolean;
170
+ onChangeInputValue: React.Dispatch<React.SetStateAction<string>>;
171
+ inputValue: string;
172
+ setSelectedOptionOnInputValue: () => void;
173
+ inputRef: React.RefObject<HTMLInputElement>;
174
+ };
175
+ export {};
@@ -0,0 +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[];
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { ReusableDropdownComponentProps } from './molecules-dropdown.type';
3
+ export declare const ReusableDropdownComponent: ({ label, variant, required, inputValue, hasError, disabled, errorMessage, onChangeInputValue, setShowSelectComponent, showSelectComponent, setSelectedOptionOnInputValue, inputRef, dataTestId, placeholder, }: ReusableDropdownComponentProps) => JSX.Element;