Elffuss BraidHub

kikocis/continue public

main · 2.6 KiBRawPermalink
1/**
2 * A component that displays config items either as tabs (on large screens) or a popover select (on small screens)
3 */
4interface ConfigItemSelectProps {
5 items: {
6 id: string;
7 label: string;
8 icon: React.ReactNode;
9 }[];
10 activeId: string;
11 onSelect: (id: string) => void;
12}
13
14import { ChevronDownIcon } from "@heroicons/react/24/outline";
15import {
16 Popover,
17 PopoverButton,
18 PopoverPanel,
19 Transition,
20} from "../../../components/ui";
21import { fontSize } from "../../../util";
22
23export function ConfigItemSelect({
24 items,
25 activeId,
26 onSelect,
27}: ConfigItemSelectProps) {
28 const activeItem = items.find((item) => item.id === activeId);
29
30 const tabContent = (
31 <div className="hidden border-0 border-b-[1px] border-solid border-b-zinc-700 p-0.5 sm:flex sm:justify-center md:grid md:grid-cols-2 md:gap-x-2">
32 {items.map((item) => (
33 <div
34 style={{ fontSize: fontSize(-2) }}
35 key={item.id}
36 className={`hover:bg-vsc-input-background flex cursor-pointer items-center justify-center gap-1.5 rounded-md px-2 py-2 ${
37 activeId === item.id ? "" : "text-gray-400"
38 }`}
39 onClick={() => onSelect(item.id)}
40 >
41 {item.icon}
42 {item.label}
43 </div>
44 ))}
45 </div>
46 );
47
48 // Render popover on smaller screens
49 const popoverContent = (
50 <div className="mt-2 px-1.5 sm:hidden">
51 <Popover className="relative">
52 <PopoverButton
53 className="flex w-full items-center justify-between gap-2 rounded-md border border-zinc-700 px-3 py-2"
54 style={{ fontSize: fontSize(-2) }}
55 >
56 <div className="flex items-center gap-2">
57 {activeItem?.icon}
58 <span>{activeItem?.label}</span>
59 </div>
60 <ChevronDownIcon className="h-4 w-4" />
61 </PopoverButton>
62
63 <Transition>
64 <PopoverPanel className="bg-vsc-input-background absolute z-10 mt-1 w-full rounded-md border border-zinc-700 py-1">
65 {items.map((item) => (
66 <div
67 key={item.id}
68 className={`hover:bg-vsc-input-background flex cursor-pointer items-center gap-2 px-3 py-2 ${
69 activeId === item.id ? "bg-vsc-input-background" : ""
70 }`}
71 onClick={() => {
72 onSelect(item.id);
73 }}
74 >
75 {item.icon}
76 <span>{item.label}</span>
77 </div>
78 ))}
79 </PopoverPanel>
80 </Transition>
81 </Popover>
82 </div>
83 );
84
85 return (
86 <>
87 {tabContent}
88 {popoverContent}
89 </>
90 );
91}