@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 110 lines 4.96 KB
Raw
1 import { DayPicker } from "@daypicker/react";
2 import { ChevronLeftIcon, ChevronRightIcon, ChevronsUpDownIcon } from "lucide-react";
3 import type * as React from "react";
4 import { cn } from "~/lib/utils";
5
6 const buttonClassNames =
7 "relative flex size-(--cell-size) text-base sm:text-sm items-center justify-center rounded-lg text-foreground not-in-data-selected:hover:bg-accent disabled:pointer-events-none disabled:opacity-64 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0";
8
9 const defaultComponents = {
10 Chevron: ({
11 className,
12 orientation,
13 ...props
14 }: {
15 className?: string;
16 orientation?: "left" | "right" | "up" | "down";
17 }): React.ReactElement => {
18 if (orientation === "left") {
19 return (
20 <ChevronLeftIcon
21 className={cn(className, "rtl:rotate-180")}
22 {...props}
23 aria-hidden="true"
24 />
25 );
26 }
27
28 if (orientation === "right") {
29 return (
30 <ChevronRightIcon
31 className={cn(className, "rtl:rotate-180")}
32 {...props}
33 aria-hidden="true"
34 />
35 );
36 }
37
38 return <ChevronsUpDownIcon className={className} {...props} aria-hidden="true" />;
39 },
40 };
41
42 export function Calendar({
43 className,
44 classNames,
45 showOutsideDays = true,
46 components: userComponents,
47 mode = "single",
48 ...props
49 }: React.ComponentProps<typeof DayPicker>): React.ReactElement {
50 const defaultClassNames = {
51 button_next: buttonClassNames,
52 button_previous: buttonClassNames,
53 caption_label: "text-base sm:text-sm font-medium flex items-center gap-2 h-full",
54 day: "size-(--cell-size) text-sm py-px",
55 day_button: cn(
56 buttonClassNames,
57 "in-data-disabled:pointer-events-none in-[.range-middle]:rounded-none in-[.range-end:not(.range-start)]:rounded-s-none in-[.range-start:not(.range-end)]:rounded-e-none in-[.range-middle]:in-data-selected:bg-accent in-data-selected:bg-primary in-[.range-middle]:in-data-selected:text-foreground in-data-disabled:text-muted-foreground/72 in-data-outside:text-muted-foreground/72 in-data-selected:in-data-outside:text-primary-foreground in-data-selected:text-primary-foreground in-data-disabled:line-through outline-none in-[[data-selected]:not(.range-middle)]:transition-[border-radius,box-shadow] focus-visible:z-1 focus-visible:ring-[3px] focus-visible:ring-inset focus-visible:ring-ring/50",
58 ),
59 dropdown: "absolute bg-popover inset-0 opacity-0",
60 dropdown_root:
61 "relative has-focus:border-ring has-focus:ring-ring/50 has-focus:ring-[3px] has-focus:ring-inset border border-input shadow-xs/5 rounded-lg px-[calc(--spacing(3)-1px)] h-9 sm:h-8 [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:-me-1",
62 dropdowns:
63 "w-full flex items-center text-base sm:text-sm justify-center h-(--cell-size) gap-1.5 *:[span]:font-medium",
64 hidden: "invisible",
65 month: "w-full",
66 month_caption:
67 "relative mx-(--cell-size) px-1 mb-1 flex h-(--cell-size) items-center justify-center z-2",
68 months: "relative flex flex-col sm:flex-row gap-2",
69 nav: "absolute top-0 flex w-full justify-between z-1",
70 outside: "text-muted-foreground data-selected:bg-accent/50 data-selected:text-muted-foreground",
71 range_end: "range-end",
72 range_middle: "range-middle",
73 range_start: "range-start",
74 today:
75 "*:after:pointer-events-none *:after:absolute *:after:bottom-1 *:after:start-1/2 *:after:z-1 *:after:size-[3px] *:after:-translate-x-1/2 *:after:rounded-full *:after:bg-primary [&[data-selected]:not(.range-middle)>*]:after:bg-background [&[data-disabled]>*]:after:bg-foreground/30",
76 week_number: "size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72",
77 weekday: "size-(--cell-size) p-0 text-xs font-medium text-muted-foreground/72",
78 };
79 const mergedClassNames: typeof defaultClassNames = Object.keys(defaultClassNames).reduce(
80 (acc, key) => {
81 const userClass = classNames?.[key as keyof typeof classNames];
82 const baseClass = defaultClassNames[key as keyof typeof defaultClassNames];
83
84 acc[key as keyof typeof defaultClassNames] = userClass ? cn(baseClass, userClass) : baseClass;
85
86 return acc;
87 },
88 { ...defaultClassNames } as typeof defaultClassNames,
89 );
90
91 const mergedComponents = {
92 ...defaultComponents,
93 ...userComponents,
94 };
95
96 const dayPickerProps = {
97 className: cn("w-fit [--cell-size:--spacing(10)] sm:[--cell-size:--spacing(9)]", className),
98 classNames: mergedClassNames,
99 components: mergedComponents,
100 "data-slot": "calendar",
101 formatters: {
102 formatMonthDropdown: (date: Date) => date.toLocaleString("default", { month: "short" }),
103 } as React.ComponentProps<typeof DayPicker>["formatters"],
104 mode,
105 showOutsideDays,
106 ...props,
107 };
108
109 return <DayPicker {...(dayPickerProps as React.ComponentProps<typeof DayPicker>)} />;
110 }