@herca/r-kit 0.0.74 → 0.0.75

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 CHANGED
@@ -17043,6 +17043,7 @@ function RoundedSpinner({
17043
17043
  var import_clsx14 = __toESM(require("clsx"), 1);
17044
17044
  var import_jsx_runtime435 = require("react/jsx-runtime");
17045
17045
  var isGroup = (item) => item != null && Array.isArray(item.options);
17046
+ var getSearchText = (option) => typeof option.label === "string" ? option.label : String(option.value ?? "");
17046
17047
  function Select({
17047
17048
  options = [],
17048
17049
  value = null,
@@ -17084,6 +17085,12 @@ function Select({
17084
17085
  const searchInputRef = (0, import_react415.useRef)(null);
17085
17086
  const optionRefs = (0, import_react415.useRef)([]);
17086
17087
  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
+ });
17087
17094
  const handleScroll = () => {
17088
17095
  const el = listContainerRef.current;
17089
17096
  if (!el || Boolean(isLoadingMore)) return;
@@ -17092,7 +17099,6 @@ function Select({
17092
17099
  onLoadMore?.();
17093
17100
  }
17094
17101
  };
17095
- const getSearchText = (option) => typeof option.label === "string" ? option.label : String(option.value ?? "");
17096
17102
  const { filteredOptions, renderEntries } = import_react415.default.useMemo(() => {
17097
17103
  const flat = [];
17098
17104
  const entries = [];
@@ -17177,7 +17183,7 @@ function Select({
17177
17183
  e.preventDefault();
17178
17184
  try {
17179
17185
  const opt = filteredOptions[highlightedIndex];
17180
- if (opt) handleSelect(opt);
17186
+ if (opt != void 0) handleSelect(opt);
17181
17187
  } catch (error) {
17182
17188
  console.error(error);
17183
17189
  }
@@ -17193,6 +17199,9 @@ function Select({
17193
17199
  (0, import_react415.useEffect)(() => {
17194
17200
  setHighlightedIndex(0);
17195
17201
  }, [searchTerm]);
17202
+ (0, import_react415.useEffect)(() => {
17203
+ optionRefs.current.length = filteredOptions.length;
17204
+ }, [filteredOptions]);
17196
17205
  (0, import_react415.useEffect)(() => {
17197
17206
  const el = optionRefs.current[highlightedIndex];
17198
17207
  if (el) {
@@ -17219,7 +17228,7 @@ function Select({
17219
17228
  }
17220
17229
  }, [isOpen, isSearchable]);
17221
17230
  (0, import_react415.useEffect)(() => {
17222
- onOptionsChange?.(filteredOptions);
17231
+ onOptionsChangeRef.current?.(filteredOptions);
17223
17232
  }, [filteredOptions]);
17224
17233
  (0, import_react415.useEffect)(() => {
17225
17234
  if (isSelectOpen !== void 0) {
@@ -17227,7 +17236,7 @@ function Select({
17227
17236
  }
17228
17237
  }, [isSelectOpen]);
17229
17238
  (0, import_react415.useEffect)(() => {
17230
- onOpenChange?.(isOpen);
17239
+ onOpenChangeRef.current?.(isOpen);
17231
17240
  }, [isOpen]);
17232
17241
  (0, import_react415.useEffect)(() => {
17233
17242
  if (searchOptions !== void 0) {
@@ -17265,6 +17274,7 @@ function Select({
17265
17274
  const hasError = fieldHasError(errorMessages);
17266
17275
  const renderOptionItem = (option, index) => {
17267
17276
  const selected = isSelected(option);
17277
+ const highlighted = index === highlightedIndex;
17268
17278
  return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
17269
17279
  "div",
17270
17280
  {
@@ -17273,11 +17283,20 @@ function Select({
17273
17283
  },
17274
17284
  onMouseEnter: () => setHighlightedIndex(index),
17275
17285
  onClick: () => handleSelect(option),
17276
- children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Chip, { className: "text-left", block: true, selected, 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 }) }) })
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
+ ] }) }) })
17277
17290
  },
17278
17291
  option.value
17279
17292
  );
17280
17293
  };
17294
+ const hanldeOnClickInput = () => {
17295
+ if (disabled || isDisabled) {
17296
+ return false;
17297
+ }
17298
+ setIsOpen(!isOpen);
17299
+ };
17281
17300
  return /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
17282
17301
  FormField,
17283
17302
  {
@@ -17299,7 +17318,7 @@ function Select({
17299
17318
  "div",
17300
17319
  {
17301
17320
  "aria-selected": isOpen,
17302
- onClick: () => (!isDisabled || !disabled) && setIsOpen(!isOpen),
17321
+ onClick: hanldeOnClickInput,
17303
17322
  tabIndex: isDisabled || disabled ? -1 : 0,
17304
17323
  className: triggerClassName,
17305
17324
  children: trigger
@@ -17315,7 +17334,7 @@ function Select({
17315
17334
  isOpen ? "border-primary-300 ring-0" : "border-gray-200",
17316
17335
  hasError && "border-danger-500"
17317
17336
  ),
17318
- onClick: () => (!isDisabled || !disabled) && setIsOpen(!isOpen),
17337
+ onClick: hanldeOnClickInput,
17319
17338
  tabIndex: isDisabled && disabled ? -1 : 0,
17320
17339
  children: [
17321
17340
  icon && /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "flex items-center border-r border-gray-200 px-3 py-2", children: /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(Icon_default, { name: icon, size: 22, className: "text-gray-600" }) }),
@@ -17380,7 +17399,15 @@ function Select({
17380
17399
  renderOptions === void 0 && /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)(import_jsx_runtime435.Fragment, { children: [
17381
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" }) : renderEntries.map(
17382
17401
  (entry, i) => entry.kind === "group" ? /* @__PURE__ */ (0, import_jsx_runtime435.jsxs)("div", { className: "space-y-2", children: [
17383
- /* @__PURE__ */ (0, import_jsx_runtime435.jsx)("div", { className: "px-3 pt-1 pb-0.5 text-xs font-semibold tracking-wide text-gray-400 uppercase", children: entry.label }),
17402
+ /* @__PURE__ */ (0, import_jsx_runtime435.jsx)(
17403
+ Text,
17404
+ {
17405
+ variant: "t2",
17406
+ weight: "semibold",
17407
+ className: "text-gray-900",
17408
+ children: entry.label
17409
+ }
17410
+ ),
17384
17411
  entry.items.map(
17385
17412
  ({ option, index }) => renderOptionItem(option, index)
17386
17413
  )