Open History to see the last commit
1import { mergeProps } from "@base-ui/react/merge-props";
2import { Select as SelectPrimitive } from "@base-ui/react/select";
3import { useRender } from "@base-ui/react/use-render";
4import type { ComponentProps } from "react";
5
6import { cn } from "~/lib/utils";
7import { Button } from "../ui/button";
8import { ComposerSelectControl } from "./ComposerControl";
9import {
10 THREAD_DETAILS_PANEL_ROW_CLASS,
11 THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
12 THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
13 THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
14 THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
15 THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
16 THREAD_DETAILS_PANEL_META_ACTION_CLASS,
17 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
18} from "./threadDetailsPanelStyles";
19import { ChevronDownIcon } from "lucide-react";
20
21const parts = {
22 row: THREAD_DETAILS_PANEL_ROW_CLASS,
23 select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
24 primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
25 secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
26 "link-primary": THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
27 icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
28 meta: THREAD_DETAILS_PANEL_META_ACTION_CLASS,
29};
30
31/** Panel controls own their fixed density; toolbar controls use the standard Button variants. */
32export function ThreadDetailsControl({
33 panel = true,
34 part = "row",
35 multiline = false,
36 tone = "default",
37 className,
38 size = "default",
39 variant = "default",
40 render,
41 ...props
42}: ComponentProps<typeof Button> & {
43 panel?: boolean;
44 part?: keyof typeof parts;
45 multiline?: boolean;
46 tone?: "default" | "muted" | "primary" | "destructive";
47}) {
48 const control = useRender({
49 defaultTagName: "button",
50 render,
51 props: mergeProps<"button">(
52 {
53 type: render ? undefined : "button",
54 className: cn(
55 "relative inline-flex shrink-0 cursor-pointer items-center whitespace-nowrap border outline-none transition-[box-shadow,scale] [&:active:not([aria-haspopup])]:scale-[0.97] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 disabled:pointer-events-none disabled:opacity-64 aria-disabled:cursor-not-allowed aria-disabled:opacity-64 [&_svg]:shrink-0",
56 parts[part],
57 multiline && "h-auto min-h-8 py-0.75 disabled:opacity-100 sm:h-auto",
58 tone === "muted" && "text-muted-foreground/70 hover:text-foreground/80",
59 tone === "primary" && "text-primary hover:text-primary",
60 tone === "destructive" &&
61 "text-destructive hover:text-destructive data-pressed:text-destructive",
62 className,
63 ),
64 },
65 props,
66 ),
67 });
68 if (!panel) {
69 return (
70 <Button
71 {...props}
72 render={render}
73 size={multiline ? "sm-multiline" : size}
74 variant={variant}
75 className={className}
76 />
77 );
78 }
79 return control;
80}
81
82export function ThreadDetailsSelectControl({
83 panel,
84 children,
85 className,
86 ...props
87}: Omit<SelectPrimitive.Trigger.Props, "className"> & { panel: boolean; className?: string }) {
88 if (!panel) {
89 return (
90 <ComposerSelectControl {...props} size="xs" className={className}>
91 {children}
92 </ComposerSelectControl>
93 );
94 }
95 return (
96 <SelectPrimitive.Trigger
97 {...props}
98 render={<ThreadDetailsControl part="select" className={className} />}
99 >
100 {children}
101 <SelectPrimitive.Icon data-slot="select-icon">
102 <ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
103 </SelectPrimitive.Icon>
104 </SelectPrimitive.Trigger>
105 );
106}