enhance-typescript-ui-components

通过将 TypeScript 逻辑更改与 CSS 更新协调,将视觉功能(如缩略图、徽章和动态样式)添加到 TypeScript 组件,提升组件的外观与交互表现。

仓库最近推送
GitHub Stars
8,134
Forks
953
Issues / PRs
39

预览截图

来自skillπ 实验室的展示

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "enhance-typescript-ui-components":https://skillpi.com/zh/skills/deepskill-0be0953baf715f0e0e8d5d585124d2a7fefe3440f10b50b08bc194610b28a346。安装前核对上游来源和版本:https://github.com/HKUDS/OpenSpace。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

通过将 TypeScript 逻辑更改与 CSS 更新协调,将视觉功能(如缩略图、徽章和动态样式)添加到 TypeScript 组件,提升组件的外观与交互表现。

0 下载

介绍来源: third_party · HKUDS · 0.0.1 参考来源

SkillPi 解读

能完成的任务
通过协调 TypeScript 逻辑变化与 CSS 更新,在 TypeScript 组件中添加视觉特性(thumbnails, 徽章, 动态样式)
适合谁
在现有组件中添加视觉指标(标签、标签、图标) 应用动态、数据驱动的颜色或样式
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: enhance-typescript-ui-components
description: Add visual features (thumbnails, badges, dynamic styling) to TypeScript components by coordinating TypeScript logic changes with CSS updates

Enhance TypeScript UI Components

A systematic workflow for adding visual enhancements to TypeScript UI components, including thumbnails, color-coded badges, and dynamic styling. This pattern applies to component files that render data items (lists, panels, cards, etc.).

When to Use This Skill

  • Adding visual indicators (badges, labels, icons) to existing components
  • Implementing thumbnail images with fallback placeholders
  • Applying dynamic, data-driven colors or styles
  • Coordinating TypeScript component logic with CSS styling

Workflow Steps

1. Add Constants at File Top

Define color mappings, size constants, and configuration data near the top of the TypeScript file, after imports but before the class definition.

// Color mappings for categories/sources
const SOURCE_COLORS: { [key: string]: string } = {
  'Category A': '#FF6B6B',
  'Category B': '#4ECDC4',
  'Category C': '#45B7D1',
  'default': '#95A5A6'
};

// Size constants
const THUMBNAIL_SIZE = 48; // pixels
const BADGE_HEIGHT = 20;

Why: Centralizes configuration for easy maintenance and avoids magic values scattered throughout code.

2. Implement Helper Methods

Create private helper methods for dynamic style calculations and data transformations. Place these before the main render method.

private getColorForItem(item: DataItem): string {
  return SOURCE_COLORS[item.category] || SOURCE_COLORS['default'];
}

private sortItemsByDate(items: DataItem[]): DataItem[] {
  return [...items].sort((a, b) => 
    new Date(b.date).getTime() - new Date(a.date).getTime()
  );
}

private getThumbnailUrl(item: DataItem): string {
  return item.imageUrl || `https://via.placeholder.com/${THUMBNAIL_SIZE}`;
}

Why: Separates logic from presentation, makes code testable, and improves readability.

3. Sort Data Before Rendering

If displaying lists, apply sorting transformations before building HTML.

public render(): void {
  const sortedItems = this.sortItemsByDate(this.items);
  const html = sortedItems.map(item => this.renderItem(item)).join('');
  this.container.innerHTML = html;
}

Why: Ensures consistent presentation order and separates data transformation from rendering.

4. Build HTML with Template Literals

Use template literals for HTML construction with conditional rendering for optional fields.

private renderItem(item: DataItem): string {
  const itemColor = this.getColorForItem(item);
  const thumbnailUrl = this.getThumbnailUrl(item);

  return `
    <div class="item-card">
      ${item.imageUrl ? `
        <img 
          src="${thumbnailUrl}" 
          alt="${item.title}"
          class="item-thumbnail"
        />
      ` : `
        <div class="item-thumbnail-placeholder"></div>
      `}

      <div class="item-content">
        <h3>${item.title}</h3>
        ${item.category ? `
          <span 
            class="item-badge" 
            style="background-color: ${itemColor};"
          >
            ${item.category}
          </span>
        ` : ''}
        <p>${item.description}</p>
      </div>
    </div>
  `;
}

Why: Enables conditional rendering and keeps HTML structure clear. Dynamic values can be safely interpolated.

5. Apply Inline Styles for Dynamic Values Only

Use inline style attributes only for data-driven dynamic values (colors, sizes from data). Keep structural/layout styles in CSS.

// ✅ Good - dynamic color from data
style="background-color: ${this.getColorForItem(item)};"

// ❌ Bad - structural styling should be in CSS
style="display: flex; padding: 10px; background-color: ${color};"

// ✅ Better - split concerns
class="item-badge" style="background-color: ${color};"

Why: Maintains separation of concerns—data-driven values in TS, structural styles in CSS.

6. Create or Update Corresponding CSS

For each new HTML element or class added in TypeScript, add corresponding CSS rules. Focus on:

  • Layout and positioning
  • Static colors and backgrounds
  • Sizing (when not dynamic)
  • Spacing (margin, padding)
  • Typography
/* Component container */
.item-card {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid #eee;
}

/* Thumbnail styles */
.item-thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.item-thumbnail-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background-color: #e0e0e0;
  flex-shrink: 0;
}

/* Badge styles (color applied inline) */
.item-badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
}

Why: CSS handles layout and static styling efficiently; inline styles only for truly dynamic values.

7. Coordinate Changes Across Files

Checklist for each enhancement:

  • [ ] TypeScript: Add constants/configuration
  • [ ] TypeScript: Implement helper methods
  • [ ] TypeScript: Update HTML template
  • [ ] TypeScript: Add inline styles for dynamic values
  • [ ] CSS: Add structural styles for new elements
  • [ ] CSS: Ensure responsive behavior if needed
  • [ ] Test with real data and edge cases (missing images, long text, etc.)

Best Practices

  1. Fallback handling: Always provide fallbacks for optional data (placeholder images, default colors, etc.)
  2. Escape user data: If rendering user-provided content, sanitize/escape to prevent XSS
  3. Keep methods focused: Each helper method should do one thing well
  4. Use semantic class names: Prefer .item-thumbnail over .img-48
  5. Test edge cases: Empty lists, missing fields, very long text, special characters

Example: Adding Source Badges

Before (simple list):

items.forEach(item => {
  html += `<div>${item.title}</div>`;
});

After (enhanced with badges):

// 1. Add constants
const SOURCE_COLORS = {
  'TechNews': '#3498db',
  'default': '#95a5a6'
};

// 2. Helper method
private getSourceColor(source: string): string {
  return SOURCE_COLORS[source] || SOURCE_COLORS['default'];
}

// 3. Enhanced template
items.forEach(item => {
  const color = this.getSourceColor(item.source);
  html += `
    <div class="news-item">
      <span class="source-badge" style="background-color: ${color};">
        ${item.source}
      </span>
      <div>${item.title}</div>
    </div>
  `;
});

// 4. CSS (in stylesheet)
// .source-badge {
//   padding: 2px 6px;
//   border-radius: 3px;
//   font-size: 11px;
//   color: white;
// }

Common Pitfalls

  • Mixing concerns: Don't put all layout styles inline; use CSS for structure
  • Forgetting fallbacks: Always handle missing/null optional fields
  • Hard-coded values: Extract magic numbers and colors to constants
  • Skipping CSS updates: Every new HTML structure needs corresponding CSS
  • Not testing edge cases: Test with missing images, empty strings, special characters

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供系统化的TypeScript UI组件视觉增强工作流
  • 涵盖缩略图、徽章、动态样式等常见前端开发需求
  • 具有明确的适用场景和实用价值
触发精准88/100

亮点

  • 触发词覆盖全面,包含visual features、thumbnails、badges等关键词
  • description清晰描述了核心功能和使用场景
结构规范92/100

待提升项

  • 缺少When to Use章节 原报告严重程度:轻微

    文档中提到了When to Use This Skill,但没有独立的章节标题

    改进建议:建议将'When to Use This Skill'部分设置为独立章节,提升文档结构清晰度

亮点

  • 工作流程步骤清晰,从常量定义到CSS更新完整覆盖
  • 提供了详细的代码示例和最佳实践
  • 包含常见陷阱和解决方案
执行可靠85/100

亮点

  • 提供了完整的实现步骤和检查清单
  • 包含异常处理建议和测试指导
  • 代码示例完整且可执行
证据可验 (前四项均值)88/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • via.placeholder.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。