@chekinapp/ui 0.0.118 → 0.0.120

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/index.cjs CHANGED
@@ -14203,26 +14203,36 @@ function SelectInternal(props, ref) {
14203
14203
  menuHeader,
14204
14204
  onMenuScrollToBottom,
14205
14205
  leftIcon,
14206
- formatGroupLabel
14206
+ formatGroupLabel,
14207
+ onReset
14207
14208
  } = props;
14208
14209
  const isSearchInDropdown = searchPosition === "dropdown";
14209
14210
  const isMulti = props.isMulti === true;
14210
14211
  const clearable = !isMulti ? props.clearable ?? true : true;
14211
14212
  const closeMenuOnSelect = isMulti ? props.closeMenuOnSelect ?? false : void 0;
14212
14213
  const { t } = (0, import_react_i18next33.useTranslation)();
14214
+ const isControlled = props.value !== void 0;
14215
+ const [internalValue, setInternalValue] = React49.useState(() => {
14216
+ if (isMulti) return props.defaultValue ?? [];
14217
+ return props.defaultValue ?? null;
14218
+ });
14219
+ const currentValue = isControlled ? props.value : internalValue;
14213
14220
  const selectedOptions = React49.useMemo(() => {
14214
- if (isMulti) return props.value ?? [];
14215
- return props.value ? [props.value] : [];
14216
- }, [isMulti, props.value]);
14221
+ if (isMulti) return currentValue ?? [];
14222
+ return currentValue ? [currentValue] : [];
14223
+ }, [isMulti, currentValue]);
14217
14224
  const onSelectionChange = React49.useCallback(
14218
14225
  (next, meta) => {
14219
14226
  if (isMulti) {
14220
- props.onChange(next, meta);
14227
+ if (!isControlled) setInternalValue(next);
14228
+ props.onChange?.(next, meta);
14221
14229
  } else {
14222
- props.onChange(next[0] ?? null, meta);
14230
+ const nextValue = next[0] ?? null;
14231
+ if (!isControlled) setInternalValue(nextValue);
14232
+ props.onChange?.(nextValue, meta);
14223
14233
  }
14224
14234
  },
14225
- [isMulti, props.onChange]
14235
+ [isMulti, isControlled, props.onChange]
14226
14236
  );
14227
14237
  const flatOptions = React49.useMemo(() => flattenGroupedOptions(options), [options]);
14228
14238
  const state = useSelectState({
@@ -14270,7 +14280,10 @@ function SelectInternal(props, ref) {
14270
14280
  const resolvedLabel = label ?? placeholder;
14271
14281
  const hasInvalidState = state.hasInvalidState || Boolean(invalid);
14272
14282
  const hiddenValue = isMulti ? selectedOptions.map((item) => String(item.value)).join(",") : selectedOptions[0] ? String(selectedOptions[0].value) : "";
14273
- const handleClear = (event) => state.clearSelection(event);
14283
+ const handleClear = (event) => {
14284
+ state.clearSelection(event);
14285
+ onReset?.();
14286
+ };
14274
14287
  const { Control, MenuList, CreateOption } = components;
14275
14288
  return /* @__PURE__ */ (0, import_jsx_runtime158.jsxs)(
14276
14289
  SelectFieldShell,
@@ -14502,7 +14515,14 @@ function VirtualMenuList(props) {
14502
14515
  if (lastLoadMoreOptionsLengthRef.current === options.length) return;
14503
14516
  lastLoadMoreOptionsLengthRef.current = options.length;
14504
14517
  loadMoreItems();
14505
- }, [virtualItems, options.length]);
14518
+ }, [
14519
+ virtualItems,
14520
+ options.length,
14521
+ canLoadMore,
14522
+ isLoadingMore,
14523
+ loadMoreItems,
14524
+ loadMoreThreshold
14525
+ ]);
14506
14526
  React51.useEffect(() => {
14507
14527
  const changed = previousHighlightedIndexRef.current !== highlightedIndex;
14508
14528
  previousHighlightedIndexRef.current = highlightedIndex;
@@ -14678,14 +14698,7 @@ function InfiniteScrollSelectInternal(props, ref) {
14678
14698
  if (synthetic) list = [synthetic, ...list];
14679
14699
  }
14680
14700
  return list;
14681
- }, [
14682
- rawOptions,
14683
- inputValue,
14684
- filterOption,
14685
- getFullSearchOption,
14686
- rest.getValueLabel,
14687
- props
14688
- ]);
14701
+ }, [rawOptions, inputValue, filterOption, getFullSearchOption, props, rest]);
14689
14702
  const contextValue = React52.useMemo(
14690
14703
  () => ({
14691
14704
  canLoadMore,
@@ -14749,13 +14762,7 @@ function hasPaginationProps(props) {
14749
14762
  return props.canLoadMore !== void 0 || props.isLoadingMore !== void 0 || props.loadMoreItems !== void 0 || props.onSearchChange !== void 0 || props.getFullSearchOption !== void 0;
14750
14763
  }
14751
14764
  function SearchingSelectInternal(props, ref) {
14752
- const {
14753
- trigger,
14754
- components: userComponents,
14755
- searchPlaceholder,
14756
- searchable = true,
14757
- ...rest
14758
- } = props;
14765
+ const { trigger, components: userComponents, searchable = true, ...rest } = props;
14759
14766
  const Control = React53.useMemo(() => {
14760
14767
  if (trigger) return makeTriggerSlot(trigger);
14761
14768
  return StaticControl;
@@ -15205,6 +15212,7 @@ function SelectCheckboxesInternal(props, ref) {
15205
15212
  const {
15206
15213
  options: rawOptions = [],
15207
15214
  value,
15215
+ defaultValue,
15208
15216
  onChange,
15209
15217
  trigger,
15210
15218
  components: userComponents,
@@ -15222,7 +15230,19 @@ function SelectCheckboxesInternal(props, ref) {
15222
15230
  paginationAndRest
15223
15231
  );
15224
15232
  const [inputValue, setInputValue] = React59.useState("");
15225
- const selected = value ?? [];
15233
+ const isControlled = value !== void 0;
15234
+ const [internalValue, setInternalValue] = React59.useState(
15235
+ () => defaultValue ?? []
15236
+ );
15237
+ const currentValue = isControlled ? value : internalValue;
15238
+ const selected = React59.useMemo(() => currentValue ?? [], [currentValue]);
15239
+ const handleChange = React59.useCallback(
15240
+ (next, meta) => {
15241
+ if (!isControlled) setInternalValue(next);
15242
+ onChange?.(next, meta);
15243
+ },
15244
+ [isControlled, onChange]
15245
+ );
15226
15246
  const flatRawOptions = React59.useMemo(
15227
15247
  () => flattenGroupedOptions(rawOptions),
15228
15248
  [rawOptions]
@@ -15249,7 +15269,7 @@ function SelectCheckboxesInternal(props, ref) {
15249
15269
  const handleToggleAll = React59.useCallback(() => {
15250
15270
  if (allVisibleSelected) {
15251
15271
  const visibleValues = new Set(filteredFlat.map((option) => option.value));
15252
- onChange(
15272
+ handleChange(
15253
15273
  selected.filter((s) => !visibleValues.has(s.value)),
15254
15274
  { action: "deselect" }
15255
15275
  );
@@ -15259,8 +15279,8 @@ function SelectCheckboxesInternal(props, ref) {
15259
15279
  for (const option of filteredFlat) {
15260
15280
  if (!merged.some((s) => s.value === option.value)) merged.push(option);
15261
15281
  }
15262
- onChange(merged, { action: "select" });
15263
- }, [allVisibleSelected, filteredFlat, onChange, selected]);
15282
+ handleChange(merged, { action: "select" });
15283
+ }, [allVisibleSelected, filteredFlat, handleChange, selected]);
15264
15284
  const Control = React59.useMemo(() => {
15265
15285
  if (trigger) return makeTriggerSlot2(trigger);
15266
15286
  return createCountTrigger({
@@ -15293,8 +15313,8 @@ function SelectCheckboxesInternal(props, ref) {
15293
15313
  );
15294
15314
  const baseSharedProps = {
15295
15315
  ...paginationAndRest,
15296
- value,
15297
- onChange,
15316
+ value: currentValue,
15317
+ onChange: handleChange,
15298
15318
  filterOption: passthroughFilter2,
15299
15319
  components,
15300
15320
  closeMenuOnSelect,
@@ -16292,7 +16312,7 @@ var Datepicker = React63.forwardRef(
16292
16312
  React63.useImperativeHandle(
16293
16313
  ref,
16294
16314
  () => dayInputRef.current ?? mobileTriggerRef.current,
16295
- [isMobile3]
16315
+ []
16296
16316
  );
16297
16317
  React63.useEffect(() => {
16298
16318
  if (!isControlled) return;
@@ -19027,7 +19047,7 @@ function useDesktopSelect({
19027
19047
  const handleSelect = React76.useCallback(
19028
19048
  (option) => {
19029
19049
  if (option.isDisabled || disabled) return;
19030
- onChange(option);
19050
+ onChange?.(option);
19031
19051
  },
19032
19052
  [disabled, onChange]
19033
19053
  );
@@ -19105,7 +19125,7 @@ function useDesktopSelect({
19105
19125
  event.preventDefault();
19106
19126
  const option = options[highlightedIndex];
19107
19127
  if (option && !option.isDisabled) {
19108
- onChange(option);
19128
+ onChange?.(option);
19109
19129
  onClose();
19110
19130
  focusTrigger();
19111
19131
  }
@@ -19434,7 +19454,7 @@ var AirbnbSelect = React79.forwardRef(function AirbnbSelect2({
19434
19454
  }
19435
19455
  const validOption = filteredOptions.find((option) => option.value === value.value);
19436
19456
  if (validOption) {
19437
- onChange(validOption);
19457
+ onChange?.(validOption);
19438
19458
  }
19439
19459
  },
19440
19460
  [onChange, filteredOptions, value]
@@ -19454,7 +19474,7 @@ var AirbnbSelect = React79.forwardRef(function AirbnbSelect2({
19454
19474
  if (isBlocked) return;
19455
19475
  const finalOption = pendingValue;
19456
19476
  if (finalOption && finalOption.value !== value?.value) {
19457
- onChange(finalOption);
19477
+ onChange?.(finalOption);
19458
19478
  }
19459
19479
  setIsOpen(false);
19460
19480
  focusTrigger();