Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)7.8k · #13053

enhance-typescript-ui-components

Skill này làm gì

Skill này hướng dẫn AI agent thêm các tính năng trực quan như ảnh thu nhỏ, huy hiệu và màu theo dữ liệu vào component TypeScript. Nó dành cho nhà phát triển muốn các mục danh sách và thẻ hiển thị thông tin rõ hơn.

Khi nào nên dùng

  • ✓Khi bạn muốn thêm huy hiệu hoặc nhãn vào các mục danh sách hoặc thẻ hiện có.
  • ✓Khi các mục cần ảnh thu nhỏ với ảnh giữ chỗ khi thiếu hình.
  • ✓Khi màu sắc hoặc style nên thay đổi theo dữ liệu.

Liên kết skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/enhance-typescript-ui-components/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/enhance-typescript-ui-components/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm một huy hiệu danh mục có màu và một ảnh thu nhỏ cho mỗi mục trong danh sách tin tức của tôi, với ảnh giữ chỗ khi không có hình.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent thêm bảng màu và hằng số kích thước ở đầu file TypeScript, rồi viết các phương thức hỗ trợ cho màu động và biến đổi. Sau đó nó cập nhật CSS để các phần trực quan mới hiển thị đúng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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: #e0e0
Câu hỏi thường gặp

Cài đặt màu được giữ ở đâu?

Skill đặt bảng ánh xạ màu và hằng số kích thước gần đầu file để dễ thay đổi.

Điều gì xảy ra nếu thiếu ảnh?

Skill có một ảnh giữ chỗ dự phòng cho ảnh thu nhỏ.

Nó có cập nhật CSS không?

Có, skill phối hợp các thay đổi TypeScript với cập nhật CSS tương ứng.

Chi tiết

Mô tả gốc của tác giả

Add visual features (thumbnails, badges, dynamic styling) to TypeScript components by coordinating TypeScript logic changes with CSS updates

repo: HKUDS/AgentPilot

Độ phổ biến

Sao GitHub
7.8k
Vị trí xếp hạng
#13053
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự