一分钟搭建影视站,支持Docker等部署方式
style(设置): 下拉框改用自定义浮层组件(Dropdown),统一三处下拉视觉与交互
bestZwei1a9e308fac1d
diff --git a/src/components/dropdown.tsx b/src/components/dropdown.tsxnew file mode 100644index 0000000..4858ed5--- /dev/null+++ b/src/components/dropdown.tsx@@ -0,0 +1,164 @@+'use client';++import { useEffect, useRef, useState, type KeyboardEvent } from 'react';+import { cn } from '@/lib/utils';+import { Icon } from './icon';++export interface DropdownOption {+ value: string;+ label: string;+ /** 选项面板内的次要说明(弱色小字,第二行),便于对比着选 */+ hint?: string;+}++/**+ * 自定义下拉:替代原生 <select>——原生展开面板由操作系统渲染,+ * 与站点风格割裂、暗色模式下尤其突兀。面板为浮层卡片(surface-raised + 阴影 ++ * fade-in),选中项带勾号;支持点击外部 / Esc 关闭与 ↑ ↓ Enter 键盘导航。+ * 焦点始终留在触发按钮上(不做选项级焦点管理),键盘高亮用 active 下标模拟。+ */+export function Dropdown({+ value,+ onChange,+ options,+ ariaLabel,+ className,+}: {+ value: string;+ onChange: (v: string) => void;+ options: DropdownOption[];+ ariaLabel: string;+ className?: string;+}) {+ const [open, setOpen] = useState(false);+ /** 键盘 / 悬停高亮项下标;-1 表示无高亮 */+ const [active, setActive] = useState(-1);+ const rootRef = useRef<HTMLDivElement>(null);++ const selected = options.find((o) => o.value === value);++ // 展开期间监听外部点击收起+ useEffect(() => {+ if (!open) return;+ const onDown = (e: MouseEvent) => {+ if (!rootRef.current?.contains(e.target as Node)) setOpen(false);+ };+ document.addEventListener('mousedown', onDown);+ return () => document.removeEventListener('mousedown', onDown);+ }, [open]);++ const toggle = () => {+ if (open) {+ setOpen(false);+ return;+ }+ setActive(options.findIndex((o) => o.value === value));+ setOpen(true);+ };++ const pick = (v: string) => {+ onChange(v);+ setOpen(false);+ };++ const onKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {+ if (!open) {+ // 收起时 Enter / Space / 方向键均可展开(原生 select 的习惯行为)+ if (e.key === 'Enter' || e.key === ' ' || e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ toggle();+ }+ return;+ }+ switch (e.key) {+ case 'Escape':+ e.preventDefault();+ setOpen(false);+ break;+ case 'ArrowDown':+ case 'ArrowUp': {+ e.preventDefault();+ const dir = e.key === 'ArrowDown' ? 1 : -1;+ setActive((i) => (Math.max(i, 0) + dir + options.length) % options.length);+ break;+ }+ case 'Enter': {+ e.preventDefault();+ const opt = options[active];+ if (opt) pick(opt.value);+ break;+ }+ }+ };++ return (+ <div ref={rootRef} className={cn('relative', className)}>+ <button+ type="button"+ aria-haspopup="listbox"+ aria-expanded={open}+ aria-label={ariaLabel}+ onClick={toggle}+ onKeyDown={onKeyDown}+ className={cn(+ 'input flex items-center justify-between gap-1.5 cursor-pointer text-left',+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 focus-visible:border-accent',+ open && 'border-accent'+ )}+ >+ <span className="truncate">{selected?.label ?? value}</span>+ <Icon+ name="chevronDown"+ className={cn(+ 'w-3.5 h-3.5 shrink-0 text-faint transition-transform duration-200',+ open && 'rotate-180 text-accent'+ )}+ />+ </button>+ {open && (+ <ul+ role="listbox"+ aria-label={ariaLabel}+ className={cn(+ 'absolute right-0 top-full z-50 mt-1.5 min-w-full w-max max-h-60 overflow-y-auto py-1',+ 'rounded-xl border border-line bg-surface-raised shadow-xl animate-fade-in'+ )}+ >+ {options.map((o, i) => {+ const isSelected = o.value === value;+ return (+ <li key={o.value}>+ <button+ type="button"+ role="option"+ aria-selected={isSelected}+ onMouseEnter={() => setActive(i)}+ onClick={() => pick(o.value)}+ className={cn(+ 'flex w-full items-center gap-2 px-3 py-1.5 text-left transition-colors',+ i === active && 'bg-hover'+ )}+ >+ <span className="min-w-0">+ <span+ className={cn(+ 'block whitespace-nowrap text-xs',+ isSelected ? 'text-accent font-medium' : 'text-content'+ )}+ >+ {o.label}+ </span>+ {o.hint && (+ <span className="block whitespace-nowrap text-[11px] text-faint">{o.hint}</span>+ )}+ </span>+ {isSelected && <Icon name="check" className="ml-auto w-3.5 h-3.5 shrink-0 text-accent" />}+ </button>+ </li>+ );+ })}+ </ul>+ )}+ </div>+ );+}diff --git a/src/components/live-channel-list.tsx b/src/components/live-channel-list.tsxindex 9262739..587d048 100644--- a/src/components/live-channel-list.tsx+++ b/src/components/live-channel-list.tsx@@ -4,6 +4,7 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useVirtualizer } from '@tanstack/react-virtual';import { cn } from '@/lib/utils';import { SmartImage } from './smart-image';+import { Dropdown } from './dropdown';import { useAppStore } from '@/lib/store';import {isSlowSource,@@ -254,18 +255,19 @@ export function LiveChannelList({ channels, groups, currentUrl, onSelect, onFilt}}}/>- <select- className="input !py-1.5 !px-1.5 text-xs w-auto shrink-0 cursor-pointer"+ <Dropdown+ className="shrink-0 [&>button]:!py-1.5 [&>button]:!px-2 [&>button]:text-xs"value={sortMode}- aria-label="排序方式"- onChange={(e) => setSortMode(e.target.value as LiveSortMode)}- >- <option value="default">默认</option>- <option value="name">名称</option>- <option value="group">分组</option>- <option value="probe">可用优先</option>- <option value="recent">最近看</option>- </select>+ ariaLabel="排序方式"+ onChange={(v) => setSortMode(v as LiveSortMode)}+ options={[+ { value: 'default', label: '默认' },+ { value: 'name', label: '名称' },+ { value: 'group', label: '分组' },+ { value: 'probe', label: '可用优先' },+ { value: 'recent', label: '最近看' },+ ]}+ /></div>{/* 测活 + 可用性筛选工具条 */}diff --git a/src/components/settings-shared.tsx b/src/components/settings-shared.tsxindex 4d60914..688f82b 100644--- a/src/components/settings-shared.tsx+++ b/src/components/settings-shared.tsx@@ -5,6 +5,7 @@ import { cn, formatDisableTtl } from '@/lib/utils';import { isInDisabledSubscription, useAppStore } from '@/lib/store';import { useToast } from './toast';import { Icon } from './icon';+import { Dropdown, type DropdownOption } from './dropdown';import { Spinner } from './states';/**@@ -115,38 +116,38 @@ export function Switch({);}+/**+ * 设置行下拉:自定义样式的下拉组件(见 Dropdown),替代原生 <select>——+ * 原生展开面板由操作系统渲染,与站点风格割裂且暗色模式下突兀;+ * 选中的详细说明由调用方经 description 随选项动态展示(对齐 ToggleRow 的布局)。+ */export function SelectRow({label,value,onChange,options,+ description,}: {label: string;value: string;onChange: (v: string) => void;- options: { value: string; label: string }[];+ options: DropdownOption[];+ /** 当前选中项的说明文案,随选中项变化 */+ description?: string;}) {return (- <div className="flex items-center justify-between gap-4">- <span className="text-sm text-content shrink-0">{label}</span>- <div className="relative min-w-0">- <select- className="input !py-1.5 !pl-2.5 !pr-7 cursor-pointer appearance-none text-xs max-w-full"- value={value}- onChange={(e) => onChange(e.target.value)}- aria-label={label}- >- {options.map((o) => (- <option key={o.value} value={o.value}>- {o.label}- </option>- ))}- </select>- <Icon- name="chevronDown"- className="pointer-events-none absolute right-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-faint"- />+ <div className="flex items-center justify-between gap-4 py-0.5">+ <div className="min-w-0">+ <div className="text-sm text-content">{label}</div>+ {description && <div className="text-xs text-faint">{description}</div>}</div>+ <Dropdown+ value={value}+ onChange={onChange}+ options={options}+ ariaLabel={label}+ className="shrink-0 [&>button]:!py-1.5 [&>button]:!pl-2.5 [&>button]:!pr-2 [&>button]:text-xs"+ /></div>);}diff --git a/src/components/source-manager.tsx b/src/components/source-manager.tsxindex bd71682..46ba411 100644--- a/src/components/source-manager.tsx+++ b/src/components/source-manager.tsx@@ -648,15 +648,15 @@ function ImagePanel() {<SelectRowlabel="加载方式"value={mode}+ description={description[mode]}onChange={(v) => store.updateSettings({ imageProxyMode: v as 'direct' | 'proxy' | 'custom' })}options={[- { value: 'direct', label: '直连优先(推荐)' },- { value: 'proxy', label: '内置代理' },- { value: 'custom', label: '自定义代理' },+ { value: 'direct', label: '直连优先', hint: '最省服务器流量' },+ { value: 'proxy', label: '内置代理', hint: '最稳定' },+ { value: 'custom', label: '自定义', hint: '自建转发模板' },]}/>{mode === 'custom' && <CustomProxyInput />}- <p className="text-xs text-faint">{description[mode]}。</p></div></section>);@@ -714,9 +714,9 @@ function HomePanel() {value={store.recommendSource}onChange={(v) => store.updateSettings({ recommendSource: v as 'douban' | 'bangumi' | 'hot-list' })}options={[- { value: 'douban', label: '豆瓣(电影/剧集)' },- { value: 'bangumi', label: 'Bangumi 新番放送' },- { value: 'hot-list', label: '影视榜单(豆瓣周榜/百度热播)' },+ { value: 'douban', label: '豆瓣', hint: '热门电影与剧集' },+ { value: 'bangumi', label: 'Bangumi', hint: '每日新番放送(免 key)' },+ { value: 'hot-list', label: '影视榜单', hint: '豆瓣周榜 / 百度热播' },]}/></div>