Chuyển đến nội dung
Skillpedia
Giao diện (UI/UX)41k · #6809

web-component-design

Skill này làm gì

Công cụ này giúp tạo các thành phần giao diện người dùng có thể tái sử dụng và có tổ chức cho website và ứng dụng. Nó hướng dẫn các mẫu xây dựng thành phần hiệu quả và đẹp mắt, dùng các công nghệ như React, Vue và Svelte.

Khi nào nên dùng

  • ✓Khi xây dựng thư viện thành phần trực quan cho dự án.
  • ✓Khi thiết kế diện mạo và hành vi của nút, thẻ hoặc các phần tử khác.
  • ✓Khi quyết định cách áp dụng kiểu dáng (màu sắc, phông chữ, kích thước) cho thành phần.

Liên kết skill

https://github.com/wshobson/agents/blob/main/plugins/ui-design/skills/web-component-design/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/wshobson/agents/blob/main/plugins/ui-design/skills/web-component-design/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

“Làm sao để tạo một nút có thể tái sử dụng trong React, có các màu khác nhau và có biểu tượng?”

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

Cách hoạt động

Công cụ dạy các cách khác nhau để kết hợp thành phần sao cho chúng hoạt động tốt cùng nhau, như “compound components” hoặc “slots”. Nó cũng trình bày các cách định kiểu thành phần, như CSS-in-JS.

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.

Web Component Design

Build reusable, maintainable UI components using modern frameworks with clean composition patterns and styling approaches.

When to Use This Skill

  • Designing reusable component libraries or design systems
  • Implementing complex component composition patterns
  • Choosing and applying CSS-in-JS solutions
  • Building accessible, responsive UI components
  • Creating consistent component APIs across a codebase
  • Refactoring legacy components into modern patterns
  • Implementing compound components or render props

Core Concepts

1. Component Composition Patterns

Compound Components: Related components that work together

// Usage
<Select value={value} onChange={setValue}>
  <Select.Trigger>Choose option</Select.Trigger>
  <Select.Options>
    <Select.Option value="a">Option A</Select.Option>
    <Select.Option value="b">Option B</Select.Option>
  </Select.Options>
</Select>

Render Props: Delegate rendering to parent

<DataFetcher url="/api/users">
  {({ data, loading, error }) =>
    loading ? <Spinner /> : <UserList users={data} />
  }
</DataFetcher>

Slots (Vue/Svelte): Named content injection points

<template>
  <Card>
    <template #header>Title</template>
    <template #content>Body text</template>
    <template #footer><Button>Action</Button></template>
  </Card>
</template>

2. CSS-in-JS Approaches

Solution Approach Best For
Tailwind CSS Utility classes Rapid prototyping, design systems
CSS Modules Scoped CSS files Existing CSS, gradual adoption
styled-components Template literals React, dynamic styling
Emotion Object/template styles Flexible, SSR-friendly
Vanilla Extract Zero-runtime Performance-critical apps

3. Component API Design

interface ButtonProps {
  variant?: "primary" | "secondary" | "ghost";
  size?: "sm" | "md" | "lg";
  isLoading?: boolean;
  isDisabled?: boolean;
  leftIcon?: React.ReactNode;
  rightIcon?: React.ReactNode;
  children: React.ReactNode;
  onClick?: () => void;
}

Principles:

  • Use semantic prop names (isLoading vs loading)
  • Provide sensible defaults
  • Support composition via children
  • Allow style overrides via className or style

Quick Start: React Component with Tailwind

import { forwardRef, type ComponentPropsWithoutRef } from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";

const buttonVariants = cva(
  "inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50",
  {
    variants: {
      variant: {
        primary: "bg-blue-600 text-white hover:bg-blue-700",
        secondary: "bg-gray-100 text-gray-900 hover:bg-gray-200",
        ghost: "hover:bg-gray-100 hover:text-gray-900",
      },
      size: {
        sm: "h-8 px-3 text-sm",
        md: "h-10 px-4 text-sm",
        lg: "h-12 px-6 text-base",
      },
    },
    defaultVariants: {
      variant: "primary",
      size: "md",
    },
  },
);

interface ButtonProps
  extends
    ComponentPropsWithoutRef<"button">,
    VariantProps<typeof buttonVariants> {
  isLoading?: boolean;
}

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant, size, isLoading, children, ...props }, ref) => (
    <button
      ref={ref}
      className={cn(buttonVariants({ variant, size }), className)}
      disabled={isLoading || props.disabled}
      {...props}
    >
      {isLoading && <Spinner className="mr-2 h-4 w-4" />}
      {children}
    </button>
  ),
);
Button.displayName = "Button";

Framework Patterns

React: Compound Components

import { createContext, useContext, useState, type ReactNode } from "react";

interface AccordionContextValue {
  openItems: Set<string>;
  toggle: (id: string) => void;
}

const AccordionContext = createContext<AccordionContextValue | null>(null);

function useAccordion() {
  const context = useContext(AccordionContext);
  if (!context) throw new Error("Must be used within Accordion");
  return context;
}

export function Accordion({ children }: { children: ReactNode }) {

…
Câu hỏi thường gặp

“Compound components” là gì?

Đó là các thành phần hoạt động như một bộ. Ví dụ, một thành phần chọn có thể gồm các phần riêng để hiển thị lựa chọn đã chọn, danh sách lựa chọn và từng mục trong danh sách, nhưng chúng hoạt động như một khối thống nhất.

“CSS-in-JS” là gì?

Đó là cách viết mã định kiểu (CSS) trực tiếp trong mã của thành phần (JavaScript/TypeScript), cho phép định kiểu linh hoạt và có tổ chức hơn.

“Component API design” nghĩa là gì?

Đó là cách bạn định nghĩa các tùy chọn và thuộc tính mà thành phần nhận (như màu, kích thước, có bị vô hiệu hóa không) để các lập trình viên khác dễ dùng.

Chi tiết

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

Master React, Vue, and Svelte component patterns including CSS-in-JS, composition strategies, and reusable component architecture. Use when building UI component libraries, designing component APIs, or implementing frontend design systems.

repo: wshobson/agents

Độ phổ biến

Sao GitHub
41k
Vị trí xếp hạng
#6809
Giấy phép
MIT
Cập nhật
15/10/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ự