本文へスキップ
Skillpedia
WebサイトとUI(フロントエンド)7.8k · #13053

enhance-typescript-ui-components

できること

このスキルは、AIエージェントがサムネイル、バッジ、データに応じた色などの視覚的な機能を、TypeScriptのコンポーネントに追加するよう導きます。リストの項目やカードを、より情報的に見せたい開発者向けです。

使う場面

  • ✓既存のリストの項目やカードに、バッジやラベルを追加したいとき。
  • ✓画像がないときにプレースホルダーを表示する、サムネイルが必要な項目があるとき。
  • ✓データに応じて、色やスタイルを変えたいとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/enhance-typescript-ui-components/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“ニュースのリストの各項目に、色付きのカテゴリーのバッジとサムネイルを追加してください。画像がないときはプレースホルダーを表示してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントは、TypeScriptファイルの先頭に色のマップとサイズの定数を追加し、動的な色と変換のためのヘルパーメソッドを書きます。その後、新しい視覚的な部分が正しく表示されるよう、CSSを更新します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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
よくある質問

色の設定はどこに置かれますか?

変更しやすいように、色の対応表とサイズの定数をファイルの先頭近くに置きます。

画像がないときはどうなりますか?

スキルは、サムネイルのための代替のプレースホルダーを含みます。

CSSも更新されますか?

はい。スキルは、TypeScriptの変更と対応するCSSの更新を調整します。

詳細

作者による元の説明

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

repo: HKUDS/AgentPilot

人気

GitHubのスター
7.8k
ランキング
#13053
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル