From 04591517fa268df0fe1b472e98606e0b3c51741e Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 28 Jun 2026 01:14:37 +0800 Subject: [PATCH] feat(webui): redesign adapter edit dialog (Apple-HIG) + custom dropdown Rework the OneBot adapter create/edit modal into an iOS grouped-list layout matching the debug-page language: captioned soft-card sections, a per-kind icon chip, settings rows, and staggered motion entrance. - reportSelfMessage: segmented control -> shared ToggleSwitch - messageFormat (+ WS role): segmented/native select -> new custom DropdownSelect (accessible listbox, keyboard nav, spring popover) - enable toggle promoted to a prominent top card - new components/ui/dropdown-select.tsx (zero new deps, hand-rolled) Presentation-only; draft/validation/data flow unchanged. --- .../components/config/node-edit-dialog.tsx | 362 ++++++++---------- .../src/components/ui/dropdown-select.tsx | 143 +++++++ 2 files changed, 313 insertions(+), 192 deletions(-) create mode 100644 packages/webui/src/components/ui/dropdown-select.tsx diff --git a/packages/webui/src/components/config/node-edit-dialog.tsx b/packages/webui/src/components/config/node-edit-dialog.tsx index 2e70eca8..8ada17a5 100644 --- a/packages/webui/src/components/config/node-edit-dialog.tsx +++ b/packages/webui/src/components/config/node-edit-dialog.tsx @@ -2,9 +2,24 @@ // copy of the adapter until the user clicks save (so cancel really does // throw away changes). Validation is minimal — blank-name and dup-name // disable the save button; everything else is best-effort coercion. +// +// Visual language: Apple-HIG grouped-list flavour (matches debug-page) — +// captioned sections, soft rounded cards, settings rows with a label on the +// left and a control (toggle / custom dropdown) on the right. -import { useRef, useState } from 'react'; -import { Check, Copy, Eye, EyeOff } from 'lucide-react'; +import { useRef, useState, type ReactNode } from 'react'; +import { motion } from 'motion/react'; +import { + ArrowLeftRight, + ArrowUpRight, + Check, + Copy, + Eye, + EyeOff, + Radio, + Server, + type LucideIcon, +} from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Dialog, @@ -14,9 +29,10 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; +import { DropdownSelect, type DropdownOption } from '@/components/ui/dropdown-select'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Select } from '@/components/ui/select'; +import { ToggleSwitch } from '@/components/ui/toggle-switch'; import { cn } from '@/lib/utils'; import type { HttpClientNetwork, @@ -32,6 +48,13 @@ import { NETWORK_TABS } from './defaults'; type AnyAdapter = OneBotNetworks[K][number]; +const KIND_ICON: Record = { + httpServers: Server, + httpClients: ArrowUpRight, + wsServers: Radio, + wsClients: ArrowLeftRight, +}; + interface NodeEditDialogProps { open: boolean; onOpenChange: (open: boolean) => void; @@ -49,6 +72,7 @@ interface NodeEditDialogProps { export function NodeEditDialog(props: NodeEditDialogProps) { const { open, onOpenChange, kind, initial, isEdit, otherNames, onSubmit } = props; const tab = NETWORK_TABS[kind]; + const Icon: LucideIcon = KIND_ICON[kind]; // Local draft. The parent unmounts this component on close so each // open gets a fresh `initial` via useState's lazy init — no effect-based @@ -63,62 +87,101 @@ export function NodeEditDialog(props: NodeEditDialogProps const patch = (changes: Partial>) => setDraft({ ...draft, ...changes } as AnyAdapter); + const isWs = kind === 'wsServers' || kind === 'wsClients'; + const role = ((draft as WsServerNetwork | WsClientNetwork).role ?? 'Universal') as WsRole; + return ( - {isEdit ? `编辑 ${tab.noun}` : `新建 ${tab.noun}`} - {tab.description} +
+
+ +
+
+ {isEdit ? `编辑 ${tab.noun}` : `新建 ${tab.noun}`} + {tab.description} +
+
-
- patch({ name: v } as Partial>)} - error={blankName ? '请填写名称' : duplicateName ? '名称与其它节点重复' : undefined} - /> - - - - patch({ accessToken: v || undefined } as Partial>)} - /> - -
- patch({ messageFormat: v } as Partial>)} - /> - patch({ reportSelfMessage: v === 'on' } as Partial>)} - /> -
- -
-
- -

+

+ +
+ +

关闭后保存即可保留配置但不启动该节点

- patch({ enabled: v ? undefined : false } as Partial>) - } + onChange={(v) => patch({ enabled: v ? undefined : false } as Partial>)} ariaLabel="启用" /> -
+ + +
+
+ patch({ name: v } as Partial>)} + error={blankName ? '请填写名称' : duplicateName ? '名称与其它节点重复' : undefined} + /> + +
+
+ +
+
+ patch({ accessToken: v || undefined } as Partial>)} + /> +
+
+ +
+
+ + patch({ messageFormat: v } as Partial>)} + /> + + + {isWs && ( + + patch({ role: v } as unknown as Partial>)} + /> + + )} + + + patch({ reportSelfMessage: v } as Partial>)} + ariaLabel="上报自身消息" + /> + +
+
@@ -141,6 +204,36 @@ export function NodeEditDialog(props: NodeEditDialogProps ); } +// ─────────────── grouped-list scaffolding ─────────────── + +/** Captioned inset section — the iOS "grouped list" unit. */ +function Section({ caption, delay, children }: { caption: string; delay: number; children: ReactNode }) { + return ( + + {caption} +
{children}
+
+ ); +} + +/** Settings row — label (+ optional subtitle) on the left, control on the right. */ +function SettingRow({ label, desc, children }: { label: string; desc?: string; children: ReactNode }) { + return ( +
+
+ + {desc &&

{desc}

} +
+
{children}
+
+ ); +} + // ─────────────── kind-specific field strips ─────────────── interface KindFieldsProps { @@ -151,7 +244,8 @@ interface KindFieldsProps { function KindFields({ kind, draft, patch }: KindFieldsProps) { // Per-branch narrowing — TS can't follow the generic relationship so - // each arm casts once. Field components receive specific shapes. + // each arm casts once. Field components receive specific shapes. The WS + // `role` lives in the behaviour section, so it is intentionally absent here. if (kind === 'httpServers') { const it = draft as HttpServerNetwork; const set = patch as (c: Partial) => void; @@ -204,41 +298,33 @@ function KindFields({ kind, draft, patch }: KindFieldsPro const it = draft as WsServerNetwork; const set = patch as (c: Partial) => void; return ( - <> -
- set({ host: v || undefined })} - /> - set({ port: Number(v) || 0 })} - /> - set({ path: v || undefined })} - /> -
- set({ role: v })} +
+ set({ host: v || undefined })} /> - + set({ port: Number(v) || 0 })} + /> + set({ path: v || undefined })} + /> +
); } if (kind === 'wsClients') { const it = draft as WsClientNetwork; const set = patch as (c: Partial) => void; return ( - <> +
({ kind, draft, patch }: KindFieldsPro value={it.url} onChange={(v) => set({ url: v })} /> -
- set({ role: v })} - /> - set({ reconnectIntervalMs: Number(v) || undefined })} - /> -
- + set({ reconnectIntervalMs: Number(v) || undefined })} + /> +
); } return null; @@ -393,112 +471,12 @@ function TokenField({ label, value, onChange, placeholder }: TokenFieldProps) { ); } -interface SegmentedOption { - value: T; - label: string; -} - -function SegmentedField({ - label, - value, - options, - onChange, -}: { - label: string; - value: T; - options: ReadonlyArray>; - onChange: (v: T) => void; -}) { - return ( -
- -
- {options.map((opt) => { - const active = value === opt.value; - return ( - - ); - })} -
-
- ); -} - -function SelectField({ - label, - value, - options, - onChange, -}: { - label: string; - value: T; - options: ReadonlyArray>; - onChange: (v: T) => void; -}) { - return ( -
- - -
- ); -} - -interface ToggleSwitchProps { - value: boolean; - onChange: (v: boolean) => void; - ariaLabel: string; -} - -function ToggleSwitch({ value, onChange, ariaLabel }: ToggleSwitchProps) { - return ( - - ); -} - -const FORMAT_OPTIONS: ReadonlyArray> = [ +const FORMAT_OPTIONS: ReadonlyArray> = [ { value: 'array', label: '数组' }, { value: 'string', label: 'CQ 码' }, ]; -const REPORT_OPTIONS: ReadonlyArray> = [ - { value: 'on', label: '开启' }, - { value: 'off', label: '关闭' }, -]; - -const WS_ROLE_OPTIONS: ReadonlyArray> = [ +const WS_ROLE_OPTIONS: ReadonlyArray> = [ { value: 'Universal', label: 'Universal' }, { value: 'Event', label: 'Event' }, { value: 'Api', label: 'Api' }, diff --git a/packages/webui/src/components/ui/dropdown-select.tsx b/packages/webui/src/components/ui/dropdown-select.tsx new file mode 100644 index 00000000..164d4ada --- /dev/null +++ b/packages/webui/src/components/ui/dropdown-select.tsx @@ -0,0 +1,143 @@ +import { useEffect, useRef, useState } from 'react'; +import { AnimatePresence, motion } from 'motion/react'; +import { Check, ChevronDown } from 'lucide-react'; +import { cn } from '@/lib/utils'; + +export interface DropdownOption { + value: T; + label: string; +} + +interface DropdownSelectProps { + value: T; + options: ReadonlyArray>; + onChange: (v: T) => void; + ariaLabel: string; + className?: string; +} + +/** + * Custom (non-native) dropdown with an Apple-HIG flavour: a calm trigger that + * mirrors {@link Input}'s height/border, a soft floating menu that springs in, + * and a trailing check on the selected row. Keyboard-driven (arrows / enter / + * escape) and closes on outside pointer-down. Use when the design wants a menu + * that matches the surrounding chrome — the plain `Select` stays the zero-dep + * native fallback for dense forms. + */ +export function DropdownSelect({ + value, + options, + onChange, + ariaLabel, + className, +}: DropdownSelectProps) { + const [open, setOpen] = useState(false); + const [active, setActive] = useState(0); + const rootRef = useRef(null); + + const selected = options.find((o) => o.value === value); + + useEffect(() => { + if (!open) return; + // Seed the keyboard highlight on the current selection each time we open. + setActive(Math.max(0, options.findIndex((o) => o.value === value))); + const onPointer = (e: PointerEvent) => { + if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false); + }; + document.addEventListener('pointerdown', onPointer); + return () => document.removeEventListener('pointerdown', onPointer); + }, [open]); // eslint-disable-line react-hooks/exhaustive-deps + + const choose = (v: T) => { + onChange(v); + setOpen(false); + }; + + const onKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Escape' && open) { + // Swallow so the surrounding Dialog doesn't also close on the same key. + e.preventDefault(); + e.stopPropagation(); + setOpen(false); + return; + } + if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { + e.preventDefault(); + if (!open) { + setOpen(true); + return; + } + setActive((i) => { + const n = options.length; + return e.key === 'ArrowDown' ? (i + 1) % n : (i - 1 + n) % n; + }); + return; + } + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + if (!open) setOpen(true); + else if (options[active]) choose(options[active].value); + } + }; + + return ( +
+ + + + {open && ( + + {options.map((o, i) => { + const isSel = o.value === value; + const isActive = i === active; + return ( +
  • + +
  • + ); + })} +
    + )} +
    +
    + ); +}