@herca/r-kit 0.0.75 → 0.0.77
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/clients.cjs +62 -120
- package/dist/clients.cjs.map +1 -1
- package/dist/clients.d.cts +1 -1
- package/dist/clients.d.ts +1 -1
- package/dist/clients.js +62 -120
- package/dist/clients.js.map +1 -1
- package/package.json +1 -1
package/dist/clients.cjs
CHANGED
|
@@ -11500,7 +11500,7 @@ function useUrlSearchParams() {
|
|
|
11500
11500
|
const next = updater(readParams());
|
|
11501
11501
|
const query = next.toString();
|
|
11502
11502
|
const url = `${window.location.pathname}${query ? `?${query}` : ""}${window.location.hash}`;
|
|
11503
|
-
if (options?.replace) {
|
|
11503
|
+
if (options?.replace == true) {
|
|
11504
11504
|
window.history.replaceState(window.history.state, "", url);
|
|
11505
11505
|
} else {
|
|
11506
11506
|
window.history.pushState(window.history.state, "", url);
|
|
@@ -17042,26 +17042,21 @@ function RoundedSpinner({
|
|
|
17042
17042
|
// src/components/select/select.tsx
|
|
17043
17043
|
var import_clsx14 = __toESM(require("clsx"), 1);
|
|
17044
17044
|
var import_jsx_runtime435 = require("react/jsx-runtime");
|
|
17045
|
-
var isGroup = (item) => item != null && Array.isArray(item.options);
|
|
17046
|
-
var getSearchText = (option) => typeof option.label === "string" ? option.label : String(option.value ?? "");
|
|
17047
17045
|
function Select({
|
|
17048
17046
|
options = [],
|
|
17049
17047
|
value = null,
|
|
17050
17048
|
onChange,
|
|
17051
17049
|
isMulti = false,
|
|
17052
|
-
multiple = false,
|
|
17053
17050
|
placeholder = "Select...",
|
|
17054
17051
|
isSearchable = true,
|
|
17055
17052
|
isClearable = true,
|
|
17056
17053
|
isDisabled = false,
|
|
17057
|
-
disabled = false,
|
|
17058
17054
|
renderOption = null,
|
|
17059
17055
|
renderValue = null,
|
|
17060
17056
|
className,
|
|
17061
17057
|
label,
|
|
17062
17058
|
description,
|
|
17063
17059
|
hint,
|
|
17064
|
-
tooltip,
|
|
17065
17060
|
errorMessages,
|
|
17066
17061
|
isLoadingMore,
|
|
17067
17062
|
onLoadMore,
|
|
@@ -17075,8 +17070,7 @@ function Select({
|
|
|
17075
17070
|
isSelectOpen,
|
|
17076
17071
|
onOpenChange,
|
|
17077
17072
|
searchOptions,
|
|
17078
|
-
searchPlaceholder = "Search..."
|
|
17079
|
-
icon
|
|
17073
|
+
searchPlaceholder = "Search..."
|
|
17080
17074
|
}) {
|
|
17081
17075
|
const [isOpen, setIsOpen] = (0, import_react415.useState)(false);
|
|
17082
17076
|
const [searchTerm, setSearchTerm] = (0, import_react415.useState)("");
|
|
@@ -17085,12 +17079,6 @@ function Select({
|
|
|
17085
17079
|
const searchInputRef = (0, import_react415.useRef)(null);
|
|
17086
17080
|
const optionRefs = (0, import_react415.useRef)([]);
|
|
17087
17081
|
const listContainerRef = (0, import_react415.useRef)(null);
|
|
17088
|
-
const onOptionsChangeRef = (0, import_react415.useRef)(onOptionsChange);
|
|
17089
|
-
const onOpenChangeRef = (0, import_react415.useRef)(onOpenChange);
|
|
17090
|
-
(0, import_react415.useEffect)(() => {
|
|
17091
|
-
onOptionsChangeRef.current = onOptionsChange;
|
|
17092
|
-
onOpenChangeRef.current = onOpenChange;
|
|
17093
|
-
});
|
|
17094
17082
|
const handleScroll = () => {
|
|
17095
17083
|
const el = listContainerRef.current;
|
|
17096
17084
|
if (!el || Boolean(isLoadingMore)) return;
|
|
@@ -17099,39 +17087,20 @@ function Select({
|
|
|
17099
17087
|
onLoadMore?.();
|
|
17100
17088
|
}
|
|
17101
17089
|
};
|
|
17102
|
-
const
|
|
17103
|
-
|
|
17104
|
-
|
|
17105
|
-
|
|
17106
|
-
const matches2 = (o) => getSearchText(o).toLowerCase().includes(term);
|
|
17107
|
-
for (const item of options) {
|
|
17108
|
-
if (isGroup(item)) {
|
|
17109
|
-
const matched = item.options.filter(matches2);
|
|
17110
|
-
if (matched.length === 0) continue;
|
|
17111
|
-
const items = matched.map((option) => {
|
|
17112
|
-
const index = flat.length;
|
|
17113
|
-
flat.push(option);
|
|
17114
|
-
return { option, index };
|
|
17115
|
-
});
|
|
17116
|
-
entries.push({ kind: "group", label: item.label, items });
|
|
17117
|
-
} else {
|
|
17118
|
-
if (!matches2(item)) continue;
|
|
17119
|
-
const index = flat.length;
|
|
17120
|
-
flat.push(item);
|
|
17121
|
-
entries.push({ kind: "option", option: item, index });
|
|
17122
|
-
}
|
|
17123
|
-
}
|
|
17124
|
-
return { filteredOptions: flat, renderEntries: entries };
|
|
17090
|
+
const filteredOptions = import_react415.default.useMemo(() => {
|
|
17091
|
+
return options.filter(
|
|
17092
|
+
(option) => option.label.toLowerCase().includes(searchTerm.toLowerCase()) === true
|
|
17093
|
+
);
|
|
17125
17094
|
}, [options, searchTerm]);
|
|
17126
17095
|
const asArray = (val) => Array.isArray(val) ? val : val ? [val] : [];
|
|
17127
17096
|
const isSelected = (option) => {
|
|
17128
|
-
if (isMulti
|
|
17097
|
+
if (isMulti) {
|
|
17129
17098
|
return asArray(value).some((v3) => v3.value === option.value);
|
|
17130
17099
|
}
|
|
17131
17100
|
return value?.value === option.value;
|
|
17132
17101
|
};
|
|
17133
17102
|
const handleSelect = (option) => {
|
|
17134
|
-
if (isMulti
|
|
17103
|
+
if (isMulti) {
|
|
17135
17104
|
const arr = asArray(value);
|
|
17136
17105
|
const exists = arr.some((v3) => v3.value === option.value);
|
|
17137
17106
|
const newValue = exists ? arr.filter((v3) => v3.value !== option.value) : [...arr, option];
|
|
@@ -17147,7 +17116,7 @@ function Select({
|
|
|
17147
17116
|
};
|
|
17148
17117
|
const handleRemove = (option, e) => {
|
|
17149
17118
|
e.stopPropagation();
|
|
17150
|
-
if (isMulti
|
|
17119
|
+
if (isMulti) {
|
|
17151
17120
|
const arr = asArray(value);
|
|
17152
17121
|
onChange?.(arr.filter((v3) => v3.value !== option.value));
|
|
17153
17122
|
} else {
|
|
@@ -17156,7 +17125,7 @@ function Select({
|
|
|
17156
17125
|
};
|
|
17157
17126
|
const handleClear = (e) => {
|
|
17158
17127
|
e.stopPropagation();
|
|
17159
|
-
onChange?.(isMulti
|
|
17128
|
+
onChange?.(isMulti ? [] : null);
|
|
17160
17129
|
};
|
|
17161
17130
|
const handleKeyDown2 = (e) => {
|
|
17162
17131
|
if (!isOpen) {
|
|
@@ -17183,7 +17152,7 @@ function Select({
|
|
|
17183
17152
|
e.preventDefault();
|
|
17184
17153
|
try {
|
|
17185
17154
|
const opt = filteredOptions[highlightedIndex];
|
|
17186
|
-
if (opt
|
|
17155
|
+
if (opt) handleSelect(opt);
|
|
17187
17156
|
} catch (error) {
|
|
17188
17157
|
console.error(error);
|
|
17189
17158
|
}
|
|
@@ -17199,9 +17168,6 @@ function Select({
|
|
|
17199
17168
|
(0, import_react415.useEffect)(() => {
|
|
17200
17169
|
setHighlightedIndex(0);
|
|
17201
17170
|
}, [searchTerm]);
|
|
17202
|
-
(0, import_react415.useEffect)(() => {
|
|
17203
|
-
optionRefs.current.length = filteredOptions.length;
|
|
17204
|
-
}, [filteredOptions]);
|
|
17205
17171
|
(0, import_react415.useEffect)(() => {
|
|
17206
17172
|
const el = optionRefs.current[highlightedIndex];
|
|
17207
17173
|
if (el) {
|
|
@@ -17228,7 +17194,7 @@ function Select({
|
|
|
17228
17194
|
}
|
|
17229
17195
|
}, [isOpen, isSearchable]);
|
|
17230
17196
|
(0, import_react415.useEffect)(() => {
|
|
17231
|
-
|
|
17197
|
+
onOptionsChange?.(filteredOptions);
|
|
17232
17198
|
}, [filteredOptions]);
|
|
17233
17199
|
(0, import_react415.useEffect)(() => {
|
|
17234
17200
|
if (isSelectOpen !== void 0) {
|
|
@@ -17236,7 +17202,7 @@ function Select({
|
|
|
17236
17202
|
}
|
|
17237
17203
|
}, [isSelectOpen]);
|
|
17238
17204
|
(0, import_react415.useEffect)(() => {
|
|
17239
|
-
|
|
17205
|
+
onOpenChange?.(isOpen);
|
|
17240
17206
|
}, [isOpen]);
|
|
17241
17207
|
(0, import_react415.useEffect)(() => {
|
|
17242
17208
|
if (searchOptions !== void 0) {
|
|
@@ -17244,11 +17210,11 @@ function Select({
|
|
|
17244
17210
|
}
|
|
17245
17211
|
}, [searchOptions]);
|
|
17246
17212
|
const getDisplayValue = () => {
|
|
17247
|
-
const isEmpty = value == null ||
|
|
17213
|
+
const isEmpty = value == null || isMulti && asArray(value).length === 0;
|
|
17248
17214
|
if (isEmpty) {
|
|
17249
17215
|
return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("span", { className: "text-gray-500", children: placeholder });
|
|
17250
17216
|
}
|
|
17251
|
-
if (isMulti
|
|
17217
|
+
if (isMulti) {
|
|
17252
17218
|
return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "flex flex-wrap gap-1", children: asArray(value).map((item) => /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)(
|
|
17253
17219
|
"div",
|
|
17254
17220
|
{
|
|
@@ -17270,33 +17236,8 @@ function Select({
|
|
|
17270
17236
|
}
|
|
17271
17237
|
return renderValue !== void 0 && renderValue !== null ? renderValue?.(value) : value.label;
|
|
17272
17238
|
};
|
|
17273
|
-
const showClearButton = isClearable && (
|
|
17239
|
+
const showClearButton = isClearable && (isMulti && asArray(value).length > 0 || !isMulti && value !== null);
|
|
17274
17240
|
const hasError = fieldHasError(errorMessages);
|
|
17275
|
-
const renderOptionItem = (option, index) => {
|
|
17276
|
-
const selected = isSelected(option);
|
|
17277
|
-
const highlighted = index === highlightedIndex;
|
|
17278
|
-
return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17279
|
-
"div",
|
|
17280
|
-
{
|
|
17281
|
-
ref: (el) => {
|
|
17282
|
-
optionRefs.current[index] = el;
|
|
17283
|
-
},
|
|
17284
|
-
onMouseEnter: () => setHighlightedIndex(index),
|
|
17285
|
-
onClick: () => handleSelect(option),
|
|
17286
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Chip, { className: "text-left", block: true, selected: highlighted, children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "flex-1", children: renderOption !== void 0 && renderOption !== null ? renderOption?.(option, { selected }) : /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
17287
|
-
option?.icon != void 0 && /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Icon_default, { name: "user", size: 12 }),
|
|
17288
|
-
/* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Text, { variant: "t2", weight: "medium", className: "text-gray-900", children: option.label })
|
|
17289
|
-
] }) }) })
|
|
17290
|
-
},
|
|
17291
|
-
option.value
|
|
17292
|
-
);
|
|
17293
|
-
};
|
|
17294
|
-
const hanldeOnClickInput = () => {
|
|
17295
|
-
if (disabled || isDisabled) {
|
|
17296
|
-
return false;
|
|
17297
|
-
}
|
|
17298
|
-
setIsOpen(!isOpen);
|
|
17299
|
-
};
|
|
17300
17241
|
return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17301
17242
|
FormField,
|
|
17302
17243
|
{
|
|
@@ -17305,7 +17246,6 @@ function Select({
|
|
|
17305
17246
|
description,
|
|
17306
17247
|
hint,
|
|
17307
17248
|
required,
|
|
17308
|
-
tooltip,
|
|
17309
17249
|
children: /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)(
|
|
17310
17250
|
"div",
|
|
17311
17251
|
{
|
|
@@ -17318,8 +17258,8 @@ function Select({
|
|
|
17318
17258
|
"div",
|
|
17319
17259
|
{
|
|
17320
17260
|
"aria-selected": isOpen,
|
|
17321
|
-
onClick:
|
|
17322
|
-
tabIndex: isDisabled
|
|
17261
|
+
onClick: () => !isDisabled && setIsOpen(!isOpen),
|
|
17262
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
17323
17263
|
className: triggerClassName,
|
|
17324
17264
|
children: trigger
|
|
17325
17265
|
}
|
|
@@ -17329,36 +17269,33 @@ function Select({
|
|
|
17329
17269
|
{
|
|
17330
17270
|
"aria-selected": isOpen,
|
|
17331
17271
|
className: cn(
|
|
17332
|
-
"focus:ring-primary-300 flex min-h-10 cursor-pointer rounded-lg border bg-white text-gray-900 transition-all focus-within:outline-none focus:ring",
|
|
17333
|
-
|
|
17272
|
+
"focus:ring-primary-300 flex min-h-10 cursor-pointer items-center justify-between rounded-lg border bg-white px-3 py-2 text-gray-900 transition-all focus-within:outline-none focus:ring",
|
|
17273
|
+
isDisabled && "cursor-not-allowed bg-gray-100",
|
|
17334
17274
|
isOpen ? "border-primary-300 ring-0" : "border-gray-200",
|
|
17335
17275
|
hasError && "border-danger-500"
|
|
17336
17276
|
),
|
|
17337
|
-
onClick:
|
|
17338
|
-
tabIndex: isDisabled
|
|
17277
|
+
onClick: () => !isDisabled && setIsOpen(!isOpen),
|
|
17278
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
17339
17279
|
children: [
|
|
17340
|
-
|
|
17341
|
-
/* @__PURE__ */ (0, import_jsx_runtime435.jsxs)("div", { className: "
|
|
17342
|
-
/* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17343
|
-
|
|
17344
|
-
|
|
17345
|
-
"button",
|
|
17346
|
-
|
|
17347
|
-
|
|
17348
|
-
|
|
17349
|
-
|
|
17350
|
-
|
|
17351
|
-
|
|
17352
|
-
|
|
17353
|
-
|
|
17354
|
-
|
|
17355
|
-
|
|
17356
|
-
|
|
17357
|
-
|
|
17358
|
-
|
|
17359
|
-
}
|
|
17360
|
-
)
|
|
17361
|
-
] })
|
|
17280
|
+
/* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "flex-1 overflow-hidden text-xs font-medium text-gray-900", children: getDisplayValue() }),
|
|
17281
|
+
/* @__PURE__ */ (0, import_jsx_runtime435.jsxs)("div", { className: "ml-2 flex items-center gap-1", children: [
|
|
17282
|
+
showClearButton && /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17283
|
+
"button",
|
|
17284
|
+
{
|
|
17285
|
+
type: "button",
|
|
17286
|
+
onClick: handleClear,
|
|
17287
|
+
className: "cursor-pointer rounded text-center text-gray-700",
|
|
17288
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Icon_default, { name: "times-circle", size: 20 })
|
|
17289
|
+
}
|
|
17290
|
+
),
|
|
17291
|
+
/* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17292
|
+
Icon_default,
|
|
17293
|
+
{
|
|
17294
|
+
className: "text-gray-700",
|
|
17295
|
+
name: isOpen ? "angle-up-small" : "angle-down-small",
|
|
17296
|
+
size: 20
|
|
17297
|
+
}
|
|
17298
|
+
)
|
|
17362
17299
|
] })
|
|
17363
17300
|
]
|
|
17364
17301
|
}
|
|
@@ -17397,22 +17334,27 @@ function Select({
|
|
|
17397
17334
|
onScroll: onLoadMore !== void 0 ? handleScroll : void 0,
|
|
17398
17335
|
children: [
|
|
17399
17336
|
renderOptions === void 0 && /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)(import_jsx_runtime435.Fragment, { children: [
|
|
17400
|
-
filteredOptions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "px-3 py-8 text-center text-sm text-gray-500", children: "No options found" }) :
|
|
17401
|
-
|
|
17402
|
-
|
|
17403
|
-
|
|
17404
|
-
|
|
17405
|
-
|
|
17406
|
-
|
|
17407
|
-
|
|
17408
|
-
|
|
17409
|
-
|
|
17410
|
-
|
|
17411
|
-
|
|
17412
|
-
|
|
17413
|
-
|
|
17414
|
-
|
|
17415
|
-
|
|
17337
|
+
filteredOptions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "px-3 py-8 text-center text-sm text-gray-500", children: "No options found" }) : filteredOptions.map((option, index) => {
|
|
17338
|
+
const selected = isSelected(option);
|
|
17339
|
+
const highlighted = index === highlightedIndex;
|
|
17340
|
+
return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17341
|
+
"div",
|
|
17342
|
+
{
|
|
17343
|
+
ref: (el) => {
|
|
17344
|
+
optionRefs.current[index] = el;
|
|
17345
|
+
},
|
|
17346
|
+
onMouseEnter: () => setHighlightedIndex(index),
|
|
17347
|
+
onClick: () => handleSelect(option),
|
|
17348
|
+
className: cn(
|
|
17349
|
+
"flex cursor-pointer items-center justify-between rounded-lg px-3 py-2 text-sm font-medium text-gray-900 transition-colors focus:outline-none",
|
|
17350
|
+
highlighted && "bg-primary-100",
|
|
17351
|
+
selected ? "bg-primary-50 border-primary-300" : "hover:bg-gray-50"
|
|
17352
|
+
),
|
|
17353
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "flex-1", children: renderOption !== void 0 && renderOption !== null ? renderOption?.(option, { selected }) : /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: cn(selected && "font-medium"), children: option.label }) })
|
|
17354
|
+
},
|
|
17355
|
+
option.value
|
|
17356
|
+
);
|
|
17357
|
+
}),
|
|
17416
17358
|
onLoadMore !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
|
|
17417
17359
|
"div",
|
|
17418
17360
|
{
|