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
package/dist/index.js
CHANGED
|
@@ -9364,22 +9364,24 @@ const Typography = ({ variant = 'B1', weight = 'MEDIUM', children, className })
|
|
|
9364
9364
|
return React__default.default.createElement("div", { className: classNames }, children);
|
|
9365
9365
|
};
|
|
9366
9366
|
|
|
9367
|
-
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}";
|
|
9367
|
+
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}";
|
|
9368
9368
|
n(css$2,{});
|
|
9369
9369
|
|
|
9370
|
-
const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, placeholder, className = {}, }) => {
|
|
9370
|
+
const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, onSelectSuggestion, suggestions, placeholder, className = {}, }) => {
|
|
9371
9371
|
const [query, setQuery] = React.useState("");
|
|
9372
9372
|
const [borderClass, setBorderClass] = React.useState("default-border");
|
|
9373
9373
|
const [timeoutId, setTimeoutId] = React.useState(null);
|
|
9374
|
-
const
|
|
9375
|
-
|
|
9374
|
+
const [filteredSuggestions, setFilteredSuggestions] = React.useState([]);
|
|
9375
|
+
const [showSuggestions, setShowSuggestions] = React.useState(false);
|
|
9376
|
+
const queryRef = React.useRef(query);
|
|
9376
9377
|
React.useEffect(() => {
|
|
9377
9378
|
queryRef.current = query;
|
|
9378
9379
|
}, [query]);
|
|
9379
9380
|
const handleChange = (e) => {
|
|
9380
9381
|
if (disabled)
|
|
9381
9382
|
return;
|
|
9382
|
-
|
|
9383
|
+
const value = e.target.value;
|
|
9384
|
+
setQuery(value);
|
|
9383
9385
|
setBorderClass("typing-border");
|
|
9384
9386
|
if (timeoutId)
|
|
9385
9387
|
clearTimeout(timeoutId);
|
|
@@ -9388,24 +9390,51 @@ const Search = ({ searchIcon, crossIcon, disabled = false, onSearch, placeholder
|
|
|
9388
9390
|
onSearch(queryRef.current);
|
|
9389
9391
|
}, 2000);
|
|
9390
9392
|
setTimeoutId(newTimeoutId);
|
|
9393
|
+
if (suggestions && value) {
|
|
9394
|
+
const filtered = suggestions
|
|
9395
|
+
.filter((suggestion) => suggestion.title.toLowerCase().includes(value.toLowerCase()))
|
|
9396
|
+
.slice(0, 5);
|
|
9397
|
+
setFilteredSuggestions(filtered);
|
|
9398
|
+
setShowSuggestions(true);
|
|
9399
|
+
}
|
|
9400
|
+
else {
|
|
9401
|
+
setShowSuggestions(false);
|
|
9402
|
+
}
|
|
9391
9403
|
};
|
|
9392
9404
|
const handleClear = () => {
|
|
9393
9405
|
if (disabled)
|
|
9394
9406
|
return;
|
|
9395
9407
|
setQuery("");
|
|
9396
9408
|
setBorderClass("default-border");
|
|
9409
|
+
setShowSuggestions(false);
|
|
9410
|
+
onSelectSuggestion(null);
|
|
9411
|
+
};
|
|
9412
|
+
const handleSelectSuggestion = (suggestion) => {
|
|
9413
|
+
setQuery(suggestion.title);
|
|
9414
|
+
setShowSuggestions(false);
|
|
9415
|
+
onSelectSuggestion(suggestion);
|
|
9397
9416
|
};
|
|
9398
9417
|
React.useEffect(() => {
|
|
9399
9418
|
if (disabled) {
|
|
9400
9419
|
setQuery("");
|
|
9401
9420
|
setBorderClass("disabled-border");
|
|
9421
|
+
setShowSuggestions(false);
|
|
9402
9422
|
}
|
|
9403
9423
|
}, [disabled]);
|
|
9404
|
-
const classNames = `${className ??
|
|
9424
|
+
const classNames = `${className ?? ""}`;
|
|
9405
9425
|
return (React__default.default.createElement("div", { className: `search-field-container ${borderClass} ${classNames}` },
|
|
9406
9426
|
React__default.default.createElement("span", { className: "search-icon" }, searchIcon),
|
|
9407
9427
|
React__default.default.createElement("input", { type: "text", value: query, onChange: handleChange, disabled: disabled, className: "search-input", placeholder: placeholder }),
|
|
9408
|
-
query && !disabled && (React__default.default.createElement("span", { onClick: handleClear, className: "cross-icon" }, crossIcon))
|
|
9428
|
+
query && !disabled && (React__default.default.createElement("span", { onClick: handleClear, className: "cross-icon" }, crossIcon)),
|
|
9429
|
+
showSuggestions &&
|
|
9430
|
+
filteredSuggestions &&
|
|
9431
|
+
filteredSuggestions?.length > 0 && (React__default.default.createElement("div", { className: "suggestions-dropdown" }, filteredSuggestions?.map((suggestion) => {
|
|
9432
|
+
return (React__default.default.createElement(React__default.default.Fragment, null,
|
|
9433
|
+
React__default.default.createElement("button", { key: suggestion.id, onClick: () => handleSelectSuggestion(suggestion), className: "row" },
|
|
9434
|
+
searchIcon,
|
|
9435
|
+
React__default.default.createElement(Typography, { variant: "B4", weight: "SEMI_BOLD", className: "suggestion-item" }, suggestion.title)),
|
|
9436
|
+
React__default.default.createElement("div", { className: "underline" })));
|
|
9437
|
+
})))));
|
|
9409
9438
|
};
|
|
9410
9439
|
|
|
9411
9440
|
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}";
|