Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadDetailsControl.tsx

91 lines3.1 KB

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} from "./threadDetailsPanelStyles";
16import { ChevronDownIcon } from "lucide-react";
17​
18const parts = {
19 row: THREAD_DETAILS_PANEL_ROW_CLASS,
20 select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
21 primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
22 secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
23 icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
24 meta: THREAD_DETAILS_PANEL_META_ACTION_CLASS,
25};
26​
27export function ThreadDetailsControl({
28 panel = true,
29 part = "row",
30 multiline = false,
31 tone = "default",
32 className,
33 children,
34 size = "default",
35 variant = "default",
36 render,
37 ...props
38}: ComponentProps<typeof Button> & {
39 panel?: boolean;
40 part?: keyof typeof parts;
41 multiline?: boolean;
42 tone?: "default" | "muted" | "primary" | "destructive";
43}) {
44 const control = useRender({
45 defaultTagName: "button",
46 render,
47 props: mergeProps<"button">(
48 {
49 type: render ? undefined : "button",
50 className: cn(
51 "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",
52 parts[part],
53 multiline && "h-auto min-h-8 py-0.75 disabled:opacity-100 sm:h-auto",
54 tone === "muted" && "text-muted-foreground/70 hover:text-foreground/80",
55 tone === "primary" && "text-primary hover:text-primary",
56 tone === "destructive" &&
57 "text-destructive hover:text-destructive data-pressed:text-destructive",
58 className,
59 ),
60 },
61 props,
62 {
63 children:
64 part === "select" ? (
65 <>
66 {children}
67 <span data-slot="select-icon">
68 <ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
69 </span>
70 </>
71 ) : (
72 children
73 ),
74 },
75 ),
76 });
77 if (!panel) {
78 return (
79 <Button
80 {...props}
81 render={render}
82 size={multiline ? "sm-multiline" : size}
83 variant={variant}
84 className={className}
85 >
86 {children}
87 </Button>
88 );
89 }
90 return control;