AgentSkillsCN

component-generator

按照 Premium Home Design 设计模式生成 React/Next.js 组件。在创建新板块、新功能或应遵循项目设计系统的 UI 组件时,可选用此功能。

SKILL.md
--- frontmatter
name: component-generator
description: Generate React/Next.js components following Premium Home Design patterns. Use when creating new sections, features, or UI components that should follow the project's design system.

Component Generator Skill

Quick Start

When generating a new component:

  1. Ask for the component's purpose and location
  2. Generate following the patterns below
  3. Include accessibility, animation, and responsive design

Component Template

Feature Section Component

tsx
"use client";

import { useReducedMotion, m } from "framer-motion";
import Image from "next/image";

interface SectionNameProps {
  className?: string;
}

const containerVariants = {
  hidden: { opacity: 0 },
  visible: {
    opacity: 1,
    transition: {
      staggerChildren: 0.1,
      delayChildren: 0.2,
    },
  },
};

const itemVariants = {
  hidden: { opacity: 0, y: 40 },
  visible: {
    opacity: 1,
    y: 0,
    transition: {
      type: "spring",
      stiffness: 100,
      damping: 20,
      mass: 1.2,
    },
  },
};

export function SectionName({ className }: SectionNameProps) {
  const prefersReducedMotion = useReducedMotion();

  return (
    <section
      aria-labelledby="section-heading"
      className={`py-24 md:py-32 bg-[var(--color-canvas)] ${className}`}
    >
      <div className="container mx-auto px-4 md:px-6 lg:px-8">
        <m.div
          initial="hidden"
          whileInView="visible"
          viewport={{ once: true, margin: "-100px" }}
          variants={prefersReducedMotion ? {} : containerVariants}
        >
          {/* Header */}
          <m.div variants={prefersReducedMotion ? {} : itemVariants} className="mb-12">
            <span className="text-xs font-mono uppercase tracking-[0.3em] text-[var(--color-accent-ui)]">
              Label
            </span>
            <h2
              id="section-heading"
              className="text-4xl md:text-5xl lg:text-6xl font-serif mt-4"
            >
              Section Title
            </h2>
          </m.div>

          {/* Content */}
          <m.div
            variants={prefersReducedMotion ? {} : itemVariants}
            className="grid md:grid-cols-2 gap-8"
          >
            {/* Add content here */}
          </m.div>
        </m.div>
      </div>
    </section>
  );
}

Design System Tokens

Colors (CSS Variables)

tsx
bg-[var(--color-canvas)]       // Warm Bone #fffbf5
text-stone-900                  // Charcoal Bronze (headings)
text-[var(--color-accent-ui)]  // Soft Coral #ff7850
text-stone-600                  // Muted text

Typography

tsx
// Headings
className="font-serif text-4xl md:text-5xl lg:text-6xl"

// Labels/Overlines
className="font-mono text-xs uppercase tracking-[0.3em]"

// Body
className="font-sans text-base md:text-lg"

Spacing

tsx
// Section padding
className="py-24 md:py-32"

// Container
className="container mx-auto px-4 md:px-6 lg:px-8"

// Grid gaps
className="gap-6 md:gap-8"

Animation Spring Config

tsx
transition: {
  type: "spring",
  stiffness: 100,  // "Heavy" feel
  damping: 20,
  mass: 1.2,
}

Required Patterns

1. Accessibility

  • aria-labelledby on sections
  • Descriptive alt on images
  • aria-hidden="true" on decorative icons
  • Native <button> elements

2. Reduced Motion

tsx
const prefersReducedMotion = useReducedMotion();
// Apply to all Framer Motion variants

3. Responsive Design

tsx
// Mobile-first breakpoints
text-2xl md:text-4xl lg:text-6xl
grid-cols-1 md:grid-cols-2 lg:grid-cols-3

4. Image Optimization

tsx
<Image
  src={image}
  alt="Descriptive text"
  width={800}
  height={600}
  sizes="(max-width: 768px) 100vw, 50vw"
  loading="lazy"
  placeholder="blur"
  blurDataURL={blurData}
/>

File Locations

TypeLocation
Feature sectionssrc/components/features/
UI componentssrc/components/ui/
Home page sectionssrc/components/home/
Layout componentssrc/components/layout/
Figma componentssrc/components/features/figma-frame/

Checklist Before Completion

  • TypeScript interface for props
  • aria-labelledby on section
  • useReducedMotion for animations
  • Responsive breakpoints (md:, lg:)
  • Images use next/image
  • Alt text is descriptive
  • Mobile-first CSS
  • Uses design system tokens