@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 156 lines 6.85 KB
Raw
1 import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
2
3 import { cn } from "~/lib/utils";
4
5 import { renderClosingPositioner } from "./closing-positioner";
6
7 const PopoverCreateHandle = PopoverPrimitive.createHandle;
8
9 const Popover = PopoverPrimitive.Root;
10
11 function PopoverTrigger({ className, children, ...props }: PopoverPrimitive.Trigger.Props) {
12 return (
13 <PopoverPrimitive.Trigger className={className} data-slot="popover-trigger" {...props}>
14 {children}
15 </PopoverPrimitive.Trigger>
16 );
17 }
18
19 const popoverPopupWidthClassName = {
20 auto: "",
21 sm: "w-64",
22 md: "w-80",
23 lg: "w-96",
24 } as const;
25
26 const popoverViewportPaddingClassName = {
27 default: "py-4 [--viewport-inline-padding:--spacing(4)]",
28 compact: "py-2 [--viewport-inline-padding:--spacing(3)]",
29 none: "rounded-[calc(var(--radius-lg)-1px)] py-0 [--viewport-inline-padding:0px]",
30 } as const;
31
32 function PopoverPopup({
33 children,
34 className,
35 padding = "default",
36 variant = "default",
37 width = "auto",
38 side = "bottom",
39 align = "center",
40 sideOffset = 4,
41 alignOffset = 0,
42 collisionAvoidance,
43 tooltipStyle = false,
44 keepMounted = false,
45 anchor,
46 touchBackdrop = false,
47 ...props
48 }: PopoverPrimitive.Popup.Props & {
49 padding?: keyof typeof popoverViewportPaddingClassName;
50 variant?: "default" | "panel";
51 side?: PopoverPrimitive.Positioner.Props["side"];
52 align?: PopoverPrimitive.Positioner.Props["align"];
53 sideOffset?: PopoverPrimitive.Positioner.Props["sideOffset"];
54 alignOffset?: PopoverPrimitive.Positioner.Props["alignOffset"];
55 collisionAvoidance?: PopoverPrimitive.Positioner.Props["collisionAvoidance"];
56 tooltipStyle?: boolean;
57 keepMounted?: PopoverPrimitive.Portal.Props["keepMounted"];
58 anchor?: PopoverPrimitive.Positioner.Props["anchor"];
59 width?: keyof typeof popoverPopupWidthClassName;
60 touchBackdrop?: boolean;
61 }) {
62 // Viewport rekeys on close; persistent single-trigger forms need stable containers for drafts and submit
63 // guards.
64 const Viewport = keepMounted ? "div" : PopoverPrimitive.Viewport;
65 return (
66 <PopoverPrimitive.Portal keepMounted={keepMounted}>
67 {touchBackdrop ? (
68 // On touch, the backdrop consumes outside taps so closing cannot also activate the control beneath.
69 <PopoverPrimitive.Backdrop
70 className="fixed inset-0 z-[130] hidden pointer-coarse:block"
71 data-slot="popover-backdrop"
72 />
73 ) : null}
74 <PopoverPrimitive.Positioner
75 align={align}
76 alignOffset={alignOffset}
77 anchor={anchor}
78 collisionAvoidance={collisionAvoidance}
79 collisionPadding={variant === "panel" ? 0 : undefined}
80 className={cn(
81 "h-(--positioner-height) max-h-(--available-height) w-(--positioner-width) max-w-(--available-width)",
82 // Kept-mounted positioners first paint at the window origin, so a transform transition slides them in from there.
83 !keepMounted && "transition-transform data-instant:transition-none",
84 variant === "panel"
85 ? "z-(--z-sheet) w-[min(calc(var(--thread-details-panel-width)+--spacing(4)),calc(var(--anchor-width)---spacing(2)))] transition-[top] duration-150 ease-out data-instant:transition-[top] motion-reduce:transition-none motion-reduce:data-instant:transition-none"
86 : "z-[130]",
87 )}
88 data-slot="popover-positioner"
89 render={renderClosingPositioner}
90 side={side}
91 sideOffset={sideOffset}
92 >
93 <PopoverPrimitive.Popup
94 className={cn(
95 "relative flex h-(--popup-height,auto) w-(--popup-width,auto) origin-(--transform-origin) rounded-lg text-popover-foreground outline-none transition-[width,height,scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] has-data-[slot=calendar]:rounded-xl has-data-[slot=calendar]:before:rounded-[calc(var(--radius-xl)-1px)] data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
96 variant !== "panel" && "dropdown-glass",
97 // Without it, Chromium re-snaps text after the scale-in at fractional zoom, so hovered rows jump a pixel.
98 "will-change-[scale]",
99 // Electron drag hit-testing ignores z-index; popups over a drag region would swallow hover.
100 "[-webkit-app-region:no-drag]",
101 tooltipStyle &&
102 "w-fit rounded-md text-xs shadow-md/5 before:rounded-[calc(var(--radius-md)-1px)]",
103 !tooltipStyle &&
104 variant !== "panel" &&
105 "shadow-[0_16px_40px_-18px_rgb(0_0_0/55%)] dark:shadow-[0_18px_44px_-18px_rgb(0_0_0/80%)]",
106 width !== "auto" && ["max-w-[calc(100vw-2rem)]", popoverPopupWidthClassName[width]],
107 variant === "panel" &&
108 "w-full overflow-visible rounded-none border-0 bg-transparent shadow-none before:hidden [backdrop-filter:none] [-webkit-backdrop-filter:none]",
109 className,
110 )}
111 data-slot="popover-popup"
112 {...props}
113 >
114 <Viewport
115 className={cn(
116 "relative size-full max-h-(--available-height) overflow-clip px-(--viewport-inline-padding) has-data-[slot=calendar]:p-2 data-instant:transition-none **:data-current:data-ending-style:opacity-0 **:data-current:data-starting-style:opacity-0 **:data-previous:data-ending-style:opacity-0 **:data-previous:data-starting-style:opacity-0 **:data-current:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-previous:w-[calc(var(--popup-width)-2*var(--viewport-inline-padding)-2px)] **:data-current:opacity-100 **:data-previous:opacity-100 **:data-current:transition-opacity **:data-previous:transition-opacity",
117 tooltipStyle && padding === "default"
118 ? "py-1 [--viewport-inline-padding:--spacing(2)]"
119 : popoverViewportPaddingClassName[padding],
120 !tooltipStyle && "not-data-transitioning:overflow-y-auto",
121 variant === "panel" &&
122 "overflow-visible py-2 [--viewport-inline-padding:--spacing(2)]",
123 )}
124 data-slot="popover-viewport"
125 >
126 {children}
127 </Viewport>
128 </PopoverPrimitive.Popup>
129 </PopoverPrimitive.Positioner>
130 </PopoverPrimitive.Portal>
131 );
132 }
133
134 function PopoverClose({ ...props }: PopoverPrimitive.Close.Props) {
135 return <PopoverPrimitive.Close data-slot="popover-close" {...props} />;
136 }
137
138 function PopoverTitle({ className, ...props }: PopoverPrimitive.Title.Props) {
139 return (
140 <PopoverPrimitive.Title
141 className={cn("font-semibold text-sm leading-none", className)}
142 data-slot="popover-title"
143 {...props}
144 />
145 );
146 }
147
148 export {
149 PopoverCreateHandle,
150 Popover,
151 PopoverTrigger,
152 PopoverPopup,
153 PopoverPopup as PopoverContent,
154 PopoverTitle,
155 PopoverClose,
156 };