dhre-component-lib 0.2.6 → 0.2.7
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/Search/Search.d.ts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.esm.js +36 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "./Search.module.scss";
|
|
3
|
+
interface Suggestion {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
faqAnswer: string;
|
|
7
|
+
faqQuestion: string;
|
|
8
|
+
fieldFaqCategory: string;
|
|
9
|
+
isBookmarked: boolean;
|
|
10
|
+
images: string[];
|
|
11
|
+
videos: string[];
|
|
12
|
+
}
|
|
3
13
|
interface CustomSearchFieldProps {
|
|
4
14
|
searchIcon: React.ReactNode;
|
|
5
15
|
crossIcon: React.ReactNode;
|
|
6
16
|
disabled?: boolean;
|
|
7
17
|
onSearch: (query: string) => void;
|
|
18
|
+
onSelectSuggestion: (selectedSuggestion: Suggestion | null) => void;
|
|
19
|
+
suggestions: Suggestion[] | null | undefined;
|
|
8
20
|
placeholder: string;
|
|
9
21
|
className?: string;
|
|
10
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -171,11 +171,23 @@ interface TypographyProps {
|
|
|
171
171
|
}
|
|
172
172
|
declare const Typography: React.FC<TypographyProps>;
|
|
173
173
|
|
|
174
|
+
interface Suggestion {
|
|
175
|
+
id: string;
|
|
176
|
+
title: string;
|
|
177
|
+
faqAnswer: string;
|
|
178
|
+
faqQuestion: string;
|
|
179
|
+
fieldFaqCategory: string;
|
|
180
|
+
isBookmarked: boolean;
|
|
181
|
+
images: string[];
|
|
182
|
+
videos: string[];
|
|
183
|
+
}
|
|
174
184
|
interface CustomSearchFieldProps {
|
|
175
185
|
searchIcon: React.ReactNode;
|
|
176
186
|
crossIcon: React.ReactNode;
|
|
177
187
|
disabled?: boolean;
|
|
178
188
|
onSearch: (query: string) => void;
|
|
189
|
+
onSelectSuggestion: (selectedSuggestion: Suggestion | null) => void;
|
|
190
|
+
suggestions: Suggestion[] | null | undefined;
|
|
179
191
|
placeholder: string;
|
|
180
192
|
className?: string;
|
|
181
193
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -9338,22 +9338,24 @@ const Typography = ({ variant = 'B1', weight = 'MEDIUM', children, className })
|
|
|
9338
9338
|
return React.createElement("div", { className: classNames }, children);
|
|
9339
9339
|
};
|
|
9340
9340
|
|
|
9341
|
-
var css$2 = ".search-field-container {\n display: flex;\n align-items: center;\n padding: 8px;\n border-radius: 10px;\n background-color: #FFFFFF;\n transition: border-color 0.3s ease;\n}\n.search-field-container.default-border {\n border: 1px solid #A7A7A7;\n}\n.search-field-container.typing-border {\n border: 1px solid #FFFFFF;\n}\n.search-field-container.stopped-border {\n border: 1px solid #00B578;\n}\n.search-field-container.disabled-border {\n border: 1px solid #4F4F4F;\n background-color: #E1E1E1;\n}\n\n.search-icon {\n margin-right: 8px;\n}\n\n.search-input {\n flex: 1;\n border: none;\n background-color: transparent;\n outline: none;\n}\n\n.cross-icon {\n margin-left: 8px;\n cursor: pointer;\n}";
|
|
9341
|
+
var css$2 = ".search-field-container {\n display: flex;\n align-items: center;\n padding: 8px;\n border-radius: 10px;\n background-color: #FFFFFF;\n transition: border-color 0.3s ease;\n}\n.search-field-container.default-border {\n border: 1px solid #A7A7A7;\n}\n.search-field-container.typing-border {\n border: 1px solid #FFFFFF;\n}\n.search-field-container.stopped-border {\n border: 1px solid #00B578;\n}\n.search-field-container.disabled-border {\n border: 1px solid #4F4F4F;\n background-color: #E1E1E1;\n}\n\n.search-icon {\n margin-right: 8px;\n}\n\n.search-input {\n flex: 1;\n border: none;\n background-color: transparent;\n outline: none;\n}\n\n.cross-icon {\n margin-left: 8px;\n cursor: pointer;\n}\n\n.suggestions-dropdown {\n list-style: none;\n margin: 0;\n border: 1px solid #ccc;\n overflow-y: auto;\n background-color: white;\n position: absolute;\n width: 585px;\n z-index: 10;\n top: 55px;\n border-radius: 10px;\n}\n@media (max-width: 767px) {\n .suggestions-dropdown {\n width: 95%;\n }\n}\n\n.suggestion-item {\n padding: 16px 8px 16px 8px;\n cursor: pointer;\n text-align: left;\n}\n\n.underline {\n height: 1px;\n background-color: #CECECE;\n margin-left: 24px;\n margin-right: 24px;\n}\n\n.suggestion-item:hover {\n background-color: none;\n}\n\n.row {\n flex-direction: row;\n display: flex;\n background: none;\n border: none;\n align-items: center;\n padding-left: 10px;\n}";
|
|
9342
9342
|
n(css$2,{});
|
|
9343
9343
|
|
|
9344
|
-
const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, placeholder, className = {}, }) => {
|
|
9344
|
+
const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, onSelectSuggestion, suggestions, placeholder, className = {}, }) => {
|
|
9345
9345
|
const [query, setQuery] = useState("");
|
|
9346
9346
|
const [borderClass, setBorderClass] = useState("default-border");
|
|
9347
9347
|
const [timeoutId, setTimeoutId] = useState(null);
|
|
9348
|
-
const
|
|
9349
|
-
|
|
9348
|
+
const [filteredSuggestions, setFilteredSuggestions] = useState([]);
|
|
9349
|
+
const [showSuggestions, setShowSuggestions] = useState(false);
|
|
9350
|
+
const queryRef = useRef(query);
|
|
9350
9351
|
useEffect(() => {
|
|
9351
9352
|
queryRef.current = query;
|
|
9352
9353
|
}, [query]);
|
|
9353
9354
|
const handleChange = (e) => {
|
|
9354
9355
|
if (disabled)
|
|
9355
9356
|
return;
|
|
9356
|
-
|
|
9357
|
+
const value = e.target.value;
|
|
9358
|
+
setQuery(value);
|
|
9357
9359
|
setBorderClass("typing-border");
|
|
9358
9360
|
if (timeoutId)
|
|
9359
9361
|
clearTimeout(timeoutId);
|
|
@@ -9362,24 +9364,51 @@ const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, placeholder
|
|
|
9362
9364
|
onSearch(queryRef.current);
|
|
9363
9365
|
}, 2000);
|
|
9364
9366
|
setTimeoutId(newTimeoutId);
|
|
9367
|
+
if (suggestions && value) {
|
|
9368
|
+
const filtered = suggestions
|
|
9369
|
+
.filter((suggestion) => suggestion.title.toLowerCase().includes(value.toLowerCase()))
|
|
9370
|
+
.slice(0, 5);
|
|
9371
|
+
setFilteredSuggestions(filtered);
|
|
9372
|
+
setShowSuggestions(true);
|
|
9373
|
+
}
|
|
9374
|
+
else {
|
|
9375
|
+
setShowSuggestions(false);
|
|
9376
|
+
}
|
|
9365
9377
|
};
|
|
9366
9378
|
const handleClear = () => {
|
|
9367
9379
|
if (disabled)
|
|
9368
9380
|
return;
|
|
9369
9381
|
setQuery("");
|
|
9370
9382
|
setBorderClass("default-border");
|
|
9383
|
+
setShowSuggestions(false);
|
|
9384
|
+
onSelectSuggestion(null);
|
|
9385
|
+
};
|
|
9386
|
+
const handleSelectSuggestion = (suggestion) => {
|
|
9387
|
+
setQuery(suggestion.title);
|
|
9388
|
+
setShowSuggestions(false);
|
|
9389
|
+
onSelectSuggestion(suggestion);
|
|
9371
9390
|
};
|
|
9372
9391
|
useEffect(() => {
|
|
9373
9392
|
if (disabled) {
|
|
9374
9393
|
setQuery("");
|
|
9375
9394
|
setBorderClass("disabled-border");
|
|
9395
|
+
setShowSuggestions(false);
|
|
9376
9396
|
}
|
|
9377
9397
|
}, [disabled]);
|
|
9378
|
-
const classNames = `${className ??
|
|
9398
|
+
const classNames = `${className ?? ""}`;
|
|
9379
9399
|
return (React.createElement("div", { className: `search-field-container ${borderClass} ${classNames}` },
|
|
9380
9400
|
React.createElement("span", { className: "search-icon" }, searchIcon),
|
|
9381
9401
|
React.createElement("input", { type: "text", value: query, onChange: handleChange, disabled: disabled, className: "search-input", placeholder: placeholder }),
|
|
9382
|
-
query && !disabled && (React.createElement("span", { onClick: handleClear, className: "cross-icon" }, crossIcon))
|
|
9402
|
+
query && !disabled && (React.createElement("span", { onClick: handleClear, className: "cross-icon" }, crossIcon)),
|
|
9403
|
+
showSuggestions &&
|
|
9404
|
+
filteredSuggestions &&
|
|
9405
|
+
filteredSuggestions?.length > 0 && (React.createElement("div", { className: "suggestions-dropdown" }, filteredSuggestions?.map((suggestion) => {
|
|
9406
|
+
return (React.createElement(React.Fragment, null,
|
|
9407
|
+
React.createElement("button", { key: suggestion.id, onClick: () => handleSelectSuggestion(suggestion), className: "row" },
|
|
9408
|
+
searchIcon,
|
|
9409
|
+
React.createElement(Typography, { variant: "B4", weight: "SEMI_BOLD", className: "suggestion-item" }, suggestion.title)),
|
|
9410
|
+
React.createElement("div", { className: "underline" })));
|
|
9411
|
+
})))));
|
|
9383
9412
|
};
|
|
9384
9413
|
|
|
9385
9414
|
var css$1 = ".modal-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background-color: rgba(0, 0, 0, 0.6);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 1000;\n}\n\n.modal-container {\n background-color: white;\n padding: 40px;\n border-radius: 20px;\n width: 560px;\n max-width: 560px;\n box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);\n position: relative;\n transition: transform 0.3s ease, opacity 0.3s ease;\n}\n@media (min-width: 768px) {\n .modal-container {\n width: 80%;\n }\n}\n@media (min-width: 1024px) {\n .modal-container {\n width: 60%;\n }\n}\n\n.modal-header {\n font-size: 1.5rem;\n font-weight: bold;\n margin-bottom: 15px;\n}\n\n.modal-content {\n margin-bottom: 20px;\n}\n\n.modal-close {\n position: absolute;\n top: 40px;\n right: 40px;\n background: none;\n border: none;\n font-size: 1.5rem;\n cursor: pointer;\n}\n\n@media (max-width: 767px) {\n .modal-container {\n width: 95%;\n }\n}";
|