Open History to see the last commit
1import type { ComponentProps } from "react";
2import { ChevronDownIcon, type LucideIcon } from "lucide-react";
3
4import { cn } from "~/lib/utils";
5import { Button } from "../ui/button";
6import { SelectTrigger } from "../ui/select";
7import { Separator } from "../ui/separator";
8
9export type ComposerControlSize = "sm" | "xs";
10
11type ComposerControlProps = Omit<ComponentProps<typeof Button>, "size"> & {
12 size?: ComposerControlSize;
13};
14
15type ComposerSelectControlProps = Omit<ComponentProps<typeof SelectTrigger>, "size"> & {
16 size?: ComposerControlSize;
17};
18
19const composerControlClassName =
20 "rounded-[var(--control-radius)] text-secondary-label transition-none hover:text-foreground [&_svg[data-composer-control-chevron]]:-mx-0.5 [&_svg[data-composer-control-icon]]:mx-0";
21const expandedComposerControlClassName = "h-7 min-h-7 gap-1.5 px-2.5";
22const restingComposerControlClassName =
23 "[--control-icon-color:currentColor] font-normal text-muted-foreground/70 hover:text-foreground/80 [&_svg[data-composer-control-chevron]]:-me-1 [&_svg[data-composer-control-chevron]]:ms-0";
24
25export function ComposerControl({
26 className,
27 size = "sm",
28 variant = "ghost",
29 ...props
30}: ComposerControlProps) {
31 return (
32 <Button
33 className={cn(
34 composerControlClassName,
35 size === "xs" ? restingComposerControlClassName : expandedComposerControlClassName,
36 className,
37 )}
38 size={size}
39 variant={variant}
40 {...props}
41 />
42 );
43}
44
45export function ComposerControlIcon({
46 icon: Icon,
47 className,
48 opticalSize = "default",
49 size = "sm",
50}: {
51 icon: LucideIcon;
52 className?: string | undefined;
53 opticalSize?: "default" | "large";
54 size?: ComposerControlSize;
55}) {
56 return (
57 <Icon
58 aria-hidden="true"
59 className={cn(
60 "shrink-0",
61 size === "xs" ? "size-3" : opticalSize === "large" ? "size-4.5" : "size-4",
62 className,
63 )}
64 data-composer-control-icon
65 />
66 );
67}
68
69export function ComposerControlChevron({
70 className,
71 size = "sm",
72}: {
73 className?: string;
74 size?: ComposerControlSize;
75} = {}) {
76 return (
77 <ChevronDownIcon
78 aria-hidden="true"
79 className={cn(
80 "shrink-0",
81 size === "xs" ? "size-3 text-current opacity-50" : "size-3.5 text-icon-muted",
82 className,
83 )}
84 data-composer-control-chevron
85 strokeWidth={2.25}
86 />
87 );
88}
89
90export function ComposerControlSeparator({
91 className,
92 size = "sm",
93 ...props
94}: Omit<ComponentProps<typeof Separator>, "orientation"> & {
95 size?: ComposerControlSize;
96}) {
97 return (
98 <Separator
99 orientation="vertical"
100 className={cn("mx-0.5 hidden sm:block", size === "xs" ? "h-3.5!" : "h-4", className)}
101 {...props}
102 />
103 );
104}
105
106export function ComposerSelectControl({
107 className,
108 size = "sm",
109 variant = "ghost",
110 ...props
111}: ComposerSelectControlProps) {
112 return (
113 <SelectTrigger
114 className={cn(
115 composerControlClassName,
116 size === "xs" ? restingComposerControlClassName : expandedComposerControlClassName,
117 className,
118 )}
119 icon={<ComposerControlChevron size={size} />}
120 size={size}
121 variant={variant}
122 {...props}
123 />
124 );
125}