-
This commit is contained in:
88
web/src/App.tsx
Normal file
88
web/src/App.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import {SidebarInset, SidebarMenuButton, SidebarMenuItem, SidebarProvider} from "@/components/ui/sidebar.tsx";
|
||||
import {EarthIcon, Grid2X2Icon, HomeIcon, Link2Icon, LogsIcon, SettingsIcon} from "lucide-react";
|
||||
import {AppSidebar} from "@/components/app-sidebar.tsx";
|
||||
import {Link, Route, Switch, useLocation} from "wouter";
|
||||
import {Home} from "@/pages/Home";
|
||||
import Proxies from "@/pages/Proxies.tsx";
|
||||
import {Profiles} from "@/pages/Profiles";
|
||||
import {Connections} from "@/pages/Connections.tsx";
|
||||
import {Logs} from "@/pages/Logs.tsx";
|
||||
import {Settings} from "@/pages/Settings.tsx";
|
||||
import {Toaster} from "@/components/ui/sonner.tsx";
|
||||
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
|
||||
|
||||
// Menu items.
|
||||
const items = [
|
||||
{
|
||||
title: "Home",
|
||||
url: "/",
|
||||
icon: HomeIcon,
|
||||
},
|
||||
{
|
||||
title: "Proxies",
|
||||
url: "/proxies",
|
||||
icon: EarthIcon,
|
||||
},
|
||||
{
|
||||
title: "Profiles",
|
||||
url: "/profiles",
|
||||
icon: Grid2X2Icon,
|
||||
},
|
||||
{
|
||||
title: "Connections",
|
||||
url: "/connections",
|
||||
icon: Link2Icon,
|
||||
},
|
||||
{
|
||||
title: "Logs",
|
||||
url: "/logs",
|
||||
icon: LogsIcon,
|
||||
},
|
||||
{
|
||||
title: "Settings",
|
||||
url: "/settings",
|
||||
icon: SettingsIcon,
|
||||
},
|
||||
]
|
||||
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
function App() {
|
||||
const [location] = useLocation();
|
||||
return (
|
||||
<div>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Toaster position="top-right" closeButton={true}/>
|
||||
<SidebarProvider>
|
||||
<AppSidebar>
|
||||
{items.map((item) => (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton asChild isActive={location == item.url}>
|
||||
<Link to={item.url}>
|
||||
<item.icon/>
|
||||
<span>{item.title}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
</AppSidebar>
|
||||
<SidebarInset className={'overflow-hidden'}>
|
||||
<div className={'flex-1 size-full min-h-0 min-w-0 overflow-hidden'}>
|
||||
<Switch>
|
||||
<Route path="/" component={Home}/>
|
||||
<Route path="/proxies" component={Proxies}/>
|
||||
<Route path="/profiles" component={Profiles}/>
|
||||
<Route path="/connections" component={Connections}/>
|
||||
<Route path="/logs" component={Logs}/>
|
||||
<Route path="/settings" component={Settings}/>
|
||||
</Switch>
|
||||
</div>
|
||||
</SidebarInset>
|
||||
</SidebarProvider>
|
||||
</QueryClientProvider>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
1
web/src/assets/react.svg
Normal file
1
web/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
41
web/src/components/app-content.tsx
Normal file
41
web/src/components/app-content.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from "react";
|
||||
import {cn} from "@/lib/utils.ts";
|
||||
import {ScrollArea} from "@/components/ui/scroll-area.tsx";
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||
import {type} from "@tauri-apps/plugin-os";
|
||||
|
||||
type DivProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
|
||||
export function ContentHeader({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: DivProps) {
|
||||
return (
|
||||
<div data-tauri-drag-region={type() == "macos"}
|
||||
className={cn('sticky top-0 h-12 flex items-center w-full text-2xl z-20 bg-white/10 backdrop-blur-[2px]', className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export function ScrollableBody({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
|
||||
return (
|
||||
<ScrollArea className={cn('w-full h-svh overflow-hidden py-2 pl-0 pr-4', className)} scrollClassName={'pt-12'} {...props} >
|
||||
{children}
|
||||
</ScrollArea>
|
||||
)
|
||||
}
|
||||
|
||||
export const Container = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: DivProps) => {
|
||||
return <div className={cn('w-full border rounded-md p-4', className)} {...props}>{children}</div>
|
||||
}
|
||||
163
web/src/components/app-sidebar.tsx
Normal file
163
web/src/components/app-sidebar.tsx
Normal file
@@ -0,0 +1,163 @@
|
||||
import {Command, Loader2, Play, Power} from "lucide-react"
|
||||
import {type} from '@tauri-apps/plugin-os';
|
||||
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel, SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from "@/components/ui/sidebar"
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {ReactNode} from "react";
|
||||
import {cn} from "@/lib/utils.ts";
|
||||
import {useMutation, useQuery} from "@tanstack/react-query";
|
||||
import {invokeCommand} from "@/lib/invoke.ts";
|
||||
|
||||
type Status =
|
||||
| { status: "NotStart" }
|
||||
| { status: "Running" }
|
||||
| { status: "Exited"; code: number }
|
||||
|
||||
const delay = (ms: number) => new Promise<void>((resolve) => {
|
||||
const timer = setTimeout(resolve, ms)
|
||||
// 返回一个清理函数
|
||||
return () => clearTimeout(timer)
|
||||
})
|
||||
|
||||
function MihomoStateBar() {
|
||||
const {data: status} = useQuery({
|
||||
queryKey: ['mihomo_status'],
|
||||
queryFn: async () => invokeCommand<Status>('mihomo_status'),
|
||||
refetchInterval: 1000
|
||||
})
|
||||
|
||||
const switchCore = useMutation({
|
||||
mutationFn: async () => {
|
||||
const duration = delay(1000)
|
||||
if (status?.status == "Running") {
|
||||
await invokeCommand<void>('mihomo_stop')
|
||||
} else {
|
||||
await invokeCommand<void>('mihomo_start')
|
||||
}
|
||||
await duration
|
||||
}
|
||||
})
|
||||
|
||||
const isRunning = status?.status == "Running";
|
||||
const isStarting = switchCore.isPending;
|
||||
|
||||
return <div className={cn(
|
||||
"flex items-center justify-between p-3 rounded-md transition-all duration-500",
|
||||
isStarting
|
||||
? "bg-yellow-500/10"
|
||||
: isRunning ? "bg-green-500/10" : "bg-transparent hover:bg-sidebar-accent"
|
||||
)}>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="relative h-2.5 w-2.5">
|
||||
{/*呼吸灯效果*/}
|
||||
{(isStarting || isRunning) && (
|
||||
<span
|
||||
className={cn(
|
||||
"absolute inset-0 rounded-full opacity-75 animate-ping",
|
||||
isStarting ? "bg-yellow-500" : "bg-green-500"
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<span
|
||||
className={cn(
|
||||
"relative block h-2.5 w-2.5 rounded-full",
|
||||
isStarting
|
||||
? "bg-yellow-500"
|
||||
: isRunning
|
||||
? "bg-green-500"
|
||||
: "bg-gray-400"
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="flex flex-col overflow-hidden transition-all duration-300 group-data-[collapsible=icon]:w-0 group-data-[collapsible=icon]:opacity-0">
|
||||
<span
|
||||
className={cn(
|
||||
"text-xs font-semibold whitespace-nowrap",
|
||||
isStarting
|
||||
? "text-yellow-600"
|
||||
: isRunning
|
||||
? "text-green-600"
|
||||
: "text-muted-foreground"
|
||||
)}
|
||||
>
|
||||
Clash
|
||||
</span>
|
||||
<span className="text-[10px] text-muted-foreground truncate">
|
||||
{isStarting ? "Starting..." : isRunning ? "Running" : "Stopped"}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={switchCore.isPending}
|
||||
className={cn(
|
||||
"h-8 w-8 rounded-lg transition-all duration-300 shrink-0",
|
||||
isStarting
|
||||
? "text-yellow-600 hover:text-yellow-700 hover:bg-yellow-500/10"
|
||||
: isRunning ? "text-green-600 hover:text-green-700 hover:bg-green-500/10" : "text-muted-foreground hover:text-foreground hover:bg-accent"
|
||||
)}
|
||||
onClick={() => switchCore.mutate()}
|
||||
>
|
||||
{switchCore.isPending ? (
|
||||
<Loader2 className="size-4 animate-spin"/>
|
||||
) : isRunning ? (
|
||||
<Power className="size-4"/>
|
||||
) : (
|
||||
<Play className="size-4 ml-0.5"/>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
|
||||
export function AppSidebar({children}: { children: ReactNode }) {
|
||||
return (
|
||||
<Sidebar collapsible='icon' variant='floating'>
|
||||
<SidebarHeader>
|
||||
{/*macOS only*/}
|
||||
{type() == "macos" && <div className='h-3'/>}
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton size="lg" asChild>
|
||||
<a href="#">
|
||||
<div>
|
||||
<Command className="size-4"/>
|
||||
</div>
|
||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||
<span className="truncate font-medium">Acme Inc</span>
|
||||
<span className="truncate text-xs">Enterprise</span>
|
||||
</div>
|
||||
</a>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Application</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{children}
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<MihomoStateBar/>
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
32
web/src/components/button.tsx
Normal file
32
web/src/components/button.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import {Tooltip, TooltipContent} from "@/components/ui/tooltip.tsx";
|
||||
import {TooltipTrigger} from "@radix-ui/react-tooltip";
|
||||
import {ReactNode} from "react";
|
||||
import * as React from "react";
|
||||
import type {VariantProps} from "class-variance-authority";
|
||||
import {Button, buttonVariants} from "@/components/ui/button.tsx";
|
||||
|
||||
|
||||
export function TipButton({tipContent, ...props}: {
|
||||
children: ReactNode,
|
||||
tipContent?: ReactNode,
|
||||
} & React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
if (!tipContent) {
|
||||
return <Button {...props}/>
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Button {...props}/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
{tipContent}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
304
web/src/components/settings/tun-config-modal.tsx
Normal file
304
web/src/components/settings/tun-config-modal.tsx
Normal file
@@ -0,0 +1,304 @@
|
||||
import { useState } from "react"
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
|
||||
import { InfoIcon, XIcon, PlusIcon } from "lucide-react"
|
||||
import { TunConfig } from "@/lib/types"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
interface TunConfigModalProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
config: TunConfig
|
||||
onSave: (config: TunConfig) => void
|
||||
}
|
||||
|
||||
interface ConfigRowProps {
|
||||
label: string
|
||||
tooltip?: string
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
function ConfigRow({ label, tooltip, children }: ConfigRowProps) {
|
||||
return (
|
||||
<div className="flex items-center justify-between py-2.5 hover:bg-muted/30 px-2 -mx-2 rounded transition-colors">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<label className="text-xs font-medium text-foreground/90">{label}</label>
|
||||
{tooltip && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<InfoIcon className="size-3 text-muted-foreground/60 cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right" className="max-w-[280px] text-xs">
|
||||
{tooltip}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<div>{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface ConfigFieldProps {
|
||||
label: string
|
||||
tooltip?: string
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
function ConfigField({ label, tooltip, children }: ConfigFieldProps) {
|
||||
return (
|
||||
<div className="space-y-2 py-2">
|
||||
<div className="flex items-center gap-1.5 px-2">
|
||||
<label className="text-xs font-medium text-foreground/90">{label}</label>
|
||||
{tooltip && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<InfoIcon className="size-3 text-muted-foreground/60 cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right" className="max-w-[280px] text-xs">
|
||||
{tooltip}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<div className="px-2">{children}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Divider() {
|
||||
return <div className="h-px bg-border/50 my-3" />
|
||||
}
|
||||
|
||||
export function TunConfigModal({
|
||||
open,
|
||||
onOpenChange,
|
||||
config: initialConfig,
|
||||
onSave,
|
||||
}: TunConfigModalProps) {
|
||||
const [config, setConfig] = useState<TunConfig>(initialConfig)
|
||||
const [dnsInput, setDnsInput] = useState('')
|
||||
|
||||
const updateConfig = <K extends keyof TunConfig>(
|
||||
key: K,
|
||||
value: TunConfig[K]
|
||||
) => {
|
||||
const newConfig = { ...config, [key]: value }
|
||||
setConfig(newConfig)
|
||||
onSave(newConfig) // 实时保存
|
||||
}
|
||||
|
||||
const addDnsHijack = () => {
|
||||
if (dnsInput.trim()) {
|
||||
const newDnsHijack = [...(config.dnsHijack || []), dnsInput.trim()]
|
||||
updateConfig('dnsHijack', newDnsHijack)
|
||||
setDnsInput('')
|
||||
}
|
||||
}
|
||||
|
||||
const removeDnsHijack = (index: number) => {
|
||||
const newDnsHijack = config.dnsHijack.filter((_, i) => i !== index)
|
||||
updateConfig('dnsHijack', newDnsHijack)
|
||||
}
|
||||
|
||||
const handleDnsInputKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
addDnsHijack()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent side="right" className="w-[340px] p-0 flex flex-col gap-0" showCloseButton={false}>
|
||||
<SheetHeader className="px-5 pt-5 pb-3 border-b">
|
||||
<SheetTitle className="text-sm font-semibold">TUN 模式配置</SheetTitle>
|
||||
<SheetDescription className="text-xs">
|
||||
配置虚拟网卡模式参数
|
||||
</SheetDescription>
|
||||
</SheetHeader>
|
||||
|
||||
<ScrollArea className="flex-1 px-5">
|
||||
<div className="py-4">
|
||||
{/* 基础开关 */}
|
||||
<ConfigRow label="启用 TUN">
|
||||
<Switch
|
||||
checked={config.enable}
|
||||
onCheckedChange={(checked) => updateConfig('enable', checked)}
|
||||
/>
|
||||
</ConfigRow>
|
||||
|
||||
<ConfigRow
|
||||
label="自动检测接口"
|
||||
tooltip="自动识别出口网卡"
|
||||
>
|
||||
<Switch
|
||||
checked={config.autoDetectInterface ?? false}
|
||||
onCheckedChange={(checked) =>
|
||||
updateConfig('autoDetectInterface', checked)
|
||||
}
|
||||
/>
|
||||
</ConfigRow>
|
||||
|
||||
<ConfigRow
|
||||
label="自动配置路由"
|
||||
tooltip="自动配置系统路由表"
|
||||
>
|
||||
<Switch
|
||||
checked={config.autoRoute ?? false}
|
||||
onCheckedChange={(checked) => updateConfig('autoRoute', checked)}
|
||||
/>
|
||||
</ConfigRow>
|
||||
|
||||
<ConfigRow
|
||||
label="自动重定向"
|
||||
tooltip="自动配置 iptables 重定向 TCP 连接(仅 Linux)"
|
||||
>
|
||||
<Switch
|
||||
checked={config.autoRedirect ?? false}
|
||||
onCheckedChange={(checked) =>
|
||||
updateConfig('autoRedirect', checked)
|
||||
}
|
||||
/>
|
||||
</ConfigRow>
|
||||
|
||||
<ConfigRow
|
||||
label="禁用 ICMP 转发"
|
||||
tooltip="防止 ICMP 环回问题,ping 将不会显示真实延迟"
|
||||
>
|
||||
<Switch
|
||||
checked={config.disableIcmpForwarding ?? false}
|
||||
onCheckedChange={(checked) =>
|
||||
updateConfig('disableIcmpForwarding', checked)
|
||||
}
|
||||
/>
|
||||
</ConfigRow>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 网络栈 - 并列切换 */}
|
||||
<ConfigField
|
||||
label="网络栈"
|
||||
tooltip="选择 TUN 设备使用的网络栈实现"
|
||||
>
|
||||
<div className="flex gap-1.5">
|
||||
<Button
|
||||
variant={config.stack === 'system' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className={cn(
|
||||
"flex-1 h-7 text-xs",
|
||||
config.stack === 'system' && "shadow-none"
|
||||
)}
|
||||
onClick={() => updateConfig('stack', 'system')}
|
||||
>
|
||||
System
|
||||
</Button>
|
||||
<Button
|
||||
variant={config.stack === 'gvisor' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className={cn(
|
||||
"flex-1 h-7 text-xs",
|
||||
config.stack === 'gvisor' && "shadow-none"
|
||||
)}
|
||||
onClick={() => updateConfig('stack', 'gvisor')}
|
||||
>
|
||||
gVisor
|
||||
</Button>
|
||||
<Button
|
||||
variant={config.stack === 'mixed' ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
className={cn(
|
||||
"flex-1 h-7 text-xs",
|
||||
config.stack === 'mixed' && "shadow-none"
|
||||
)}
|
||||
onClick={() => updateConfig('stack', 'mixed')}
|
||||
>
|
||||
Mixed
|
||||
</Button>
|
||||
</div>
|
||||
</ConfigField>
|
||||
|
||||
{/* 输入配置 */}
|
||||
|
||||
<ConfigField
|
||||
label="MTU"
|
||||
tooltip="最大传输单元,默认 9000"
|
||||
>
|
||||
<Input
|
||||
type="number"
|
||||
value={config.mtu || ''}
|
||||
onChange={(e) => updateConfig('mtu', parseInt(e.target.value) || undefined)}
|
||||
placeholder="9000"
|
||||
className="h-7 text-xs shadow-none"
|
||||
/>
|
||||
</ConfigField>
|
||||
|
||||
<ConfigField
|
||||
label="DNS 劫持"
|
||||
tooltip="需要劫持的 DNS 地址(例如:0.0.0.0:53)"
|
||||
>
|
||||
<div className="space-y-2">
|
||||
{/* DNS 列表 */}
|
||||
{config.dnsHijack && config.dnsHijack.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{config.dnsHijack.map((dns, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="inline-flex items-center gap-1 bg-muted hover:bg-muted/80 text-foreground rounded px-2 py-1 text-xs font-mono transition-colors"
|
||||
>
|
||||
<span>{dns}</span>
|
||||
<button
|
||||
onClick={() => removeDnsHijack(index)}
|
||||
className="hover:text-destructive transition-colors"
|
||||
>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 添加输入框 */}
|
||||
<div className="flex gap-1.5">
|
||||
<Input
|
||||
value={dnsInput}
|
||||
onChange={(e) => setDnsInput(e.target.value)}
|
||||
onKeyDown={handleDnsInputKeyDown}
|
||||
placeholder="0.0.0.0:53"
|
||||
className="h-7 text-xs shadow-none font-mono flex-1"
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-7 w-7 p-0"
|
||||
onClick={addDnsHijack}
|
||||
>
|
||||
<PlusIcon className="size-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</ConfigField>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<SheetFooter className="px-5 py-3 border-t mt-auto">
|
||||
<Button variant="outline" size="sm" onClick={() => onOpenChange(false)} className="w-full">
|
||||
关闭
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
133
web/src/components/tun-settings-dialog.tsx
Normal file
133
web/src/components/tun-settings-dialog.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
// import {useState, useEffect} from "react";
|
||||
// import {Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogClose} from "@/components/ui/dialog";
|
||||
// import {Button} from "@/components/ui/button";
|
||||
// import {Input} from "@/components/ui/input";
|
||||
// import {Label} from "@/components/ui/label";
|
||||
// import {Switch} from "@/components/ui/switch";
|
||||
// import {TunConfig} from "@/lib/types";
|
||||
// import {toast} from "sonner";
|
||||
// import {Tabs, TabsList, TabsTrigger} from "@/components/ui/tabs.tsx";
|
||||
//
|
||||
// interface TunSettingsDialogProps {
|
||||
// open: boolean;
|
||||
// onOpenChange: (open: boolean) => void;
|
||||
// config: TunConfig;
|
||||
// onSave: (config: TunConfig) => Promise<void>;
|
||||
// }
|
||||
//
|
||||
// export function TunSettingsDialog({open, onOpenChange, config, onSave}: TunSettingsDialogProps) {
|
||||
// const [localConfig, setLocalConfig] = useState<TunConfig>(config);
|
||||
//
|
||||
// useEffect(() => {
|
||||
// setLocalConfig(config);
|
||||
// }, [config, open]);
|
||||
//
|
||||
// const handleSave = async () => {
|
||||
// try {
|
||||
// await onSave(localConfig);
|
||||
// onOpenChange(false);
|
||||
// toast.success("TUN settings saved successfully");
|
||||
// } catch (error) {
|
||||
// console.error(error);
|
||||
// // toast.error is handled in fetch wrapper usually, but good to be safe
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// return (
|
||||
// <Dialog open={open} onOpenChange={onOpenChange}>
|
||||
// <DialogContent className="sm:max-w-[425px]">
|
||||
// <DialogHeader>
|
||||
// <DialogTitle>TUN Mode Settings</DialogTitle>
|
||||
// </DialogHeader>
|
||||
// <div className="grid gap-4 py-4">
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="stack" className="text-right">
|
||||
// Stack
|
||||
// </Label>
|
||||
//
|
||||
// <div className="col-span-3 flex justify-end">
|
||||
// <Tabs defaultValue={'system'}>
|
||||
// <TabsList>
|
||||
// <TabsTrigger value={'system'}>System</TabsTrigger>
|
||||
// <TabsTrigger value={'gvisor'}>Gvisor</TabsTrigger>
|
||||
// <TabsTrigger value={'mixed'}>Mixed</TabsTrigger>
|
||||
// </TabsList>
|
||||
// </Tabs>
|
||||
// </div>
|
||||
// </div>
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="auto-route" className="text-right">
|
||||
// Auto Route
|
||||
// </Label>
|
||||
// <div className="col-span-3 flex justify-end">
|
||||
// <Switch
|
||||
// id="auto-route"
|
||||
// checked={localConfig.auto_route}
|
||||
// onCheckedChange={(checked) => setLocalConfig({...localConfig, auto_route: checked})}
|
||||
// />
|
||||
// </div>
|
||||
// </div>
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="strict-route" className="text-right">
|
||||
// Strict Route
|
||||
// </Label>
|
||||
// <div className="col-span-3 flex justify-end">
|
||||
// <Switch
|
||||
// id="strict-route"
|
||||
// checked={localConfig.strict_route}
|
||||
// onCheckedChange={(checked) => setLocalConfig({...localConfig, strict_route: checked})}
|
||||
// />
|
||||
// </div>
|
||||
// </div>
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="device" className="text-right">
|
||||
// Device
|
||||
// </Label>
|
||||
// <Input
|
||||
// id="device"
|
||||
// value={localConfig.device}
|
||||
// onChange={(e) => setLocalConfig({...localConfig, device: e.target.value})}
|
||||
// className="col-span-3"
|
||||
// />
|
||||
// </div>
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="mtu" className="text-right">
|
||||
// MTU
|
||||
// </Label>
|
||||
// <Input
|
||||
// id="mtu"
|
||||
// type="number"
|
||||
// value={localConfig.mtu}
|
||||
// onChange={(e) => setLocalConfig({...localConfig, mtu: parseInt(e.target.value) || 0})}
|
||||
// className="col-span-3"
|
||||
// />
|
||||
// </div>
|
||||
// <div className="grid grid-cols-4 items-center gap-4">
|
||||
// <Label htmlFor="dns-hijack" className="text-right">
|
||||
// DNS Hijack
|
||||
// </Label>
|
||||
// <Input
|
||||
// id="dns-hijack"
|
||||
// value={localConfig.dns_hijack.join(", ")}
|
||||
// onChange={(e) =>
|
||||
// setLocalConfig({
|
||||
// ...localConfig,
|
||||
// dns_hijack: e.target.value.split(",").map((s) => s.trim()).filter(Boolean),
|
||||
// })
|
||||
// }
|
||||
// className="col-span-3"
|
||||
// placeholder="any:53, tcp://any:53"
|
||||
// />
|
||||
// </div>
|
||||
//
|
||||
// </div>
|
||||
// <DialogFooter>
|
||||
// <DialogClose asChild>
|
||||
// <Button variant="outline">Cancel</Button>
|
||||
// </DialogClose>
|
||||
// <Button onClick={handleSave}>Save changes</Button>
|
||||
// </DialogFooter>
|
||||
// </DialogContent>
|
||||
// </Dialog>
|
||||
// );
|
||||
// }
|
||||
64
web/src/components/ui/accordion.tsx
Normal file
64
web/src/components/ui/accordion.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import * as React from "react"
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
||||
import { ChevronDownIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Accordion({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
return <AccordionPrimitive.Root data-slot="accordion" {...props} />
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("border-b last:border-b-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
||||
return (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon className="text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
data-slot="accordion-content"
|
||||
className="data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm duration-75"
|
||||
{...props}
|
||||
>
|
||||
<div className={cn("pt-0 pb-4", className)}>{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
)
|
||||
}
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
||||
51
web/src/components/ui/avatar.tsx
Normal file
51
web/src/components/ui/avatar.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as React from "react"
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
className={cn(
|
||||
"relative flex size-8 shrink-0 overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarImage({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn("aspect-square size-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
"bg-muted flex size-full items-center justify-center rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback }
|
||||
46
web/src/components/ui/badge.tsx
Normal file
46
web/src/components/ui/badge.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||
secondary:
|
||||
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||
destructive:
|
||||
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "span"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants }
|
||||
83
web/src/components/ui/button-group.tsx
Normal file
83
web/src/components/ui/button-group.tsx
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
|
||||
const buttonGroupVariants = cva(
|
||||
"flex w-fit items-stretch [&>*]:focus-visible:z-10 [&>*]:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md has-[>[data-slot=button-group]]:gap-2",
|
||||
{
|
||||
variants: {
|
||||
orientation: {
|
||||
horizontal:
|
||||
"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
|
||||
vertical:
|
||||
"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
orientation: "horizontal",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function ButtonGroup({
|
||||
className,
|
||||
orientation,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="button-group"
|
||||
data-orientation={orientation}
|
||||
className={cn(buttonGroupVariants({ orientation }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ButtonGroupText({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(
|
||||
"bg-muted flex items-center gap-2 rounded-md border px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ButtonGroupSeparator({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="button-group-separator"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-input relative !m-0 self-stretch data-[orientation=vertical]:h-auto",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
ButtonGroup,
|
||||
ButtonGroupSeparator,
|
||||
ButtonGroupText,
|
||||
buttonGroupVariants,
|
||||
}
|
||||
60
web/src/components/ui/button.tsx
Normal file
60
web/src/components/ui/button.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
destructive:
|
||||
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||
outline:
|
||||
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
ghost:
|
||||
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||
icon: "size-9",
|
||||
"icon-sm": "size-8",
|
||||
"icon-lg": "size-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="button"
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Button, buttonVariants }
|
||||
92
web/src/components/ui/card.tsx
Normal file
92
web/src/components/ui/card.tsx
Normal file
@@ -0,0 +1,92 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
className={cn(
|
||||
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn("leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn(
|
||||
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-content"
|
||||
className={cn("px-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Card,
|
||||
CardHeader,
|
||||
CardFooter,
|
||||
CardTitle,
|
||||
CardAction,
|
||||
CardDescription,
|
||||
CardContent,
|
||||
}
|
||||
250
web/src/components/ui/context-menu.tsx
Normal file
250
web/src/components/ui/context-menu.tsx
Normal file
@@ -0,0 +1,250 @@
|
||||
import * as React from "react"
|
||||
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu"
|
||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ContextMenu({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Root>) {
|
||||
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
|
||||
}
|
||||
|
||||
function ContextMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Trigger>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Trigger data-slot="context-menu-trigger" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Group>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Group data-slot="context-menu-group" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Portal>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal data-slot="context-menu-portal" {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSub({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Sub>) {
|
||||
return <ContextMenuPrimitive.Sub data-slot="context-menu-sub" {...props} />
|
||||
}
|
||||
|
||||
function ContextMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioGroup>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioGroup
|
||||
data-slot="context-menu-radio-group"
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubTrigger
|
||||
data-slot="context-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</ContextMenuPrimitive.SubTrigger>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.SubContent
|
||||
data-slot="context-menu-sub-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Content>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<ContextMenuPrimitive.Content
|
||||
data-slot="context-menu-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
variant?: "default" | "destructive"
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Item
|
||||
data-slot="context-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.CheckboxItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.CheckboxItem
|
||||
data-slot="context-menu-checkbox-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.CheckboxItem>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.RadioItem>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.RadioItem
|
||||
data-slot="context-menu-radio-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<CircleIcon className="size-2 fill-current" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.RadioItem>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Label
|
||||
data-slot="context-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"text-foreground px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<ContextMenuPrimitive.Separator
|
||||
data-slot="context-menu-separator"
|
||||
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ContextMenuShortcut({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="context-menu-shortcut"
|
||||
className={cn(
|
||||
"text-muted-foreground ml-auto text-xs tracking-widest",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
ContextMenu,
|
||||
ContextMenuTrigger,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuCheckboxItem,
|
||||
ContextMenuRadioItem,
|
||||
ContextMenuLabel,
|
||||
ContextMenuSeparator,
|
||||
ContextMenuShortcut,
|
||||
ContextMenuGroup,
|
||||
ContextMenuPortal,
|
||||
ContextMenuSub,
|
||||
ContextMenuSubContent,
|
||||
ContextMenuSubTrigger,
|
||||
ContextMenuRadioGroup,
|
||||
}
|
||||
141
web/src/components/ui/dialog.tsx
Normal file
141
web/src/components/ui/dialog.tsx
Normal file
@@ -0,0 +1,141 @@
|
||||
import * as React from "react"
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Dialog({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||
}
|
||||
|
||||
function DialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||
}
|
||||
|
||||
function DialogPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||
}
|
||||
|
||||
function DialogClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal data-slot="dialog-portal">
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close
|
||||
data-slot="dialog-close"
|
||||
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
||||
>
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-header"
|
||||
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("text-lg leading-none font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
}
|
||||
104
web/src/components/ui/empty.tsx
Normal file
104
web/src/components/ui/empty.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Empty({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty"
|
||||
className={cn(
|
||||
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-header"
|
||||
className={cn(
|
||||
"flex max-w-sm flex-col items-center gap-2 text-center",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const emptyMediaVariants = cva(
|
||||
"flex shrink-0 items-center justify-center mb-2 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
icon: "bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-lg [&_svg:not([class*='size-'])]:size-6",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function EmptyMedia({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-icon"
|
||||
data-variant={variant}
|
||||
className={cn(emptyMediaVariants({ variant, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-title"
|
||||
className={cn("text-lg font-medium tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-description"
|
||||
className={cn(
|
||||
"text-muted-foreground [&>a:hover]:text-primary text-sm/relaxed [&>a]:underline [&>a]:underline-offset-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-content"
|
||||
className={cn(
|
||||
"flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Empty,
|
||||
EmptyHeader,
|
||||
EmptyTitle,
|
||||
EmptyDescription,
|
||||
EmptyContent,
|
||||
EmptyMedia,
|
||||
}
|
||||
246
web/src/components/ui/field.tsx
Normal file
246
web/src/components/ui/field.tsx
Normal file
@@ -0,0 +1,246 @@
|
||||
import { useMemo } from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
|
||||
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
||||
return (
|
||||
<fieldset
|
||||
data-slot="field-set"
|
||||
className={cn(
|
||||
"flex flex-col gap-6",
|
||||
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldLegend({
|
||||
className,
|
||||
variant = "legend",
|
||||
...props
|
||||
}: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
|
||||
return (
|
||||
<legend
|
||||
data-slot="field-legend"
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"mb-3 font-medium",
|
||||
"data-[variant=legend]:text-base",
|
||||
"data-[variant=label]:text-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-group"
|
||||
className={cn(
|
||||
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const fieldVariants = cva(
|
||||
"group/field flex w-full gap-3 data-[invalid=true]:text-destructive",
|
||||
{
|
||||
variants: {
|
||||
orientation: {
|
||||
vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],
|
||||
horizontal: [
|
||||
"flex-row items-center",
|
||||
"[&>[data-slot=field-label]]:flex-auto",
|
||||
"has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
||||
],
|
||||
responsive: [
|
||||
"flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto",
|
||||
"@md/field-group:[&>[data-slot=field-label]]:flex-auto",
|
||||
"@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
||||
],
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
orientation: "vertical",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Field({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="field"
|
||||
data-orientation={orientation}
|
||||
className={cn(fieldVariants({ orientation }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-content"
|
||||
className={cn(
|
||||
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Label>) {
|
||||
return (
|
||||
<Label
|
||||
data-slot="field-label"
|
||||
className={cn(
|
||||
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
||||
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
|
||||
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-label"
|
||||
className={cn(
|
||||
"flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<p
|
||||
data-slot="field-description"
|
||||
className={cn(
|
||||
"text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
||||
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
|
||||
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
children?: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-separator"
|
||||
data-content={!!children}
|
||||
className={cn(
|
||||
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<Separator className="absolute inset-0 top-1/2" />
|
||||
{children && (
|
||||
<span
|
||||
className="bg-background text-muted-foreground relative mx-auto block w-fit px-2"
|
||||
data-slot="field-separator-content"
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function FieldError({
|
||||
className,
|
||||
children,
|
||||
errors,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
errors?: Array<{ message?: string } | undefined>
|
||||
}) {
|
||||
const content = useMemo(() => {
|
||||
if (children) {
|
||||
return children
|
||||
}
|
||||
|
||||
if (!errors?.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const uniqueErrors = [
|
||||
...new Map(errors.map((error) => [error?.message, error])).values(),
|
||||
]
|
||||
|
||||
if (uniqueErrors?.length == 1) {
|
||||
return uniqueErrors[0]?.message
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="ml-4 flex list-disc flex-col gap-1">
|
||||
{uniqueErrors.map(
|
||||
(error, index) =>
|
||||
error?.message && <li key={index}>{error.message}</li>
|
||||
)}
|
||||
</ul>
|
||||
)
|
||||
}, [children, errors])
|
||||
|
||||
if (!content) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
data-slot="field-error"
|
||||
className={cn("text-destructive text-sm font-normal", className)}
|
||||
{...props}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Field,
|
||||
FieldLabel,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLegend,
|
||||
FieldSeparator,
|
||||
FieldSet,
|
||||
FieldContent,
|
||||
FieldTitle,
|
||||
}
|
||||
167
web/src/components/ui/form.tsx
Normal file
167
web/src/components/ui/form.tsx
Normal file
@@ -0,0 +1,167 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import {
|
||||
Controller,
|
||||
FormProvider,
|
||||
useFormContext,
|
||||
useFormState,
|
||||
type ControllerProps,
|
||||
type FieldPath,
|
||||
type FieldValues,
|
||||
} from "react-hook-form"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Label } from "@/components/ui/label"
|
||||
|
||||
const Form = FormProvider
|
||||
|
||||
type FormFieldContextValue<
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
> = {
|
||||
name: TName
|
||||
}
|
||||
|
||||
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||
{} as FormFieldContextValue
|
||||
)
|
||||
|
||||
const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => {
|
||||
return (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
const useFormField = () => {
|
||||
const fieldContext = React.useContext(FormFieldContext)
|
||||
const itemContext = React.useContext(FormItemContext)
|
||||
const { getFieldState } = useFormContext()
|
||||
const formState = useFormState({ name: fieldContext.name })
|
||||
const fieldState = getFieldState(fieldContext.name, formState)
|
||||
|
||||
if (!fieldContext) {
|
||||
throw new Error("useFormField should be used within <FormField>")
|
||||
}
|
||||
|
||||
const { id } = itemContext
|
||||
|
||||
return {
|
||||
id,
|
||||
name: fieldContext.name,
|
||||
formItemId: `${id}-form-item`,
|
||||
formDescriptionId: `${id}-form-item-description`,
|
||||
formMessageId: `${id}-form-item-message`,
|
||||
...fieldState,
|
||||
}
|
||||
}
|
||||
|
||||
type FormItemContextValue = {
|
||||
id: string
|
||||
}
|
||||
|
||||
const FormItemContext = React.createContext<FormItemContextValue>(
|
||||
{} as FormItemContextValue
|
||||
)
|
||||
|
||||
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||
const id = React.useId()
|
||||
|
||||
return (
|
||||
<FormItemContext.Provider value={{ id }}>
|
||||
<div
|
||||
data-slot="form-item"
|
||||
className={cn("grid gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
</FormItemContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function FormLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
const { error, formItemId } = useFormField()
|
||||
|
||||
return (
|
||||
<Label
|
||||
data-slot="form-label"
|
||||
data-error={!!error}
|
||||
className={cn("data-[error=true]:text-destructive", className)}
|
||||
htmlFor={formItemId}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
||||
|
||||
return (
|
||||
<Slot
|
||||
data-slot="form-control"
|
||||
id={formItemId}
|
||||
aria-describedby={
|
||||
!error
|
||||
? `${formDescriptionId}`
|
||||
: `${formDescriptionId} ${formMessageId}`
|
||||
}
|
||||
aria-invalid={!!error}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { formDescriptionId } = useFormField()
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-description"
|
||||
id={formDescriptionId}
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||
const { error, formMessageId } = useFormField()
|
||||
const body = error ? String(error?.message ?? "") : props.children
|
||||
|
||||
if (!body) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<p
|
||||
data-slot="form-message"
|
||||
id={formMessageId}
|
||||
className={cn("text-destructive text-sm", className)}
|
||||
{...props}
|
||||
>
|
||||
{body}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
useFormField,
|
||||
Form,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormControl,
|
||||
FormDescription,
|
||||
FormMessage,
|
||||
FormField,
|
||||
}
|
||||
168
web/src/components/ui/input-group.tsx
Normal file
168
web/src/components/ui/input-group.tsx
Normal file
@@ -0,0 +1,168 @@
|
||||
import * as React from "react"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
|
||||
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="input-group"
|
||||
role="group"
|
||||
className={cn(
|
||||
"group/input-group border-input dark:bg-input/30 relative flex w-full items-center rounded-md border shadow-xs transition-[color,box-shadow] outline-none",
|
||||
"h-9 min-w-0 has-[>textarea]:h-auto",
|
||||
|
||||
// Variants based on alignment.
|
||||
"has-[>[data-align=inline-start]]:[&>input]:pl-2",
|
||||
"has-[>[data-align=inline-end]]:[&>input]:pr-2",
|
||||
"has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3",
|
||||
"has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3",
|
||||
|
||||
// Focus state.
|
||||
"has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot=input-group-control]:focus-visible]:ring-[3px]",
|
||||
|
||||
// Error state.
|
||||
"has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
|
||||
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const inputGroupAddonVariants = cva(
|
||||
"text-muted-foreground flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium select-none [&>svg:not([class*='size-'])]:size-4 [&>kbd]:rounded-[calc(var(--radius)-5px)] group-data-[disabled=true]/input-group:opacity-50",
|
||||
{
|
||||
variants: {
|
||||
align: {
|
||||
"inline-start":
|
||||
"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
|
||||
"inline-end":
|
||||
"order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
|
||||
"block-start":
|
||||
"order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3 group-has-[>input]/input-group:pt-2.5",
|
||||
"block-end":
|
||||
"order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3 group-has-[>input]/input-group:pb-2.5",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
align: "inline-start",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function InputGroupAddon({
|
||||
className,
|
||||
align = "inline-start",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="input-group-addon"
|
||||
data-align={align}
|
||||
className={cn(inputGroupAddonVariants({ align }), className)}
|
||||
onClick={(e) => {
|
||||
if ((e.target as HTMLElement).closest("button")) {
|
||||
return
|
||||
}
|
||||
e.currentTarget.parentElement?.querySelector("input")?.focus()
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const inputGroupButtonVariants = cva(
|
||||
"text-sm shadow-none flex gap-2 items-center",
|
||||
{
|
||||
variants: {
|
||||
size: {
|
||||
xs: "h-6 gap-1 px-2 rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-3.5 has-[>svg]:px-2",
|
||||
sm: "h-8 px-2.5 gap-1.5 rounded-md has-[>svg]:px-2.5",
|
||||
"icon-xs":
|
||||
"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
||||
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "xs",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function InputGroupButton({
|
||||
className,
|
||||
type = "button",
|
||||
variant = "ghost",
|
||||
size = "xs",
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof Button>, "size"> &
|
||||
VariantProps<typeof inputGroupButtonVariants>) {
|
||||
return (
|
||||
<Button
|
||||
type={type}
|
||||
data-size={size}
|
||||
variant={variant}
|
||||
className={cn(inputGroupButtonVariants({ size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="input-group-control"
|
||||
className={cn(
|
||||
"flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function InputGroupTextarea({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<Textarea
|
||||
data-slot="input-group-control"
|
||||
className={cn(
|
||||
"flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupText,
|
||||
InputGroupInput,
|
||||
InputGroupTextarea,
|
||||
}
|
||||
21
web/src/components/ui/input.tsx
Normal file
21
web/src/components/ui/input.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Input }
|
||||
193
web/src/components/ui/item.tsx
Normal file
193
web/src/components/ui/item.tsx
Normal file
@@ -0,0 +1,193 @@
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
|
||||
function ItemGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
role="list"
|
||||
data-slot="item-group"
|
||||
className={cn("group/item-group flex flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="item-separator"
|
||||
orientation="horizontal"
|
||||
className={cn("my-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const itemVariants = cva(
|
||||
"group/item flex items-center border border-transparent text-sm rounded-md transition-colors [a]:hover:bg-accent/50 [a]:transition-colors duration-100 flex-wrap outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
outline: "border-border",
|
||||
muted: "bg-muted/50",
|
||||
},
|
||||
size: {
|
||||
default: "p-4 gap-4 ",
|
||||
sm: "py-3 px-4 gap-2.5",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Item({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> &
|
||||
VariantProps<typeof itemVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
return (
|
||||
<Comp
|
||||
data-slot="item"
|
||||
data-variant={variant}
|
||||
data-size={size}
|
||||
className={cn(itemVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const itemMediaVariants = cva(
|
||||
"flex shrink-0 items-center justify-center gap-2 group-has-[[data-slot=item-description]]/item:self-start [&_svg]:pointer-events-none group-has-[[data-slot=item-description]]/item:translate-y-0.5",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
icon: "size-8 border rounded-sm bg-muted [&_svg:not([class*='size-'])]:size-4",
|
||||
image:
|
||||
"size-10 rounded-sm overflow-hidden [&_img]:size-full [&_img]:object-cover",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function ItemMedia({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof itemMediaVariants>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-media"
|
||||
data-variant={variant}
|
||||
className={cn(itemMediaVariants({ variant, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-content"
|
||||
className={cn(
|
||||
"flex flex-1 flex-col gap-1 [&+[data-slot=item-content]]:flex-none",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-title"
|
||||
className={cn(
|
||||
"flex w-fit items-center gap-2 text-sm leading-snug font-medium",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<p
|
||||
data-slot="item-description"
|
||||
className={cn(
|
||||
"text-muted-foreground line-clamp-2 text-sm leading-normal font-normal text-balance",
|
||||
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemActions({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-actions"
|
||||
className={cn("flex items-center gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-header"
|
||||
className={cn(
|
||||
"flex basis-full items-center justify-between gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ItemFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="item-footer"
|
||||
className={cn(
|
||||
"flex basis-full items-center justify-between gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Item,
|
||||
ItemMedia,
|
||||
ItemContent,
|
||||
ItemActions,
|
||||
ItemGroup,
|
||||
ItemSeparator,
|
||||
ItemTitle,
|
||||
ItemDescription,
|
||||
ItemHeader,
|
||||
ItemFooter,
|
||||
}
|
||||
22
web/src/components/ui/label.tsx
Normal file
22
web/src/components/ui/label.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as React from "react"
|
||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Label({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Label }
|
||||
29
web/src/components/ui/progress.tsx
Normal file
29
web/src/components/ui/progress.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as React from "react"
|
||||
import * as ProgressPrimitive from "@radix-ui/react-progress"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Progress({
|
||||
className,
|
||||
value,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ProgressPrimitive.Root>) {
|
||||
return (
|
||||
<ProgressPrimitive.Root
|
||||
data-slot="progress"
|
||||
className={cn(
|
||||
"bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ProgressPrimitive.Indicator
|
||||
data-slot="progress-indicator"
|
||||
className="bg-primary h-full w-full flex-1 transition-all"
|
||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
||||
/>
|
||||
</ProgressPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Progress }
|
||||
58
web/src/components/ui/scroll-area.tsx
Normal file
58
web/src/components/ui/scroll-area.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as React from "react"
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function ScrollArea({
|
||||
className,
|
||||
children,
|
||||
scrollClassName,
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root> & { scrollClassName?: string }) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.Root
|
||||
data-slot="scroll-area"
|
||||
className={cn("relative", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
data-slot="scroll-area-viewport"
|
||||
className="focus-visible:ring-ring/50 size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1"
|
||||
>
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar className={scrollClassName} />
|
||||
<ScrollBar orientation="horizontal" />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
function ScrollBar({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
|
||||
return (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
data-slot="scroll-area-scrollbar"
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none p-px transition-colors select-none",
|
||||
orientation === "vertical" &&
|
||||
"h-full w-2.5 border-l border-l-transparent",
|
||||
orientation === "horizontal" &&
|
||||
"h-2.5 flex-col border-t border-t-transparent",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb
|
||||
data-slot="scroll-area-thumb"
|
||||
className="bg-border relative flex-1 rounded-full"
|
||||
/>
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
)
|
||||
}
|
||||
|
||||
export { ScrollArea, ScrollBar }
|
||||
185
web/src/components/ui/select.tsx
Normal file
185
web/src/components/ui/select.tsx
Normal file
@@ -0,0 +1,185 @@
|
||||
import * as React from "react"
|
||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Select({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||
}
|
||||
|
||||
function SelectGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return <SelectPrimitive.Group data-slot="select-group" {...props} />
|
||||
}
|
||||
|
||||
function SelectValue({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="size-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "popper",
|
||||
align = "center",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
className={cn(
|
||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className
|
||||
)}
|
||||
position={position}
|
||||
align={align}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute right-2 flex size-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="size-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"flex cursor-default items-center justify-center py-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon className="size-4" />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
26
web/src/components/ui/separator.tsx
Normal file
26
web/src/components/ui/separator.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as React from "react"
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Separator }
|
||||
143
web/src/components/ui/sheet.tsx
Normal file
143
web/src/components/ui/sheet.tsx
Normal file
@@ -0,0 +1,143 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog"
|
||||
import { XIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||
}
|
||||
|
||||
function SheetTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||
}
|
||||
|
||||
function SheetClose({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||
}
|
||||
|
||||
function SheetPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||
}
|
||||
|
||||
function SheetOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
|
||||
return (
|
||||
<SheetPrimitive.Overlay
|
||||
data-slot="sheet-overlay"
|
||||
className={cn(
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
className,
|
||||
children,
|
||||
side = "right",
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||
side?: "top" | "right" | "bottom" | "left"
|
||||
showCloseButton?: boolean
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
data-slot="sheet-content"
|
||||
className={cn(
|
||||
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
|
||||
side === "right" &&
|
||||
"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
|
||||
side === "left" &&
|
||||
"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
|
||||
side === "top" &&
|
||||
"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b",
|
||||
side === "bottom" &&
|
||||
"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">
|
||||
<XIcon className="size-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
)}
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-header"
|
||||
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
||||
return (
|
||||
<SheetPrimitive.Title
|
||||
data-slot="sheet-title"
|
||||
className={cn("text-foreground font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SheetDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Description>) {
|
||||
return (
|
||||
<SheetPrimitive.Description
|
||||
data-slot="sheet-description"
|
||||
className={cn("text-muted-foreground text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
}
|
||||
726
web/src/components/ui/sidebar.tsx
Normal file
726
web/src/components/ui/sidebar.tsx
Normal file
@@ -0,0 +1,726 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { cva, VariantProps } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
|
||||
import { useIsMobile } from "@/hooks/use-mobile"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
const SIDEBAR_WIDTH = "10rem"
|
||||
const SIDEBAR_WIDTH_MOBILE = "10rem"
|
||||
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed"
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
openMobile: boolean
|
||||
setOpenMobile: (open: boolean) => void
|
||||
isMobile: boolean
|
||||
toggleSidebar: () => void
|
||||
}
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext)
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
onOpenChange: setOpenProp,
|
||||
className,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}) {
|
||||
const isMobile = useIsMobile()
|
||||
const [openMobile, setOpenMobile] = React.useState(false)
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen)
|
||||
const open = openProp ?? _open
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState)
|
||||
} else {
|
||||
_setOpen(openState)
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
||||
},
|
||||
[setOpenProp, open]
|
||||
)
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
||||
}, [isMobile, setOpen, setOpenMobile])
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (
|
||||
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
||||
(event.metaKey || event.ctrlKey)
|
||||
) {
|
||||
event.preventDefault()
|
||||
toggleSidebar()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown)
|
||||
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||
}, [toggleSidebar])
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed"
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
||||
)
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<div
|
||||
data-slot="sidebar-wrapper"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
</SidebarContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right"
|
||||
variant?: "sidebar" | "floating" | "inset"
|
||||
collapsible?: "offcanvas" | "icon" | "none"
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
className={cn(
|
||||
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
<SheetContent
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
data-mobile="true"
|
||||
className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer text-sidebar-foreground hidden md:block"
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
data-slot="sidebar-gap"
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
data-slot="sidebar-container"
|
||||
className={cn(
|
||||
"inset-y-0 z-10 hidden w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex h-full",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarTrigger({
|
||||
className,
|
||||
onClick,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn("size-7", className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event)
|
||||
toggleSidebar()
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
className={cn(
|
||||
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
return (
|
||||
<main
|
||||
data-slot="sidebar-inset"
|
||||
className={cn(
|
||||
"bg-background relative flex w-full flex-1 flex-col",
|
||||
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInput({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="sidebar-input"
|
||||
data-sidebar="input"
|
||||
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-header"
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-footer"
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="sidebar-separator"
|
||||
data-sidebar="separator"
|
||||
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-content"
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group"
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-label"
|
||||
data-sidebar="group-label"
|
||||
className={cn(
|
||||
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupAction({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-action"
|
||||
data-sidebar="group-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroupContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group-content"
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu"
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-item"
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
isActive?: boolean
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const { isMobile, state } = useSidebar()
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-button"
|
||||
data-sidebar="menu-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
|
||||
if (!tooltip) {
|
||||
return button
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
className,
|
||||
asChild = false,
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean
|
||||
showOnHover?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-action"
|
||||
data-sidebar="menu-action"
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
showOnHover &&
|
||||
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-badge"
|
||||
data-sidebar="menu-badge"
|
||||
className={cn(
|
||||
"text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const width = React.useMemo(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && (
|
||||
<Skeleton
|
||||
className="size-4 rounded-md"
|
||||
data-sidebar="menu-skeleton-icon"
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu-sub"
|
||||
data-sidebar="menu-sub"
|
||||
className={cn(
|
||||
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
data-sidebar="menu-sub-item"
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
asChild = false,
|
||||
size = "md",
|
||||
isActive = false,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean
|
||||
size?: "sm" | "md"
|
||||
isActive?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-sub-button"
|
||||
data-sidebar="menu-sub-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
}
|
||||
13
web/src/components/ui/skeleton.tsx
Normal file
13
web/src/components/ui/skeleton.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
className={cn("bg-accent animate-pulse rounded-md", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Skeleton }
|
||||
38
web/src/components/ui/sonner.tsx
Normal file
38
web/src/components/ui/sonner.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
CircleCheckIcon,
|
||||
InfoIcon,
|
||||
Loader2Icon,
|
||||
OctagonXIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react"
|
||||
import { useTheme } from "next-themes"
|
||||
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme()
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
success: <CircleCheckIcon className="size-4" />,
|
||||
info: <InfoIcon className="size-4" />,
|
||||
warning: <TriangleAlertIcon className="size-4" />,
|
||||
error: <OctagonXIcon className="size-4" />,
|
||||
loading: <Loader2Icon className="size-4 animate-spin" />,
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
"--border-radius": "var(--radius)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
29
web/src/components/ui/switch.tsx
Normal file
29
web/src/components/ui/switch.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import * as React from "react"
|
||||
import * as SwitchPrimitive from "@radix-ui/react-switch"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Switch({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
|
||||
return (
|
||||
<SwitchPrimitive.Root
|
||||
data-slot="switch"
|
||||
className={cn(
|
||||
"peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SwitchPrimitive.Thumb
|
||||
data-slot="switch-thumb"
|
||||
className={cn(
|
||||
"bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0"
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitive.Root>
|
||||
)
|
||||
}
|
||||
|
||||
export { Switch }
|
||||
116
web/src/components/ui/table.tsx
Normal file
116
web/src/components/ui/table.tsx
Normal file
@@ -0,0 +1,116 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Table({ className,isScrollable, ...props }: React.ComponentProps<"table">&{
|
||||
isScrollable?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="table-container"
|
||||
className={cn(!isScrollable && "relative w-full overflow-x-auto")}
|
||||
>
|
||||
<table
|
||||
data-slot="table"
|
||||
className={cn("w-full caption-bottom text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||
return (
|
||||
<thead
|
||||
data-slot="table-header"
|
||||
className={cn("[&_tr]:border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||
return (
|
||||
<tbody
|
||||
data-slot="table-body"
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||
return (
|
||||
<tfoot
|
||||
data-slot="table-footer"
|
||||
className={cn(
|
||||
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||
return (
|
||||
<tr
|
||||
data-slot="table-row"
|
||||
className={cn(
|
||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||
return (
|
||||
<th
|
||||
data-slot="table-head"
|
||||
className={cn(
|
||||
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||
return (
|
||||
<td
|
||||
data-slot="table-cell"
|
||||
className={cn(
|
||||
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TableCaption({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"caption">) {
|
||||
return (
|
||||
<caption
|
||||
data-slot="table-caption"
|
||||
className={cn("text-muted-foreground mt-4 text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableFooter,
|
||||
TableHead,
|
||||
TableRow,
|
||||
TableCell,
|
||||
TableCaption,
|
||||
}
|
||||
64
web/src/components/ui/tabs.tsx
Normal file
64
web/src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
18
web/src/components/ui/textarea.tsx
Normal file
18
web/src/components/ui/textarea.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from "react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Textarea }
|
||||
59
web/src/components/ui/tooltip.tsx
Normal file
59
web/src/components/ui/tooltip.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
import * as React from "react"
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function TooltipProvider({
|
||||
delayDuration = 0,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||
return (
|
||||
<TooltipPrimitive.Provider
|
||||
data-slot="tooltip-provider"
|
||||
delayDuration={delayDuration}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function Tooltip({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||
</TooltipProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function TooltipTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
className,
|
||||
sideOffset = 0,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
data-slot="tooltip-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<TooltipPrimitive.Arrow className="bg-foreground fill-foreground z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
16
web/src/hooks/use-app-config.ts
Normal file
16
web/src/hooks/use-app-config.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
import {invokeCommand} from "@/lib/invoke.ts";
|
||||
import {AppConfig} from "@/lib/types.ts";
|
||||
|
||||
|
||||
export function useAppConfig() {
|
||||
const config = useQuery({
|
||||
queryKey: ['app_config'],
|
||||
queryFn: async () => invokeCommand<AppConfig>('app_config')
|
||||
});
|
||||
|
||||
return {
|
||||
config
|
||||
}
|
||||
|
||||
}
|
||||
23
web/src/hooks/use-mihomo-config.ts
Normal file
23
web/src/hooks/use-mihomo-config.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {invokeCommand} from "@/lib/invoke.ts";
|
||||
import {AppConfig, MihomoConfig} from "@/lib/types.ts";
|
||||
|
||||
export function useMihomoConfig() {
|
||||
const client = useQueryClient();
|
||||
const config = useQuery({
|
||||
queryKey: ['app_config'],
|
||||
queryFn: async () => (await invokeCommand<AppConfig>('app_config')).mihomo
|
||||
});
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (config: MihomoConfig) => invokeCommand<void>('mihomo_config_update', {config}),
|
||||
onSuccess: async () => {
|
||||
await client.invalidateQueries({queryKey: ['app_config']});
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
config, mutation
|
||||
}
|
||||
|
||||
}
|
||||
19
web/src/hooks/use-mobile.ts
Normal file
19
web/src/hooks/use-mobile.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
50
web/src/hooks/use-profiles.ts
Normal file
50
web/src/hooks/use-profiles.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import {invokeCommand} from "@/lib/invoke.ts";
|
||||
import {Profile} from "@/pages/Profiles/Dialog.tsx";
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
|
||||
interface ProfileSet {
|
||||
current?: string;
|
||||
items: Profile[]
|
||||
}
|
||||
|
||||
export function useProfiles() {
|
||||
const client = useQueryClient();
|
||||
|
||||
const reload = () => client.invalidateQueries({
|
||||
queryKey: ['profile']
|
||||
});
|
||||
|
||||
const profiles = useQuery({
|
||||
queryKey: ['profile'],
|
||||
queryFn: async () => invokeCommand<ProfileSet>('profile_list'),
|
||||
})
|
||||
const add = useMutation({
|
||||
mutationFn: async (profile: Profile) => invokeCommand<void>('profile_add', {profile}),
|
||||
onSuccess: reload
|
||||
})
|
||||
const use = useMutation({
|
||||
mutationFn: async (id: string) => invokeCommand<void>('switch_profile', {id}),
|
||||
onSuccess: reload
|
||||
})
|
||||
const update = useMutation({
|
||||
mutationFn: async (profile: Profile) => invokeCommand<void>('profile_update', {profile}),
|
||||
onSuccess: reload
|
||||
})
|
||||
const remove = useMutation({
|
||||
mutationFn: async (id: string) => invokeCommand<void>('profile_delete', {id}),
|
||||
onSuccess: reload
|
||||
})
|
||||
const refresh = useMutation({
|
||||
mutationFn: async (id: string) => invokeCommand<void>('profile_refresh', {id}),
|
||||
onSuccess: reload
|
||||
})
|
||||
const editingFile = useMutation({
|
||||
mutationFn: async (id: string) => invokeCommand<void>('profile_edit_file', {id}),
|
||||
onSuccess: reload
|
||||
})
|
||||
|
||||
return {
|
||||
profiles, add, use, update, remove, refresh, editingFile,
|
||||
}
|
||||
|
||||
}
|
||||
56
web/src/hooks/use-service-status.ts
Normal file
56
web/src/hooks/use-service-status.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {invokeCommand} from "@/lib/invoke.ts";
|
||||
import {ServiceStatus} from "@/lib/types.ts";
|
||||
import {toast} from "sonner";
|
||||
|
||||
export function useServiceStatus() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Query to fetch service status
|
||||
const status = useQuery({
|
||||
queryKey: ['service', 'status'],
|
||||
queryFn: () => invokeCommand<ServiceStatus>("service_status"),
|
||||
// Refresh periodically if needed, or stick to default stale time
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
|
||||
const reload = useMutation({
|
||||
mutationFn: () => invokeCommand<void>('service_reload'),
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries({queryKey: ['service', 'status']});
|
||||
toast.success("Reload status successfully");
|
||||
}
|
||||
})
|
||||
|
||||
// Mutation for installation
|
||||
const install = useMutation({
|
||||
mutationFn: () => invokeCommand<void>("service_install"),
|
||||
onSuccess: async () => {
|
||||
toast.success("Service installed successfully");
|
||||
await queryClient.invalidateQueries({queryKey: ['service', 'status']});
|
||||
},
|
||||
onError: (error) => {
|
||||
// Error is already toasted in invokeCommand, but we can add specific handling if needed
|
||||
console.error("Install failed:", error);
|
||||
}
|
||||
});
|
||||
|
||||
// Mutation for uninstallation
|
||||
const uninstall = useMutation({
|
||||
mutationFn: () => invokeCommand<void>("service_uninstall"),
|
||||
onSuccess: async () => {
|
||||
toast.success("Service uninstalled successfully");
|
||||
await queryClient.invalidateQueries({queryKey: ['service', 'status']});
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Uninstall failed:", error);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
status,
|
||||
reload,
|
||||
install,
|
||||
uninstall
|
||||
};
|
||||
}
|
||||
156
web/src/index.css
Normal file
156
web/src/index.css
Normal file
@@ -0,0 +1,156 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
@theme inline {
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
--color-chart-1: var(--chart-1);
|
||||
--color-chart-2: var(--chart-2);
|
||||
--color-chart-3: var(--chart-3);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||
--color-sidebar-accent: var(--sidebar-accent);
|
||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||
--color-sidebar-border: var(--sidebar-border);
|
||||
--color-sidebar-ring: var(--sidebar-ring);
|
||||
}
|
||||
|
||||
:root {
|
||||
--radius: 0.625rem;
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.97 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.646 0.222 41.116);
|
||||
--chart-2: oklch(0.6 0.118 184.704);
|
||||
--chart-3: oklch(0.398 0.07 227.392);
|
||||
--chart-4: oklch(0.828 0.189 84.429);
|
||||
--chart-5: oklch(0.769 0.188 70.08);
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--secondary: oklch(0.269 0 0);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.269 0 0);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.488 0.243 264.376);
|
||||
--chart-2: oklch(0.696 0.17 162.48);
|
||||
--chart-3: oklch(0.769 0.188 70.08);
|
||||
--chart-4: oklch(0.627 0.265 303.9);
|
||||
--chart-5: oklch(0.645 0.246 16.439);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.269 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
@apply border-border outline-ring/50;
|
||||
}
|
||||
|
||||
body {
|
||||
@apply bg-background text-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
@keyframes breathing {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
|
||||
}
|
||||
70% {
|
||||
box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
|
||||
}
|
||||
100% {
|
||||
box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-breathing {
|
||||
animation: breathing 3s infinite;
|
||||
}
|
||||
|
||||
|
||||
@keyframes force-animate-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.force-animate-spin {
|
||||
animation: force-animate-spin 0.4s linear forwards;
|
||||
}
|
||||
12
web/src/lib/invoke.ts
Normal file
12
web/src/lib/invoke.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {invoke} from "@tauri-apps/api/core";
|
||||
import {toast} from "sonner";
|
||||
|
||||
|
||||
export async function invokeCommand<R>(command: string, data?: Record<string, unknown>): Promise<R> {
|
||||
try {
|
||||
return await invoke<R>(command, data);
|
||||
} catch (e) {
|
||||
toast.error(e as unknown as string);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
59
web/src/lib/types.ts
Normal file
59
web/src/lib/types.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
export interface AppConfig {
|
||||
logLevel: 'Trace' | 'Debug' | 'Info' | 'Warn' | 'Error',
|
||||
autoStart: boolean,
|
||||
silentStart: boolean,
|
||||
mihomo: MihomoConfig,
|
||||
}
|
||||
|
||||
export interface MihomoConfig {
|
||||
logLevel: 'Debug' | 'Info' | 'Warn' | 'Error' | 'Silent'
|
||||
tunMode: boolean
|
||||
allowLan: boolean
|
||||
ipv6: boolean
|
||||
uniLatency: boolean
|
||||
mix: Port,
|
||||
http: Port,
|
||||
socks: Port
|
||||
}
|
||||
|
||||
export interface Port {
|
||||
port: number;
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export interface TunConfig {
|
||||
enable: boolean
|
||||
stack: 'system' | 'gvisor' | 'mixed'
|
||||
dnsHijack: string[]
|
||||
autoDetectInterface?: boolean
|
||||
autoRoute?: boolean
|
||||
mtu?: number
|
||||
gso?: boolean
|
||||
gsoMaxSize?: number
|
||||
autoRedirect?: boolean
|
||||
strictRoute?: boolean
|
||||
disableIcmpForwarding?: boolean
|
||||
routeAddressSet?: string[]
|
||||
routeExcludeAddressSet?: string[]
|
||||
routeAddress?: string[]
|
||||
inet4RouteAddress?: string[]
|
||||
inet6RouteAddress?: string[]
|
||||
endpointIndependentNat?: boolean
|
||||
includeInterface?: string[]
|
||||
excludeInterface?: string[]
|
||||
includeUid?: number[]
|
||||
includeUidRange?: string[]
|
||||
excludeUid?: number[]
|
||||
excludeUidRange?: string[]
|
||||
includeAndroidUser?: number[]
|
||||
includePackage?: string[]
|
||||
excludePackage?: string[]
|
||||
}
|
||||
|
||||
export interface ServiceStatus {
|
||||
|
||||
installed: boolean
|
||||
sidecar: boolean
|
||||
status: 'Ready' | { "Unavailable": string }
|
||||
|
||||
}
|
||||
6
web/src/lib/utils.ts
Normal file
6
web/src/lib/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
19
web/src/main.tsx
Normal file
19
web/src/main.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./index.css";
|
||||
import {getCurrentWindow} from '@tauri-apps/api/window';
|
||||
|
||||
await getCurrentWindow().show();
|
||||
|
||||
window.addEventListener('dragstart', e => {
|
||||
if (e.target instanceof Element && ['A', 'IMG'].includes(e.target.tagName)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
})
|
||||
|
||||
ReactDOM.createRoot(document.querySelector("#root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<App/>
|
||||
</React.StrictMode>
|
||||
);
|
||||
36
web/src/pages/Connections.tsx
Normal file
36
web/src/pages/Connections.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import {ScrollableBody, ContentHeader} from "@/components/app-content.tsx";
|
||||
import {
|
||||
Item,
|
||||
ItemMedia,
|
||||
ItemContent,
|
||||
ItemTitle,
|
||||
ItemActions,
|
||||
} from "@/components/ui/item.tsx";
|
||||
import {BadgeCheckIcon, ChevronRightIcon} from "lucide-react";
|
||||
|
||||
export function Connections() {
|
||||
return (
|
||||
<ScrollableBody>
|
||||
<ContentHeader>
|
||||
Connections
|
||||
</ContentHeader>
|
||||
<div className={'flex flex-col gap-y-2'}>
|
||||
{new Array(100).fill(0).map(() => (
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
))}
|
||||
</div>
|
||||
</ScrollableBody>
|
||||
)
|
||||
}
|
||||
50
web/src/pages/Home/LocationCard.tsx
Normal file
50
web/src/pages/Home/LocationCard.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import {BadgeCheckIcon, GlobeIcon} from "lucide-react";
|
||||
import {Container} from "@/components/app-content.tsx";
|
||||
import {LabelItem, LabelName, LabelValue} from "@/pages/Home/index.tsx";
|
||||
|
||||
const Latency = () => {
|
||||
return <div className={'flex gap-1'}>
|
||||
<span
|
||||
className={'text-[11px] text-gray-500 font-medium whitespace-nowrap'}>Github</span>
|
||||
<span
|
||||
className={'text-[11px] text-gray-800 font-semibold whitespace-nowrap'}>122ms</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
export function LocationCard() {
|
||||
return (<Container>
|
||||
{/*底部*/}
|
||||
<div className={'grid grid-cols-2 gap-6'}>
|
||||
<LabelItem>
|
||||
<LabelName className="flex items-center gap-1.5 mb-1">
|
||||
<GlobeIcon size={12}/>
|
||||
IP
|
||||
</LabelName>
|
||||
<LabelValue>47.238.198.100</LabelValue>
|
||||
</LabelItem>
|
||||
<LabelItem>
|
||||
<LabelName className="flex items-center gap-1.5 mb-1">
|
||||
<GlobeIcon size={12}/>
|
||||
所属地址
|
||||
</LabelName>
|
||||
<LabelValue>日本 · 东京</LabelValue>
|
||||
</LabelItem>
|
||||
</div>
|
||||
<LabelItem className={'flex flex-col mt-4'}>
|
||||
<LabelName className={'mt-1 flex items-center gap-1.5 mb-2'}>
|
||||
<BadgeCheckIcon size={12}/>
|
||||
延迟
|
||||
</LabelName>
|
||||
<div className={'grid grid-cols-4 gap-y-2'}>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
<Latency/>
|
||||
</div>
|
||||
</LabelItem>
|
||||
</Container>)
|
||||
}
|
||||
64
web/src/pages/Home/ProfileCard.tsx
Normal file
64
web/src/pages/Home/ProfileCard.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import {Container} from "@/components/app-content.tsx";
|
||||
import {BadgeCheckIcon, CloudDownloadIcon, GlobeIcon, RotateCwIcon} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {Badge} from "@/components/ui/badge.tsx";
|
||||
import {LabelItem, LabelName, LabelValue} from "@/pages/Home/index.tsx";
|
||||
|
||||
|
||||
export function ProfileCard() {
|
||||
return (
|
||||
<Container>
|
||||
{/*第一行*/}
|
||||
<div className={'flex items-center justify-between pb-4 border-b border-border/40'}>
|
||||
<div className={'flex items-center gap-3'}>
|
||||
<div className="p-2.5 bg-primary/10 rounded-xl text-primary">
|
||||
<CloudDownloadIcon size={24}/>
|
||||
</div>
|
||||
<div>
|
||||
<p className={'text-lg font-bold text-foreground flex items-center gap-2'}>
|
||||
NanoCloud
|
||||
</p>
|
||||
<div className={'flex items-center gap-2 mt-0.5'}>
|
||||
<GlobeIcon size={12} className="text-muted-foreground"/>
|
||||
<p className="text-xs text-muted-foreground font-medium">免费-日本1-Ver.7</p>
|
||||
<div className={'flex gap-1'}>
|
||||
<Badge variant={'outline'} className={'text-gray-500 text-[10px] rounded-md px-1 h-4'}>Vmess</Badge>
|
||||
<Badge variant={'outline'} className={'text-gray-500 text-[10px] rounded-md px-1 h-4'}>UDP</Badge>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="ghost" size="icon" className="h-4 w-4 text-muted-foreground hover:text-foreground">
|
||||
<RotateCwIcon size={10}/>
|
||||
</Button>
|
||||
</div>
|
||||
{/*底部*/}
|
||||
<div className={'grid grid-cols-3 gap-6 mt-4'}>
|
||||
<LabelItem>
|
||||
<LabelName className="flex items-center gap-1.5 mb-1">
|
||||
<CloudDownloadIcon size={12}/>
|
||||
已使用 / 总量
|
||||
</LabelName>
|
||||
<LabelValue>1.26GB / 100GB</LabelValue>
|
||||
</LabelItem>
|
||||
<LabelItem>
|
||||
<LabelName className="flex items-center gap-1.5 mb-1">
|
||||
<BadgeCheckIcon size={12}/>
|
||||
到期时间
|
||||
</LabelName>
|
||||
<LabelValue>2025-11-11</LabelValue>
|
||||
</LabelItem>
|
||||
<LabelItem>
|
||||
<div className="flex items-center justify-between">
|
||||
<LabelName className="flex items-center gap-1.5 mb-1">
|
||||
<BadgeCheckIcon size={12}/>
|
||||
更新时间
|
||||
</LabelName>
|
||||
</div>
|
||||
<LabelValue>2025-10-12 10:05</LabelValue>
|
||||
</LabelItem>
|
||||
</div>
|
||||
</Container>
|
||||
|
||||
)
|
||||
}
|
||||
271
web/src/pages/Home/SettingCard.tsx
Normal file
271
web/src/pages/Home/SettingCard.tsx
Normal file
@@ -0,0 +1,271 @@
|
||||
import {Container} from "@/components/app-content.tsx";
|
||||
import {Item, ItemActions, ItemContent, ItemMedia, ItemTitle} from "@/components/ui/item.tsx";
|
||||
import {BadgeCheckIcon, Loader2, RotateCwIcon, ServerIcon, Trash2Icon} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {Switch} from "@/components/ui/switch.tsx";
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog.tsx";
|
||||
import {Input} from "@/components/ui/input.tsx";
|
||||
import {z} from "zod/v4";
|
||||
import {Controller, useForm} from "react-hook-form";
|
||||
import {zodResolver} from "@hookform/resolvers/zod";
|
||||
import {useState} from "react";
|
||||
import {useMihomoConfig} from "@/hooks/use-mihomo-config";
|
||||
import {useServiceStatus} from "@/hooks/use-service-status.ts";
|
||||
import {Badge} from "@/components/ui/badge.tsx";
|
||||
import {TipButton} from "@/components/button.tsx";
|
||||
import {Tooltip, TooltipContent, TooltipTrigger} from "@/components/ui/tooltip.tsx";
|
||||
import {WrenchScrewdriverIcon} from "@heroicons/react/24/outline";
|
||||
|
||||
const port = z.object({
|
||||
port: z.number().min(0).max(65535),
|
||||
enabled: z.boolean()
|
||||
});
|
||||
|
||||
const schema = z.object({
|
||||
mix: port,
|
||||
http: port,
|
||||
socks: port,
|
||||
});
|
||||
|
||||
export type Ports = z.infer<typeof schema>;
|
||||
|
||||
function PortSettingDialog({open, onOpenChange}: {
|
||||
open: boolean,
|
||||
onOpenChange: (open: boolean) => void,
|
||||
}) {
|
||||
|
||||
const {config, mutation} = useMihomoConfig()
|
||||
|
||||
const form = useForm<Ports>({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: config.data!
|
||||
});
|
||||
|
||||
const onSubmit = (ports: Ports) => {
|
||||
mutation.mutate({
|
||||
...config.data!,
|
||||
...ports
|
||||
});
|
||||
onOpenChange(false)
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className='w-96' aria-describedby={undefined}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>端口设置</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form id="port-form" onSubmit={form.handleSubmit(onSubmit)} className="py-2 flex flex-col gap-3">
|
||||
{(['mix', 'http', 'socks'] as const).map((key) => (
|
||||
<Controller
|
||||
key={key}
|
||||
control={form.control}
|
||||
name={key}
|
||||
render={({field}) => (
|
||||
<div className={`p-2`}>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm font-semibold capitalize tracking-wide">{key} Port</span>
|
||||
</div>
|
||||
<Switch
|
||||
disabled={key == 'mix'}
|
||||
checked={field.value.enabled}
|
||||
onCheckedChange={(enabled) => field.onChange({
|
||||
...field.value,
|
||||
enabled
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<Input
|
||||
type="number"
|
||||
|
||||
value={field.value.port}
|
||||
disabled={!field.value.enabled}
|
||||
onChange={(e) => field.onChange({
|
||||
...field.value,
|
||||
port: parseInt(e.target.value) || 0
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
))}
|
||||
</form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="ghost">取消</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit" form="port-form" disabled={mutation.isPending}>
|
||||
{mutation.isPending ? "保存中..." : "保存更改"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function ServiceControlDialog(props: {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}) {
|
||||
const {status: {data: status}, install, uninstall} = useServiceStatus();
|
||||
const action = status?.installed ? uninstall : install;
|
||||
|
||||
const mutate = async () => {
|
||||
action.mutate();
|
||||
props.onOpenChange(false)
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{status?.installed ? '卸载服务' : '安装服务'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{status?.installed
|
||||
? '卸载服务后,TUN 模式将无法使用。此操作需要管理员权限。'
|
||||
: '如果不安装服务,程序将只能以受限模式运行,无法使用 TUN 模式等高级功能。此操作需要管理员权限。'}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => props.onOpenChange(false)}>取消</Button>
|
||||
<Button onClick={async () => mutate()} disabled={action.isPending}>
|
||||
{action.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin"/>}
|
||||
{status?.installed ? '确认卸载' : '确认安装'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function DaemonSetting() {
|
||||
const [serviceDialog, setServiceDialog] = useState(false)
|
||||
|
||||
const {status: {data: status}, reload} = useServiceStatus();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ServiceControlDialog
|
||||
open={serviceDialog}
|
||||
onOpenChange={setServiceDialog}
|
||||
/>
|
||||
|
||||
<Item variant="default" size="sm" className={'py-1 h-10'} asChild>
|
||||
<a className={'rounded-none'}>
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<div className={'flex gap-2'}>
|
||||
<ItemTitle>服务模式</ItemTitle>
|
||||
{status?.installed && status.sidecar ? (
|
||||
<>
|
||||
<Tooltip>
|
||||
<TooltipTrigger>
|
||||
<Badge variant={'outline'}
|
||||
className={'text-yellow-500 rounded-sm bg-yellow-50'}><ServerIcon/>Sidecar
|
||||
</Badge>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>系统服务已安装但未启动, 回退到Sidecar模式</TooltipContent>
|
||||
</Tooltip>
|
||||
</>
|
||||
) : (
|
||||
<Badge variant={'outline'}
|
||||
className={'text-green-500 rounded-sm bg-green-50'}>
|
||||
<div className={'bg-green-500 size-1 rounded-full'}/>
|
||||
运行中
|
||||
</Badge>
|
||||
)}
|
||||
<TipButton
|
||||
variant={'ghost'}
|
||||
size={'icon-sm'}
|
||||
className={`p-0 m-0 text-muted-foreground ${status?.installed && 'hover:text-red-500'}`}
|
||||
onClick={() => setServiceDialog(true)}
|
||||
tipContent={status?.installed ? '卸载系统服务' : '安装系统服务'}
|
||||
>
|
||||
{status?.installed ? <Trash2Icon/> : <WrenchScrewdriverIcon/>}
|
||||
</TipButton>
|
||||
</div>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<TipButton
|
||||
variant={'ghost'}
|
||||
size={'icon-sm'}
|
||||
className={'text-muted-foreground'}
|
||||
tipContent={'重载daemon状态'}
|
||||
onClick={() => reload.mutate()}
|
||||
>
|
||||
<RotateCwIcon/>
|
||||
</TipButton>
|
||||
|
||||
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export function SettingCard() {
|
||||
const [portUpdateDialog, setPortUpdateDialog] = useState(false);
|
||||
const {config, mutation} = useMihomoConfig();
|
||||
|
||||
if (!config.data) {
|
||||
return (<div>Loading</div>)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container className={'px-0 py-2'}>
|
||||
<DaemonSetting/>
|
||||
<Item variant="default" size="sm" className={'py-1 h-10'}>
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Tun 模式</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch onCheckedChange={tunMode => mutation.mutate({...config.data, tunMode})}/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item variant="default" size="sm" className={'py-1 h-10'}>
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>系统代理</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item variant="default" size="sm" className={'py-1 h-10'}>
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>代理端口</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button variant={'link'} className={'p-0 h-5'} onClick={() => setPortUpdateDialog(true)}>
|
||||
{config.data.mix.port || '--'}
|
||||
</Button>
|
||||
<PortSettingDialog open={portUpdateDialog} onOpenChange={setPortUpdateDialog}/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
50
web/src/pages/Home/index.tsx
Normal file
50
web/src/pages/Home/index.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import {cn} from "@/lib/utils.ts";
|
||||
import {ContentHeader, ScrollableBody} from "@/components/app-content.tsx";
|
||||
import {ProfileCard} from "@/pages/Home/ProfileCard.tsx";
|
||||
import {LocationCard} from "@/pages/Home/LocationCard.tsx";
|
||||
import {SettingCard} from "@/pages/Home/SettingCard.tsx";
|
||||
|
||||
type DivProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
|
||||
type SpanProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
||||
|
||||
export const LabelItem = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: DivProps) => {
|
||||
return <div className={cn('flex flex-col', className)} {...props}>{children}</div>
|
||||
}
|
||||
|
||||
export const LabelName = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: SpanProps) => {
|
||||
return <span
|
||||
className={cn('text-[11px] text-gray-400 uppercase tracking-[0.5px] font-semibold', className)} {...props}>{children}</span>
|
||||
}
|
||||
|
||||
export const LabelValue = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: SpanProps) => {
|
||||
return <span className={cn('text-[13px] text-gray-800 font-medium', className)} {...props}>{children}</span>
|
||||
}
|
||||
|
||||
export function Home() {
|
||||
|
||||
return (
|
||||
<ScrollableBody>
|
||||
<ContentHeader>
|
||||
Home
|
||||
</ContentHeader>
|
||||
<div className={'flex flex-col gap-2'}>
|
||||
<ProfileCard/>
|
||||
<LocationCard/>
|
||||
<SettingCard/>
|
||||
</div>
|
||||
</ScrollableBody>
|
||||
)
|
||||
}
|
||||
94
web/src/pages/Logs.tsx
Normal file
94
web/src/pages/Logs.tsx
Normal file
@@ -0,0 +1,94 @@
|
||||
import {ContentHeader} from "@/components/app-content.tsx";
|
||||
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {invoke} from "@tauri-apps/api/core";
|
||||
import {ScrollArea} from "@/components/ui/scroll-area";
|
||||
import {useQuery} from "@tanstack/react-query";
|
||||
|
||||
|
||||
function LogView({logs}: { logs: Record<string, string>[] }) {
|
||||
return (
|
||||
<ScrollArea className="h-full px-2 min-h-0 overflow-hidden">
|
||||
<div className="font-mono text-xs pb-4">
|
||||
{logs.map((log, i) => (
|
||||
<LogRow key={i} log={log}/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function formatTime(isoTime?: string) {
|
||||
if (!isoTime) return "";
|
||||
try {
|
||||
return new Date(isoTime).toLocaleTimeString('zh-CN', {hour12: false});
|
||||
} catch (e) {
|
||||
console.error("Error formatting date ", e);
|
||||
return isoTime;
|
||||
}
|
||||
}
|
||||
|
||||
interface Log {
|
||||
time?: string
|
||||
level?: 'debug' | 'info' | 'warn' | 'error'
|
||||
msg: string
|
||||
}
|
||||
|
||||
const LEVEL_COLOR = {
|
||||
debug: 'text-red-500',
|
||||
info: 'text-blue-500',
|
||||
warn: 'text-yellow-500',
|
||||
error: 'text-red-500',
|
||||
default: 'text-muted-foreground'
|
||||
}
|
||||
|
||||
function LogRow({log}: { log: Record<string, string> }) {
|
||||
const {time, level, msg} = log as unknown as Log;
|
||||
const color = LEVEL_COLOR[level ?? 'default']
|
||||
|
||||
return (
|
||||
<div
|
||||
className="flex items-start gap-2 px-2 py-0.5 hover:bg-muted/50 odd:bg-muted/20 rounded-sm transition-colors whitespace-nowrap">
|
||||
{time && <span className="text-muted-foreground w-16 shrink-0">{formatTime(time)}</span>}
|
||||
{level && <span className={cn("w-10 font-bold shrink-0 uppercase", color)}>{level}</span>}
|
||||
<span className="text-foreground">{msg}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function Logs() {
|
||||
|
||||
|
||||
const {data: mihomoLogs} = useQuery({
|
||||
queryKey: ['mihomo_logs'],
|
||||
queryFn: async () => await invoke<Record<string, string>[]>("mihomo_logs"),
|
||||
refetchInterval: 1000
|
||||
})
|
||||
const {data: appLogs} = useQuery({
|
||||
queryKey: ['app_logs'],
|
||||
queryFn: async () => await invoke<Record<string, string>[]>("mihomo_logs"),
|
||||
refetchInterval: 1000
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="h-svh w-full flex flex-col overflow-hidden py-2 pl-0 pr-4">
|
||||
<Tabs defaultValue={'mihomo'} className="size-full min-h-0">
|
||||
<ContentHeader className="justify-between">
|
||||
Logs
|
||||
<TabsList className="sticky z-50">
|
||||
<TabsTrigger value="mihomo">Mihomo Logs</TabsTrigger>
|
||||
<TabsTrigger value="app">App Logs</TabsTrigger>
|
||||
</TabsList>
|
||||
</ContentHeader>
|
||||
<TabsContent value="mihomo" className="flex-1 overflow-hidden">
|
||||
<LogView logs={mihomoLogs ?? []}/>
|
||||
</TabsContent>
|
||||
<TabsContent value="app" className="flex-1 overflow-hidden">
|
||||
<LogView logs={appLogs ?? []}/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
247
web/src/pages/Profiles/Dialog.tsx
Normal file
247
web/src/pages/Profiles/Dialog.tsx
Normal file
@@ -0,0 +1,247 @@
|
||||
import {Controller, ControllerFieldState, useForm} from "react-hook-form";
|
||||
import React, {createContext, ReactNode, useContext, useState} from "react";
|
||||
import {Field, FieldLabel, FieldSet} from "@/components/ui/field.tsx";
|
||||
import {Tooltip, TooltipContent, TooltipTrigger} from "@/components/ui/tooltip.tsx";
|
||||
import {Badge} from "@/components/ui/badge.tsx";
|
||||
import {InfoIcon, PlusIcon, TrashIcon} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {zodResolver} from "@hookform/resolvers/zod";
|
||||
import {z} from "zod/v4";
|
||||
import {toast} from "sonner";
|
||||
import {open as openFileSelector} from '@tauri-apps/plugin-dialog';
|
||||
import {Dialog, DialogClose, DialogContent, DialogFooter, DialogTitle} from "@/components/ui/dialog.tsx";
|
||||
import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select.tsx";
|
||||
import {Input} from "@/components/ui/input.tsx";
|
||||
import {InputGroup, InputGroupAddon, InputGroupInput} from "@/components/ui/input-group.tsx";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import {useProfiles} from "@/hooks/use-profiles";
|
||||
|
||||
|
||||
const schema = z.discriminatedUnion('type', [
|
||||
z.object({
|
||||
type: z.literal('local'),
|
||||
name: z.string("输入配置名").trim().min(1, "输入配置名"),
|
||||
file: z.string("选择文件").trim().min(1, "选择文件"),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('remote'),
|
||||
name: z.string("输入配置名").trim().min(1, "输入配置名"),
|
||||
url: z.url("订阅地址无效"),
|
||||
interval: z.number().min(5, "更新间隔不合法")
|
||||
})
|
||||
])
|
||||
|
||||
export type Profile = { id?: string } & z.infer<typeof schema>
|
||||
|
||||
|
||||
/**
|
||||
* 错误展示在Label上
|
||||
*/
|
||||
function NoticeFieldLabel({fieldState, children}: { fieldState: ControllerFieldState, children: React.ReactNode }) {
|
||||
return <FieldLabel>{children}
|
||||
{fieldState.invalid && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Badge className={'p-0 text-red-500 '} variant={'outline'}><InfoIcon/></Badge>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>{fieldState.error?.message}</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
</FieldLabel>
|
||||
}
|
||||
|
||||
|
||||
function ProfileDialog({profile, ...props}: React.ComponentProps<typeof DialogPrimitive.Root> & {
|
||||
profile?: Profile
|
||||
}) {
|
||||
const profiles = useProfiles();
|
||||
const form = useForm<z.infer<typeof schema>>({
|
||||
mode: 'all',
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: profile || {
|
||||
type: 'remote',
|
||||
name: '',
|
||||
url: '',
|
||||
interval: 1440,
|
||||
},
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
if (props.open) {
|
||||
form.reset(profile || {
|
||||
type: 'remote',
|
||||
name: '',
|
||||
url: '',
|
||||
interval: 1440,
|
||||
})
|
||||
}
|
||||
}, [props.open, profile]);
|
||||
|
||||
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||
try {
|
||||
if (profile?.id) {
|
||||
profiles.update.mutate({...data, id: profile.id})
|
||||
} else {
|
||||
profiles.add.mutate(data)
|
||||
}
|
||||
props.onOpenChange?.(false)
|
||||
} catch (e) {
|
||||
toast.error(e as string)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelectFile = async () => {
|
||||
return await openFileSelector({
|
||||
multiple: false,
|
||||
directory: false,
|
||||
filters: [{
|
||||
name: 'yml',
|
||||
extensions: ['yml', 'yaml']
|
||||
}]
|
||||
}) ?? '';
|
||||
}
|
||||
|
||||
const type = form.watch('type')
|
||||
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogContent className={'w-96'} aria-describedby={undefined}>
|
||||
<DialogTitle>{profile ? '编辑配置' : '添加配置'}</DialogTitle>
|
||||
<form id='profile-editor' onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<FieldSet>
|
||||
<Controller name={'type'} control={form.control} render={({field, fieldState}) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<NoticeFieldLabel fieldState={fieldState}>
|
||||
配置类型
|
||||
</NoticeFieldLabel>
|
||||
<Select name={field.name} value={field.value} defaultValue={'remote'}
|
||||
onValueChange={field.onChange}>
|
||||
<SelectTrigger className="w-full" aria-invalid={fieldState.invalid}>
|
||||
<SelectValue placeholder={'选择配置类型'}/>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="local">本地</SelectItem>
|
||||
<SelectItem value="remote">远程</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
)}/>
|
||||
<Controller name={'name'} control={form.control} render={({field, fieldState}) =>
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<NoticeFieldLabel fieldState={fieldState}>配置名</NoticeFieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id="name"
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="请输入配置名"
|
||||
autoComplete="off"
|
||||
/>
|
||||
</Field>
|
||||
}/>
|
||||
{type == 'remote' && (
|
||||
<>
|
||||
<Controller name={'url'} control={form.control} render={({field, fieldState}) =>
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<NoticeFieldLabel fieldState={fieldState}>订阅链接</NoticeFieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id="url"
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="请输入订阅链接"
|
||||
autoComplete="off"
|
||||
/>
|
||||
</Field>
|
||||
}/>
|
||||
<Controller name={'interval'} control={form.control} render={({field, fieldState}) =>
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<NoticeFieldLabel fieldState={fieldState}>更新间隔</NoticeFieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
{...field}
|
||||
onChange={(e) => field.onChange(Number(e.target.value))}
|
||||
id="interval"
|
||||
type={'number'}
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="更新间隔"
|
||||
autoComplete="off"
|
||||
/>
|
||||
<InputGroupAddon align="inline-end">分钟</InputGroupAddon>
|
||||
</InputGroup>
|
||||
</Field>
|
||||
}/>
|
||||
</>
|
||||
)}
|
||||
{type == 'local' && (
|
||||
<Controller name={'file'} control={form.control} render={({field, fieldState}) =>
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<NoticeFieldLabel fieldState={fieldState}>选择文件</NoticeFieldLabel>
|
||||
|
||||
{field.value ? (
|
||||
<div className={'flex space-x-2'}>
|
||||
<Input {...field}
|
||||
readOnly={true}
|
||||
aria-invalid={fieldState.invalid}/>
|
||||
<Button variant={'outline'}
|
||||
onClick={() => field.onChange('')}><TrashIcon/></Button>
|
||||
</div>
|
||||
) : (
|
||||
<Button variant={'outline'}
|
||||
onClick={async () => {
|
||||
field.onChange(await handleSelectFile())
|
||||
}}
|
||||
><PlusIcon/>请选择文件</Button>
|
||||
)}
|
||||
</Field>
|
||||
}/>
|
||||
)}
|
||||
</FieldSet>
|
||||
</form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit" form={'profile-editor'}>Save changes</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
type DialogContextProps = {
|
||||
edit: (profile?: Profile) => void,
|
||||
close: () => void
|
||||
}
|
||||
const DialogContext = createContext<DialogContextProps | null>(null);
|
||||
|
||||
export function DialogProvider({children}: { children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [profile, setProfile] = useState<Profile | undefined>()
|
||||
const edit = (profile?: Profile) => {
|
||||
setProfile(profile)
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
setOpen(false);
|
||||
setProfile(undefined)
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContext.Provider value={{edit, close}}>
|
||||
{children}
|
||||
<ProfileDialog open={open} profile={profile} onOpenChange={open => {
|
||||
if (!open) close();
|
||||
else setOpen(true);
|
||||
}}/>
|
||||
</DialogContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useDialog() {
|
||||
const ctx = useContext(DialogContext);
|
||||
if (!ctx) throw new Error("useDialog must be used within Provider");
|
||||
return ctx;
|
||||
}
|
||||
101
web/src/pages/Profiles/Item.tsx
Normal file
101
web/src/pages/Profiles/Item.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
import {Profile, useDialog} from "@/pages/Profiles/Dialog.tsx";
|
||||
import {
|
||||
ContextMenu,
|
||||
ContextMenuContent,
|
||||
ContextMenuItem,
|
||||
ContextMenuSeparator,
|
||||
ContextMenuTrigger
|
||||
} from "@/components/ui/context-menu.tsx";
|
||||
import {Item, ItemContent, ItemDescription, ItemTitle} from "@/components/ui/item.tsx";
|
||||
import {cn} from "@/lib/utils.ts";
|
||||
import {CloudDownloadIcon, FileIcon, RotateCwIcon} from "lucide-react";
|
||||
import {useProfiles} from "@/hooks/use-profiles.ts";
|
||||
|
||||
|
||||
function ProfileItemContent({item}: { item: Profile }) {
|
||||
const {refresh} = useProfiles()
|
||||
if (item.type == 'local') {
|
||||
return (
|
||||
<ItemContent className={'min-w-0 h-full'}>
|
||||
<ItemTitle className={'text-base'}><FileIcon size={20}/>{item.name}</ItemTitle>
|
||||
<ItemDescription>
|
||||
<span className={'block truncate flex-1'}>A simple item with title and description. Abcdef</span>
|
||||
</ItemDescription>
|
||||
<div className="flex justify-between text-[10px] text-muted-foreground mt-auto">
|
||||
<span>Local Profile</span>
|
||||
</div>
|
||||
</ItemContent>
|
||||
)
|
||||
}
|
||||
if (item.type == 'remote') {
|
||||
return (
|
||||
<>
|
||||
<div className="absolute inset-0 bg-primary/10 z-0 pointer-events-none transition-all" style={{width: '66%'}}/>
|
||||
<ItemContent className={'min-w-0 z-10'}>
|
||||
<ItemTitle className="w-full justify-between text-base">
|
||||
<div className={'flex items-center gap-2'}><CloudDownloadIcon size={20}/>{item.name}</div>
|
||||
<div
|
||||
className="p-1 rounded-md hover:bg-secondary transition-colors cursor-pointer"
|
||||
onClick={async (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
refresh.mutate(item.id!)
|
||||
}}>
|
||||
<RotateCwIcon size={16}
|
||||
className={cn("text-muted-foreground", refresh.isPending && "force-animate-spin")}/>
|
||||
</div>
|
||||
</ItemTitle>
|
||||
<ItemDescription>
|
||||
<span className={'block truncate flex-1'}>A simple item with title and description. Abcdef</span>
|
||||
</ItemDescription>
|
||||
<div className="flex justify-between text-[10px] text-muted-foreground mt-1">
|
||||
<span>Updated: Just now</span>
|
||||
<span>66 / 100 GB</span>
|
||||
</div>
|
||||
</ItemContent>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function ProfileItem({item, selected}: { item: Profile, selected: boolean }) {
|
||||
const dialog = useDialog();
|
||||
const {use, remove, refresh, editingFile} = useProfiles()
|
||||
|
||||
return <div id={item.id}>
|
||||
<ContextMenu>
|
||||
<ContextMenuTrigger asChild>
|
||||
<Item
|
||||
className={cn('relative overflow-hidden transition-all items-start h-24', selected && 'border-primary/50 bg-accent/60')}
|
||||
variant="outline" size="sm"
|
||||
onClick={() => (!selected) && use.mutate(item.id!)}
|
||||
asChild>
|
||||
<a>
|
||||
<ProfileItemContent item={item}/>
|
||||
</a>
|
||||
</Item>
|
||||
</ContextMenuTrigger>
|
||||
<ContextMenuContent>
|
||||
<ContextMenuItem onClick={() => item.id && use.mutate(item.id)}>
|
||||
Use
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => dialog.edit(item)}>
|
||||
Edit
|
||||
</ContextMenuItem>
|
||||
<ContextMenuItem onClick={() => item.id && editingFile.mutate(item.id)}>
|
||||
Edit File
|
||||
</ContextMenuItem>
|
||||
{item.type === 'remote' && (
|
||||
<ContextMenuItem onClick={() => refresh.mutate(item.id!)}>
|
||||
Update
|
||||
</ContextMenuItem>
|
||||
)}
|
||||
<ContextMenuSeparator/>
|
||||
<ContextMenuItem className="text-red-600"
|
||||
onClick={() => remove.mutate((item.id!))}>
|
||||
Delete
|
||||
</ContextMenuItem>
|
||||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
</div>
|
||||
}
|
||||
66
web/src/pages/Profiles/index.tsx
Normal file
66
web/src/pages/Profiles/index.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
import {ScrollableBody, ContentHeader} from "@/components/app-content.tsx";
|
||||
import {
|
||||
PlusIcon,
|
||||
RotateCwIcon,
|
||||
} from "lucide-react";
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {DialogProvider, useDialog} from "@/pages/Profiles/Dialog.tsx";
|
||||
import {ProfileItem} from "@/pages/Profiles/Item.tsx";
|
||||
import {useProfiles} from "@/hooks/use-profiles.ts";
|
||||
|
||||
|
||||
function ProfileSetContent() {
|
||||
const {profiles: {isPending, error, data}} = useProfiles()
|
||||
|
||||
if (isPending) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
if (error) {
|
||||
return <div>Error: {error.message}</div>;
|
||||
}
|
||||
if (!data?.items.length) {
|
||||
return <div>Nothing</div>
|
||||
}
|
||||
|
||||
return data.items.map((item) => {
|
||||
return (
|
||||
<ProfileItem key={item.id} item={item} selected={data.current === item.id}/>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 主要是因为 DialogProvider 内才能useDialog(), 所以单独拿出来
|
||||
* @constructor
|
||||
*/
|
||||
function Inner() {
|
||||
const dialog = useDialog();
|
||||
return (
|
||||
<>
|
||||
<ContentHeader className={'justify-between'}>
|
||||
Profiles
|
||||
<div>
|
||||
<Button variant={'ghost'} size={'icon'} onClick={() => dialog.edit()}>
|
||||
<PlusIcon/>
|
||||
</Button>
|
||||
<Button variant={'ghost'} size={'icon'}>
|
||||
<RotateCwIcon/>
|
||||
</Button>
|
||||
</div>
|
||||
</ContentHeader>
|
||||
<div className={'grid grid-cols-[repeat(auto-fill,minmax(18rem,1fr))] gap-2'}>
|
||||
<ProfileSetContent/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function Profiles() {
|
||||
return (
|
||||
<ScrollableBody>
|
||||
<DialogProvider>
|
||||
<Inner/>
|
||||
</DialogProvider>
|
||||
</ScrollableBody>
|
||||
)
|
||||
}
|
||||
347
web/src/pages/Proxies.tsx
Normal file
347
web/src/pages/Proxies.tsx
Normal file
@@ -0,0 +1,347 @@
|
||||
import {Container, ScrollableBody, ContentHeader} from "@/components/app-content.tsx";
|
||||
import {Tabs, TabsTrigger, TabsContent, TabsList} from "@/components/ui/tabs.tsx";
|
||||
import {Accordion, AccordionItem, AccordionTrigger, AccordionContent} from "@/components/ui/accordion.tsx";
|
||||
import {Item, ItemMedia, ItemContent, ItemTitle, ItemActions} from "@/components/ui/item.tsx";
|
||||
import {BadgeCheckIcon, ChevronRightIcon} from "lucide-react";
|
||||
|
||||
|
||||
export default function Proxies() {
|
||||
return (
|
||||
<ScrollableBody className={'pr-4'}>
|
||||
<Tabs defaultValue="rule" className="size-full">
|
||||
<ContentHeader className={'justify-between'}>
|
||||
Proxies
|
||||
<TabsList className={'sticky z-50'}>
|
||||
<TabsTrigger className={'w-14'} value="rule">Rule</TabsTrigger>
|
||||
<TabsTrigger className={'w-14'} value="global">Global</TabsTrigger>
|
||||
<TabsTrigger className={'w-14'} value="direct">Direct</TabsTrigger>
|
||||
</TabsList>
|
||||
</ContentHeader>
|
||||
|
||||
<TabsContent value="rule" className={'size-full min-h-0'}>
|
||||
<div className={'size-full flex flex-col gap-y-2'}>
|
||||
<Container className={'py-0'}>
|
||||
<Accordion
|
||||
type="multiple"
|
||||
className="w-full"
|
||||
defaultValue={[]}
|
||||
>
|
||||
<AccordionItem value="item1">
|
||||
<AccordionTrigger>Product Information</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className={'grid grid-cols-2 gap-4 text-balance'}>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</Container>
|
||||
<Container className={'py-0'}>
|
||||
<Accordion
|
||||
type="multiple"
|
||||
className="w-full"
|
||||
defaultValue={[]}
|
||||
>
|
||||
<AccordionItem value="item1">
|
||||
<AccordionTrigger>Product Information</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className={'grid grid-cols-2 gap-4 text-balance'}>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</Container>
|
||||
<Container className={'py-0'}>
|
||||
<Accordion
|
||||
type="multiple"
|
||||
className="w-full"
|
||||
defaultValue={[]}
|
||||
>
|
||||
<AccordionItem value="item1">
|
||||
<AccordionTrigger>Product Information</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className={'grid grid-cols-2 gap-4 text-balance'}>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</Container>
|
||||
<Container className={'py-0'}>
|
||||
<Accordion
|
||||
type="multiple"
|
||||
className="w-full"
|
||||
defaultValue={[]}
|
||||
>
|
||||
<AccordionItem value="item1">
|
||||
<AccordionTrigger>Product Information</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className={'grid grid-cols-2 gap-4 text-balance'}>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
<Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been
|
||||
verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item><Item variant="outline" size="sm" asChild>
|
||||
<a href="#">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>Your profile has been verified.</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<ChevronRightIcon className="size-4"/>
|
||||
</ItemActions>
|
||||
</a>
|
||||
</Item>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</Container>
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent value="global">Change your password here.</TabsContent>
|
||||
<TabsContent value="direct">Change your password here.</TabsContent>
|
||||
</Tabs>
|
||||
</ScrollableBody>
|
||||
)
|
||||
|
||||
}
|
||||
253
web/src/pages/Settings.tsx
Normal file
253
web/src/pages/Settings.tsx
Normal file
@@ -0,0 +1,253 @@
|
||||
import {ScrollableBody, ContentHeader, Container} from "@/components/app-content.tsx";
|
||||
import {BadgeCheckIcon, SettingsIcon} from "lucide-react";
|
||||
import {Item, ItemActions, ItemContent, ItemMedia, ItemTitle} from "@/components/ui/item.tsx";
|
||||
import {Switch} from "@/components/ui/switch.tsx";
|
||||
import {Button} from "@/components/ui/button.tsx";
|
||||
import {TunConfigModal} from "@/components/settings/tun-config-modal.tsx";
|
||||
import {useState} from "react";
|
||||
import {TunConfig} from "@/lib/types.ts";
|
||||
|
||||
export function Settings() {
|
||||
const [tunModalOpen, setTunModalOpen] = useState(false);
|
||||
|
||||
// 示例 TUN 配置数据
|
||||
const [tunConfig, setTunConfig] = useState<TunConfig>({
|
||||
enable: false,
|
||||
stack: 'system',
|
||||
dnsHijack: ['0.0.0.0:53'],
|
||||
autoRoute: true,
|
||||
autoDetectInterface: true,
|
||||
mtu: 9000,
|
||||
});
|
||||
|
||||
const handleSaveTunConfig = (newConfig: TunConfig) => {
|
||||
setTunConfig(newConfig);
|
||||
// TODO: 这里应该调用 Tauri 命令保存配置到后端
|
||||
console.log('保存 TUN 配置:', newConfig);
|
||||
};
|
||||
|
||||
const config = {
|
||||
auto_route: false,
|
||||
device: "",
|
||||
dns_hijack: [],
|
||||
enable: false,
|
||||
mtu: 0,
|
||||
stack: 'System',
|
||||
strict_route: false
|
||||
}
|
||||
|
||||
|
||||
if (!config) {
|
||||
return (
|
||||
<ScrollableBody>
|
||||
<ContentHeader>Settings</ContentHeader>
|
||||
<div className="p-4">Loading...</div>
|
||||
</ScrollableBody>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollableBody>
|
||||
<ContentHeader>Settings</ContentHeader>
|
||||
<Container className={'py-2 px-4'}>
|
||||
<span>App 设置</span>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>开机自启</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>静默启动</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>Clash 内核</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
</Container>
|
||||
<Container className={'py-2 px-4 mt-2'}>
|
||||
<span>Clash 设置</span>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle className="flex items-center gap-1.5">
|
||||
<span>虚拟网卡模式</span>
|
||||
<Button
|
||||
size={'icon-sm'}
|
||||
variant={'ghost'}
|
||||
onClick={() => setTunModalOpen(true)}
|
||||
className="h-5 w-5 p-0"
|
||||
>
|
||||
<SettingsIcon className="size-3.5 text-muted-foreground hover:text-foreground transition-colors" />
|
||||
</Button>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch
|
||||
checked={tunConfig.enable}
|
||||
onCheckedChange={(checked) => {
|
||||
setTunConfig({ ...tunConfig, enable: checked });
|
||||
}}
|
||||
/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>允许局域网</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>Ipv6</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>统一延迟</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Switch/>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>日志等级</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
INFO
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>端口设置</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button size={'icon-sm'} variant={'link'}>7890</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
</Container>
|
||||
<Container>
|
||||
<span>杂项</span>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>App 目录</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button size={'icon-sm'} variant={'link'}>7890</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>App 配置目录</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button size={'icon-sm'} variant={'link'}>7890</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>内核目录</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button size={'icon-sm'} variant={'link'}>7890</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
<Item className={'py-2 px-0'} variant="default" size="sm">
|
||||
<ItemMedia>
|
||||
<BadgeCheckIcon className="size-5"/>
|
||||
</ItemMedia>
|
||||
<ItemContent>
|
||||
<ItemTitle>
|
||||
<span>App 版本</span>
|
||||
</ItemTitle>
|
||||
</ItemContent>
|
||||
<ItemActions>
|
||||
<Button size={'icon-sm'} variant={'link'}>7890</Button>
|
||||
</ItemActions>
|
||||
</Item>
|
||||
</Container>
|
||||
|
||||
<TunConfigModal
|
||||
open={tunModalOpen}
|
||||
onOpenChange={setTunModalOpen}
|
||||
config={tunConfig}
|
||||
onSave={handleSaveTunConfig}
|
||||
/>
|
||||
</ScrollableBody>
|
||||
);
|
||||
}
|
||||
1
web/src/vite-env.d.ts
vendored
Normal file
1
web/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
Reference in New Issue
Block a user