@codapet/design-system 0.4.0 → 0.4.1

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
@@ -249,6 +249,7 @@ interface InputProps extends Omit<React$1.ComponentProps<'input'>, 'size'>, Vari
249
249
  }
250
250
  declare const Input: React$1.ForwardRefExoticComponent<Omit<InputProps, "ref"> & React$1.RefAttributes<HTMLInputElement>>;
251
251
 
252
+ type DateFormat = 'MM/DD/YYYY' | 'DD/MM/YYYY' | 'YYYY-MM-DD' | 'DD-MM-YYYY' | 'MM-DD-YYYY' | 'DD.MM.YYYY' | 'MMMM D, YYYY' | 'D MMMM YYYY';
252
253
  type NativeInputProps = Omit<React$1.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'min' | 'max' | 'size' | 'disabled' | 'onSelect'>;
253
254
  type FlattenedCalendarProps = Omit<React$1.ComponentProps<typeof Calendar>, keyof React$1.InputHTMLAttributes<HTMLInputElement> | 'className' | 'mode' | 'selected' | 'onSelect' | 'month' | 'onMonthChange' | 'disabled' | 'captionLayout' | 'showOutsideDays' | 'classNames'>;
254
255
  interface DateInputProps extends NativeInputProps, FlattenedCalendarProps {
@@ -261,6 +262,7 @@ interface DateInputProps extends NativeInputProps, FlattenedCalendarProps {
261
262
  size?: VariantProps<typeof inputVariants>['size'];
262
263
  inputClassName?: string;
263
264
  calendarClassName?: string;
265
+ dateFormat?: DateFormat;
264
266
  mode?: React$1.ComponentProps<typeof Calendar>['mode'];
265
267
  selected?: Date;
266
268
  onSelect?: (selectedDate: Date | undefined) => void;
@@ -271,7 +273,7 @@ interface DateInputProps extends NativeInputProps, FlattenedCalendarProps {
271
273
  showOutsideDays?: React$1.ComponentProps<typeof Calendar>['showOutsideDays'];
272
274
  classNames?: React$1.ComponentProps<typeof Calendar>['classNames'];
273
275
  }
274
- 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;
276
+ declare function DateInput({ date, setDate, maxDate, minDate, disableFuture, className, inputClassName, calendarClassName, inputDisabled, dateFormat, mode, selected, onSelect, month, onMonthChange, disabled: calendarDisabled, captionLayout, showOutsideDays, classNames, placeholder, onBlur, ...restProps }: DateInputProps): react_jsx_runtime.JSX.Element;
275
277
 
276
278
  declare function Drawer({ ...props }: React$1.ComponentProps<typeof Drawer$1.Root>): react_jsx_runtime.JSX.Element;
277
279
  declare function DrawerTrigger({ ...props }: React$1.ComponentProps<typeof Drawer$1.Trigger>): react_jsx_runtime.JSX.Element;
@@ -593,4 +595,4 @@ declare function cn(...inputs: ClassValue[]): string;
593
595
 
594
596
  declare function useIsMobile(): boolean;
595
597
 
596
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AspectRatio, AutoResizeTextarea, Avatar, AvatarFallback, AvatarImage, Badge, Body, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Carousel, type CarouselApi, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, DateInput, type DateInputProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DisplayHeading, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, HeadingL, HeadingM, HeadingS, HeadingXL, HeadingXS, HeadingXXS, HoverCard, HoverCardContent, HoverCardTrigger, Input, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, Label, Menubar, MenubarCheckboxItem, MenubarContent, MenubarGroup, MenubarItem, MenubarLabel, MenubarMenu, MenubarPortal, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, Slider, SmartDialog, SmartDialogClose, SmartDialogContent, SmartDialogDescription, SmartDialogFooter, SmartDialogHeader, SmartDialogTitle, SmartDialogTrigger, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, type TextareaProps, Toaster, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, bodyTextVariants, buttonVariants, cn, displayTextVariants, inputVariants, labelTextVariants, navigationMenuTriggerStyle, toggleVariants, useFormField, useIsMobile, useSidebar };
598
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AspectRatio, AutoResizeTextarea, Avatar, AvatarFallback, AvatarImage, Badge, Body, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Carousel, type CarouselApi, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartStyle, ChartTooltip, ChartTooltipContent, Checkbox, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, type DateFormat, DateInput, type DateInputProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DisplayHeading, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerOverlay, DrawerPortal, DrawerTitle, DrawerTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, HeadingL, HeadingM, HeadingS, HeadingXL, HeadingXS, HeadingXXS, HoverCard, HoverCardContent, HoverCardTrigger, Input, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, Label, Menubar, MenubarCheckboxItem, MenubarContent, MenubarGroup, MenubarItem, MenubarLabel, MenubarMenu, MenubarPortal, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, Slider, SmartDialog, SmartDialogClose, SmartDialogContent, SmartDialogDescription, SmartDialogFooter, SmartDialogHeader, SmartDialogTitle, SmartDialogTrigger, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, type TextareaProps, Toaster, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, bodyTextVariants, buttonVariants, cn, displayTextVariants, inputVariants, labelTextVariants, navigationMenuTriggerStyle, toggleVariants, useFormField, useIsMobile, useSidebar };
package/dist/index.mjs CHANGED
@@ -1886,6 +1886,7 @@ function ContextMenuShortcut({
1886
1886
 
1887
1887
  // src/components/ui/date-input.tsx
1888
1888
  import "class-variance-authority";
1889
+ import { format as dateFnsFormat, parse as dateFnsParse, isValid } from "date-fns";
1889
1890
  import { CalendarDays } from "lucide-react";
1890
1891
  import * as React20 from "react";
1891
1892
 
@@ -2063,6 +2064,26 @@ function PopoverAnchor({
2063
2064
 
2064
2065
  // src/components/ui/date-input.tsx
2065
2066
  import { jsx as jsx22, jsxs as jsxs10 } from "react/jsx-runtime";
2067
+ var DATE_FORMAT_TOKENS = {
2068
+ "MM/DD/YYYY": "MM/dd/yyyy",
2069
+ "DD/MM/YYYY": "dd/MM/yyyy",
2070
+ "YYYY-MM-DD": "yyyy-MM-dd",
2071
+ "DD-MM-YYYY": "dd-MM-yyyy",
2072
+ "MM-DD-YYYY": "MM-dd-yyyy",
2073
+ "DD.MM.YYYY": "dd.MM.yyyy",
2074
+ "MMMM D, YYYY": "MMMM d, yyyy",
2075
+ "D MMMM YYYY": "d MMMM yyyy"
2076
+ };
2077
+ var DATE_FORMAT_PLACEHOLDER = {
2078
+ "MM/DD/YYYY": "mm/dd/yyyy",
2079
+ "DD/MM/YYYY": "dd/mm/yyyy",
2080
+ "YYYY-MM-DD": "yyyy-mm-dd",
2081
+ "DD-MM-YYYY": "dd-mm-yyyy",
2082
+ "MM-DD-YYYY": "mm-dd-yyyy",
2083
+ "DD.MM.YYYY": "dd.mm.yyyy",
2084
+ "MMMM D, YYYY": "Month d, yyyy",
2085
+ "D MMMM YYYY": "d Month yyyy"
2086
+ };
2066
2087
  var INPUT_PROP_KEYS = /* @__PURE__ */ new Set([
2067
2088
  "accept",
2068
2089
  "alt",
@@ -2122,21 +2143,16 @@ var INPUT_PROP_KEYS = /* @__PURE__ */ new Set([
2122
2143
  "onCompositionStart",
2123
2144
  "onCompositionUpdate"
2124
2145
  ]);
2125
- function formatDate(date) {
2126
- if (!date) {
2146
+ function formatDate(date, dateFormat = "MM/DD/YYYY") {
2147
+ if (!date || !isValid(date)) {
2127
2148
  return "";
2128
2149
  }
2129
- return date.toLocaleDateString("en-US", {
2130
- day: "2-digit",
2131
- month: "2-digit",
2132
- year: "numeric"
2133
- });
2134
- }
2135
- function isValidDate(date) {
2136
- if (!date) {
2137
- return false;
2138
- }
2139
- return !isNaN(date.getTime());
2150
+ return dateFnsFormat(date, DATE_FORMAT_TOKENS[dateFormat]);
2151
+ }
2152
+ function parseDate(value, dateFormat = "MM/DD/YYYY") {
2153
+ if (!value) return null;
2154
+ const parsed = dateFnsParse(value, DATE_FORMAT_TOKENS[dateFormat], /* @__PURE__ */ new Date());
2155
+ return isValid(parsed) ? parsed : null;
2140
2156
  }
2141
2157
  function DateInput({
2142
2158
  date,
@@ -2148,6 +2164,7 @@ function DateInput({
2148
2164
  inputClassName,
2149
2165
  calendarClassName,
2150
2166
  inputDisabled,
2167
+ dateFormat = "MM/DD/YYYY",
2151
2168
  mode,
2152
2169
  selected,
2153
2170
  onSelect,
@@ -2157,13 +2174,14 @@ function DateInput({
2157
2174
  captionLayout = "dropdown",
2158
2175
  showOutsideDays = false,
2159
2176
  classNames,
2160
- placeholder = "mm/dd/yyyy",
2177
+ placeholder,
2161
2178
  onBlur,
2162
2179
  ...restProps
2163
2180
  }) {
2181
+ const resolvedPlaceholder = placeholder ?? DATE_FORMAT_PLACEHOLDER[dateFormat];
2164
2182
  const [open, setOpen] = React20.useState(false);
2165
2183
  const [monthState, setMonthState] = React20.useState(date ?? null);
2166
- const [value, setValue] = React20.useState(formatDate(date ?? null));
2184
+ const [value, setValue] = React20.useState(formatDate(date ?? null, dateFormat));
2167
2185
  const [inputProps, calendarProps] = React20.useMemo(() => {
2168
2186
  const nextInputProps = {};
2169
2187
  const nextCalendarProps = {};
@@ -2211,10 +2229,10 @@ function DateInput({
2211
2229
  }, [minDate]);
2212
2230
  React20.useEffect(() => {
2213
2231
  if (date) {
2214
- setValue(formatDate(date));
2232
+ setValue(formatDate(date, dateFormat));
2215
2233
  setMonthState(date);
2216
2234
  }
2217
- }, [date]);
2235
+ }, [date, dateFormat]);
2218
2236
  const effectiveMonth = month ?? monthState ?? void 0;
2219
2237
  const effectiveSelected = selected ?? date ?? void 0;
2220
2238
  const isInputDisabled = inputDisabled ?? (typeof calendarDisabled === "boolean" ? calendarDisabled : false);
@@ -2226,7 +2244,7 @@ function DateInput({
2226
2244
  const isBeforeMax = !effectiveMaxDate || dateObj <= effectiveMaxDate;
2227
2245
  if (isAfterMin && isBeforeMax) {
2228
2246
  setDate(selectedDate);
2229
- setValue(formatDate(selectedDate));
2247
+ setValue(formatDate(selectedDate, dateFormat));
2230
2248
  setOpen(false);
2231
2249
  }
2232
2250
  }
@@ -2257,8 +2275,8 @@ function DateInput({
2257
2275
  const handleInputChange = (e) => {
2258
2276
  const inputValue = e.target.value;
2259
2277
  setValue(inputValue);
2260
- const parsedDate = new Date(inputValue);
2261
- if (isValidDate(parsedDate)) {
2278
+ const parsedDate = parseDate(inputValue, dateFormat);
2279
+ if (parsedDate) {
2262
2280
  const selectedDate = new Date(parsedDate);
2263
2281
  selectedDate.setHours(0, 0, 0, 0);
2264
2282
  const isAfterMin = !effectiveMinDate || selectedDate >= effectiveMinDate;
@@ -2281,16 +2299,16 @@ function DateInput({
2281
2299
  }
2282
2300
  return;
2283
2301
  }
2284
- const parsedDate = new Date(value);
2285
- if (!isValidDate(parsedDate)) {
2286
- setValue(formatDate(date));
2302
+ const parsedDate = parseDate(value, dateFormat);
2303
+ if (!parsedDate) {
2304
+ setValue(formatDate(date, dateFormat));
2287
2305
  } else {
2288
2306
  const selectedDate = new Date(parsedDate);
2289
2307
  selectedDate.setHours(0, 0, 0, 0);
2290
2308
  const isAfterMin = !effectiveMinDate || selectedDate >= effectiveMinDate;
2291
2309
  const isBeforeMax = !effectiveMaxDate || selectedDate <= effectiveMaxDate;
2292
2310
  if (!isAfterMin || !isBeforeMax) {
2293
- setValue(formatDate(date));
2311
+ setValue(formatDate(date, dateFormat));
2294
2312
  }
2295
2313
  }
2296
2314
  };
@@ -2300,7 +2318,7 @@ function DateInput({
2300
2318
  {
2301
2319
  id: "date",
2302
2320
  value,
2303
- placeholder,
2321
+ placeholder: resolvedPlaceholder,
2304
2322
  className: cn("bg-background cursor-pointer", inputClassName),
2305
2323
  onChange: handleInputChange,
2306
2324
  onBlur: handleBlur,