pixelize-design-library 1.1.20 → 1.1.22
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/Components/ButtonGroupIcon/ButtonGoupIconProps.d.ts +6 -0
- package/dist/Components/ButtonGroupIcon/ButtonGroupIcon.d.ts +1 -1
- package/dist/Components/ButtonGroupIcon/ButtonGroupIcon.js +14 -14
- package/dist/Components/KaTable/CustomHeader.d.ts +1 -1
- package/dist/Components/KaTable/CustomHeader.js +23 -23
- package/dist/Components/KaTable/KaTable.d.ts +1 -1
- package/dist/Components/KaTable/KaTable.js +3 -2
- package/dist/Components/KaTable/KaTableProps.d.ts +1 -0
- package/dist/Components/KaTable/SelectionCell.js +9 -6
- package/dist/Components/KaTable/SelectionHeader.js +5 -4
- package/dist/Components/KaTable/useMergedChildComponents.d.ts +1 -1
- package/dist/Components/KaTable/useMergedChildComponents.js +29 -6
- package/dist/Components/MultiSelect/MultiSelect.js +6 -19
- package/dist/Components/NavigationBar/NavigationBar.js +0 -4
- package/dist/Components/ProfilePhotoViewer/ProfilePhotoViewer.js +12 -10
- package/dist/Components/SelectSearch/SelectSearch.d.ts +1 -1
- package/dist/Components/SelectSearch/SelectSearch.js +499 -28
- package/dist/Components/SelectSearch/SelectSearchProps.d.ts +6 -4
- package/dist/Pages/KaTableExample.js +27 -18
- package/dist/Pages/selectSearch.d.ts +2 -2
- package/dist/Pages/selectSearch.js +36 -9
- package/dist/Theme/Default/fonts.d.ts +35 -0
- package/dist/Theme/Default/fonts.js +37 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/Pages/katable.d.ts +0 -3
- package/dist/Pages/katable.js +0 -194
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import React, {
|
|
3
|
+
// useCallback,
|
|
4
|
+
// useEffect,
|
|
5
|
+
// useMemo,
|
|
6
|
+
// useRef,
|
|
7
|
+
// useState,
|
|
8
|
+
// } from "react";
|
|
9
|
+
// import {
|
|
10
|
+
// Box,
|
|
11
|
+
// Input,
|
|
12
|
+
// Spinner,
|
|
13
|
+
// VStack,
|
|
14
|
+
// Text,
|
|
15
|
+
// InputGroup,
|
|
16
|
+
// InputRightElement,
|
|
17
|
+
// } from "@chakra-ui/react";
|
|
18
|
+
// import { selectOptions, SelectSearchProps } from "./SelectSearchProps";
|
|
19
|
+
// import { TextLabel } from "../Common/FormLabel";
|
|
20
|
+
// import { useCustomTheme } from "../../Theme/useCustomTheme";
|
|
2
21
|
var __assign = (this && this.__assign) || function () {
|
|
3
22
|
__assign = Object.assign || function(t) {
|
|
4
23
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -33,31 +52,496 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
52
|
__setModuleDefault(result, mod);
|
|
34
53
|
return result;
|
|
35
54
|
};
|
|
55
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
56
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
57
|
+
if (ar || !(i in from)) {
|
|
58
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
59
|
+
ar[i] = from[i];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
63
|
+
};
|
|
36
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
// export default function SelectSearch({
|
|
66
|
+
// options,
|
|
67
|
+
// initialSelectedOption = null,
|
|
68
|
+
// onOptionSelect,
|
|
69
|
+
// inputOnchange,
|
|
70
|
+
// id,
|
|
71
|
+
// name,
|
|
72
|
+
// label,
|
|
73
|
+
// inputStyle,
|
|
74
|
+
// dropdownStyle,
|
|
75
|
+
// isOptionLoading,
|
|
76
|
+
// loadingText = "loading",
|
|
77
|
+
// boxStyle,
|
|
78
|
+
// placeholder = "Select Option",
|
|
79
|
+
// searchQuery = "",
|
|
80
|
+
// isInformation = false,
|
|
81
|
+
// informationMessage,
|
|
82
|
+
// rightIcon,
|
|
83
|
+
// rightElementStyle,
|
|
84
|
+
// isMultipleSelect,
|
|
85
|
+
// }: Readonly<SelectSearchProps>) {
|
|
86
|
+
// const theme = useCustomTheme();
|
|
87
|
+
// // const [inputValue, setInputValue] = useState(
|
|
88
|
+
// // initialSelectedOption ? initialSelectedOption?.label : ""
|
|
89
|
+
// // );
|
|
90
|
+
// const [selecedOption,setSelectedOption] = useState<any>([]);
|
|
91
|
+
// const [inputValue, setInputValue] = useState();
|
|
92
|
+
// const [isOpen, setIsOpen] = useState(false);
|
|
93
|
+
// const [position, setPosition] = useState<"above" | "below">("below");
|
|
94
|
+
// const inputRef = useRef<HTMLInputElement>(null);
|
|
95
|
+
// const dropdownRef = useRef<HTMLDivElement>(null);
|
|
96
|
+
// const filteredOptions = useMemo(() => {
|
|
97
|
+
// return options;
|
|
98
|
+
// // return options?.filter((option) =>
|
|
99
|
+
// // option.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
100
|
+
// // );
|
|
101
|
+
// }, [options, inputValue]);
|
|
102
|
+
// const handleOptionClick = useCallback(
|
|
103
|
+
// (option: selectOptions) => {
|
|
104
|
+
// if(isMultipleSelect){
|
|
105
|
+
// setSelectedOption((prev:any) => [...prev, option]);
|
|
106
|
+
// }else{
|
|
107
|
+
// setIsOpen(false);
|
|
108
|
+
// onOptionSelect(option);
|
|
109
|
+
// }
|
|
110
|
+
// },
|
|
111
|
+
// [onOptionSelect]
|
|
112
|
+
// );
|
|
113
|
+
// console.log(selecedOption);
|
|
114
|
+
// // useEffect(() => {
|
|
115
|
+
// // setInputValue(searchQuery);
|
|
116
|
+
// // }, [searchQuery]);
|
|
117
|
+
// const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
118
|
+
// // if (e.key === "Enter") {
|
|
119
|
+
// // const matchingOption = options.find(
|
|
120
|
+
// // (option) => option.label.toLowerCase() === inputValue.toLowerCase()
|
|
121
|
+
// // );
|
|
122
|
+
// // if (matchingOption) {
|
|
123
|
+
// // handleOptionClick(matchingOption);
|
|
124
|
+
// // }
|
|
125
|
+
// // }
|
|
126
|
+
// };
|
|
127
|
+
// const updateDropdownPosition = () => {
|
|
128
|
+
// if (inputRef.current && dropdownRef.current) {
|
|
129
|
+
// const inputRect = inputRef.current.getBoundingClientRect();
|
|
130
|
+
// const dropdownRect = dropdownRef.current.getBoundingClientRect();
|
|
131
|
+
// const viewportHeight = window.innerHeight;
|
|
132
|
+
// const spaceBelow = viewportHeight - inputRect.bottom + window.scrollY;
|
|
133
|
+
// const spaceAbove = inputRect.top + window.scrollY;
|
|
134
|
+
// if (spaceBelow >= dropdownRect.height) {
|
|
135
|
+
// setPosition("below");
|
|
136
|
+
// } else if (spaceAbove >= dropdownRect.height) {
|
|
137
|
+
// setPosition("above");
|
|
138
|
+
// } else {
|
|
139
|
+
// setPosition("below");
|
|
140
|
+
// }
|
|
141
|
+
// }
|
|
142
|
+
// };
|
|
143
|
+
// useEffect(() => {
|
|
144
|
+
// if (isOpen) {
|
|
145
|
+
// updateDropdownPosition();
|
|
146
|
+
// }
|
|
147
|
+
// const handleClickOutside = (event: MouseEvent) => {
|
|
148
|
+
// if (
|
|
149
|
+
// inputRef.current &&
|
|
150
|
+
// dropdownRef.current &&
|
|
151
|
+
// !inputRef.current.contains(event.target as Node) &&
|
|
152
|
+
// !dropdownRef.current.contains(event.target as Node)
|
|
153
|
+
// ) {
|
|
154
|
+
// setIsOpen(false);
|
|
155
|
+
// }
|
|
156
|
+
// };
|
|
157
|
+
// const handleScroll = () => {
|
|
158
|
+
// if (isOpen) {
|
|
159
|
+
// updateDropdownPosition();
|
|
160
|
+
// }
|
|
161
|
+
// };
|
|
162
|
+
// const handleResize = () => {
|
|
163
|
+
// if (isOpen) {
|
|
164
|
+
// updateDropdownPosition();
|
|
165
|
+
// }
|
|
166
|
+
// };
|
|
167
|
+
// document.addEventListener("mousedown", handleClickOutside);
|
|
168
|
+
// window.addEventListener("scroll", handleScroll);
|
|
169
|
+
// window.addEventListener("resize", handleResize);
|
|
170
|
+
// return () => {
|
|
171
|
+
// document.removeEventListener("mousedown", handleClickOutside);
|
|
172
|
+
// window.removeEventListener("scroll", handleScroll);
|
|
173
|
+
// window.removeEventListener("resize", handleResize);
|
|
174
|
+
// };
|
|
175
|
+
// }, [isOpen]);
|
|
176
|
+
// const RenderOptions = useCallback(() => {
|
|
177
|
+
// if (isOptionLoading) {
|
|
178
|
+
// return (
|
|
179
|
+
// <VStack py={2}>
|
|
180
|
+
// <Spinner size="sm" color="blue.500" />
|
|
181
|
+
// <Text color="blue.500">{loadingText}</Text>
|
|
182
|
+
// </VStack>
|
|
183
|
+
// );
|
|
184
|
+
// }
|
|
185
|
+
// if (filteredOptions?.length) {
|
|
186
|
+
// return filteredOptions.map((option) => (
|
|
187
|
+
// <Box
|
|
188
|
+
// key={option.id}
|
|
189
|
+
// px={4}
|
|
190
|
+
// py={2}
|
|
191
|
+
// cursor="pointer"
|
|
192
|
+
// _hover={{ backgroundColor: "blue.50" }}
|
|
193
|
+
// onClick={() => handleOptionClick(option)}
|
|
194
|
+
// >
|
|
195
|
+
// {option.label}
|
|
196
|
+
// </Box>
|
|
197
|
+
// ));
|
|
198
|
+
// }
|
|
199
|
+
// return (
|
|
200
|
+
// <Text px={4} py={2} color="gray.500">
|
|
201
|
+
// No options found
|
|
202
|
+
// </Text>
|
|
203
|
+
// );
|
|
204
|
+
// }, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
|
|
205
|
+
// return (
|
|
206
|
+
// <Box
|
|
207
|
+
// display="flex"
|
|
208
|
+
// flexDirection="column"
|
|
209
|
+
// position="relative"
|
|
210
|
+
// sx={boxStyle}
|
|
211
|
+
// >
|
|
212
|
+
// {label && (
|
|
213
|
+
// <TextLabel
|
|
214
|
+
// label={label}
|
|
215
|
+
// id={id}
|
|
216
|
+
// isRequired={false}
|
|
217
|
+
// isInformation={isInformation}
|
|
218
|
+
// informationMessage={informationMessage}
|
|
219
|
+
// />
|
|
220
|
+
// )}
|
|
221
|
+
// <InputGroup>
|
|
222
|
+
// <Input
|
|
223
|
+
// ref={inputRef}
|
|
224
|
+
// variant="flushed"
|
|
225
|
+
// value={inputValue}
|
|
226
|
+
// onClick={() => setIsOpen(true)}
|
|
227
|
+
// onChange={(e) => inputOnchange(e.target.value)}
|
|
228
|
+
// placeholder={placeholder}
|
|
229
|
+
// onKeyDown={handleKeyDown}
|
|
230
|
+
// id={id}
|
|
231
|
+
// name={name}
|
|
232
|
+
// cursor="pointer"
|
|
233
|
+
// borderColor="gray.300"
|
|
234
|
+
// _hover={{ borderColor: "blue.500" }}
|
|
235
|
+
// _focus={{ borderColor: "blue.500" }}
|
|
236
|
+
// // {...inputStyle}
|
|
237
|
+
// style={{
|
|
238
|
+
// ...inputStyle,
|
|
239
|
+
// backgroundColor: theme.colors.backgroundColor.main,
|
|
240
|
+
// fontWeight: 800,
|
|
241
|
+
// color: theme.colors.gray[700],
|
|
242
|
+
// padding: "0 0.5rem",
|
|
243
|
+
// fontSize: 15,
|
|
244
|
+
// letterSpacing: 0.7,
|
|
245
|
+
// }}
|
|
246
|
+
// />
|
|
247
|
+
// {rightIcon && (
|
|
248
|
+
// <InputRightElement
|
|
249
|
+
// pointerEvents="none"
|
|
250
|
+
// children={rightIcon}
|
|
251
|
+
// style={{ ...rightElementStyle }}
|
|
252
|
+
// />
|
|
253
|
+
// )}
|
|
254
|
+
// </InputGroup>
|
|
255
|
+
// {isOpen && (
|
|
256
|
+
// <Box
|
|
257
|
+
// ref={dropdownRef}
|
|
258
|
+
// position="absolute"
|
|
259
|
+
// top={position === "below" ? "100%" : "auto"}
|
|
260
|
+
// bottom={position === "above" ? "100%" : "auto"}
|
|
261
|
+
// left={0}
|
|
262
|
+
// right={0}
|
|
263
|
+
// border="1px solid"
|
|
264
|
+
// borderColor="gray.300"
|
|
265
|
+
// borderRadius="md"
|
|
266
|
+
// bg="white"
|
|
267
|
+
// maxHeight="150px"
|
|
268
|
+
// overflowY="auto"
|
|
269
|
+
// zIndex={10}
|
|
270
|
+
// // {...dropdownStyle}
|
|
271
|
+
// >
|
|
272
|
+
// {RenderOptions()}
|
|
273
|
+
// </Box>
|
|
274
|
+
// )}
|
|
275
|
+
// </Box>
|
|
276
|
+
// );
|
|
277
|
+
// }
|
|
278
|
+
// import React, {
|
|
279
|
+
// useCallback,
|
|
280
|
+
// useEffect,
|
|
281
|
+
// useMemo,
|
|
282
|
+
// useRef,
|
|
283
|
+
// useState,
|
|
284
|
+
// } from "react";
|
|
285
|
+
// import {
|
|
286
|
+
// Box,
|
|
287
|
+
// Input,
|
|
288
|
+
// Spinner,
|
|
289
|
+
// VStack,
|
|
290
|
+
// Text,
|
|
291
|
+
// InputGroup,
|
|
292
|
+
// InputRightElement,
|
|
293
|
+
// } from "@chakra-ui/react";
|
|
294
|
+
// import { selectOptions, SelectSearchProps } from "./SelectSearchProps";
|
|
295
|
+
// import { TextLabel } from "../Common/FormLabel";
|
|
296
|
+
// import { useCustomTheme } from "../../Theme/useCustomTheme";
|
|
297
|
+
// export default function SelectSearch({
|
|
298
|
+
// options,
|
|
299
|
+
// initialSelectedOption = null,
|
|
300
|
+
// onOptionSelect,
|
|
301
|
+
// inputOnchange,
|
|
302
|
+
// id,
|
|
303
|
+
// name,
|
|
304
|
+
// label,
|
|
305
|
+
// inputStyle,
|
|
306
|
+
// dropdownStyle,
|
|
307
|
+
// isOptionLoading,
|
|
308
|
+
// loadingText = "loading",
|
|
309
|
+
// boxStyle,
|
|
310
|
+
// placeholder = "Select Option",
|
|
311
|
+
// searchQuery = "",
|
|
312
|
+
// isInformation = false,
|
|
313
|
+
// informationMessage,
|
|
314
|
+
// rightIcon,
|
|
315
|
+
// rightElementStyle,
|
|
316
|
+
// isMultipleSelect,
|
|
317
|
+
// }: Readonly<SelectSearchProps>) {
|
|
318
|
+
// const theme = useCustomTheme();
|
|
319
|
+
// const [selectedOptions, setSelectedOptions] = useState<any>([]);
|
|
320
|
+
// const [inputValue, setInputValue] = useState<any>("");
|
|
321
|
+
// const [isOpen, setIsOpen] = useState(false);
|
|
322
|
+
// const [position, setPosition] = useState<"above" | "below">("below");
|
|
323
|
+
// const inputRef = useRef<HTMLInputElement>(null);
|
|
324
|
+
// const dropdownRef = useRef<HTMLDivElement>(null);
|
|
325
|
+
// const filteredOptions = useMemo(() => {
|
|
326
|
+
// return options.filter(option =>
|
|
327
|
+
// option.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
328
|
+
// );
|
|
329
|
+
// }, [options, inputValue]);
|
|
330
|
+
// const handleOptionClick = useCallback(
|
|
331
|
+
// (option: selectOptions) => {
|
|
332
|
+
// if (isMultipleSelect) {
|
|
333
|
+
// setSelectedOptions((prev:any) => {
|
|
334
|
+
// const isSelected = prev.some((selected:any) => selected.id === option.id);
|
|
335
|
+
// const newSelected = isSelected
|
|
336
|
+
// ? prev.filter((selected:any) => selected.id !== option.id) // Remove if already selected
|
|
337
|
+
// : [...prev, option]; // Add if not selected
|
|
338
|
+
// setInputValue(newSelected.map((opt:any) => opt.label).join(", ")); // Update input value
|
|
339
|
+
// return newSelected;
|
|
340
|
+
// });
|
|
341
|
+
// } else {
|
|
342
|
+
// setInputValue(option.label);
|
|
343
|
+
// setIsOpen(false);
|
|
344
|
+
// onOptionSelect(option); // Call the onOptionSelect for single select
|
|
345
|
+
// }
|
|
346
|
+
// },
|
|
347
|
+
// [isMultipleSelect, onOptionSelect]
|
|
348
|
+
// );
|
|
349
|
+
// const handleInputChange = (value:any) => {
|
|
350
|
+
// setInputValue(value);
|
|
351
|
+
// inputOnchange(value); // Call the inputOnchange prop
|
|
352
|
+
// };
|
|
353
|
+
// const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
354
|
+
// if (e.key === "Enter") {
|
|
355
|
+
// const matchingOption = options.find(
|
|
356
|
+
// option => option.label.toLowerCase() === inputValue.toLowerCase()
|
|
357
|
+
// );
|
|
358
|
+
// if (matchingOption) {
|
|
359
|
+
// handleOptionClick(matchingOption);
|
|
360
|
+
// }
|
|
361
|
+
// }
|
|
362
|
+
// };
|
|
363
|
+
// const updateDropdownPosition = () => {
|
|
364
|
+
// if (inputRef.current && dropdownRef.current) {
|
|
365
|
+
// const inputRect = inputRef.current.getBoundingClientRect();
|
|
366
|
+
// const dropdownRect = dropdownRef.current.getBoundingClientRect();
|
|
367
|
+
// const viewportHeight = window.innerHeight;
|
|
368
|
+
// const spaceBelow = viewportHeight - inputRect.bottom + window.scrollY;
|
|
369
|
+
// const spaceAbove = inputRect.top + window.scrollY;
|
|
370
|
+
// if (spaceBelow >= dropdownRect.height) {
|
|
371
|
+
// setPosition("below");
|
|
372
|
+
// } else if (spaceAbove >= dropdownRect.height) {
|
|
373
|
+
// setPosition("above");
|
|
374
|
+
// } else {
|
|
375
|
+
// setPosition("below");
|
|
376
|
+
// }
|
|
377
|
+
// }
|
|
378
|
+
// };
|
|
379
|
+
// useEffect(() => {
|
|
380
|
+
// if (isOpen) {
|
|
381
|
+
// updateDropdownPosition();
|
|
382
|
+
// }
|
|
383
|
+
// const handleClickOutside = (event: MouseEvent) => {
|
|
384
|
+
// if (
|
|
385
|
+
// inputRef.current &&
|
|
386
|
+
// dropdownRef.current &&
|
|
387
|
+
// !inputRef.current.contains(event.target as Node) &&
|
|
388
|
+
// !dropdownRef.current.contains(event.target as Node)
|
|
389
|
+
// ) {
|
|
390
|
+
// setIsOpen(false);
|
|
391
|
+
// }
|
|
392
|
+
// };
|
|
393
|
+
// document.addEventListener("mousedown", handleClickOutside);
|
|
394
|
+
// return () => {
|
|
395
|
+
// document.removeEventListener("mousedown", handleClickOutside);
|
|
396
|
+
// };
|
|
397
|
+
// }, [isOpen]);
|
|
398
|
+
// const RenderOptions = useCallback(() => {
|
|
399
|
+
// if (isOptionLoading) {
|
|
400
|
+
// return (
|
|
401
|
+
// <VStack py={2}>
|
|
402
|
+
// <Spinner size="sm" color="blue.500" />
|
|
403
|
+
// <Text color="blue.500">{loadingText}</Text>
|
|
404
|
+
// </VStack>
|
|
405
|
+
// );
|
|
406
|
+
// }
|
|
407
|
+
// if (filteredOptions?.length) {
|
|
408
|
+
// return filteredOptions.map(option => (
|
|
409
|
+
// <Box
|
|
410
|
+
// key={option.id}
|
|
411
|
+
// px={4}
|
|
412
|
+
// py={2}
|
|
413
|
+
// cursor="pointer"
|
|
414
|
+
// _hover={{ backgroundColor: "blue.50" }}
|
|
415
|
+
// onClick={() => handleOptionClick(option)}
|
|
416
|
+
// >
|
|
417
|
+
// {option.label}
|
|
418
|
+
// </Box>
|
|
419
|
+
// ));
|
|
420
|
+
// }
|
|
421
|
+
// return (
|
|
422
|
+
// <Text px={4} py={2} color="gray.500">
|
|
423
|
+
// No options found
|
|
424
|
+
// </Text>
|
|
425
|
+
// );
|
|
426
|
+
// }, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
|
|
427
|
+
// return (
|
|
428
|
+
// <Box display="flex" flexDirection="column" position="relative" sx={boxStyle}>
|
|
429
|
+
// {label && (
|
|
430
|
+
// <TextLabel
|
|
431
|
+
// label={label}
|
|
432
|
+
// id={id}
|
|
433
|
+
// isRequired={false}
|
|
434
|
+
// isInformation={isInformation}
|
|
435
|
+
// informationMessage={informationMessage}
|
|
436
|
+
// />
|
|
437
|
+
// )}
|
|
438
|
+
// <InputGroup>
|
|
439
|
+
// <Input
|
|
440
|
+
// ref={inputRef}
|
|
441
|
+
// variant="flushed"
|
|
442
|
+
// value={inputValue}
|
|
443
|
+
// onClick={() => setIsOpen(true)}
|
|
444
|
+
// onChange={(e) => handleInputChange(e.target.value)}
|
|
445
|
+
// placeholder={placeholder}
|
|
446
|
+
// onKeyDown={handleKeyDown}
|
|
447
|
+
// id={id}
|
|
448
|
+
// name={name}
|
|
449
|
+
// cursor="pointer"
|
|
450
|
+
// borderColor="gray.300"
|
|
451
|
+
// _hover={{ borderColor: "blue.500" }}
|
|
452
|
+
// _focus={{ borderColor: "blue.500" }}
|
|
453
|
+
// style={{
|
|
454
|
+
// ...inputStyle,
|
|
455
|
+
// backgroundColor: theme.colors.backgroundColor.main,
|
|
456
|
+
// fontWeight: 800,
|
|
457
|
+
// color: theme.colors.gray[700],
|
|
458
|
+
// padding: "0 0.5rem",
|
|
459
|
+
// fontSize: 15,
|
|
460
|
+
// letterSpacing: 0.7,
|
|
461
|
+
// }}
|
|
462
|
+
// />
|
|
463
|
+
// {rightIcon && (
|
|
464
|
+
// <InputRightElement
|
|
465
|
+
// pointerEvents="none"
|
|
466
|
+
// children={rightIcon}
|
|
467
|
+
// style={{ ...rightElementStyle }}
|
|
468
|
+
// />
|
|
469
|
+
// )}
|
|
470
|
+
// </InputGroup>
|
|
471
|
+
// {isOpen && (
|
|
472
|
+
// <Box
|
|
473
|
+
// ref={dropdownRef}
|
|
474
|
+
// position="absolute"
|
|
475
|
+
// top={position === "below" ? "100%" : "auto"}
|
|
476
|
+
// bottom={position === "above" ? "100%" : "auto"}
|
|
477
|
+
// left={0}
|
|
478
|
+
// right={0}
|
|
479
|
+
// border="1px solid"
|
|
480
|
+
// borderColor="gray.300"
|
|
481
|
+
// borderRadius="md"
|
|
482
|
+
// bg="white"
|
|
483
|
+
// maxHeight="150px"
|
|
484
|
+
// overflowY="auto"
|
|
485
|
+
// zIndex={10}
|
|
486
|
+
// >
|
|
487
|
+
// {RenderOptions()}
|
|
488
|
+
// </Box>
|
|
489
|
+
// )}
|
|
490
|
+
// </Box>
|
|
491
|
+
// );
|
|
492
|
+
// }
|
|
37
493
|
var react_1 = __importStar(require("react"));
|
|
38
494
|
var react_2 = require("@chakra-ui/react");
|
|
39
495
|
var FormLabel_1 = require("../Common/FormLabel");
|
|
40
496
|
var useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
41
497
|
function SelectSearch(_a) {
|
|
42
|
-
var options = _a.options, _b = _a.initialSelectedOption, initialSelectedOption = _b === void 0 ? null : _b, onOptionSelect = _a.onOptionSelect, inputOnchange = _a.inputOnchange, id = _a.id, name = _a.name, label = _a.label, inputStyle = _a.inputStyle, dropdownStyle = _a.dropdownStyle, isOptionLoading = _a.isOptionLoading, _c = _a.loadingText, loadingText = _c === void 0 ? "loading" : _c, boxStyle = _a.boxStyle, _d = _a.placeholder, placeholder = _d === void 0 ? "Select Option" : _d, _e = _a.searchQuery, searchQuery = _e === void 0 ? "" : _e, _f = _a.isInformation, isInformation = _f === void 0 ? false : _f, informationMessage = _a.informationMessage, rightIcon = _a.rightIcon, rightElementStyle = _a.rightElementStyle;
|
|
498
|
+
var options = _a.options, _b = _a.initialSelectedOption, initialSelectedOption = _b === void 0 ? null : _b, onOptionSelect = _a.onOptionSelect, inputOnchange = _a.inputOnchange, id = _a.id, name = _a.name, label = _a.label, inputStyle = _a.inputStyle, dropdownStyle = _a.dropdownStyle, isOptionLoading = _a.isOptionLoading, _c = _a.loadingText, loadingText = _c === void 0 ? "loading" : _c, boxStyle = _a.boxStyle, _d = _a.placeholder, placeholder = _d === void 0 ? "Select Option" : _d, _e = _a.searchQuery, searchQuery = _e === void 0 ? "" : _e, _f = _a.isInformation, isInformation = _f === void 0 ? false : _f, informationMessage = _a.informationMessage, rightIcon = _a.rightIcon, rightElementStyle = _a.rightElementStyle, isMultipleSelect = _a.isMultipleSelect, onOptionMultiSelect = _a.onOptionMultiSelect;
|
|
43
499
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
44
|
-
var _g = (0, react_1.useState)(
|
|
45
|
-
var _h = (0, react_1.useState)(
|
|
46
|
-
var _j = (0, react_1.useState)(
|
|
500
|
+
var _g = (0, react_1.useState)([]), selectedOptions = _g[0], setSelectedOptions = _g[1];
|
|
501
|
+
var _h = (0, react_1.useState)(""), inputValue = _h[0], setInputValue = _h[1];
|
|
502
|
+
var _j = (0, react_1.useState)(false), isOpen = _j[0], setIsOpen = _j[1];
|
|
503
|
+
var _k = (0, react_1.useState)("below"), position = _k[0], setPosition = _k[1];
|
|
47
504
|
var inputRef = (0, react_1.useRef)(null);
|
|
48
505
|
var dropdownRef = (0, react_1.useRef)(null);
|
|
49
506
|
var filteredOptions = (0, react_1.useMemo)(function () {
|
|
50
|
-
return options
|
|
507
|
+
return options.filter(function (option) {
|
|
51
508
|
return option.label.toLowerCase().includes(inputValue.toLowerCase());
|
|
52
509
|
});
|
|
53
510
|
}, [options, inputValue]);
|
|
54
511
|
var handleOptionClick = (0, react_1.useCallback)(function (option) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
512
|
+
if (isMultipleSelect) {
|
|
513
|
+
setSelectedOptions(function (prev) {
|
|
514
|
+
var isSelected = prev.some(function (selected) { return selected.id === option.id; });
|
|
515
|
+
var newSelected = isSelected
|
|
516
|
+
? prev.filter(function (selected) { return selected.id !== option.id; })
|
|
517
|
+
: __spreadArray(__spreadArray([], prev, true), [option], false);
|
|
518
|
+
setInputValue("");
|
|
519
|
+
if (onOptionMultiSelect) {
|
|
520
|
+
onOptionMultiSelect(newSelected);
|
|
521
|
+
}
|
|
522
|
+
return newSelected;
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
setInputValue(option.label);
|
|
527
|
+
setIsOpen(false);
|
|
528
|
+
if (onOptionSelect) {
|
|
529
|
+
onOptionSelect(option);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}, [isMultipleSelect, onOptionSelect]);
|
|
533
|
+
var handleRemoveOption = function (option) {
|
|
534
|
+
setSelectedOptions(function (prev) {
|
|
535
|
+
return prev.filter(function (selected) { return selected.id !== option.id; });
|
|
536
|
+
});
|
|
537
|
+
if (onOptionMultiSelect) {
|
|
538
|
+
onOptionMultiSelect(selectedOptions.filter(function (selected) { return selected.id !== option.id; }));
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
var handleInputChange = function (value) {
|
|
542
|
+
setInputValue(value);
|
|
543
|
+
inputOnchange(value);
|
|
544
|
+
};
|
|
61
545
|
var handleKeyDown = function (e) {
|
|
62
546
|
if (e.key === "Enter") {
|
|
63
547
|
var matchingOption = options.find(function (option) { return option.label.toLowerCase() === inputValue.toLowerCase(); });
|
|
@@ -96,23 +580,9 @@ function SelectSearch(_a) {
|
|
|
96
580
|
setIsOpen(false);
|
|
97
581
|
}
|
|
98
582
|
};
|
|
99
|
-
var handleScroll = function () {
|
|
100
|
-
if (isOpen) {
|
|
101
|
-
updateDropdownPosition();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
var handleResize = function () {
|
|
105
|
-
if (isOpen) {
|
|
106
|
-
updateDropdownPosition();
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
583
|
document.addEventListener("mousedown", handleClickOutside);
|
|
110
|
-
window.addEventListener("scroll", handleScroll);
|
|
111
|
-
window.addEventListener("resize", handleResize);
|
|
112
584
|
return function () {
|
|
113
585
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
114
|
-
window.removeEventListener("scroll", handleScroll);
|
|
115
|
-
window.removeEventListener("resize", handleResize);
|
|
116
586
|
};
|
|
117
587
|
}, [isOpen]);
|
|
118
588
|
var RenderOptions = (0, react_1.useCallback)(function () {
|
|
@@ -128,10 +598,11 @@ function SelectSearch(_a) {
|
|
|
128
598
|
}, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
|
|
129
599
|
return (react_1.default.createElement(react_2.Box, { display: "flex", flexDirection: "column", position: "relative", sx: boxStyle },
|
|
130
600
|
label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, id: id, isRequired: false, isInformation: isInformation, informationMessage: informationMessage })),
|
|
601
|
+
isMultipleSelect && selectedOptions.length > 0 && (react_1.default.createElement(react_2.HStack, { spacing: 2, mb: 2 }, selectedOptions.map(function (option) { return (react_1.default.createElement(react_2.Tag, { size: "md", key: option.id, borderRadius: "full", variant: "solid", sx: { backgroundColor: theme.colors.primary[500] } },
|
|
602
|
+
react_1.default.createElement(react_2.TagLabel, { width: "50px" }, option.label),
|
|
603
|
+
react_1.default.createElement(react_2.TagCloseButton, { onClick: function () { return handleRemoveOption(option); } }))); }))),
|
|
131
604
|
react_1.default.createElement(react_2.InputGroup, null,
|
|
132
|
-
react_1.default.createElement(react_2.Input, { ref: inputRef, variant: "flushed", value: inputValue, onClick: function () { return setIsOpen(true); }, onChange: function (e) { return
|
|
133
|
-
// {...inputStyle}
|
|
134
|
-
style: __assign(__assign({}, inputStyle), { backgroundColor: theme.colors.backgroundColor.main, fontWeight: 800, color: theme.colors.gray[700], padding: "0 0.5rem", fontSize: 15, letterSpacing: 0.7 }) }),
|
|
605
|
+
react_1.default.createElement(react_2.Input, { ref: inputRef, variant: "flushed", value: inputValue, onClick: function () { return setIsOpen(true); }, onChange: function (e) { return handleInputChange(e.target.value); }, placeholder: placeholder, onKeyDown: handleKeyDown, id: id, name: name, cursor: "pointer", borderColor: "gray.300", _hover: { borderColor: "blue.500" }, _focus: { borderColor: "blue.500" }, style: __assign(__assign({}, inputStyle), { backgroundColor: theme.colors.backgroundColor.main, fontWeight: 800, color: theme.colors.gray[700], padding: "0 0.5rem", fontSize: 15, letterSpacing: 0.7 }) }),
|
|
135
606
|
rightIcon && (react_1.default.createElement(react_2.InputRightElement, { pointerEvents: "none", children: rightIcon, style: __assign({}, rightElementStyle) }))),
|
|
136
607
|
isOpen && (react_1.default.createElement(react_2.Box, { ref: dropdownRef, position: "absolute", top: position === "below" ? "100%" : "auto", bottom: position === "above" ? "100%" : "auto", left: 0, right: 0, border: "1px solid", borderColor: "gray.300", borderRadius: "md", bg: "white", maxHeight: "150px", overflowY: "auto", zIndex: 10 }, RenderOptions()))));
|
|
137
608
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type SelectSearchProps = {
|
|
3
|
-
options:
|
|
3
|
+
options: selectOptions[];
|
|
4
4
|
isSearchEnabled?: boolean;
|
|
5
|
-
initialSelectedOption?:
|
|
6
|
-
onOptionSelect
|
|
5
|
+
initialSelectedOption?: selectOptions | null;
|
|
6
|
+
onOptionSelect?: (option: selectOptions) => void;
|
|
7
|
+
onOptionMultiSelect?: (option: selectOptions[]) => void;
|
|
7
8
|
inputOnchange: (value: string | number) => void;
|
|
8
9
|
id?: string;
|
|
9
10
|
name?: string;
|
|
@@ -19,8 +20,9 @@ export type SelectSearchProps = {
|
|
|
19
20
|
informationMessage?: string;
|
|
20
21
|
rightIcon?: React.ReactNode;
|
|
21
22
|
rightElementStyle?: {};
|
|
23
|
+
isMultipleSelect?: boolean;
|
|
22
24
|
};
|
|
23
|
-
export type
|
|
25
|
+
export type selectOptions = {
|
|
24
26
|
id: string;
|
|
25
27
|
label: string;
|
|
26
28
|
};
|