mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 13:01:24 +00:00
- Restore currentAgentId from active session when switching scopes - Add i18n for "Agent Settings" label in agent selector - Add agent icons to settings page default agent dropdown - Replace catty.svg with new icon, use Settings icon for manage button - Fix lint: missing useCallback deps, no-restricted-globals, useMemo deps - Guard webContents.send against disposed render frames in windowManager Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
141 lines
5.4 KiB
TypeScript
141 lines
5.4 KiB
TypeScript
import React from "react";
|
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
|
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
|
import { cn } from "../../lib/utils";
|
|
import { ScrollArea } from "../ui/scroll-area";
|
|
import { TabsContent } from "../ui/tabs";
|
|
|
|
interface ToggleProps {
|
|
checked: boolean;
|
|
onChange: (checked: boolean) => void;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export const Toggle: React.FC<ToggleProps> = ({ checked, onChange, disabled }) => (
|
|
<button
|
|
type="button"
|
|
role="switch"
|
|
aria-checked={checked}
|
|
disabled={disabled}
|
|
onClick={() => onChange(!checked)}
|
|
className={cn(
|
|
"relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
|
|
checked ? "bg-primary" : "bg-input",
|
|
)}
|
|
>
|
|
<span
|
|
className={cn(
|
|
"pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform",
|
|
checked ? "translate-x-4" : "translate-x-0",
|
|
)}
|
|
/>
|
|
</button>
|
|
);
|
|
|
|
interface SelectProps {
|
|
value: string;
|
|
options: { value: string; label: string; icon?: React.ReactNode }[];
|
|
onChange: (value: string) => void;
|
|
className?: string;
|
|
disabled?: boolean;
|
|
placeholder?: string;
|
|
}
|
|
|
|
export const Select: React.FC<SelectProps> = ({
|
|
value,
|
|
options,
|
|
onChange,
|
|
className,
|
|
disabled,
|
|
placeholder,
|
|
}) => {
|
|
const selectedOption = options.find((opt) => opt.value === value);
|
|
return (
|
|
<SelectPrimitive.Root value={value} onValueChange={onChange} disabled={disabled}>
|
|
<SelectPrimitive.Trigger
|
|
className={cn(
|
|
"flex h-9 items-center justify-between rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
|
className,
|
|
)}
|
|
>
|
|
<SelectPrimitive.Value placeholder={placeholder}>
|
|
<span className="flex items-center gap-2">
|
|
{selectedOption?.icon}
|
|
{selectedOption?.label}
|
|
</span>
|
|
</SelectPrimitive.Value>
|
|
<SelectPrimitive.Icon asChild>
|
|
<ChevronDown className="ml-2 h-4 w-4 opacity-50" />
|
|
</SelectPrimitive.Icon>
|
|
</SelectPrimitive.Trigger>
|
|
<SelectPrimitive.Portal>
|
|
<SelectPrimitive.Content
|
|
className="z-[200000] max-h-80 min-w-[12rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1"
|
|
position="popper"
|
|
sideOffset={4}
|
|
>
|
|
<SelectPrimitive.ScrollUpButton className="flex cursor-default items-center justify-center py-1">
|
|
<ChevronUp className="h-4 w-4" />
|
|
</SelectPrimitive.ScrollUpButton>
|
|
<SelectPrimitive.Viewport className="p-1 h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]">
|
|
{options.map((opt) => (
|
|
<SelectPrimitive.Item
|
|
key={opt.value}
|
|
value={opt.value}
|
|
className="relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
|
|
>
|
|
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
<SelectPrimitive.ItemIndicator>
|
|
<Check className="h-4 w-4" />
|
|
</SelectPrimitive.ItemIndicator>
|
|
</span>
|
|
<SelectPrimitive.ItemText>
|
|
<span className="flex items-center gap-2">
|
|
{opt.icon}
|
|
{opt.label}
|
|
</span>
|
|
</SelectPrimitive.ItemText>
|
|
</SelectPrimitive.Item>
|
|
))}
|
|
</SelectPrimitive.Viewport>
|
|
<SelectPrimitive.ScrollDownButton className="flex cursor-default items-center justify-center py-1">
|
|
<ChevronDown className="h-4 w-4" />
|
|
</SelectPrimitive.ScrollDownButton>
|
|
</SelectPrimitive.Content>
|
|
</SelectPrimitive.Portal>
|
|
</SelectPrimitive.Root>
|
|
);
|
|
};
|
|
|
|
export const SectionHeader: React.FC<{ title: string; className?: string }> = ({
|
|
title,
|
|
className,
|
|
}) => <h3 className={cn("text-sm font-semibold text-foreground mb-3", className)}>{title}</h3>;
|
|
|
|
interface SettingRowProps {
|
|
label: string;
|
|
description?: string;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export const SettingRow: React.FC<SettingRowProps> = ({ label, description, children }) => (
|
|
<div className="flex items-center justify-between py-3 gap-4">
|
|
<div className="flex-1 min-w-0">
|
|
<div className="text-sm font-medium">{label}</div>
|
|
{description && <div className="text-xs text-muted-foreground mt-0.5">{description}</div>}
|
|
</div>
|
|
<div className="shrink-0">{children}</div>
|
|
</div>
|
|
);
|
|
|
|
export const SettingsTabContent: React.FC<{
|
|
value: string;
|
|
children: React.ReactNode;
|
|
}> = ({ value, children }) => (
|
|
<TabsContent value={value} className="flex-1 m-0 h-full overflow-hidden">
|
|
<ScrollArea className="h-full">
|
|
<div className="p-6 space-y-6">{children}</div>
|
|
</ScrollArea>
|
|
</TabsContent>
|
|
);
|