From 4366d30b0ae72848442a8eb45da4eaa47242d3c3 Mon Sep 17 00:00:00 2001 From: "ZEONFUNG NGAU(ox)" Date: Thu, 5 Oct 2023 20:16:47 +0900 Subject: [PATCH] fix(calendar): fix TS type error --- apps/www/public/registry/styles/default/calendar.json | 2 +- apps/www/public/registry/styles/new-york/calendar.json | 2 +- .../registry/default/example/calendar-dropdown-button.tsx | 1 - apps/www/registry/default/ui/calendar.tsx | 7 ++++--- .../registry/new-york/example/calendar-dropdown-button.tsx | 1 - apps/www/registry/new-york/ui/calendar.tsx | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/www/public/registry/styles/default/calendar.json b/apps/www/public/registry/styles/default/calendar.json index d42eae8c207..0153f65fda3 100644 --- a/apps/www/public/registry/styles/default/calendar.json +++ b/apps/www/public/registry/styles/default/calendar.json @@ -10,7 +10,7 @@ "files": [ { "name": "calendar.tsx", - "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@radix-ui/react-icons\"\nimport { DayPicker } from \"react-day-picker\"\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/registry/default/ui/button\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/registry/default/ui/select\"\n\nexport type CalendarProps = React.ComponentProps\n\nfunction Calendar({\n className,\n classNames,\n showOutsideDays = true,\n ...props\n}: CalendarProps & { onChange?: React.ChangeEventHandler }) {\n\n const handleCalendarChange = (_value: string | number, _e: React.ChangeEventHandler) => {\n const _event = {\n target: {\n value: String(_value)\n },\n } as React.ChangeEvent\n _e(_event);\n };\n\n return (\n .day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md\"\n : \"[&:has([aria-selected])]:rounded-md\"\n ),\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\"\n ),\n day_range_start: \"day-range-start\",\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside: \"text-muted-foreground opacity-50\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n }}\n components={{\n IconLeft: ({ ...props }) => ,\n IconRight: ({ ...props }) => ,\n Dropdown: ({ ...props }) => (\n {\n if (props.onChange) {\n handleCalendarChange(value, props.onChange)\n }\n }}\n {...props}\n value={`${props.value}`}\n >\n \n {props?.caption}\n \n \n {props.children &&\n React.Children.map(props.children, (child) =>\n )?.props?.value} className=\"min-w-[var(--radix-popper-anchor-width)]\">{(child as React.ReactElement)?.props?.children}\n )\n }\n \n \n ),\n }}\n {...props}\n />\n )\n}\nCalendar.displayName = \"Calendar\"\n\nexport { Calendar }\n" + "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@radix-ui/react-icons\"\nimport { DayPicker } from \"react-day-picker\"\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/registry/default/ui/button\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/registry/default/ui/select\"\n\nexport type CalendarProps = React.ComponentProps\n\nfunction Calendar({\n className,\n classNames,\n showOutsideDays = true,\n ...props\n}: CalendarProps & { onChange?: React.ChangeEventHandler }) {\n\n const handleCalendarChange = (_value: string | number, _e: React.ChangeEventHandler) => {\n const _event = {\n target: {\n value: String(_value)\n },\n } as React.ChangeEvent\n _e(_event);\n \n };\n\n return (\n .day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md\"\n : \"[&:has([aria-selected])]:rounded-md\"\n ),\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-9 w-9 p-0 font-normal aria-selected:opacity-100\"\n ),\n day_range_start: \"day-range-start\",\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside: \"text-muted-foreground opacity-50\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n }}\n components={{\n IconLeft: ({ ...props }) => ,\n IconRight: ({ ...props }) => ,\n Dropdown: ({ ...props }) => (\n {\n if (props.onChange) {\n handleCalendarChange(value, props.onChange)\n }\n }}\n value={props.value as string}\n >\n \n {props?.caption}\n \n \n {props.children &&\n React.Children.map(props.children, (child) =>\n )?.props?.value} className=\"min-w-[var(--radix-popper-anchor-width)]\">{(child as React.ReactElement)?.props?.children}\n )\n }\n \n \n ),\n }}\n {...props}\n />\n )\n}\nCalendar.displayName = \"Calendar\"\n\nexport { Calendar }\n" } ], "type": "components:ui" diff --git a/apps/www/public/registry/styles/new-york/calendar.json b/apps/www/public/registry/styles/new-york/calendar.json index 423f51acb10..b04d5eee868 100644 --- a/apps/www/public/registry/styles/new-york/calendar.json +++ b/apps/www/public/registry/styles/new-york/calendar.json @@ -10,7 +10,7 @@ "files": [ { "name": "calendar.tsx", - "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@radix-ui/react-icons\"\nimport { DayPicker } from \"react-day-picker\"\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/registry/new-york/ui/button\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/registry/new-york/ui/select\"\n\nexport type CalendarProps = React.ComponentProps\n\nfunction Calendar({\n className,\n classNames,\n showOutsideDays = true,\n ...props\n}: CalendarProps & { onChange?: React.ChangeEventHandler }) {\n\n const handleCalendarChange = (_value: string | number, _e: React.ChangeEventHandler) => {\n const _event = {\n target: {\n value: String(_value)\n },\n } as React.ChangeEvent\n _e(_event);\n };\n\n return (\n .day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md\"\n : \"[&:has([aria-selected])]:rounded-md\"\n ),\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-8 w-8 p-0 font-normal aria-selected:opacity-100\"\n ),\n day_range_start: \"day-range-start\",\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside: \"text-muted-foreground opacity-50\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n components={{\n IconLeft: ({ ...props }) => ,\n IconRight: ({ ...props }) => ,\n Dropdown: ({ ...props }) => (\n {\n if (props.onChange) {\n handleCalendarChange(value, props.onChange)\n }\n }}\n {...props}\n value={`${props.value}`}\n >\n \n {props?.caption}\n \n \n {props.children &&\n React.Children.map(props.children, (child) =>\n )?.props?.value} className=\"min-w-[var(--radix-popper-anchor-width)] pr-7\">{(child as React.ReactElement)?.props?.children}\n )\n }\n \n \n ),\n }}\n {...props}\n />\n )\n}\nCalendar.displayName = \"Calendar\"\n\nexport { Calendar }\n" + "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@radix-ui/react-icons\"\nimport { DayPicker } from \"react-day-picker\"\nimport { cn } from \"@/lib/utils\"\nimport { buttonVariants } from \"@/registry/new-york/ui/button\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/registry/new-york/ui/select\"\n\nexport type CalendarProps = React.ComponentProps\n\nfunction Calendar({\n className,\n classNames,\n showOutsideDays = true,\n ...props\n}: CalendarProps & { onChange?: React.ChangeEventHandler }) {\n\n const handleCalendarChange = (_value: string | number, _e: React.ChangeEventHandler) => {\n const _event = {\n target: {\n value: String(_value)\n },\n } as React.ChangeEvent\n _e(_event);\n };\n\n return (\n .day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md\"\n : \"[&:has([aria-selected])]:rounded-md\"\n ),\n day: cn(\n buttonVariants({ variant: \"ghost\" }),\n \"h-8 w-8 p-0 font-normal aria-selected:opacity-100\"\n ),\n day_range_start: \"day-range-start\",\n day_range_end: \"day-range-end\",\n day_selected:\n \"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground\",\n day_today: \"bg-accent text-accent-foreground\",\n day_outside: \"text-muted-foreground opacity-50\",\n day_disabled: \"text-muted-foreground opacity-50\",\n day_range_middle: \"aria-selected:bg-accent aria-selected:text-accent-foreground\",\n day_hidden: \"invisible\",\n ...classNames,\n }}\n components={{\n IconLeft: ({ ...props }) => ,\n IconRight: ({ ...props }) => ,\n Dropdown: ({ ...props }) => (\n {\n if (props.onChange) {\n handleCalendarChange(value, props.onChange)\n }\n }}\n value={props.value as string}\n >\n \n {props?.caption}\n \n \n {props.children &&\n React.Children.map(props.children, (child) =>\n )?.props?.value} className=\"min-w-[var(--radix-popper-anchor-width)] pr-7\">{(child as React.ReactElement)?.props?.children}\n )\n }\n \n \n ),\n }}\n {...props}\n />\n )\n}\nCalendar.displayName = \"Calendar\"\n\nexport { Calendar }\n" } ], "type": "components:ui" diff --git a/apps/www/registry/default/example/calendar-dropdown-button.tsx b/apps/www/registry/default/example/calendar-dropdown-button.tsx index 299c902b37d..40f9aa8628b 100644 --- a/apps/www/registry/default/example/calendar-dropdown-button.tsx +++ b/apps/www/registry/default/example/calendar-dropdown-button.tsx @@ -14,7 +14,6 @@ export default function CalendarDropdown() { captionLayout="dropdown-buttons" fromYear={2022} toYear={2023} - // numberOfMonths={2} selected={date} onSelect={setDate} className="rounded-md border" diff --git a/apps/www/registry/default/ui/calendar.tsx b/apps/www/registry/default/ui/calendar.tsx index ff3024575fa..d1235b06563 100644 --- a/apps/www/registry/default/ui/calendar.tsx +++ b/apps/www/registry/default/ui/calendar.tsx @@ -23,6 +23,7 @@ function Calendar({ }, } as React.ChangeEvent _e(_event); + }; return ( @@ -76,16 +77,16 @@ function Calendar({ IconRight: ({ ...props }) => , Dropdown: ({ ...props }) => ( { if (props.onChange) { handleCalendarChange(value, props.onChange) } }} - {...props} - value={`${props.value}`} + value={props.value as string} > {props?.caption}