pixelize-design-library 1.1.26 → 1.1.28

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.
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
2
  // import React, {
3
- // useCallback,
4
- // useEffect,
5
- // useMemo,
6
- // useRef,
7
- // useState,
3
+ // useCallback,
4
+ // useEffect,
5
+ // useMemo,
6
+ // useRef,
7
+ // useState,
8
8
  // } from "react";
9
9
  // import {
10
- // Box,
11
- // Input,
12
- // Spinner,
13
- // VStack,
14
- // Text,
15
- // InputGroup,
16
- // InputRightElement,
10
+ // Box,
11
+ // Input,
12
+ // Spinner,
13
+ // VStack,
14
+ // Text,
15
+ // InputGroup,
16
+ // InputRightElement,
17
+ // HStack,
18
+ // Tag,
19
+ // TagLabel,
20
+ // TagCloseButton,
17
21
  // } from "@chakra-ui/react";
18
22
  // import { selectOptions, SelectSearchProps } from "./SelectSearchProps";
19
23
  // import { TextLabel } from "../Common/FormLabel";
@@ -63,444 +67,258 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
63
67
  };
64
68
  Object.defineProperty(exports, "__esModule", { value: true });
65
69
  // 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,
70
+ // options,
71
+ // initialSelectedOption,
72
+ // onOptionSelect,
73
+ // inputOnchange,
74
+ // id,
75
+ // name,
76
+ // label,
77
+ // inputStyle,
78
+ // dropdownStyle,
79
+ // isOptionLoading,
80
+ // loadingText = "loading",
81
+ // boxStyle,
82
+ // placeholder = "Select Option",
83
+ // searchQuery = "",
84
+ // isInformation = false,
85
+ // informationMessage,
86
+ // rightIcon,
87
+ // rightElementStyle,
88
+ // isMultipleSelect,
89
+ // isRequired=false,
90
+ // onOptionMultiSelect,
85
91
  // }: 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]
92
+ // const theme = useCustomTheme();
93
+ // const [selectedOptions, setSelectedOptions] = useState<selectOptions[]>(
94
+ // initialSelectedOption ? [initialSelectedOption] : []
112
95
  // );
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
- // }
96
+ // const [inputValue, setInputValue] = useState(searchQuery);
97
+ // const [isOpen, setIsOpen] = useState(false);
98
+ // const [position, setPosition] = useState<"above" | "below">("below");
99
+ // const inputRef = useRef<HTMLInputElement>(null);
100
+ // const dropdownRef = useRef<HTMLDivElement>(null);
101
+ // const filteredOptions = useMemo(() => {
102
+ // return options.filter((option) =>
103
+ // option.label.toLowerCase().includes(inputValue.toLowerCase())
104
+ // );
105
+ // }, [options, inputValue]);
106
+ // const handleOptionClick = useCallback(
107
+ // (option: selectOptions) => {
108
+ // if (isMultipleSelect) {
109
+ // setSelectedOptions((prev) => {
110
+ // const isSelected = prev.some((selected) => selected.id === option.id);
111
+ // const newSelected = isSelected
112
+ // ? prev.filter((selected) => selected.id !== option.id)
113
+ // : [...prev, option];
114
+ // setInputValue("");
115
+ // if (onOptionMultiSelect) {
116
+ // onOptionMultiSelect(newSelected);
117
+ // }
118
+ // return newSelected;
119
+ // });
120
+ // } else {
121
+ // setInputValue(option.label);
122
+ // setIsOpen(false);
123
+ // if (onOptionSelect) {
124
+ // onOptionSelect(option);
141
125
  // }
126
+ // }
127
+ // },
128
+ // [isMultipleSelect, onOptionSelect]
129
+ // );
130
+ // const handleRemoveOption = (option: selectOptions) => {
131
+ // setSelectedOptions((prev) =>
132
+ // prev.filter((selected) => selected.id !== option.id)
133
+ // );
134
+ // if (onOptionMultiSelect) {
135
+ // onOptionMultiSelect(selectedOptions.filter((selected) => selected.id !== option.id));
136
+ // }
137
+ // };
138
+ // const handleInputChange = (value: any) => {
139
+ // setInputValue(value);
140
+ // inputOnchange(value);
141
+ // };
142
+ // const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
143
+ // if (e.key === "Enter") {
144
+ // const matchingOption = options.find(
145
+ // (option) => option.label.toLowerCase() === inputValue.toLowerCase()
146
+ // );
147
+ // if (matchingOption) {
148
+ // handleOptionClick(matchingOption);
149
+ // }
150
+ // }
151
+ // };
152
+ // const updateDropdownPosition = () => {
153
+ // if (inputRef.current && dropdownRef.current) {
154
+ // const inputRect = inputRef.current.getBoundingClientRect();
155
+ // const dropdownRect = dropdownRef.current.getBoundingClientRect();
156
+ // const viewportHeight = window.innerHeight;
157
+ // const spaceBelow = viewportHeight - inputRect.bottom + window.scrollY;
158
+ // const spaceAbove = inputRect.top + window.scrollY;
159
+ // if (spaceBelow >= dropdownRect.height) {
160
+ // setPosition("below");
161
+ // } else if (spaceAbove >= dropdownRect.height) {
162
+ // setPosition("above");
163
+ // } else {
164
+ // setPosition("below");
165
+ // }
166
+ // }
167
+ // };
168
+ // useEffect(() => {
169
+ // if (isOpen) {
170
+ // updateDropdownPosition();
171
+ // }
172
+ // const handleClickOutside = (event: MouseEvent) => {
173
+ // if (
174
+ // inputRef.current &&
175
+ // dropdownRef.current &&
176
+ // !inputRef.current.contains(event.target as Node) &&
177
+ // !dropdownRef.current.contains(event.target as Node)
178
+ // ) {
179
+ // setIsOpen(false);
180
+ // }
142
181
  // };
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 (
182
+ // document.addEventListener("mousedown", handleClickOutside);
183
+ // return () => {
184
+ // document.removeEventListener("mousedown", handleClickOutside);
185
+ // };
186
+ // }, [isOpen]);
187
+ // const RenderOptions = useCallback(() => {
188
+ // if (isOptionLoading) {
189
+ // return (
190
+ // <VStack py={2}>
191
+ // <Spinner size="sm" color="blue.500" />
192
+ // <Text color="blue.500">{loadingText}</Text>
193
+ // </VStack>
194
+ // );
195
+ // }
196
+ // if (filteredOptions?.length) {
197
+ // return filteredOptions.map((option) => (
206
198
  // <Box
207
- // display="flex"
208
- // flexDirection="column"
209
- // position="relative"
210
- // sx={boxStyle}
199
+ // key={option.id}
200
+ // px={4}
201
+ // py={2}
202
+ // cursor="pointer"
203
+ // _hover={{ backgroundColor: "blue.50" }}
204
+ // onClick={() => handleOptionClick(option)}
211
205
  // >
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
- // )}
206
+ // {option.label}
275
207
  // </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]);
208
+ // ));
209
+ // }
427
210
  // 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>
211
+ // <Text px={4} py={2} color="gray.500">
212
+ // No options found
213
+ // </Text>
491
214
  // );
215
+ // }, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
216
+ // return (
217
+ // <Box display="flex" flexDirection="column" position="relative" sx={boxStyle}>
218
+ // {label && (
219
+ // <TextLabel
220
+ // label={label}
221
+ // id={id}
222
+ // isRequired={isRequired}
223
+ // isInformation={isInformation}
224
+ // informationMessage={informationMessage}
225
+ // />
226
+ // )}
227
+ // {/* Display selected options as chips */}
228
+ // {isMultipleSelect && selectedOptions.length > 0 && (
229
+ // <HStack spacing={2} mb={2}>
230
+ // {selectedOptions.map((option) => (
231
+ // <Tag
232
+ // size="md"
233
+ // key={option.id}
234
+ // borderRadius="full"
235
+ // variant="solid"
236
+ // sx={{ backgroundColor: theme.colors.primary[500] }}
237
+ // >
238
+ // <TagLabel width={"50px"}>{option.label}</TagLabel>
239
+ // <TagCloseButton onClick={() => handleRemoveOption(option)} />
240
+ // </Tag>
241
+ // ))}
242
+ // </HStack>
243
+ // )}
244
+ // <InputGroup>
245
+ // <Input
246
+ // ref={inputRef}
247
+ // variant="flushed"
248
+ // value={inputValue}
249
+ // onClick={() => setIsOpen(true)}
250
+ // onChange={(e) => handleInputChange(e.target.value)}
251
+ // placeholder={placeholder}
252
+ // onKeyDown={handleKeyDown}
253
+ // id={id}
254
+ // name={name}
255
+ // cursor="pointer"
256
+ // borderColor="gray.300"
257
+ // _hover={{ borderColor: "blue.500" }}
258
+ // _focus={{ borderColor: "blue.500" }}
259
+ // style={{
260
+ // ...inputStyle,
261
+ // backgroundColor: theme.colors.backgroundColor.main,
262
+ // fontWeight: 800,
263
+ // color: theme.colors.gray[700],
264
+ // padding: "0 0.5rem",
265
+ // fontSize: 15,
266
+ // letterSpacing: 0.7,
267
+ // }}
268
+ // />
269
+ // {rightIcon && (
270
+ // <InputRightElement
271
+ // pointerEvents="none"
272
+ // children={rightIcon}
273
+ // style={{ ...rightElementStyle }}
274
+ // />
275
+ // )}
276
+ // </InputGroup>
277
+ // {isOpen && (
278
+ // <Box
279
+ // ref={dropdownRef}
280
+ // position="absolute"
281
+ // top={position === "below" ? "100%" : "auto"}
282
+ // bottom={position === "above" ? "100%" : "auto"}
283
+ // left={0}
284
+ // right={0}
285
+ // border="1px solid"
286
+ // borderColor="gray.300"
287
+ // borderRadius="md"
288
+ // bg="white"
289
+ // maxHeight="150px"
290
+ // overflowY="auto"
291
+ // zIndex={10}
292
+ // >
293
+ // {RenderOptions()}
294
+ // </Box>
295
+ // )}
296
+ // </Box>
297
+ // );
492
298
  // }
493
299
  var react_1 = __importStar(require("react"));
494
300
  var react_2 = require("@chakra-ui/react");
495
301
  var FormLabel_1 = require("../Common/FormLabel");
496
302
  var useCustomTheme_1 = require("../../Theme/useCustomTheme");
303
+ var RenderOptions = function (_a) {
304
+ var isOptionLoading = _a.isOptionLoading, filteredOptions = _a.filteredOptions, loadingText = _a.loadingText, handleOptionClick = _a.handleOptionClick;
305
+ if (isOptionLoading) {
306
+ return (react_1.default.createElement(react_2.VStack, { py: 2 },
307
+ react_1.default.createElement(react_2.Spinner, { size: "sm", color: "blue.500" }),
308
+ react_1.default.createElement(react_2.Text, { color: "blue.500" }, loadingText)));
309
+ }
310
+ if (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length) {
311
+ return (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map(function (option) { return (react_1.default.createElement(react_2.Box, { key: option.id, px: 4, py: 2, cursor: "pointer", _hover: { backgroundColor: "blue.50" }, onClick: function () { return handleOptionClick(option); } }, option.label)); })));
312
+ }
313
+ return (react_1.default.createElement(react_2.Text, { px: 4, py: 2, color: "gray.500" }, "No options found"));
314
+ };
497
315
  function SelectSearch(_a) {
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, _g = _a.isRequired, isRequired = _g === void 0 ? false : _g, onOptionMultiSelect = _a.onOptionMultiSelect;
316
+ var options = _a.options, initialSelectedOption = _a.initialSelectedOption, onOptionSelect = _a.onOptionSelect, inputOnchange = _a.inputOnchange, id = _a.id, name = _a.name, label = _a.label, inputStyle = _a.inputStyle, dropdownStyle = _a.dropdownStyle, isOptionLoading = _a.isOptionLoading, _b = _a.loadingText, loadingText = _b === void 0 ? "loading" : _b, boxStyle = _a.boxStyle, _c = _a.placeholder, placeholder = _c === void 0 ? "Select Option" : _c, _d = _a.searchQuery, searchQuery = _d === void 0 ? "" : _d, _e = _a.isInformation, isInformation = _e === void 0 ? false : _e, informationMessage = _a.informationMessage, rightIcon = _a.rightIcon, rightElementStyle = _a.rightElementStyle, isMultipleSelect = _a.isMultipleSelect, _f = _a.isRequired, isRequired = _f === void 0 ? false : _f, onOptionMultiSelect = _a.onOptionMultiSelect;
499
317
  var theme = (0, useCustomTheme_1.useCustomTheme)();
500
- var _h = (0, react_1.useState)([]), selectedOptions = _h[0], setSelectedOptions = _h[1];
501
- var _j = (0, react_1.useState)(""), inputValue = _j[0], setInputValue = _j[1];
502
- var _k = (0, react_1.useState)(false), isOpen = _k[0], setIsOpen = _k[1];
503
- var _l = (0, react_1.useState)("below"), position = _l[0], setPosition = _l[1];
318
+ var _g = (0, react_1.useState)(initialSelectedOption ? [initialSelectedOption] : []), selectedOptions = _g[0], setSelectedOptions = _g[1];
319
+ var _h = (0, react_1.useState)(searchQuery), inputValue = _h[0], setInputValue = _h[1];
320
+ var _j = (0, react_1.useState)(false), isOpen = _j[0], setIsOpen = _j[1];
321
+ var _k = (0, react_1.useState)("below"), position = _k[0], setPosition = _k[1];
504
322
  var inputRef = (0, react_1.useRef)(null);
505
323
  var dropdownRef = (0, react_1.useRef)(null);
506
324
  var filteredOptions = (0, react_1.useMemo)(function () {
@@ -508,6 +326,30 @@ function SelectSearch(_a) {
508
326
  return option.label.toLowerCase().includes(inputValue.toLowerCase());
509
327
  });
510
328
  }, [options, inputValue]);
329
+ // const handleOptionClick = useCallback(
330
+ // (option: selectOptions) => {
331
+ // if (isMultipleSelect) {
332
+ // setSelectedOptions((prev) => {
333
+ // const isSelected = prev.some((selected) => selected.id === option.id);
334
+ // const newSelected = isSelected
335
+ // ? prev.filter((selected) => selected.id !== option.id)
336
+ // : [...prev, option];
337
+ // setInputValue("");
338
+ // if (onOptionMultiSelect) {
339
+ // onOptionMultiSelect(newSelected);
340
+ // }
341
+ // return newSelected;
342
+ // });
343
+ // } else {
344
+ // setInputValue(option.label);
345
+ // setIsOpen(false);
346
+ // if (onOptionSelect) {
347
+ // onOptionSelect(option);
348
+ // }
349
+ // }
350
+ // },
351
+ // [isMultipleSelect, onOptionSelect, onOptionMultiSelect]
352
+ // );
511
353
  var handleOptionClick = (0, react_1.useCallback)(function (option) {
512
354
  if (isMultipleSelect) {
513
355
  setSelectedOptions(function (prev) {
@@ -515,9 +357,12 @@ function SelectSearch(_a) {
515
357
  var newSelected = isSelected
516
358
  ? prev.filter(function (selected) { return selected.id !== option.id; })
517
359
  : __spreadArray(__spreadArray([], prev, true), [option], false);
360
+ // Update the input value and notify the parent
518
361
  setInputValue("");
519
362
  if (onOptionMultiSelect) {
520
- onOptionMultiSelect(newSelected);
363
+ // Call the prop to update state in the parent component
364
+ // Note: This should not directly set the state in SelectSearch
365
+ setTimeout(function () { return onOptionMultiSelect(newSelected); }, 0);
521
366
  }
522
367
  return newSelected;
523
368
  });
@@ -529,13 +374,14 @@ function SelectSearch(_a) {
529
374
  onOptionSelect(option);
530
375
  }
531
376
  }
532
- }, [isMultipleSelect, onOptionSelect]);
377
+ }, [isMultipleSelect, onOptionSelect, onOptionMultiSelect]);
533
378
  var handleRemoveOption = function (option) {
534
379
  setSelectedOptions(function (prev) {
535
380
  return prev.filter(function (selected) { return selected.id !== option.id; });
536
381
  });
537
382
  if (onOptionMultiSelect) {
538
383
  onOptionMultiSelect(selectedOptions.filter(function (selected) { return selected.id !== option.id; }));
384
+ setInputValue("");
539
385
  }
540
386
  };
541
387
  var handleInputChange = function (value) {
@@ -585,17 +431,6 @@ function SelectSearch(_a) {
585
431
  document.removeEventListener("mousedown", handleClickOutside);
586
432
  };
587
433
  }, [isOpen]);
588
- var RenderOptions = (0, react_1.useCallback)(function () {
589
- if (isOptionLoading) {
590
- return (react_1.default.createElement(react_2.VStack, { py: 2 },
591
- react_1.default.createElement(react_2.Spinner, { size: "sm", color: "blue.500" }),
592
- react_1.default.createElement(react_2.Text, { color: "blue.500" }, loadingText)));
593
- }
594
- if (filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.length) {
595
- return filteredOptions.map(function (option) { return (react_1.default.createElement(react_2.Box, { key: option.id, px: 4, py: 2, cursor: "pointer", _hover: { backgroundColor: "blue.50" }, onClick: function () { return handleOptionClick(option); } }, option.label)); });
596
- }
597
- return (react_1.default.createElement(react_2.Text, { px: 4, py: 2, color: "gray.500" }, "No options found"));
598
- }, [filteredOptions, isOptionLoading, loadingText, handleOptionClick]);
599
434
  return (react_1.default.createElement(react_2.Box, { display: "flex", flexDirection: "column", position: "relative", sx: boxStyle },
600
435
  label && (react_1.default.createElement(FormLabel_1.TextLabel, { label: label, id: id, isRequired: isRequired, isInformation: isInformation, informationMessage: informationMessage })),
601
436
  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] } },
@@ -604,6 +439,7 @@ function SelectSearch(_a) {
604
439
  react_1.default.createElement(react_2.InputGroup, null,
605
440
  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 }) }),
606
441
  rightIcon && (react_1.default.createElement(react_2.InputRightElement, { pointerEvents: "none", children: rightIcon, style: __assign({}, rightElementStyle) }))),
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()))));
442
+ 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 },
443
+ react_1.default.createElement(RenderOptions, { isOptionLoading: isOptionLoading, filteredOptions: filteredOptions, loadingText: loadingText, handleOptionClick: handleOptionClick })))));
608
444
  }
609
445
  exports.default = SelectSearch;