@codapet/design-system 0.3.6 → 0.3.7

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.d.mts CHANGED
@@ -246,18 +246,29 @@ interface InputProps extends Omit<React$1.ComponentProps<'input'>, 'size'>, Vari
246
246
  }
247
247
  declare const Input: React$1.ForwardRefExoticComponent<Omit<InputProps, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
248
248
 
249
- interface DateInputProps extends Omit<React$1.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'min' | 'max' | 'size'> {
249
+ type NativeInputProps = Omit<React$1.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'min' | 'max' | 'size' | 'disabled' | 'onSelect'>;
250
+ type FlattenedCalendarProps = Omit<React$1.ComponentProps<typeof Calendar>, keyof React$1.InputHTMLAttributes<HTMLInputElement> | 'className' | 'mode' | 'selected' | 'onSelect' | 'month' | 'onMonthChange' | 'disabled' | 'captionLayout' | 'showOutsideDays' | 'classNames'>;
251
+ interface DateInputProps extends NativeInputProps, FlattenedCalendarProps {
250
252
  date: Date | null;
251
253
  setDate: (date: Date | null) => void;
252
254
  maxDate?: Date | null;
253
255
  minDate?: Date | null;
254
256
  disableFuture?: boolean;
257
+ inputDisabled?: boolean;
255
258
  size?: VariantProps<typeof inputVariants>['size'];
256
259
  inputClassName?: string;
257
260
  calendarClassName?: string;
258
- calendarProps?: React$1.ComponentProps<typeof Calendar>;
261
+ mode?: React$1.ComponentProps<typeof Calendar>['mode'];
262
+ selected?: Date;
263
+ onSelect?: (selectedDate: Date | undefined) => void;
264
+ month?: React$1.ComponentProps<typeof Calendar>['month'];
265
+ onMonthChange?: React$1.ComponentProps<typeof Calendar>['onMonthChange'];
266
+ disabled?: React$1.ComponentProps<typeof Calendar>['disabled'];
267
+ captionLayout?: React$1.ComponentProps<typeof Calendar>['captionLayout'];
268
+ showOutsideDays?: React$1.ComponentProps<typeof Calendar>['showOutsideDays'];
269
+ classNames?: React$1.ComponentProps<typeof Calendar>['classNames'];
259
270
  }
260
- declare function DateInput({ date, setDate, maxDate, minDate, disableFuture, className, inputClassName, calendarClassName, calendarProps, placeholder, disabled, onBlur, ...props }: DateInputProps): react_jsx_runtime.JSX.Element;
271
+ declare function DateInput({ date, setDate, maxDate, minDate, disableFuture, className, inputClassName, calendarClassName, inputDisabled, mode, selected, onSelect, month, onMonthChange, disabled: calendarDisabled, captionLayout, showOutsideDays, classNames, placeholder, onBlur, ...restProps }: DateInputProps): react_jsx_runtime.JSX.Element;
261
272
 
262
273
  declare function Drawer({ ...props }: React$1.ComponentProps<typeof Drawer$1.Root>): react_jsx_runtime.JSX.Element;
263
274
  declare function DrawerTrigger({ ...props }: React$1.ComponentProps<typeof Drawer$1.Trigger>): react_jsx_runtime.JSX.Element;
package/dist/index.mjs CHANGED
@@ -2056,6 +2056,65 @@ function PopoverAnchor({
2056
2056
 
2057
2057
  // src/components/ui/date-input.tsx
2058
2058
  import { jsx as jsx22, jsxs as jsxs10 } from "react/jsx-runtime";
2059
+ var INPUT_PROP_KEYS = /* @__PURE__ */ new Set([
2060
+ "accept",
2061
+ "alt",
2062
+ "autoComplete",
2063
+ "autoFocus",
2064
+ "capture",
2065
+ "checked",
2066
+ "dirName",
2067
+ "form",
2068
+ "formAction",
2069
+ "formEncType",
2070
+ "formMethod",
2071
+ "formNoValidate",
2072
+ "formTarget",
2073
+ "height",
2074
+ "list",
2075
+ "maxLength",
2076
+ "minLength",
2077
+ "multiple",
2078
+ "name",
2079
+ "pattern",
2080
+ "readOnly",
2081
+ "required",
2082
+ "size",
2083
+ "src",
2084
+ "step",
2085
+ "type",
2086
+ "width",
2087
+ "id",
2088
+ "inputMode",
2089
+ "lang",
2090
+ "tabIndex",
2091
+ "title",
2092
+ "role",
2093
+ "style",
2094
+ "onFocus",
2095
+ "onFocusCapture",
2096
+ "onBlurCapture",
2097
+ "onInput",
2098
+ "onInvalid",
2099
+ "onKeyDownCapture",
2100
+ "onKeyPress",
2101
+ "onKeyPressCapture",
2102
+ "onKeyUp",
2103
+ "onKeyUpCapture",
2104
+ "onPaste",
2105
+ "onPasteCapture",
2106
+ "onPointerDown",
2107
+ "onPointerDownCapture",
2108
+ "onPointerUp",
2109
+ "onPointerUpCapture",
2110
+ "onMouseDown",
2111
+ "onMouseDownCapture",
2112
+ "onMouseUp",
2113
+ "onMouseUpCapture",
2114
+ "onCompositionEnd",
2115
+ "onCompositionStart",
2116
+ "onCompositionUpdate"
2117
+ ]);
2059
2118
  function formatDate(date) {
2060
2119
  if (!date) {
2061
2120
  return "";
@@ -2081,15 +2140,39 @@ function DateInput({
2081
2140
  className,
2082
2141
  inputClassName,
2083
2142
  calendarClassName,
2084
- calendarProps,
2143
+ inputDisabled,
2144
+ mode,
2145
+ selected,
2146
+ onSelect,
2147
+ month,
2148
+ onMonthChange,
2149
+ disabled: calendarDisabled,
2150
+ captionLayout = "dropdown",
2151
+ showOutsideDays = false,
2152
+ classNames,
2085
2153
  placeholder = "mm/dd/yyyy",
2086
- disabled,
2087
2154
  onBlur,
2088
- ...props
2155
+ ...restProps
2089
2156
  }) {
2090
2157
  const [open, setOpen] = React20.useState(false);
2091
- const [month, setMonth] = React20.useState(date ?? null);
2158
+ const [monthState, setMonthState] = React20.useState(date ?? null);
2092
2159
  const [value, setValue] = React20.useState(formatDate(date ?? null));
2160
+ const [inputProps, calendarProps] = React20.useMemo(() => {
2161
+ const nextInputProps = {};
2162
+ const nextCalendarProps = {};
2163
+ for (const [key, val] of Object.entries(restProps)) {
2164
+ const isInputProp = INPUT_PROP_KEYS.has(key) || key.startsWith("aria-") || key.startsWith("data-");
2165
+ if (isInputProp) {
2166
+ nextInputProps[key] = val;
2167
+ } else {
2168
+ nextCalendarProps[key] = val;
2169
+ }
2170
+ }
2171
+ return [
2172
+ nextInputProps,
2173
+ nextCalendarProps
2174
+ ];
2175
+ }, [restProps]);
2093
2176
  const today = React20.useMemo(() => {
2094
2177
  const d = /* @__PURE__ */ new Date();
2095
2178
  d.setHours(0, 0, 0, 0);
@@ -2122,9 +2205,48 @@ function DateInput({
2122
2205
  React20.useEffect(() => {
2123
2206
  if (date) {
2124
2207
  setValue(formatDate(date));
2125
- setMonth(date);
2208
+ setMonthState(date);
2126
2209
  }
2127
2210
  }, [date]);
2211
+ const effectiveMonth = month ?? monthState ?? void 0;
2212
+ const effectiveSelected = selected ?? date ?? void 0;
2213
+ const isInputDisabled = inputDisabled ?? (typeof calendarDisabled === "boolean" ? calendarDisabled : false);
2214
+ const defaultCalendarOnSelect = (selectedDate) => {
2215
+ if (selectedDate) {
2216
+ const dateObj = new Date(selectedDate);
2217
+ dateObj.setHours(0, 0, 0, 0);
2218
+ const isAfterMin = !effectiveMinDate || dateObj >= effectiveMinDate;
2219
+ const isBeforeMax = !effectiveMaxDate || dateObj <= effectiveMaxDate;
2220
+ if (isAfterMin && isBeforeMax) {
2221
+ setDate(selectedDate);
2222
+ setValue(formatDate(selectedDate));
2223
+ setOpen(false);
2224
+ }
2225
+ }
2226
+ };
2227
+ const defaultCalendarDisabled = (date2) => {
2228
+ const checkDate = new Date(date2);
2229
+ checkDate.setHours(0, 0, 0, 0);
2230
+ const isBeforeMin = effectiveMinDate !== null && checkDate < effectiveMinDate;
2231
+ const isAfterMax = effectiveMaxDate !== void 0 && checkDate > effectiveMaxDate;
2232
+ return isBeforeMin || isAfterMax;
2233
+ };
2234
+ const resolvedCalendarProps = {
2235
+ ...calendarProps,
2236
+ mode: mode ?? "single",
2237
+ selected: effectiveSelected,
2238
+ captionLayout,
2239
+ month: effectiveMonth,
2240
+ onMonthChange: onMonthChange ?? setMonthState,
2241
+ showOutsideDays,
2242
+ className: cn(
2243
+ "md:w-auto w-[calc(100vw-50px)] mx-auto h-[350px] overflow-y-auto md:h-auto m-2",
2244
+ calendarClassName
2245
+ ),
2246
+ classNames,
2247
+ onSelect: onSelect ?? defaultCalendarOnSelect,
2248
+ disabled: calendarDisabled ?? defaultCalendarDisabled
2249
+ };
2128
2250
  const handleInputChange = (e) => {
2129
2251
  const inputValue = e.target.value;
2130
2252
  setValue(inputValue);
@@ -2136,7 +2258,7 @@ function DateInput({
2136
2258
  const isBeforeMax = !effectiveMaxDate || selectedDate <= effectiveMaxDate;
2137
2259
  if (isAfterMin && isBeforeMax) {
2138
2260
  setDate(parsedDate);
2139
- setMonth(parsedDate);
2261
+ setMonthState(parsedDate);
2140
2262
  }
2141
2263
  } else if (inputValue === "") {
2142
2264
  setDate(null);
@@ -2166,7 +2288,7 @@ function DateInput({
2166
2288
  }
2167
2289
  };
2168
2290
  return /* @__PURE__ */ jsx22("div", { className: cn("relative flex gap-2", className), children: /* @__PURE__ */ jsxs10(Popover, { open, onOpenChange: setOpen, children: [
2169
- /* @__PURE__ */ jsx22(PopoverTrigger, { asChild: true, disabled, children: /* @__PURE__ */ jsx22("div", { className: "w-full relative", children: /* @__PURE__ */ jsx22(
2291
+ /* @__PURE__ */ jsx22(PopoverTrigger, { asChild: true, disabled: isInputDisabled, children: /* @__PURE__ */ jsx22("div", { className: "w-full relative", children: /* @__PURE__ */ jsx22(
2170
2292
  Input,
2171
2293
  {
2172
2294
  id: "date",
@@ -2175,17 +2297,17 @@ function DateInput({
2175
2297
  className: cn("bg-background cursor-pointer", inputClassName),
2176
2298
  onChange: handleInputChange,
2177
2299
  onBlur: handleBlur,
2178
- disabled,
2300
+ disabled: isInputDisabled,
2179
2301
  onKeyDown: (e) => {
2180
- if (e.key === "ArrowDown" && !disabled) {
2302
+ if (e.key === "ArrowDown" && !isInputDisabled) {
2181
2303
  e.preventDefault();
2182
2304
  setOpen(true);
2183
2305
  }
2184
2306
  },
2185
2307
  rightIcon: /* @__PURE__ */ jsx22(CalendarDays, { className: "h-4 w-4 text-muted-foreground" }),
2186
- rightIconOnClick: disabled ? void 0 : () => setOpen(!open),
2187
- rightIconButtonProps: { disabled },
2188
- ...props
2308
+ rightIconOnClick: isInputDisabled ? void 0 : () => setOpen(!open),
2309
+ rightIconButtonProps: { disabled: isInputDisabled },
2310
+ ...inputProps
2189
2311
  }
2190
2312
  ) }) }),
2191
2313
  /* @__PURE__ */ jsx22(
@@ -2196,43 +2318,7 @@ function DateInput({
2196
2318
  alignOffset: -8,
2197
2319
  sideOffset: 10,
2198
2320
  side: "top",
2199
- children: /* @__PURE__ */ jsx22(
2200
- Calendar,
2201
- {
2202
- ...calendarProps,
2203
- mode: "single",
2204
- selected: date ?? void 0,
2205
- captionLayout: "dropdown",
2206
- month: month ?? void 0,
2207
- onMonthChange: setMonth,
2208
- showOutsideDays: false,
2209
- className: cn(
2210
- "md:w-auto w-[calc(100vw-50px)] mx-auto h-[350px] overflow-y-auto md:h-auto m-2",
2211
- calendarClassName
2212
- ),
2213
- classNames: calendarProps?.classNames,
2214
- onSelect: (selectedDate) => {
2215
- if (selectedDate) {
2216
- const dateObj = new Date(selectedDate);
2217
- dateObj.setHours(0, 0, 0, 0);
2218
- const isAfterMin = !effectiveMinDate || dateObj >= effectiveMinDate;
2219
- const isBeforeMax = !effectiveMaxDate || dateObj <= effectiveMaxDate;
2220
- if (isAfterMin && isBeforeMax) {
2221
- setDate(selectedDate);
2222
- setValue(formatDate(selectedDate));
2223
- setOpen(false);
2224
- }
2225
- }
2226
- },
2227
- disabled: (date2) => {
2228
- const checkDate = new Date(date2);
2229
- checkDate.setHours(0, 0, 0, 0);
2230
- const isBeforeMin = effectiveMinDate !== null && checkDate < effectiveMinDate;
2231
- const isAfterMax = effectiveMaxDate !== void 0 && checkDate > effectiveMaxDate;
2232
- return isBeforeMin || isAfterMax;
2233
- }
2234
- }
2235
- )
2321
+ children: /* @__PURE__ */ jsx22(Calendar, { ...resolvedCalendarProps })
2236
2322
  }
2237
2323
  )
2238
2324
  ] }) });