Files
jiang13-bbs/frontend/components/admin/AdminSearchField.tsx
freefire d93635c961 feat: 全站评论开关,并统一后台表单控件
关闭评论后前台隐藏评论能力;外观/设置/公告改用 AdminField 与 Stepper。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 01:22:00 +08:00

62 lines
1.5 KiB
TypeScript

"use client";
import { Search, X } from "lucide-react";
import type { FormEvent } from "react";
/** 左图标、可清除、Enter 提交;壳层聚焦与聊天搜索一致 */
export default function AdminSearchField({
value,
onChange,
onSubmit,
onClear,
placeholder,
ariaLabel,
}: {
value: string;
onChange: (v: string) => void;
onSubmit?: () => void;
onClear?: () => void;
placeholder?: string;
ariaLabel: string;
}) {
const handleSubmit = (e: FormEvent) => {
e.preventDefault();
onSubmit?.();
};
const clear = () => {
onChange("");
onClear?.();
};
return (
<form onSubmit={handleSubmit} className="admin-field-shell admin-search-shell relative flex-1 min-w-0" role="search">
<Search
size={15}
className="shrink-0 pointer-events-none"
style={{ color: value ? "var(--accent)" : "var(--ink-3)" }}
aria-hidden
/>
<input
type="text"
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
aria-label={ariaLabel}
className="admin-field-input"
/>
{value ? (
<button
type="button"
onClick={clear}
aria-label="清除搜索"
className="w-6 h-6 inline-flex items-center justify-center rounded-full shrink-0 transition-colors hover:bg-[var(--accent-soft)]"
style={{ color: "var(--ink-3)" }}
>
<X size={14} />
</button>
) : null}
</form>
);
}