@chekinapp/ui 0.2.7 → 0.2.8

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
@@ -44,6 +44,7 @@ __export(index_exports, {
44
44
  AirbnbSearchableSelect: () => AirbnbSearchableSelect,
45
45
  AirbnbSelect: () => AirbnbSelect,
46
46
  AirbnbSwitch: () => AirbnbSwitch,
47
+ AirbnbTimePicker: () => AirbnbTimePicker,
47
48
  Alert: () => Alert,
48
49
  AlertBox: () => AlertBox,
49
50
  AlertDescription: () => AlertDescription,
@@ -18915,13 +18916,13 @@ var import_date_fns2 = require("date-fns");
18915
18916
  var import_date_fns = require("date-fns");
18916
18917
  var DEFAULT_DISPLAY_FORMAT = "dd-MM-yyyy";
18917
18918
  var SUPPORTED_FORMATS = ["dd-MM-yyyy", "dd.MM.yyyy", "dd/MM/yyyy"];
18918
- var formatDate = (format2 = DEFAULT_DISPLAY_FORMAT) => (date) => (0, import_date_fns.format)(date, format2);
18919
+ var formatDate = (format3 = DEFAULT_DISPLAY_FORMAT) => (date) => (0, import_date_fns.format)(date, format3);
18919
18920
  var parseDate = (displayFormat) => (dateStr) => {
18920
18921
  if (!dateStr) return void 0;
18921
18922
  const formats = displayFormat ? Array.from(/* @__PURE__ */ new Set([...SUPPORTED_FORMATS, displayFormat])) : SUPPORTED_FORMATS;
18922
- for (const format2 of formats) {
18923
- const parsed = (0, import_date_fns.parse)(dateStr, format2, /* @__PURE__ */ new Date());
18924
- if ((0, import_date_fns.isValid)(parsed) && (0, import_date_fns.format)(parsed, format2) === dateStr) {
18923
+ for (const format3 of formats) {
18924
+ const parsed = (0, import_date_fns.parse)(dateStr, format3, /* @__PURE__ */ new Date());
18925
+ if ((0, import_date_fns.isValid)(parsed) && (0, import_date_fns.format)(parsed, format3) === dateStr) {
18925
18926
  return parsed;
18926
18927
  }
18927
18928
  }
@@ -19022,14 +19023,14 @@ function useRangeValue({
19022
19023
  var React66 = __toESM(require("react"), 1);
19023
19024
 
19024
19025
  // src/fields/date-range-picker/utils/inputFormat.ts
19025
- function parseDateInputFormat(format2) {
19026
+ function parseDateInputFormat(format3) {
19026
19027
  const tokens = [];
19027
19028
  let i = 0;
19028
- while (i < format2.length) {
19029
- const ch = format2[i];
19029
+ while (i < format3.length) {
19030
+ const ch = format3[i];
19030
19031
  if (/[a-zA-Z]/.test(ch)) {
19031
19032
  let len = 1;
19032
- while (i + len < format2.length && format2[i + len] === ch) len++;
19033
+ while (i + len < format3.length && format3[i + len] === ch) len++;
19033
19034
  tokens.push({ type: "digits", length: len });
19034
19035
  i += len;
19035
19036
  } else {
@@ -19101,8 +19102,8 @@ function autoFormatDateInput(raw, tokens) {
19101
19102
  var countDigits = (text) => text.replace(/\D/g, "").length;
19102
19103
  function useRangeTextInputs({
19103
19104
  value,
19104
- format: format2,
19105
- parse: parse3,
19105
+ format: format3,
19106
+ parse: parse4,
19106
19107
  displayFormat,
19107
19108
  onCommit,
19108
19109
  onBlur,
@@ -19114,23 +19115,23 @@ function useRangeTextInputs({
19114
19115
  [displayFormat]
19115
19116
  );
19116
19117
  const maxDigits = React66.useMemo(() => getMaxDigits(tokens), [tokens]);
19117
- const [fromText, setFromText] = React66.useState(value?.from ? format2(value.from) : "");
19118
- const [toText, setToText] = React66.useState(value?.to ? format2(value.to) : "");
19118
+ const [fromText, setFromText] = React66.useState(value?.from ? format3(value.from) : "");
19119
+ const [toText, setToText] = React66.useState(value?.to ? format3(value.to) : "");
19119
19120
  React66.useEffect(() => {
19120
- setFromText(value?.from ? format2(value.from) : "");
19121
- setToText(value?.to ? format2(value.to) : "");
19122
- }, [format2, value?.from, value?.to]);
19121
+ setFromText(value?.from ? format3(value.from) : "");
19122
+ setToText(value?.to ? format3(value.to) : "");
19123
+ }, [format3, value?.from, value?.to]);
19123
19124
  const handleFromChange = React66.useCallback(
19124
19125
  (raw) => {
19125
19126
  const formatted = autoFormatDateInput(raw, tokens);
19126
19127
  const wasComplete = countDigits(fromText) === maxDigits;
19127
19128
  const isComplete = countDigits(formatted) === maxDigits;
19128
19129
  setFromText(formatted);
19129
- if (!wasComplete && isComplete && parse3(formatted)) {
19130
+ if (!wasComplete && isComplete && parse4(formatted)) {
19130
19131
  setTimeout(() => onFromComplete?.(), 0);
19131
19132
  }
19132
19133
  },
19133
- [fromText, maxDigits, onFromComplete, parse3, tokens]
19134
+ [fromText, maxDigits, onFromComplete, parse4, tokens]
19134
19135
  );
19135
19136
  const handleToChange = React66.useCallback(
19136
19137
  (raw) => {
@@ -19138,11 +19139,11 @@ function useRangeTextInputs({
19138
19139
  const wasComplete = countDigits(toText) === maxDigits;
19139
19140
  const isComplete = countDigits(formatted) === maxDigits;
19140
19141
  setToText(formatted);
19141
- if (!wasComplete && isComplete && parse3(formatted)) {
19142
+ if (!wasComplete && isComplete && parse4(formatted)) {
19142
19143
  setTimeout(() => onToComplete?.(), 0);
19143
19144
  }
19144
19145
  },
19145
- [maxDigits, onToComplete, parse3, toText, tokens]
19146
+ [maxDigits, onToComplete, parse4, toText, tokens]
19146
19147
  );
19147
19148
  const handleFromBlur = React66.useCallback(() => {
19148
19149
  if (!fromText) {
@@ -19151,16 +19152,16 @@ function useRangeTextInputs({
19151
19152
  onBlur?.(next);
19152
19153
  return void 0;
19153
19154
  }
19154
- const parsed = parse3(fromText);
19155
+ const parsed = parse4(fromText);
19155
19156
  if (parsed) {
19156
19157
  const next = { from: parsed, to: value?.to };
19157
19158
  onCommit(next);
19158
19159
  onBlur?.(next);
19159
19160
  return parsed;
19160
19161
  }
19161
- setFromText(value?.from ? format2(value.from) : "");
19162
+ setFromText(value?.from ? format3(value.from) : "");
19162
19163
  return void 0;
19163
- }, [format2, fromText, onBlur, onCommit, parse3, value]);
19164
+ }, [format3, fromText, onBlur, onCommit, parse4, value]);
19164
19165
  const handleToBlur = React66.useCallback(() => {
19165
19166
  if (!toText) {
19166
19167
  const next = { from: value?.from, to: void 0 };
@@ -19168,15 +19169,15 @@ function useRangeTextInputs({
19168
19169
  onBlur?.(next);
19169
19170
  return;
19170
19171
  }
19171
- const parsed = parse3(toText);
19172
+ const parsed = parse4(toText);
19172
19173
  if (parsed) {
19173
19174
  const next = { from: value?.from, to: parsed };
19174
19175
  onCommit(next);
19175
19176
  onBlur?.(next);
19176
19177
  return;
19177
19178
  }
19178
- setToText(value?.to ? format2(value.to) : "");
19179
- }, [format2, onBlur, onCommit, parse3, toText, value]);
19179
+ setToText(value?.to ? format3(value.to) : "");
19180
+ }, [format3, onBlur, onCommit, parse4, toText, value]);
19180
19181
  return {
19181
19182
  fromText,
19182
19183
  toText,
@@ -20361,7 +20362,7 @@ function AirbnbFieldHelperText({
20361
20362
  {
20362
20363
  id,
20363
20364
  className: cn(
20364
- "mt-2 text-[12px] font-normal leading-5 text-[var(--chekin-airbnb-gray-text)]",
20365
+ "mt-2 text-[12px] leading-5 text-[var(--chekin-airbnb-gray-text)]",
20365
20366
  disabled && "opacity-50",
20366
20367
  className
20367
20368
  ),
@@ -22762,6 +22763,62 @@ var AirbnbSwitch = React84.forwardRef(
22762
22763
  }
22763
22764
  );
22764
22765
  AirbnbSwitch.displayName = "AirbnbSwitch";
22766
+
22767
+ // src/airbnb-fields/time-picker/TimePicker.tsx
22768
+ var React85 = __toESM(require("react"), 1);
22769
+ var import_date_fns6 = require("date-fns");
22770
+ var import_jsx_runtime198 = require("react/jsx-runtime");
22771
+ var SHORT_TIME_FORMAT2 = "HH:mm";
22772
+ function parseTime2(value) {
22773
+ return (0, import_date_fns6.parse)(value, SHORT_TIME_FORMAT2, /* @__PURE__ */ new Date());
22774
+ }
22775
+ function getRange2(settings) {
22776
+ const min = parseTime2(settings.min_time);
22777
+ const max = settings.max_time === "00:00" && settings.addNextDay ? (0, import_date_fns6.addDays)(parseTime2(settings.max_time), 1) : parseTime2(settings.max_time);
22778
+ return { min, max };
22779
+ }
22780
+ function buildOptions2(settings) {
22781
+ const interval_unit = settings.interval_unit ?? "M";
22782
+ const interval = settings.interval ?? (interval_unit === "H" ? 1 : 60);
22783
+ const min_time = settings.min_time ?? "00:00";
22784
+ const max_time = settings.max_time ?? (interval_unit === "H" ? "23:00" : "23:00");
22785
+ const addNextDay = settings.addNextDay !== false;
22786
+ const { min, max } = getRange2({ interval_unit, interval, min_time, max_time, addNextDay });
22787
+ const options = [];
22788
+ let current = new Date(min.getTime());
22789
+ while (current.getTime() <= max.getTime()) {
22790
+ const text = (0, import_date_fns6.format)(current, SHORT_TIME_FORMAT2);
22791
+ options.push({ value: text, label: text });
22792
+ current = interval_unit === "H" ? (0, import_date_fns6.addHours)(current, interval) : (0, import_date_fns6.addMinutes)(current, interval);
22793
+ }
22794
+ return options;
22795
+ }
22796
+ var FORMAT_SETTINGS2 = {
22797
+ time: { interval_unit: "M", interval: 30, min_time: "00:00", max_time: "23:30" },
22798
+ timeEach15Minutes: {
22799
+ interval_unit: "M",
22800
+ interval: 15,
22801
+ min_time: "00:00",
22802
+ max_time: "23:45"
22803
+ },
22804
+ timeEach30Minutes: {
22805
+ interval_unit: "M",
22806
+ interval: 30,
22807
+ min_time: "00:00",
22808
+ max_time: "23:30"
22809
+ },
22810
+ hours: { interval_unit: "H", interval: 1, min_time: "00:00", max_time: "23:00" }
22811
+ };
22812
+ var AirbnbTimePicker = React85.forwardRef(
22813
+ function AirbnbTimePicker2({ format: formatName = "time", timeSettings, options, ...selectProps }, ref) {
22814
+ const resolvedOptions = React85.useMemo(() => {
22815
+ if (options) return options;
22816
+ const settings = timeSettings ?? FORMAT_SETTINGS2[formatName];
22817
+ return buildOptions2(settings);
22818
+ }, [formatName, options, timeSettings]);
22819
+ return /* @__PURE__ */ (0, import_jsx_runtime198.jsx)(AirbnbSelect, { ref, ...selectProps, options: resolvedOptions });
22820
+ }
22821
+ );
22765
22822
  // Annotate the CommonJS export names for ESM import in node:
22766
22823
  0 && (module.exports = {
22767
22824
  ALERT_BOX_VARIANTS,
@@ -22778,6 +22835,7 @@ AirbnbSwitch.displayName = "AirbnbSwitch";
22778
22835
  AirbnbSearchableSelect,
22779
22836
  AirbnbSelect,
22780
22837
  AirbnbSwitch,
22838
+ AirbnbTimePicker,
22781
22839
  Alert,
22782
22840
  AlertBox,
22783
22841
  AlertDescription,