analytica-frontend-lib 1.1.72 → 1.1.73
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/Search/index.js +73 -27
- package/dist/Search/index.js.map +1 -1
- package/dist/Search/index.mjs +74 -28
- package/dist/Search/index.mjs.map +1 -1
- package/dist/index.js +73 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/Search/index.js
CHANGED
|
@@ -1095,11 +1095,15 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1095
1095
|
value,
|
|
1096
1096
|
onChange,
|
|
1097
1097
|
placeholder = "Buscar...",
|
|
1098
|
+
onKeyDown: userOnKeyDown,
|
|
1098
1099
|
...props
|
|
1099
1100
|
}, ref) => {
|
|
1100
1101
|
const [dropdownOpen, setDropdownOpen] = (0, import_react6.useState)(false);
|
|
1102
|
+
const [forceClose, setForceClose] = (0, import_react6.useState)(false);
|
|
1103
|
+
const justSelectedRef = (0, import_react6.useRef)(false);
|
|
1101
1104
|
const dropdownStore = (0, import_react6.useRef)(createDropdownStore()).current;
|
|
1102
1105
|
const dropdownRef = (0, import_react6.useRef)(null);
|
|
1106
|
+
const inputElRef = (0, import_react6.useRef)(null);
|
|
1103
1107
|
const filteredOptions = (0, import_react6.useMemo)(() => {
|
|
1104
1108
|
if (!options.length) {
|
|
1105
1109
|
return [];
|
|
@@ -1107,24 +1111,35 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1107
1111
|
const filtered = filterOptions(options, value || "");
|
|
1108
1112
|
return filtered;
|
|
1109
1113
|
}, [options, value]);
|
|
1110
|
-
const showDropdown = controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0);
|
|
1114
|
+
const showDropdown = !forceClose && (controlledShowDropdown ?? (dropdownOpen && value && String(value).length > 0));
|
|
1115
|
+
const setOpenAndNotify = (open) => {
|
|
1116
|
+
setDropdownOpen(open);
|
|
1117
|
+
dropdownStore.setState({ open });
|
|
1118
|
+
onDropdownChange?.(open);
|
|
1119
|
+
};
|
|
1111
1120
|
(0, import_react6.useEffect)(() => {
|
|
1121
|
+
if (justSelectedRef.current) {
|
|
1122
|
+
justSelectedRef.current = false;
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (forceClose) {
|
|
1126
|
+
setOpenAndNotify(false);
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1112
1129
|
const shouldShow = Boolean(value && String(value).length > 0);
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
onDropdownChange?.(shouldShow);
|
|
1116
|
-
}, [value, onDropdownChange, dropdownStore]);
|
|
1130
|
+
setOpenAndNotify(shouldShow);
|
|
1131
|
+
}, [value, forceClose, onDropdownChange, dropdownStore]);
|
|
1117
1132
|
const handleSelectOption = (option) => {
|
|
1133
|
+
justSelectedRef.current = true;
|
|
1134
|
+
setForceClose(true);
|
|
1118
1135
|
onSelect?.(option);
|
|
1119
|
-
|
|
1120
|
-
dropdownStore.setState({ open: false });
|
|
1136
|
+
setOpenAndNotify(false);
|
|
1121
1137
|
updateInputValue(option, ref, onChange);
|
|
1122
1138
|
};
|
|
1123
1139
|
(0, import_react6.useEffect)(() => {
|
|
1124
1140
|
const handleClickOutside = (event) => {
|
|
1125
1141
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
1126
|
-
|
|
1127
|
-
dropdownStore.setState({ open: false });
|
|
1142
|
+
setOpenAndNotify(false);
|
|
1128
1143
|
}
|
|
1129
1144
|
};
|
|
1130
1145
|
if (showDropdown) {
|
|
@@ -1133,9 +1148,10 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1133
1148
|
return () => {
|
|
1134
1149
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
1135
1150
|
};
|
|
1136
|
-
}, [showDropdown, dropdownStore]);
|
|
1151
|
+
}, [showDropdown, dropdownStore, onDropdownChange]);
|
|
1137
1152
|
const generatedId = (0, import_react6.useId)();
|
|
1138
1153
|
const inputId = id ?? `search-${generatedId}`;
|
|
1154
|
+
const dropdownId = `${inputId}-dropdown`;
|
|
1139
1155
|
const handleClear = () => {
|
|
1140
1156
|
if (onClear) {
|
|
1141
1157
|
onClear();
|
|
@@ -1148,21 +1164,40 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1148
1164
|
e.stopPropagation();
|
|
1149
1165
|
handleClear();
|
|
1150
1166
|
};
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1167
|
+
const handleSearchIconClick = (e) => {
|
|
1168
|
+
e.preventDefault();
|
|
1169
|
+
e.stopPropagation();
|
|
1170
|
+
setTimeout(() => {
|
|
1171
|
+
inputElRef.current?.focus();
|
|
1172
|
+
}, 0);
|
|
1155
1173
|
};
|
|
1156
1174
|
const handleInputChange = (e) => {
|
|
1175
|
+
setForceClose(false);
|
|
1157
1176
|
onChange?.(e);
|
|
1158
1177
|
onSearch?.(e.target.value);
|
|
1159
1178
|
};
|
|
1179
|
+
const handleKeyDown = (e) => {
|
|
1180
|
+
userOnKeyDown?.(e);
|
|
1181
|
+
if (e.defaultPrevented) return;
|
|
1182
|
+
if (e.key === "Enter") {
|
|
1183
|
+
e.preventDefault();
|
|
1184
|
+
if (showDropdown && filteredOptions.length > 0) {
|
|
1185
|
+
handleSelectOption(filteredOptions[0]);
|
|
1186
|
+
} else if (value) {
|
|
1187
|
+
onSearch?.(String(value));
|
|
1188
|
+
setForceClose(true);
|
|
1189
|
+
setOpenAndNotify(false);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1160
1193
|
const getInputStateClasses = (disabled2, readOnly2) => {
|
|
1161
1194
|
if (disabled2) return "cursor-not-allowed opacity-40";
|
|
1162
1195
|
if (readOnly2) return "cursor-default focus:outline-none !text-text-900";
|
|
1163
1196
|
return "hover:border-border-400";
|
|
1164
1197
|
};
|
|
1165
|
-
const
|
|
1198
|
+
const hasValue = String(value ?? "").length > 0;
|
|
1199
|
+
const showClearButton = hasValue && !disabled && !readOnly;
|
|
1200
|
+
const showSearchIcon = !hasValue && !disabled && !readOnly;
|
|
1166
1201
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
1167
1202
|
"div",
|
|
1168
1203
|
{
|
|
@@ -1170,30 +1205,30 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1170
1205
|
className: `w-full max-w-lg md:w-[488px] ${containerClassName}`,
|
|
1171
1206
|
children: [
|
|
1172
1207
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "relative flex items-center", children: [
|
|
1173
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "absolute left-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1174
|
-
"button",
|
|
1175
|
-
{
|
|
1176
|
-
type: "button",
|
|
1177
|
-
className: "w-6 h-6 text-text-800 flex items-center justify-center bg-transparent border-0 p-0 cursor-pointer hover:text-text-600 transition-colors",
|
|
1178
|
-
onClick: handleLeftIconClick,
|
|
1179
|
-
"aria-label": "Voltar",
|
|
1180
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_phosphor_react4.CaretLeft, {})
|
|
1181
|
-
}
|
|
1182
|
-
) }),
|
|
1183
1208
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1184
1209
|
"input",
|
|
1185
1210
|
{
|
|
1186
|
-
ref
|
|
1211
|
+
ref: (node) => {
|
|
1212
|
+
if (ref) {
|
|
1213
|
+
if (typeof ref === "function") ref(node);
|
|
1214
|
+
else
|
|
1215
|
+
ref.current = node;
|
|
1216
|
+
}
|
|
1217
|
+
inputElRef.current = node;
|
|
1218
|
+
},
|
|
1187
1219
|
id: inputId,
|
|
1188
1220
|
type: "text",
|
|
1189
|
-
className: `w-full py-0 px-4
|
|
1221
|
+
className: `w-full py-0 px-4 pr-10 font-normal text-text-900 focus:outline-primary-950 border rounded-full bg-background focus:bg-primary-50 border-border-300 focus:border-2 focus:border-primary-950 h-10 placeholder:text-text-600 ${getInputStateClasses(disabled, readOnly)} ${className}`,
|
|
1190
1222
|
value,
|
|
1191
1223
|
onChange: handleInputChange,
|
|
1224
|
+
onKeyDown: handleKeyDown,
|
|
1192
1225
|
disabled,
|
|
1193
1226
|
readOnly,
|
|
1194
1227
|
placeholder,
|
|
1195
1228
|
"aria-expanded": showDropdown ? "true" : void 0,
|
|
1196
1229
|
"aria-haspopup": options.length > 0 ? "listbox" : void 0,
|
|
1230
|
+
"aria-controls": showDropdown ? dropdownId : void 0,
|
|
1231
|
+
"aria-autocomplete": "list",
|
|
1197
1232
|
role: options.length > 0 ? "combobox" : void 0,
|
|
1198
1233
|
...props
|
|
1199
1234
|
}
|
|
@@ -1207,11 +1242,22 @@ var Search = (0, import_react6.forwardRef)(
|
|
|
1207
1242
|
"aria-label": "Limpar busca",
|
|
1208
1243
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_phosphor_react4.X, {}) })
|
|
1209
1244
|
}
|
|
1245
|
+
) }),
|
|
1246
|
+
showSearchIcon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "absolute right-3 top-1/2 transform -translate-y-1/2", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1247
|
+
"button",
|
|
1248
|
+
{
|
|
1249
|
+
type: "button",
|
|
1250
|
+
className: "p-0 border-0 bg-transparent cursor-pointer",
|
|
1251
|
+
onMouseDown: handleSearchIconClick,
|
|
1252
|
+
"aria-label": "Buscar",
|
|
1253
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "w-6 h-6 text-text-800 flex items-center justify-center hover:text-text-600 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_phosphor_react4.MagnifyingGlass, {}) })
|
|
1254
|
+
}
|
|
1210
1255
|
) })
|
|
1211
1256
|
] }),
|
|
1212
1257
|
showDropdown && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DropdownMenu_default, { open: showDropdown, onOpenChange: setDropdownOpen, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1213
1258
|
DropdownMenuContent,
|
|
1214
1259
|
{
|
|
1260
|
+
id: dropdownId,
|
|
1215
1261
|
className: "w-full mt-1",
|
|
1216
1262
|
style: { maxHeight: dropdownMaxHeight },
|
|
1217
1263
|
align: "start",
|