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