Skillpedia
المواقع والواجهات (frontend)7.8k · #13053

enhance-typescript-ui-components

ما الذي تفعله

توجّه هذه المهارة وكيل الذكاء الاصطناعي إلى إضافة عناصر بصرية مثل الصور المصغرة والشارات والألوان المرتبطة بالبيانات إلى مكونات TypeScript. وهي مناسبة لمن يريد أن تبدو القوائم والبطاقات أكثر وضوحًا.

متى تستخدمها

  • ✓عندما تريد إضافة شارات أو تسميات إلى عناصر قائمة أو بطاقات موجودة.
  • ✓عندما تحتاج العناصر إلى صور مصغرة مع صورة بديلة عند غياب الصورة.
  • ✓عندما يجب أن تتغير الألوان أو الأنماط حسب البيانات.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/enhance-typescript-ui-components/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أضف شارة فئة ملونة وصورة مصغرة إلى كل عنصر في قائمة الأخبار، مع صورة بديلة عند غياب الصورة.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

يضيف الوكيل خرائط الألوان وثوابت الحجم في أعلى ملف 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
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة