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_ACTION_CLASS,
15 THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
16 THREAD_DETAILS_PANEL_SPLIT_CHECKS_CLASS,
17 THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
18 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
19} from "./threadDetailsPanelStyles";
20import { ChevronDownIcon } from "lucide-react";
21
22const parts = {
23 row: THREAD_DETAILS_PANEL_ROW_CLASS,
24 select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
25 primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
26 secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
27 action: THREAD_DETAILS_PANEL_LINK_SPLIT_ACTION_CLASS,
28 "link-primary": THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
29 checks: THREAD_DETAILS_PANEL_SPLIT_CHECKS_CLASS,
30 icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
31};
32
33/** Panel controls own their fixed density; toolbar controls use the standard Button variants. */
34export function ThreadDetailsControl({
35 panel = true,
36 part = "row",
37 multiline = false,
38 tone = "default",
39 className,
40 size = "default",
41 variant = "default",
42 render,
43 ...props
44}: ComponentProps<typeof Button> & {
45 panel?: boolean;
46 part?: keyof typeof parts;
47 multiline?: boolean;
48 tone?: "default" | "muted" | "destructive";
49}) {
50 const control = useRender({
51 defaultTagName: "button",
52 render,
53 props: mergeProps<"button">(
54 {
55 type: render ? undefined : "button",
56 className: cn(
57 "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",
58 parts[part],
59 multiline && "h-auto min-h-9 py-0.75 disabled:opacity-100 sm:h-auto",
60 tone === "muted" && "text-muted-foreground/70 hover:text-foreground/80",
61 tone === "destructive" &&
62 "text-destructive hover:text-destructive data-pressed:text-destructive",
63 className,
64 ),
65 },
66 props,
67 ),
68 });
69 if (!panel) {
70 return (
71 <Button
72 {...props}
73 render={render}
74 size={multiline ? "sm-multiline" : size}
75 variant={variant}
76 className={className}
77 />
78 );
79 }
80 return control;
81}
82
83export function ThreadDetailsSelectControl({
84 panel,
85 children,
86 className,
87 ...props
88}: Omit<SelectPrimitive.Trigger.Props, "className"> & { panel: boolean; className?: string }) {
89 if (!panel) {
90 return (
91 <ComposerSelectControl {...props} size="xs" className={className}>
92 {children}
93 </ComposerSelectControl>
94 );
95 }
96 return (
97 <SelectPrimitive.Trigger
98 {...props}
99 render={<ThreadDetailsControl part="select" className={className} />}
100 >
101 {children}
102 <SelectPrimitive.Icon data-slot="select-icon">
103 <ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
104 </SelectPrimitive.Icon>
105 </SelectPrimitive.Trigger>
106 );
107}