From 80fbf0da2f8055df5dfbf8153b434975cb9d911a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A4=A7=E7=8C=AB?= <16399091+binaricat@users.noreply.github.com> Date: Thu, 9 Apr 2026 01:38:50 +0800 Subject: [PATCH] feat: add data-section hooks for Custom CSS targeting (#642) (#655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Custom CSS already exists in Settings → Appearance, but major UI components use only Tailwind utility classes, making it hard for users to reliably target regions in their custom styles. This adds stable `data-section="..."` attributes on the root element of the most commonly customized UI regions so users can write selectors like `[data-section="snippets-panel"] { font-size: 14px !important; }` without depending on implementation details. Instrumented regions: - snippets-panel (ScriptsSidePanel) - host-details-panel (HostDetailsPanel via AsidePanel dataSection prop) - group-details-panel (GroupDetailsPanel) - serial-host-details-panel (SerialHostDetailsPanel) - ai-chat-panel (AIChatSidePanel) - vault-view / vault-sidebar / vault-main / vault-hosts-header / vault-host-list (VaultView) - terminal-workspace / terminal-workspace-sidebar (TerminalLayer) - top-tabs (TopTabs — also keeps existing data-top-tabs-root) Also updated the Custom CSS description and placeholder in both English and Chinese to list available hooks and show a working example (snippet panel font-size override). Closes #642 Co-authored-by: Claude Opus 4.6 (1M context) --- application/i18n/locales/en.ts | 4 ++-- application/i18n/locales/zh-CN.ts | 5 +++-- components/AIChatSidePanel.tsx | 2 +- components/GroupDetailsPanel.tsx | 1 + components/HostDetailsPanel.tsx | 1 + components/ScriptsSidePanel.tsx | 5 ++++- components/SerialHostDetailsPanel.tsx | 1 + components/TerminalLayer.tsx | 6 +++++- components/TopTabs.tsx | 1 + components/VaultView.tsx | 20 ++++++++++++++------ components/ui/aside-panel.tsx | 18 ++++++++++++++++-- 11 files changed, 49 insertions(+), 15 deletions(-) diff --git a/application/i18n/locales/en.ts b/application/i18n/locales/en.ts index 2953f6318..85cc624ac 100644 --- a/application/i18n/locales/en.ts +++ b/application/i18n/locales/en.ts @@ -237,9 +237,9 @@ const en: Messages = { 'settings.appearance.themeColor.dark': 'Dark palette', 'settings.appearance.customCss': 'Custom CSS', 'settings.appearance.customCss.desc': - 'Add custom CSS to personalize the app appearance. Changes apply immediately.', + 'Add custom CSS to personalize the app appearance. Changes apply immediately. Major UI regions expose a [data-section="..."] attribute you can target — e.g. snippets-panel, host-details-panel, group-details-panel, serial-host-details-panel, ai-chat-panel, vault-sidebar, vault-main, vault-hosts-header, vault-host-list, vault-view, terminal-workspace, terminal-workspace-sidebar, top-tabs.', 'settings.appearance.customCss.placeholder': - '/* Example: */\n.terminal { background: #1a1a2e !important; }\n:root { --radius: 0.25rem; }', + '/* Examples — use !important to beat Tailwind utility specificity */\n\n/* Make snippet sidebar text larger */\n[data-section="snippets-panel"] {\n font-size: 14px !important;\n}\n\n/* Custom terminal background */\n.terminal { background: #1a1a2e !important; }\n\n/* Tweak global border radius */\n:root { --radius: 0.25rem; }', 'settings.appearance.language': 'Language', 'settings.appearance.language.desc': 'Choose the UI language', 'settings.appearance.uiFont': 'Interface Font', diff --git a/application/i18n/locales/zh-CN.ts b/application/i18n/locales/zh-CN.ts index cde328602..04ea04a61 100644 --- a/application/i18n/locales/zh-CN.ts +++ b/application/i18n/locales/zh-CN.ts @@ -220,9 +220,10 @@ const zhCN: Messages = { 'settings.appearance.themeColor.light': '浅色主题', 'settings.appearance.themeColor.dark': '深色主题', 'settings.appearance.customCss': '自定义 CSS', - 'settings.appearance.customCss.desc': '使用自定义 CSS 个性化界面,修改会立即生效。', + 'settings.appearance.customCss.desc': + '使用自定义 CSS 个性化界面,修改会立即生效。主要 UI 区块都暴露了 [data-section="..."] 属性供你定位,比如:snippets-panel、host-details-panel、group-details-panel、serial-host-details-panel、ai-chat-panel、vault-sidebar、vault-main、vault-hosts-header、vault-host-list、vault-view、terminal-workspace、terminal-workspace-sidebar、top-tabs。', 'settings.appearance.customCss.placeholder': - '/* 示例:*/\n.terminal { background: #1a1a2e !important; }\n:root { --radius: 0.25rem; }', + '/* 示例 — 由于 Tailwind 优先级较高,需要使用 !important */\n\n/* 放大代码片段侧边栏字号 */\n[data-section="snippets-panel"] {\n font-size: 14px !important;\n}\n\n/* 自定义终端背景色 */\n.terminal { background: #1a1a2e !important; }\n\n/* 调整全局圆角 */\n:root { --radius: 0.25rem; }', 'settings.appearance.language': '语言', 'settings.appearance.language.desc': '选择界面语言', 'settings.appearance.uiFont': '界面字体', diff --git a/components/AIChatSidePanel.tsx b/components/AIChatSidePanel.tsx index 299b1981a..261da0fda 100644 --- a/components/AIChatSidePanel.tsx +++ b/components/AIChatSidePanel.tsx @@ -775,7 +775,7 @@ const AIChatSidePanelInner: React.FC = ({ if (!isVisible) return null; return ( -
+
{/* ── Header ── */}
= ({ open={true} onClose={onCancel} width="w-[380px]" + dataSection="group-details-panel" title={t("vault.groups.details")} layout={layout} actions={ diff --git a/components/HostDetailsPanel.tsx b/components/HostDetailsPanel.tsx index 3af8aae58..d383670fc 100644 --- a/components/HostDetailsPanel.tsx +++ b/components/HostDetailsPanel.tsx @@ -634,6 +634,7 @@ const HostDetailsPanel: React.FC = ({ onClose={onCancel} width="w-[420px]" layout={layout} + dataSection="host-details-panel" title={ initialData ? t("hostDetails.title.details") : t("hostDetails.title.new") } diff --git a/components/ScriptsSidePanel.tsx b/components/ScriptsSidePanel.tsx index c0481b22b..1d9572667 100644 --- a/components/ScriptsSidePanel.tsx +++ b/components/ScriptsSidePanel.tsx @@ -124,7 +124,10 @@ const ScriptsSidePanelInner: React.FC = ({ const hasAnyContent = snippets.length > 0 || packages.length > 0; return ( -
+
{/* Search */}
diff --git a/components/SerialHostDetailsPanel.tsx b/components/SerialHostDetailsPanel.tsx index 908aae438..0787603e4 100644 --- a/components/SerialHostDetailsPanel.tsx +++ b/components/SerialHostDetailsPanel.tsx @@ -168,6 +168,7 @@ export const SerialHostDetailsPanel: React.FC = ({ subtitle={initialData.label} className="z-40" layout={layout} + dataSection="serial-host-details-panel" > {/* Label */} diff --git a/components/TerminalLayer.tsx b/components/TerminalLayer.tsx index 0c9e9c888..4a7403f68 100644 --- a/components/TerminalLayer.tsx +++ b/components/TerminalLayer.tsx @@ -1819,7 +1819,10 @@ const TerminalLayerInner: React.FC = ({ if (!activeWorkspace || !isFocusMode) return null; return ( -
+
{/* Header with view toggle */}
@@ -1890,6 +1893,7 @@ const TerminalLayerInner: React.FC = ({
= ({ return (
= ({ // Component no longer handles visibility - that's done by VaultViewWrapper return ( -
+
{/* Sidebar */} -
+
= ({ {/* Main Area */} -
+
@@ -1935,6 +1942,7 @@ const VaultViewInner: React.FC = ({ "flex-1 overflow-auto px-4 py-4 space-y-6", !isHostsSectionActive && "hidden", )} + data-section="vault-host-list" onDragEndCapture={() => setDragOverDropTarget(null)} >
diff --git a/components/ui/aside-panel.tsx b/components/ui/aside-panel.tsx index 9a57ccd0a..cbe81dda7 100644 --- a/components/ui/aside-panel.tsx +++ b/components/ui/aside-panel.tsx @@ -45,6 +45,11 @@ interface AsidePanelProps { className?: string; width?: string; layout?: AsidePanelLayout; + /** + * Optional stable identifier emitted as `data-section` on the panel + * root. Used as a targeting hook for Custom CSS (Settings → Appearance). + */ + dataSection?: string; } interface AsidePanelHeaderProps { @@ -173,6 +178,11 @@ interface AsidePanelStackProps { className?: string; width?: string; layout?: AsidePanelLayout; + /** + * Optional stable identifier emitted as `data-section` on the panel + * root. Used as a targeting hook for Custom CSS. + */ + dataSection?: string; } export type AsidePanelLayout = 'overlay' | 'inline'; @@ -200,6 +210,7 @@ export const AsidePanelStack: React.FC = ({ className, width = 'w-[380px]', layout = 'overlay', + dataSection, }) => { const [stack, setStack] = useState([initialItem]); @@ -252,7 +263,8 @@ export const AsidePanelStack: React.FC = ({ layout === 'overlay' && width, className )} - style={inlineStyle}> + style={inlineStyle} + data-section={dataSection}> = ({ className, width = 'w-[380px]', layout = 'overlay', + dataSection, }) => { if (!open) return null; @@ -299,7 +312,8 @@ export const AsidePanel: React.FC = ({ layout === 'overlay' && width, className )} - style={inlineStyle}> + style={inlineStyle} + data-section={dataSection}> {title && (