@chekinapp/ui 0.0.122 → 0.0.124

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
@@ -13562,6 +13562,7 @@ function useSelectState(params) {
13562
13562
  closeMenuOnSelect,
13563
13563
  openMenuOnFocus = true,
13564
13564
  onKeyDown,
13565
+ onFocus,
13565
13566
  onBlur,
13566
13567
  isSearchInDropdown
13567
13568
  } = params;
@@ -13577,7 +13578,8 @@ function useSelectState(params) {
13577
13578
  () => resolveValueLabel(singleSelected, getValueLabel),
13578
13579
  [singleSelected, getValueLabel]
13579
13580
  );
13580
- const [inputValue, setInputValue] = React48.useState(isMulti ? "" : valueLabel);
13581
+ const isSearchOnlyInput = isMulti || Boolean(isSearchInDropdown);
13582
+ const [inputValue, setInputValue] = React48.useState(isSearchOnlyInput ? "" : valueLabel);
13581
13583
  const hasValue = selectedOptions.length > 0;
13582
13584
  const isBlocked = Boolean(disabled) || Boolean(loading) || Boolean(readOnly);
13583
13585
  const hasInvalidState = Boolean(error);
@@ -13592,18 +13594,18 @@ function useSelectState(params) {
13592
13594
  const ids = useSelectIds({ name, hasValue, error, hideErrorMessage });
13593
13595
  const { listboxId, getOptionId: getOptionId2 } = ids;
13594
13596
  React48.useEffect(() => {
13595
- if (isMulti) return;
13597
+ if (isSearchOnlyInput) return;
13596
13598
  if (!isFocused) setInputValue(valueLabel);
13597
- }, [valueLabel, isFocused, isMulti]);
13599
+ }, [valueLabel, isFocused, isSearchOnlyInput]);
13598
13600
  React48.useEffect(() => {
13599
- if (!isMulti) return;
13601
+ if (!isSearchOnlyInput) return;
13600
13602
  if (!isOpen) {
13601
13603
  setInputValue("");
13602
13604
  setHighlightedIndex(-1);
13603
13605
  }
13604
- }, [isOpen, isMulti]);
13606
+ }, [isOpen, isSearchOnlyInput]);
13605
13607
  const trimmedInput = inputValue.trim();
13606
- const isFiltering = isMulti ? trimmedInput.length > 0 : trimmedInput.length > 0 && trimmedInput.toLowerCase() !== valueLabel.toLowerCase();
13608
+ const isFiltering = isSearchOnlyInput ? trimmedInput.length > 0 : trimmedInput.length > 0 && trimmedInput.toLowerCase() !== valueLabel.toLowerCase();
13607
13609
  const filteredOptions = React48.useMemo(() => {
13608
13610
  if (!isFiltering) return options;
13609
13611
  return options.filter((option) => filterOption(option, trimmedInput));
@@ -13664,7 +13666,7 @@ function useSelectState(params) {
13664
13666
  return;
13665
13667
  }
13666
13668
  onSelectionChange([option], { action: "select" });
13667
- setInputValue(resolveValueLabel(option, getValueLabel));
13669
+ setInputValue(isSearchInDropdown ? "" : resolveValueLabel(option, getValueLabel));
13668
13670
  setIsOpen(false);
13669
13671
  setIsFocused(false);
13670
13672
  inputRef.current?.blur();
@@ -13677,7 +13679,8 @@ function useSelectState(params) {
13677
13679
  onSelectionChange,
13678
13680
  closeMenuOnSelect,
13679
13681
  setIsOpen,
13680
- getValueLabel
13682
+ getValueLabel,
13683
+ isSearchInDropdown
13681
13684
  ]
13682
13685
  );
13683
13686
  const removeOption = React48.useCallback(
@@ -13712,7 +13715,7 @@ function useSelectState(params) {
13712
13715
  return;
13713
13716
  }
13714
13717
  onSelectionChange([newOption], { action: "create" });
13715
- setInputValue(resolveValueLabel(newOption, getValueLabel));
13718
+ setInputValue(isSearchInDropdown ? "" : resolveValueLabel(newOption, getValueLabel));
13716
13719
  setIsOpen(false);
13717
13720
  setIsFocused(false);
13718
13721
  inputRef.current?.blur();
@@ -13725,7 +13728,8 @@ function useSelectState(params) {
13725
13728
  selectedOptions,
13726
13729
  closeMenuOnSelect,
13727
13730
  setIsOpen,
13728
- getValueLabel
13731
+ getValueLabel,
13732
+ isSearchInDropdown
13729
13733
  ]);
13730
13734
  const handleInputChange = React48.useCallback(
13731
13735
  (event) => {
@@ -13734,14 +13738,18 @@ function useSelectState(params) {
13734
13738
  },
13735
13739
  [isOpen, setIsOpen]
13736
13740
  );
13737
- const handleInputFocus = React48.useCallback(() => {
13738
- if (isBlocked) return;
13739
- setIsFocused(true);
13740
- if (openMenuOnFocus) setIsOpen(true);
13741
- if (!isMulti) {
13742
- requestAnimationFrame(() => inputRef.current?.select());
13743
- }
13744
- }, [isBlocked, openMenuOnFocus, setIsOpen, isMulti]);
13741
+ const handleInputFocus = React48.useCallback(
13742
+ (event) => {
13743
+ if (isBlocked) return;
13744
+ onFocus?.(event);
13745
+ setIsFocused(true);
13746
+ if (openMenuOnFocus) setIsOpen(true);
13747
+ if (!isMulti) {
13748
+ requestAnimationFrame(() => inputRef.current?.select());
13749
+ }
13750
+ },
13751
+ [isBlocked, onFocus, openMenuOnFocus, setIsOpen, isMulti]
13752
+ );
13745
13753
  const handleContainerClick = React48.useCallback(() => {
13746
13754
  if (isBlocked) return;
13747
13755
  inputRef.current?.focus();
@@ -13751,10 +13759,10 @@ function useSelectState(params) {
13751
13759
  (event) => {
13752
13760
  if (containerRef.current?.contains(event.relatedTarget)) return;
13753
13761
  setIsFocused(false);
13754
- if (!isMulti) setInputValue(valueLabel);
13762
+ if (!isSearchOnlyInput) setInputValue(valueLabel);
13755
13763
  onBlur?.(event);
13756
13764
  },
13757
- [containerRef, isMulti, valueLabel, onBlur]
13765
+ [containerRef, isSearchOnlyInput, valueLabel, onBlur]
13758
13766
  );
13759
13767
  const handleInputKeyDown = React48.useCallback(
13760
13768
  (event) => {
@@ -13808,7 +13816,7 @@ function useSelectState(params) {
13808
13816
  }
13809
13817
  if (event.key === "Escape") {
13810
13818
  event.preventDefault();
13811
- if (!isMulti) setInputValue(valueLabel);
13819
+ if (!isSearchOnlyInput) setInputValue(valueLabel);
13812
13820
  setIsOpen(false);
13813
13821
  inputRef.current?.blur();
13814
13822
  }
@@ -13816,6 +13824,7 @@ function useSelectState(params) {
13816
13824
  [
13817
13825
  onKeyDown,
13818
13826
  isMulti,
13827
+ isSearchOnlyInput,
13819
13828
  inputValue,
13820
13829
  selectedOptions,
13821
13830
  onSelectionChange,
@@ -14153,12 +14162,28 @@ function mergeComponents(overrides) {
14153
14162
  };
14154
14163
  }
14155
14164
 
14165
+ // src/dashboard/select/useSetCorrectOptionIfThereIsOnlyValue.ts
14166
+ var import_react89 = require("react");
14167
+ function useSetCorrectOptionIfThereIsOnlyValue({ value, options, onChange, enabled = true }) {
14168
+ (0, import_react89.useEffect)(() => {
14169
+ if (!enabled || !value || !onChange || !options?.length) return;
14170
+ if (value.value === void 0 || value.value === null) return;
14171
+ if (value.label !== "NONE" && value.label !== "") return;
14172
+ const validOption = flattenGroupedOptions(options).find(
14173
+ (option) => option.value === value.value
14174
+ );
14175
+ if (!validOption) return;
14176
+ onChange({ ...validOption, isPrefilled: true }, { action: "select" });
14177
+ }, [enabled, onChange, options, value]);
14178
+ }
14179
+
14156
14180
  // src/dashboard/select/Select.tsx
14157
14181
  var import_jsx_runtime158 = require("react/jsx-runtime");
14158
14182
  function SelectInternal(props, ref) {
14159
14183
  const {
14160
14184
  options = [],
14161
14185
  onBlur,
14186
+ onFocus,
14162
14187
  label,
14163
14188
  topLabel,
14164
14189
  placeholder,
@@ -14213,6 +14238,12 @@ function SelectInternal(props, ref) {
14213
14238
  return props.defaultValue ?? null;
14214
14239
  });
14215
14240
  const currentValue = isControlled ? props.value : internalValue;
14241
+ useSetCorrectOptionIfThereIsOnlyValue({
14242
+ enabled: !isMulti,
14243
+ value: !isMulti ? props.value : void 0,
14244
+ options,
14245
+ onChange: !isMulti ? props.onChange : void 0
14246
+ });
14216
14247
  const selectedOptions = React49.useMemo(() => {
14217
14248
  if (isMulti) return currentValue ?? [];
14218
14249
  return currentValue ? [currentValue] : [];
@@ -14254,6 +14285,7 @@ function SelectInternal(props, ref) {
14254
14285
  closeMenuOnSelect,
14255
14286
  openMenuOnFocus,
14256
14287
  onKeyDown,
14288
+ onFocus,
14257
14289
  onBlur,
14258
14290
  isSearchInDropdown
14259
14291
  });
@@ -14480,6 +14512,7 @@ var PhoneInput = React50.forwardRef(
14480
14512
  options,
14481
14513
  value,
14482
14514
  onChange,
14515
+ onFocus,
14483
14516
  onBlur,
14484
14517
  name,
14485
14518
  codeName,
@@ -14619,6 +14652,7 @@ var PhoneInput = React50.forwardRef(
14619
14652
  tooltip,
14620
14653
  "aria-label": resolvedLabel || name,
14621
14654
  onChange: handleNumberChange,
14655
+ onFocus,
14622
14656
  onBlur,
14623
14657
  renderErrorMessage: false,
14624
14658
  wrapperClassName: "!max-w-none"
@@ -16208,6 +16242,9 @@ var Datepicker = React62.forwardRef(
16208
16242
  value,
16209
16243
  defaultValue,
16210
16244
  onChange,
16245
+ onFocus,
16246
+ onFieldFocus,
16247
+ onFieldBlur,
16211
16248
  name,
16212
16249
  invalid,
16213
16250
  error,
@@ -16271,9 +16308,30 @@ var Datepicker = React62.forwardRef(
16271
16308
  const [monthInputValue, setMonthInputValue] = React62.useState("");
16272
16309
  const [monthHighlightIndex, setMonthHighlightIndex] = React62.useState(-1);
16273
16310
  const isMobile3 = useIsMobile();
16311
+ const emitChangeRef = React62.useRef(() => {
16312
+ });
16313
+ const dayStateRef = React62.useRef(day);
16314
+ const yearStateRef = React62.useRef(year);
16315
+ const monthIndexRef = React62.useRef(monthIndex);
16316
+ dayStateRef.current = day;
16317
+ yearStateRef.current = year;
16318
+ monthIndexRef.current = monthIndex;
16274
16319
  React62.useImperativeHandle(
16275
16320
  ref,
16276
- () => dayInputRef.current ?? mobileTriggerRef.current,
16321
+ () => ({
16322
+ getDayValue: () => dayStateRef.current,
16323
+ getYearValue: () => yearStateRef.current,
16324
+ setDayValue: (next) => {
16325
+ if (!PARTIAL_DAY_PATTERN.test(next)) return;
16326
+ setDay(next);
16327
+ emitChangeRef.current(next, monthIndexRef.current, yearStateRef.current);
16328
+ },
16329
+ setYearValue: (next) => {
16330
+ if (!PARTIAL_YEAR_PATTERN.test(next)) return;
16331
+ setYear(next);
16332
+ emitChangeRef.current(dayStateRef.current, monthIndexRef.current, next);
16333
+ }
16334
+ }),
16277
16335
  []
16278
16336
  );
16279
16337
  React62.useEffect(() => {
@@ -16334,6 +16392,7 @@ var Datepicker = React62.forwardRef(
16334
16392
  },
16335
16393
  [name, onChange]
16336
16394
  );
16395
+ emitChangeRef.current = emitChange;
16337
16396
  const handleDayChange = (event) => {
16338
16397
  const next = event.target.value;
16339
16398
  if (!PARTIAL_DAY_PATTERN.test(next)) return;
@@ -16521,6 +16580,7 @@ var Datepicker = React62.forwardRef(
16521
16580
  "aria-busy": loading,
16522
16581
  disabled: isBlocked || readOnly,
16523
16582
  onClick: openWheel,
16583
+ onFocus,
16524
16584
  className: cn(
16525
16585
  "relative m-0 box-border flex h-12 w-full cursor-pointer items-center justify-between gap-2 rounded-[6px] border-0 px-4 text-left text-[16px] font-medium leading-5 outline-none transition-colors duration-200",
16526
16586
  triggerText ? "bg-transparent text-[var(--chekin-color-brand-navy)]" : "bg-[var(--empty-field-background)] text-[var(--chekin-color-gray-1)]",
@@ -16563,8 +16623,15 @@ var Datepicker = React62.forwardRef(
16563
16623
  "aria-invalid": isInvalid,
16564
16624
  "aria-labelledby": labelId,
16565
16625
  onChange: handleDayChange,
16566
- onFocus: () => setFocusedField("day"),
16567
- onBlur: () => setFocusedField(null),
16626
+ onFocus: (event) => {
16627
+ onFocus?.(event);
16628
+ onFieldFocus?.("day");
16629
+ setFocusedField("day");
16630
+ },
16631
+ onBlur: () => {
16632
+ onFieldBlur?.("day");
16633
+ setFocusedField(null);
16634
+ },
16568
16635
  maxLength: 2,
16569
16636
  className: subInputClass
16570
16637
  }
@@ -16591,7 +16658,9 @@ var Datepicker = React62.forwardRef(
16591
16658
  disabled: isBlocked,
16592
16659
  readOnly,
16593
16660
  onChange: handleMonthInputChange,
16594
- onFocus: () => {
16661
+ onFocus: (event) => {
16662
+ onFocus?.(event);
16663
+ onFieldFocus?.("month");
16595
16664
  setFocusedField("month");
16596
16665
  if (!isBlocked && !readOnly) {
16597
16666
  setIsMonthOpen(true);
@@ -16599,6 +16668,7 @@ var Datepicker = React62.forwardRef(
16599
16668
  }
16600
16669
  },
16601
16670
  onBlur: () => {
16671
+ onFieldBlur?.("month");
16602
16672
  setFocusedField(null);
16603
16673
  commitMonthInput();
16604
16674
  },
@@ -16646,8 +16716,15 @@ var Datepicker = React62.forwardRef(
16646
16716
  "aria-invalid": isInvalid,
16647
16717
  "aria-labelledby": labelId,
16648
16718
  onChange: handleYearChange,
16649
- onFocus: () => setFocusedField("year"),
16650
- onBlur: () => setFocusedField(null),
16719
+ onFocus: (event) => {
16720
+ onFocus?.(event);
16721
+ onFieldFocus?.("year");
16722
+ setFocusedField("year");
16723
+ },
16724
+ onBlur: () => {
16725
+ onFieldBlur?.("year");
16726
+ setFocusedField(null);
16727
+ },
16651
16728
  maxLength: 4,
16652
16729
  className: subInputClass
16653
16730
  }
@@ -17177,6 +17254,7 @@ var DateRangePicker = React66.forwardRef(function DateRangePicker2({
17177
17254
  value: externalValue,
17178
17255
  defaultValue,
17179
17256
  onChange,
17257
+ onFocus,
17180
17258
  onBlur,
17181
17259
  name,
17182
17260
  invalid,
@@ -17372,11 +17450,13 @@ var DateRangePicker = React66.forwardRef(function DateRangePicker2({
17372
17450
  openCalendarLabel: t("open_calendar"),
17373
17451
  onFromTextChange: setFromText,
17374
17452
  onToTextChange: setToText,
17375
- onFromFocus: () => {
17453
+ onFromFocus: (event) => {
17454
+ onFocus?.(event);
17376
17455
  setFocusedInput("from");
17377
17456
  if (!readOnly && !isBlocked) setIsOpen(true);
17378
17457
  },
17379
- onToFocus: () => {
17458
+ onToFocus: (event) => {
17459
+ onFocus?.(event);
17380
17460
  setFocusedInput("to");
17381
17461
  if (!readOnly && !isBlocked) setIsOpen(true);
17382
17462
  },
@@ -17630,6 +17710,7 @@ var FileInput = React69.forwardRef(function FileInput2({
17630
17710
  label,
17631
17711
  value,
17632
17712
  onChange,
17713
+ onFocus,
17633
17714
  onDownload = defaultDownload,
17634
17715
  name = "file",
17635
17716
  placeholder,
@@ -17703,6 +17784,7 @@ var FileInput = React69.forwardRef(function FileInput2({
17703
17784
  multiple,
17704
17785
  disabled: isBlocked || readOnly,
17705
17786
  onChange: handleFileChange,
17787
+ onFocus,
17706
17788
  className: "absolute h-[0.1px] w-[0.1px] opacity-0",
17707
17789
  "aria-labelledby": labelId,
17708
17790
  "aria-invalid": isInvalid
@@ -17803,6 +17885,7 @@ var SelectIconsBox = React70.forwardRef(
17803
17885
  isOpen: controlledOpen,
17804
17886
  defaultOpen = false,
17805
17887
  onOpenChange,
17888
+ onFocus,
17806
17889
  position = "left",
17807
17890
  className,
17808
17891
  boxClassName
@@ -17830,6 +17913,7 @@ var SelectIconsBox = React70.forwardRef(
17830
17913
  setOpen(false);
17831
17914
  };
17832
17915
  const handleContainerFocus = (event) => {
17916
+ onFocus?.(event);
17833
17917
  if (event.target !== event.currentTarget) return;
17834
17918
  const focusable = event.currentTarget.querySelector(
17835
17919
  FOCUSABLE_TRIGGER_SELECTOR2
@@ -17962,11 +18046,11 @@ function toastResponseError(error, options = {}) {
17962
18046
  }
17963
18047
 
17964
18048
  // src/legacy-fields/textarea/Textarea.tsx
17965
- var import_react89 = require("react");
18049
+ var import_react90 = require("react");
17966
18050
  var import_jsx_runtime182 = require("react/jsx-runtime");
17967
- var LegacyTextarea = (0, import_react89.forwardRef)(
18051
+ var LegacyTextarea = (0, import_react90.forwardRef)(
17968
18052
  ({ className, textareaClassName, label, disabled, name, invalid, ...textareaProps }, ref) => {
17969
- const inputId = (0, import_react89.useId)();
18053
+ const inputId = (0, import_react90.useId)();
17970
18054
  return /* @__PURE__ */ (0, import_jsx_runtime182.jsxs)("div", { className: cn("relative", className), children: [
17971
18055
  /* @__PURE__ */ (0, import_jsx_runtime182.jsx)(
17972
18056
  "textarea",
@@ -19786,7 +19870,7 @@ AirbnbPhoneField.displayName = "AirbnbPhoneField";
19786
19870
  var React80 = __toESM(require("react"), 1);
19787
19871
  var import_lucide_react57 = require("lucide-react");
19788
19872
  var import_react_virtual3 = require("@tanstack/react-virtual");
19789
- var import_react90 = require("react");
19873
+ var import_react91 = require("react");
19790
19874
  var import_jsx_runtime193 = require("react/jsx-runtime");
19791
19875
  var ROW_HEIGHT = 48;
19792
19876
  var DESKTOP_LIST_HEIGHT = 280;
@@ -19864,7 +19948,7 @@ var AirbnbSearchableSelectInternal = ({
19864
19948
  isDisabled: !open || isMobile3
19865
19949
  });
19866
19950
  const handleOnOpenChange = useEvent(onOpenChange);
19867
- const setSelectOpen = (0, import_react90.useCallback)(
19951
+ const setSelectOpen = (0, import_react91.useCallback)(
19868
19952
  (nextOpen, options2) => {
19869
19953
  setOpen(nextOpen);
19870
19954
  handleOnOpenChange?.(nextOpen);