Elffuss BraidHub

kikocis/continue public

main · 2.3 KiBRawPermalink
1import React from "react";
2import { Button } from "../../../components/ui/Button";
3import { cn } from "../../../util/cn";
4
5export interface ConfigRowProps {
6 title: string;
7 description: string;
8 icon?: React.ComponentType<React.SVGProps<SVGSVGElement>>;
9 onClick?: () => void;
10 disabled?: boolean;
11 children?: React.ReactNode;
12 className?: string;
13}
14
15export function ConfigRow({
16 title,
17 description,
18 icon: Icon,
19 onClick,
20 disabled = false,
21 children,
22 className = "",
23}: ConfigRowProps) {
24 const baseClasses =
25 "flex items-start justify-between rounded-md transition-colors px-4 py-3";
26 const interactiveClasses = onClick
27 ? "hover:bg-list-hover cursor-pointer"
28 : "";
29 const disabledClasses = disabled ? "opacity-50 cursor-not-allowed" : "";
30
31 const handleClick = (event: React.MouseEvent) => {
32 if (!disabled && onClick) {
33 const target = event.target as HTMLElement;
34 const isInteractiveChild = target.closest(
35 'button, input, textarea, select, [role="button"], [role="switch"]',
36 );
37
38 if (
39 !isInteractiveChild ||
40 target.closest("[data-config-row]") === event.currentTarget
41 ) {
42 onClick();
43 }
44 }
45 };
46
47 if (onClick) {
48 return (
49 <Button
50 variant="ghost"
51 className={cn(
52 baseClasses,
53 interactiveClasses,
54 disabledClasses,
55 "!my-0 text-left",
56 className,
57 )}
58 onClick={handleClick}
59 disabled={disabled}
60 data-config-row
61 >
62 <div className="flex flex-col">
63 <span className="text-sm font-medium">{title}</span>
64 <p className="mt-0.5 text-xs text-gray-500">{description}</p>
65 </div>
66 <div className="flex items-center gap-4">
67 {children}
68 {Icon && <Icon className="h-5 w-5 flex-shrink-0 text-gray-400" />}
69 </div>
70 </Button>
71 );
72 }
73
74 return (
75 <div
76 className={cn(baseClasses, disabledClasses, className)}
77 data-config-row
78 >
79 <div className="flex flex-col">
80 <span className="text-sm font-medium">{title}</span>
81 <p className="mt-0.5 text-xs text-gray-500">{description}</p>
82 </div>
83 <div className="flex items-center gap-4">
84 {children}
85 {Icon && <Icon className="h-5 w-5 flex-shrink-0 text-gray-400" />}
86 </div>
87 </div>
88 );
89}