panel-visual-badges
它能做什么
这个技能为仪表盘面板添加视觉元素,例如状态标签、小缩略图和颜色标签。它建立在带有重试和设置保存功能的面板模式之上。适合需要便于快速浏览的数据仪表盘制作者。
适用场景
- ✓当你想用彩色标签显示仪表盘项目的来源或状态时。
- ✓当你想在仪表盘列表的项目旁边显示小缩略图时。
- ✓当你希望颜色根据数据变化,例如根据状态或来源变化时。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-visual-badges/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我在仪表盘的新闻面板中加入彩色状态标签和小缩略图。”
每周 5 个新技能,1 分钟读完。
工作原理
颜色和来源的设置保存在同一处。面板读取这些数据,并为每个项目添加标签或图片。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Robust UI Panel Components
Build visually rich, robust TypeScript UI components using a panel architecture pattern. This skill combines enhanced panel features (retry logic, state persistence) with a systematic workflow for adding visual enhancements (badges, thumbnails, dynamic styling).
Architecture Overview
Core Panel Features
- Retry Logic: Automatically retries failed data fetches with exponential backoff.
- State Persistence: Saves panel state (expanded/collapsed, size) to localStorage.
- Detailed Error Handling: Provides granular error messages and recovery options.
- Visual Enhancements: Systematic approach for adding badges, thumbnails, and dynamic styling.
Panel (base class)
├── element: HTMLElement (outer container, .panel)
│ ├── header: HTMLElement (.panel-header)
│ │ ├── headerLeft (.panel-header-left)
│ │ │ ├── title (.panel-title)
│ │ │ └── newBadge (.panel-new-badge) [optional]
│ │ ├── statusBadge (.panel-data-badge) [optional]
│ │ └── countEl (.panel-count) [optional]
│ ├── content: HTMLElement (.panel-content)
│ └── resizeHandle (.panel-resize-handle)
Implementation Workflow
1. Define Constants and Configuration
// Panel configuration
const PANEL_DEFAULTS = {
maxRetries: 3,
initialRetryDelay: 1000, // 1s
};
// Visual configuration
const SOURCE_COLORS: { [key: string]: string } = {
'Category A': '#FF6B6B',
'Category B': '#4ECDC4',
'default': '#95A5A6'
};
const THUMBNAIL_SIZE = 48; // pixels
2. Base Panel Class with Enhanced Features
export class Panel {
protected element: HTMLElement;
protected content: HTMLElement;
protected panelId: string;
private retryAttempts = 0;
private retryDelay = PANEL_DEFAULTS.initialRetryDelay;
constructor(options: PanelOptions) {
// ... existing constructor code ...
this.loadState();
}
protected async fetchWithRetry(url: string):<any> {
while (this.retryAttempts < PANEL_DEFAULTS.maxRetries) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.json();
} catch (error) {
this.retryAttempts++;
if (this.retryAttempts >= PANEL_DEFAULTS.maxRetries) {
throw new Error(`Failed after ${PANEL_DEFAULTS.maxRetries} attempts: ${error.message}`);
}
await new Promise(resolve => setTimeout(resolve, this.retryDelay));
this.retryDelay *= 2;
}
}
}
public saveState(): void {
localStorage.setItem(`panelState_${this.panelId}`, JSON.stringify({
isExpanded: !this.element.classList.contains('collapsed'),
width: this.element.style.width,
height: this.element.style.height
}));
}
public loadState(): void {
const savedState = localStorage.getItem(`panelState_${this.panelId}`);
if (savedState) {
const { isExpanded, width, height } = JSON.parse(savedState);
if (!isExpanded) this.element.classList.add('collapsed');
if (width) this.element.style.width = width;
if (height) this.element.style.height = height;
}
}
// Visual enhancement helpers
protected getColorForSource(source: string): string {
return SOURCE_COLORS[source] || SOURCE_COLORS['default'];
}
protected getThumbnailUrl(imageUrl?: string): string {
return imageUrl || `https://via.placeholder.com/${THUMBNAIL_SIZE}`;
}
}
3. Creating Enhanced Components
export class NewsPanel extends Panel {
private refreshTimer: ReturnType<typeof setInterval> | null = null;
constructor() {
super({ id: 'news', title: 'News Feed', showCount: true });
this.fetchData();
this.refreshTimer = setInterval(() => this.fetchData(), 60_000);
}
private async fetchData(): Promise<void> {
try {
const newsItems = await this.fetchWithRetry('/api/news');
this.render(newsItems);
this.setCount(newsItems.length);
this.saveState();
} catch (err) {
this.showError(`Failed to load news: ${err.message}`, () => {
this.retryAttempts = 0;
this.retryDelay = PANEL_DEFAULTS.initialRetryDelay;
this.fetchData();
});
}
}
private render(items: NewsItem[]): void {
const html = items.map(item => `
<div class="news-item">
<img src="${this.getThumbnailUrl(item.imageUrl)}" class="news-thumbnail">
<div class="news-content">
<h3>${item.tit
常见问题
在哪里设置标签颜色?
颜色列在一个配置对象中,你可以在那里修改。
这需要重试和设置保存模式吗?
标签可以单独使用,但这个技能的设计是基于带有重试和设置保存功能的面板模式。
我可以添加自己的标签类型吗?
可以。在配置中添加一个新条目,然后就可以在面板中使用了。
详情
作者的原始描述
Create visually rich, robust TypeScript UI components with panel architecture, combining enhanced features like retry logic, state persistence, and dynamic styling with a systematic workflow for visual enhancements.
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #13075
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。