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 title: cn(
23 THREAD_DETAILS_PANEL_ROW_CLASS,
24 "h-auto min-h-8 items-start pt-1.5 pb-0 disabled:opacity-100 sm:h-auto [&>svg]:mt-px",
25 ),
26 select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
27 primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
28 secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
29 icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
30 meta: THREAD_DETAILS_PANEL_META_ACTION_CLASS,
31};
32
33export function ThreadDetailsControl({
34 panel = true,
35 part = "row",
36 multiline = false,
37 tone = "default",
38 className,
39 children,
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" | "primary" | "destructive";
49}) {
50 const control = useRender({
51 defaultTagName: "button",
52 render,
53 props: mergeProps<"button">(
54 {
55 type: render ? undefined : "button",
56 // The touch target stays centered within the panel's 32px rows; spilling past them makes scrolling lists overflow.
57 className: cn(
58 "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:top-1/2 pointer-coarse:after:left-1/2 pointer-coarse:after:size-full pointer-coarse:after:min-h-8 pointer-coarse:after:min-w-8 pointer-coarse:after:-translate-x-1/2 pointer-coarse:after:-translate-y-1/2 [&_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",
59 parts[part],
60 multiline && "h-auto min-h-8 py-1.5 disabled:opacity-100 sm:h-auto",
61 tone === "muted" && "text-muted-foreground hover:text-foreground/80",
62 tone === "primary" &&
63 // The row surface forces a faint hover fill with !important; the pill keeps its own.
64 "bg-black/[0.035] text-foreground/80 hover:text-foreground hover:!bg-black/[0.06] data-pressed:!bg-black/[0.06] dark:bg-white/[0.08] dark:hover:!bg-white/[0.12] dark:data-pressed:!bg-white/[0.12]",
65 tone === "destructive" &&
66 "text-destructive hover:text-destructive data-pressed:text-destructive",
67 // Keep the inset focus ring clear of the 20px PR action label.
68 part === "meta" &&
69 (tone === "primary" || tone === "destructive") &&
70 "h-5 focus-visible:ring-1 focus-visible:ring-offset-0",
71 part === "meta" &&
72 tone === "destructive" &&
73 "bg-destructive/10 hover:!bg-destructive/16 data-pressed:!bg-destructive/16 dark:hover:!bg-destructive/16 dark:data-pressed:!bg-destructive/16",
74 className,
75 ),
76 },
77 props,
78 {
79 children:
80 part === "select" ? (
81 <>
82 <span data-slot="select-label" className={THREAD_DETAILS_PANEL_SELECT_LABEL_CLASS}>
83 {children}
84 </span>
85 <span data-slot="select-icon" className={THREAD_DETAILS_PANEL_SELECT_ICON_CLASS}>
86 <ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
87 </span>
88 </>
89 ) : (
90 children
91 ),
92 },
93 ),
94 });
95 if (!panel) {
96 return (
97 <Button
98 {...props}
99 render={render}
100 size={multiline ? "sm-multiline" : size}
101 variant={variant}
102 className={className}
103 >
104 {children}
105 </Button>
106 );
107 }
108 return control;
109}