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 { Select as SelectPrimitive } from "@base-ui/react/select"; |
| 3 | import { useRender } from "@base-ui/react/use-render"; |
| 4 | import type { ComponentType, SVGProps } from "react"; |
| 5 | |
| 6 | import { cn } from "~/lib/utils"; |
| 7 | |
| 8 | export type ComposerControlSize = "sm" | "xs"; |
| 9 | |
| 10 | function composerControlClassName(size: ComposerControlSize, className?: string) { |
| 11 | return cn( |
| 12 | "relative inline-flex shrink-0 cursor-pointer items-center justify-center whitespace-nowrap rounded-(--control-radius) border border-transparent text-base outline-none hover:bg-accent data-pressed:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 data-disabled:pointer-events-none data-disabled:opacity-64 pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 [&:active:not([aria-haspopup])]:scale-[0.97] [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:-mx-0.5 [&_svg[data-composer-control-icon]]:mx-0", |
| 13 | "[&_:is([data-composer-control-label],[data-chat-provider-model-picker-label])]:[text-box:trim-both_cap_alphabetic] supports-[text-box:trim-both_cap_alphabetic]:[&_:is([data-composer-control-label],[data-chat-provider-model-picker-label])]:py-1.5", |
| 14 | size === "xs" |
| 15 | ? "h-7 gap-1 has-[[data-composer-label]]:gap-1.5 px-1.75 font-normal text-foreground/70 text-sm hover:text-foreground dark:text-muted-foreground sm:h-6 sm:text-xs [&_svg:not([class*='size-'])]:size-4 sm:[&_svg:not([class*='size-'])]:size-3.5 [&_svg]:mx-0 [&_svg[data-composer-control-chevron]]:ms-0 [&_svg[data-composer-control-chevron]]:-me-1" |
| 16 | : "h-7 gap-1.5 px-2 font-medium text-foreground/80 [&_svg:not([class*='text-'])]:text-muted-foreground hover:text-foreground sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4", |
| 17 | "aria-pressed:bg-accent aria-pressed:text-accent-foreground aria-pressed:hover:bg-accent/80", |
| 18 | className, |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | type ComposerControlProps = useRender.ComponentProps<"button"> & { |
| 23 | size?: ComposerControlSize; |
| 24 | }; |
| 25 | |
| 26 | export function ComposerControl({ |
| 27 | className, |
| 28 | size = "sm", |
| 29 | render, |
| 30 | ...props |
| 31 | }: ComposerControlProps) { |
| 32 | const defaultProps = { |
| 33 | className: composerControlClassName(size, className), |
| 34 | type: render ? undefined : ("button" as const), |
| 35 | }; |
| 36 | return useRender({ |
| 37 | defaultTagName: "button", |
| 38 | props: mergeProps<"button">(defaultProps, props), |
| 39 | render, |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | export function ComposerControlIcon({ |
| 44 | icon: Icon, |
| 45 | className, |
| 46 | opticalSize = "default", |
| 47 | size = "sm", |
| 48 | }: { |
| 49 | icon: ComponentType<SVGProps<SVGSVGElement>>; |
| 50 | className?: string | undefined; |
| 51 | opticalSize?: "default" | "large"; |
| 52 | size?: ComposerControlSize; |
| 53 | }) { |
| 54 | return ( |
| 55 | <Icon |
| 56 | aria-hidden="true" |
| 57 | className={cn( |
| 58 | "shrink-0", |
| 59 | size === "xs" ? "size-3" : opticalSize === "large" ? "size-4.5" : "size-4", |
| 60 | className, |
| 61 | )} |
| 62 | data-composer-control-icon |
| 63 | /> |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | export function ComposerSelectControl({ |
| 68 | className, |
| 69 | children, |
| 70 | size = "sm", |
| 71 | ...props |
| 72 | }: Omit<SelectPrimitive.Trigger.Props, "className"> & { |
| 73 | className?: string | undefined; |
| 74 | size?: ComposerControlSize; |
| 75 | }) { |
| 76 | return ( |
| 77 | <SelectPrimitive.Trigger className={composerControlClassName(size, className)} {...props}> |
| 78 | {children} |
| 79 | </SelectPrimitive.Trigger> |
| 80 | ); |
| 81 | } |