The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { mergeProps } from "@base-ui/react/merge-props"; |
| 2 | import { useRender } from "@base-ui/react/use-render"; |
| 3 | import { ChevronDownIcon, XIcon } from "lucide-react"; |
| 4 | import type { ComponentProps } from "react"; |
| 5 | |
| 6 | import { cn } from "~/lib/utils"; |
| 7 | import { Button } from "../ui/button"; |
| 8 | import { ScrollArea } from "../ui/scroll-area"; |
| 9 | |
| 10 | export type ComposerBannerVariant = "default" | "error" | "info" | "success" | "warning"; |
| 11 | |
| 12 | const surfaceColors = cn( |
| 13 | "[--chat-composer-attached-surface:var(--chat-composer-glass-surface,var(--card))]", |
| 14 | "dark:[--chat-composer-attached-surface:var(--chat-composer-glass-surface,var(--surface-raised))]", |
| 15 | "[html[data-theme-id]_&]:[--chat-composer-attached-surface:var(--app-theme-surface-raised)]", |
| 16 | ); |
| 17 | |
| 18 | const neutralOutline = cn( |
| 19 | "[--chat-composer-attached-outline:var(--chat-composer-outline,color-mix(in_srgb,var(--contrast-foreground)_8%,transparent))]", |
| 20 | "dark:[--chat-composer-attached-outline:var(--chat-composer-outline,color-mix(in_srgb,var(--color-white)_5%,transparent))]", |
| 21 | "[html[data-theme-id]_&]:[--chat-composer-attached-outline:var(--chat-composer-outline,var(--app-theme-toolbar-border))]", |
| 22 | "dark:[html[data-theme-id]:not([data-theme-id=t3-chat])_&]:[--chat-composer-attached-outline:var(--chat-composer-outline,color-mix(in_srgb,var(--app-theme-input)_30%,var(--background)))]", |
| 23 | "dark:[html[data-theme-id=t3-chat]_&]:[--chat-composer-attached-outline:#241e28]", |
| 24 | ); |
| 25 | |
| 26 | const errorColors = |
| 27 | "[--chat-composer-attached-outline:color-mix(in_srgb,var(--error)_32%,transparent)] [--chat-composer-attached-tint:color-mix(in_srgb,var(--error)_8%,transparent)]"; |
| 28 | |
| 29 | const variantColors: Record<ComposerBannerVariant, string> = { |
| 30 | default: neutralOutline, |
| 31 | error: errorColors, |
| 32 | info: neutralOutline, |
| 33 | success: neutralOutline, |
| 34 | warning: |
| 35 | "[--chat-composer-attached-outline:color-mix(in_srgb,var(--warning)_28%,transparent)] [--chat-composer-attached-tint:color-mix(in_srgb,var(--warning)_8%,transparent)]", |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * An attached surface tucks its bottom under the card below it. A detached one is a whole card |
| 40 | * of its own, for a notice that sits apart from the composer. |
| 41 | */ |
| 42 | function Surface({ |
| 43 | variant = "default", |
| 44 | detached = false, |
| 45 | className, |
| 46 | ...props |
| 47 | }: ComponentProps<"div"> & { |
| 48 | variant?: ComposerBannerVariant; |
| 49 | detached?: boolean; |
| 50 | }) { |
| 51 | return ( |
| 52 | <div |
| 53 | data-composer-banner-surface={detached ? "detached" : "attached"} |
| 54 | data-variant={variant} |
| 55 | className={cn( |
| 56 | surfaceColors, |
| 57 | "relative isolate border-0 bg-transparent shadow-none [--chat-composer-attached-tint:transparent]", |
| 58 | variantColors[variant], |
| 59 | detached |
| 60 | ? "[--chat-composer-attachment-overlap:0px] before:rounded-2xl" |
| 61 | : // Bleed the mask 1px past the seam to cover Chromium's fractional-pixel backdrop loss. |
| 62 | "[--chat-composer-attachment-overlap:calc(1rem+1px)] before:rounded-t-2xl before:mask-t-from-transparent before:mask-t-from-4 before:mask-t-to-black before:mask-t-to-4", |
| 63 | "before:pointer-events-none before:absolute before:inset-0 before:-z-1 before:border before:border-(--chat-composer-attached-outline)", |
| 64 | "before:bg-(--chat-composer-attached-surface)/(--glass-opacity) before:bg-linear-to-b before:from-(--chat-composer-attached-tint) before:to-(--chat-composer-attached-tint) before:backdrop-blur-(--glass-blur) before:backdrop-saturate-(--glass-saturation)", |
| 65 | "before:shadow-composer dark:before:shadow-composer-dark", |
| 66 | !detached && |
| 67 | "dark:supports-[(backdrop-filter:blur(1px))_or_(-webkit-backdrop-filter:blur(1px))]:before:bg-composer-seam-above", |
| 68 | "not-supports-[((backdrop-filter:blur(1px))_or_(-webkit-backdrop-filter:blur(1px)))]:before:bg-(--chat-composer-attached-surface)", |
| 69 | className, |
| 70 | )} |
| 71 | {...props} |
| 72 | /> |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | function Attachment({ className, ...props }: ComponentProps<"div">) { |
| 77 | return ( |
| 78 | <div |
| 79 | data-slot="composer-banner-attachment" |
| 80 | className={cn( |
| 81 | "mx-auto -mb-[calc(1rem+1px)] w-[calc(100%-2*var(--chat-composer-drawer-inset))]", |
| 82 | // Only the banner touching the composer gets the dark seam shade; stacked ones would band. |
| 83 | "[&:has(+[data-slot=composer-banner-attachment])]:[--chat-composer-attached-seam:transparent]", |
| 84 | "[&+[data-slot=composer-banner-attachment]_[data-composer-banner-surface=attached]]:before:rounded-none [&+[data-slot=composer-banner-attachment]_[data-composer-banner-surface=attached]]:before:border-t-0 [&+[data-slot=composer-banner-attachment]_[data-composer-banner-surface=attached]]:[--composer-banner-corner-top:var(--control-radius)]", |
| 85 | className, |
| 86 | )} |
| 87 | {...props} |
| 88 | /> |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | function Dock({ className, ...props }: ComponentProps<"div">) { |
| 93 | return ( |
| 94 | <Attachment |
| 95 | className={cn( |
| 96 | "flex items-end gap-1 not-has-data-[composer-banner-surface=attached]:hidden", |
| 97 | className, |
| 98 | )} |
| 99 | {...props} |
| 100 | /> |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | function Column({ className, ...props }: ComponentProps<"div">) { |
| 105 | return ( |
| 106 | <div |
| 107 | className={cn( |
| 108 | "flex min-w-0 flex-1 flex-col empty:hidden", |
| 109 | "[&>[data-slot=composer-banner-attachment]]:w-full [&>[data-slot=composer-banner-attachment]:last-child]:mb-0", |
| 110 | className, |
| 111 | )} |
| 112 | {...props} |
| 113 | /> |
| 114 | ); |
| 115 | } |
| 116 | |
| 117 | function Root({ |
| 118 | className, |
| 119 | density = "default", |
| 120 | variant = "default", |
| 121 | width = "fill", |
| 122 | ...props |
| 123 | }: ComponentProps<typeof Surface> & { |
| 124 | density?: "default" | "comfortable" | "spacious"; |
| 125 | width?: "fill" | "content"; |
| 126 | }) { |
| 127 | return ( |
| 128 | <Surface |
| 129 | className={cn( |
| 130 | "min-w-0 px-1 py-(--composer-banner-padding-block) after:block after:h-(--chat-composer-attachment-overlap) text-xs/4 [--composer-banner-corner-top:var(--radius-xl)] [--composer-banner-icon-column:--spacing(7)] [--composer-banner-padding-block:--spacing(1)] sm:[--composer-banner-icon-column:--spacing(6)]", |
| 131 | density === "comfortable" && "[--composer-banner-padding-block:--spacing(1.25)]", |
| 132 | density === "spacious" && "px-3 [--composer-banner-padding-block:--spacing(3)]", |
| 133 | width === "content" ? "w-fit max-w-full flex-none" : "@container", |
| 134 | // A corner button nests inside the banner's radius only when the padding |
| 135 | // is tight; spacious padding already leaves the default radius concentric. |
| 136 | // Joined cards have a square top, and only detached cards round the bottom. |
| 137 | density !== "spacious" && [ |
| 138 | "[&>[data-composer-banner-row]:first-child>[data-slot=composer-banner-actions]>[data-slot=button]:last-child]:rounded-se-(--composer-banner-corner-top)", |
| 139 | "[&>[data-composer-banner-row]:first-child>[data-slot=composer-banner-actions]>:last-child>[data-slot=button]:last-of-type]:rounded-se-(--composer-banner-corner-top)", |
| 140 | "[&>:first-child>[data-composer-banner-row]:first-child>[data-slot=composer-banner-actions]>[data-slot=button]:last-child]:rounded-se-(--composer-banner-corner-top)", |
| 141 | "data-[composer-banner-surface=detached]:[&>[data-composer-banner-row]:only-child>[data-slot=composer-banner-actions]>[data-slot=button]:last-child]:rounded-ee-xl", |
| 142 | "data-[composer-banner-surface=detached]:[&>[data-composer-banner-row]:only-child>[data-slot=composer-banner-actions]>:last-child>[data-slot=button]:last-of-type]:rounded-ee-xl", |
| 143 | ], |
| 144 | className, |
| 145 | )} |
| 146 | data-slot="composer-banner" |
| 147 | data-composer-banner-width={width} |
| 148 | variant={variant} |
| 149 | {...props} |
| 150 | /> |
| 151 | ); |
| 152 | } |
| 153 | |
| 154 | function Row({ |
| 155 | className, |
| 156 | render, |
| 157 | layout = "inline", |
| 158 | ...props |
| 159 | }: useRender.ComponentProps<"div"> & { |
| 160 | layout?: "inline" | "wrap-actions" | "approval"; |
| 161 | }) { |
| 162 | const rowProps = { |
| 163 | className: cn( |
| 164 | "group/banner-row grid min-h-(--composer-banner-icon-column) w-full min-w-0 grid-cols-[var(--composer-banner-icon-column)_minmax(0,1fr)_auto] items-center gap-x-1 text-start", |
| 165 | "not-has-[>[data-slot=composer-banner-actions]]:grid-cols-[var(--composer-banner-icon-column)_minmax(0,1fr)]", |
| 166 | "[&:is(button)]:cursor-pointer [&:is(button)]:rounded-xl [&:is(button)]:hover:bg-foreground/5 [&:is(button)]:focus-visible:outline-2 [&:is(button)]:focus-visible:-outline-offset-2 [&:is(button)]:focus-visible:outline-ring", |
| 167 | layout === "wrap-actions" && |
| 168 | "flex flex-wrap *:data-[slot=composer-banner-content]:max-w-[calc(100%-var(--composer-banner-icon-column)-var(--spacing))] *:data-[slot=composer-banner-content]:grow", |
| 169 | layout === "approval" && "items-start gap-x-2 gap-y-3", |
| 170 | className, |
| 171 | ), |
| 172 | "data-composer-banner-row": "true", |
| 173 | "data-composer-banner-layout": layout, |
| 174 | }; |
| 175 | return useRender({ |
| 176 | defaultTagName: "div", |
| 177 | render, |
| 178 | props: mergeProps<"div">(rowProps, props), |
| 179 | }); |
| 180 | } |
| 181 | |
| 182 | function Icon({ className, ...props }: ComponentProps<"span">) { |
| 183 | return ( |
| 184 | <span |
| 185 | aria-hidden |
| 186 | data-slot="composer-banner-icon" |
| 187 | className={cn( |
| 188 | "col-start-1 row-start-1 flex w-(--composer-banner-icon-column) min-w-0 flex-none items-center justify-center text-muted-foreground [&>svg]:size-3", |
| 189 | "group-data-[composer-banner-layout=approval]/banner-row:pt-0.5 group-data-[composer-banner-layout=approval]/banner-row:text-warning group-data-[composer-banner-layout=approval]/banner-row:[&>svg]:size-4", |
| 190 | className, |
| 191 | )} |
| 192 | {...props} |
| 193 | /> |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | function Content({ className, ...props }: ComponentProps<"span">) { |
| 198 | return ( |
| 199 | <span |
| 200 | data-slot="composer-banner-content" |
| 201 | className={cn( |
| 202 | "col-start-2 row-start-1 flex min-w-0 items-center gap-1 *:data-[slot=composer-banner-separator]:mx-0", |
| 203 | "@max-[560px]:group-data-[composer-banner-layout=approval]/banner-row:col-end-4", |
| 204 | "group-not-has-[>[data-slot=composer-banner-icon]]/banner-row:col-[1/3] group-not-has-[>[data-slot=composer-banner-icon]]/banner-row:ps-2 sm:group-not-has-[>[data-slot=composer-banner-icon]]/banner-row:ps-1.5", |
| 205 | "group-not-has-[>[data-slot=composer-banner-icon],>[data-slot=composer-banner-actions]]/banner-row:pe-2 sm:group-not-has-[>[data-slot=composer-banner-icon],>[data-slot=composer-banner-actions]]/banner-row:pe-1.5", |
| 206 | className, |
| 207 | )} |
| 208 | {...props} |
| 209 | /> |
| 210 | ); |
| 211 | } |
| 212 | |
| 213 | function Separator() { |
| 214 | return ( |
| 215 | <span |
| 216 | aria-hidden |
| 217 | data-slot="composer-banner-separator" |
| 218 | className="mx-1 inline-block flex-none text-muted-foreground/40" |
| 219 | > |
| 220 | · |
| 221 | </span> |
| 222 | ); |
| 223 | } |
| 224 | |
| 225 | function Actions({ className, ...props }: ComponentProps<"span">) { |
| 226 | return ( |
| 227 | <span |
| 228 | data-slot="composer-banner-actions" |
| 229 | className={cn( |
| 230 | "col-start-3 row-start-1 flex flex-wrap items-center justify-end gap-1", |
| 231 | "group-data-[composer-banner-layout=approval]/banner-row:self-center group-data-[composer-banner-layout=approval]/banner-row:gap-1.5 @max-[560px]:group-data-[composer-banner-layout=approval]/banner-row:col-start-2 @max-[560px]:group-data-[composer-banner-layout=approval]/banner-row:col-end-4 @max-[560px]:group-data-[composer-banner-layout=approval]/banner-row:row-start-2", |
| 232 | "group-data-[composer-banner-layout=wrap-actions]/banner-row:ms-auto", |
| 233 | className, |
| 234 | )} |
| 235 | {...props} |
| 236 | /> |
| 237 | ); |
| 238 | } |
| 239 | |
| 240 | function Children({ className, render, ...props }: useRender.ComponentProps<"div">) { |
| 241 | return useRender({ |
| 242 | defaultTagName: "div", |
| 243 | render, |
| 244 | props: mergeProps<"div">( |
| 245 | { className: cn("grid gap-px [&_[data-composer-banner-row]]:min-h-5", className) }, |
| 246 | props, |
| 247 | ), |
| 248 | }); |
| 249 | } |
| 250 | |
| 251 | function Scroll({ className, children, ...props }: ComponentProps<typeof ScrollArea>) { |
| 252 | return ( |
| 253 | <ScrollArea |
| 254 | radius="none" |
| 255 | scrollFade |
| 256 | className={cn("h-auto max-h-[min(24rem,40dvh)]", className)} |
| 257 | {...props} |
| 258 | > |
| 259 | {} |
| 260 | <div className="[[data-has-overflow-y]>&]:pe-2">{children}</div> |
| 261 | </ScrollArea> |
| 262 | ); |
| 263 | } |
| 264 | |
| 265 | function Count({ className, ...props }: ComponentProps<"span">) { |
| 266 | return ( |
| 267 | <span |
| 268 | className={cn( |
| 269 | "inline-flex min-w-(--composer-banner-icon-column,1em) flex-none justify-center font-medium text-muted-foreground tabular-nums", |
| 270 | className, |
| 271 | )} |
| 272 | {...props} |
| 273 | /> |
| 274 | ); |
| 275 | } |
| 276 | |
| 277 | function Body({ className, ...props }: ComponentProps<"div">) { |
| 278 | return <div className={cn("min-w-0 ps-8 sm:ps-7", className)} {...props} />; |
| 279 | } |
| 280 | |
| 281 | function Dot({ className, ...props }: ComponentProps<"span">) { |
| 282 | return ( |
| 283 | <span className={cn("size-1.5 flex-none rounded-full bg-current", className)} {...props} /> |
| 284 | ); |
| 285 | } |
| 286 | |
| 287 | function ToggleIcon({ expanded }: { expanded: boolean }) { |
| 288 | return ( |
| 289 | <Button |
| 290 | render={<span aria-hidden />} |
| 291 | size="icon-xs" |
| 292 | variant="ghost" |
| 293 | tabIndex={-1} |
| 294 | className="pointer-events-none" |
| 295 | > |
| 296 | <ChevronDownIcon className={cn("size-3.5", !expanded && "rotate-180")} /> |
| 297 | </Button> |
| 298 | ); |
| 299 | } |
| 300 | |
| 301 | function Dismiss({ className, children, ...props }: ComponentProps<typeof Button>) { |
| 302 | return ( |
| 303 | <Button size="icon-xs" variant="ghost" className={className} {...props}> |
| 304 | {children ?? <XIcon className="size-3.5" />} |
| 305 | </Button> |
| 306 | ); |
| 307 | } |
| 308 | |
| 309 | export const ComposerBanner = { |
| 310 | Surface, |
| 311 | Attachment, |
| 312 | Dock, |
| 313 | Column, |
| 314 | Root, |
| 315 | Row, |
| 316 | Icon, |
| 317 | Content, |
| 318 | Separator, |
| 319 | Actions, |
| 320 | Children, |
| 321 | Scroll, |
| 322 | Count, |
| 323 | Body, |
| 324 | Dot, |
| 325 | ToggleIcon, |
| 326 | Dismiss, |
| 327 | }; |