Community编程与开发github.com

alfathafp/portofolio-web-design

构建生产级质量、可访问且响应迅速的用户界面。适用于构建或修改界面和页面、创建组件、实现布局、满足WCAG可访问性要求、管理状态,或者当输出需要看起来具有生产级品质而非AI生成时使用。

portofolio-web-design 是什么?

该技能旨在指导AI Agent构建具有生产级质量的前端用户界面,强调设计系统一致性、可访问性(WCAG 2.1 AA)和响应式设计。其核心目标是使生成的UI看起来像是由顶级公司的设计意识的工程师精心打造的,而非AI随意生成。技能涵盖了从组件架构、状态管理、设计系统遵守(包括避免“AI美学”)到可访问性实践、响应式设计和加载状态的全面指南。它通过清晰的正面示例和负面示例(如避免紫色渐变、过度圆角等AI默认样式)来训练Agent产出高质量代码。该技能适用于Claude Code、Cursor等支持技能文件(SKILL.md)的AI编码助手,开发者可将其作为开发前端UI时的行为准则。技能详细描述了文件结构、组件模式(组合优于配置、分离数据获取与展示)、状态管理选择策略,并提供了一个包含键盘导航、ARIA标签、焦点管理和有意义空状态/错误状态的可访问性清单。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/frontend-ui-engineering

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

前端用户界面工程

概述

构建生产级质量的用户界面,确保其可访问、高性能且视觉上精良。目标是让UI看起来像是顶级公司中具有设计意识的工程师构建的——而不是由AI生成的。这意味着要真正遵循设计系统、确保正确的可访问性、设计周到的交互模式,并避免通用的“AI审美”。

何时使用

  • 构建新的UI组件或页面
  • 修改现有的面向用户的界面
  • 实现响应式布局
  • 添加交互性或状态管理
  • 修复视觉或用户体验问题

组件架构

文件结构

将与组件相关的所有内容放在一起:

src/components/
  TaskList/
    TaskList.tsx          # 组件实现
    TaskList.test.tsx     # 测试
    TaskList.stories.tsx  # Storybook 故事(如果使用)
    use-task-list.ts      # 自定义 Hook(如果状态复杂)
    types.ts              # 组件特定类型(如果需要)

组件模式

组合优于配置:

// 好的做法:可组合
<Card>
  <CardHeader>
    <CardTitle>Tasks</CardTitle>
  </CardHeader>
  <CardBody>
    <TaskList tasks={tasks} />
  </CardBody>
</Card>

// 避免:过度配置
<Card
  title="Tasks"
  headerVariant="large"
  bodyPadding="md"
  content={<TaskList tasks={tasks} />}
/>

保持组件职责单一:

// 好的做法:只做一件事
export function TaskItem({ task, onToggle, onDelete }: TaskItemProps) {
  return (
    <li className="flex items-center gap-3 p-3">
      <Checkbox checked={task.done} onChange={() => onToggle(task.id)} />
      <span className={task.done ? 'line-through text-muted' : ''}>{task.title}</span>
      <Button variant="ghost" size="sm" onClick={() => onDelete(task.id)}>
        <TrashIcon />
      </Button>
    </li>
  );
}

分离数据获取与呈现:

// 容器:处理数据
export function TaskListContainer() {
  const { tasks, isLoading, error, refetch } = useTasks();

  if (isLoading) return <TaskListSkeleton />;
  if (error) return <ErrorState message="Failed to load tasks" retry={refetch} />;
  if (tasks.length === 0) return <EmptyState message="No tasks yet" />;

  return <TaskList tasks={tasks} />;
}

// 呈现:处理渲染
export function TaskList({ tasks }: { tasks: Task[] }) {
  return (
    <ul role="list" className="divide-y">
      {tasks.map(task => <TaskItem key={task.id} task={task} />)}
    </ul>
  );
}

状态管理

选择最简单有效的方法:

本地状态 (useState)           → 组件特定的 UI 状态
提升状态                     → 在2-3个兄弟组件间共享
Context                       → 主题、认证、地区(读多写少)
URL 状态 (searchParams)       → 过滤器、分页、可共享的 UI 状态
服务端状态 (React Query, SWR) → 带缓存的远程数据
全局存储 (Zustand, Redux)     → 应用范围内共享的复杂客户端状态

避免 prop 深度超过3层。 如果你正在通过不使用的组件传递 props,请引入 context 或重构组件树。

设计系统一致性

参考驱动的 UI 质量

当产品需要独特的视觉方向时,在选择布局之前收集参考证据:

  1. 搜索受信任的参考目录或使用产品团队提供的参考。
  2. 研究两到三个相关的界面。记录关于层次结构、密度、导航、控件、响应式行为和交互状态的决定。
  3. 在实现之前,将这些决定转化为简短的设计契约。命名界面的职责、主要操作、所需状态、响应式规则和要拒绝的模式。
  4. 使用产品自身的组件、令牌、内容和视觉语言重建有用的结构。切勿复制其他产品的品牌标识、专有文本、图像或精确布局。

将参考用作证据,而不是模板。如果参考不可用,请记录假设并根据产品现有的设计系统验证结果。

避免 AI 审美

AI 生成的 UI 具有可识别的模式。避免所有这些:

AI 默认行为为什么这是个问题生产级质量
到处都是紫/靛蓝色模型默认使用视觉上“安全”的调色板,使每个应用看起来都一样使用项目实际的调色板
过度的渐变渐变增加了视觉噪音,并与大多数设计系统冲突符合设计系统的扁平或微妙渐变
一切圆角 (rounded-2xl)最大圆角表示“友好”,但忽略了实际设计中圆角半径的层次结构来自设计系统的一致 border-radius
通用英雄区域模板驱动的布局,与实际内容或用户需求无关内容优先的布局
Lorem ipsum 风格的文本占位符文本隐藏了真实内容可能揭示的布局问题(长度、换行、溢出)现实的占位符内容
所有地方都超大内边距均匀的慷慨内边距破坏了视觉层次并浪费了屏幕空间一致的间距比例
股票卡片网格统一的网格是一种布局捷径,忽略了信息优先级和扫描模式目的驱动的布局
大量阴影的设计多层阴影增加了与内容竞争的深度,并会减慢低端设备上的渲染速度微妙的阴影或无阴影,除非设计系统指定

间距与布局

使用一致的间距比例。不要发明值:

/* 使用比例:0.25rem 的增量(或项目使用的任何值) */
/* 好的做法 */  padding: 1rem;      /* 16px */
/* 好的做法 */  gap: 0.75rem;       /* 12px */
/* 坏的做法 */  padding: 13px;      /* 不在任何比例上 */
/* 坏的做法 */  margin-top: 2.3rem; /* 不在任何比例上 */

排版

尊重标题层次结构:

h1 → 页面标题(每页一个)
h2 → 区块标题
h3 → 子区块标题
body → 默认文本
small → 辅助/说明文本

不要跳过标题级别。不要为非标题内容使用标题样式。

颜色

  • 使用语义化颜色令牌:text-primary、bg-surface、border-default — 而不是原始十六进制值
  • 确保足够的对比度(普通文本 4.5:1,大文本 3:1)
  • 不要仅仅依赖颜色来传达信息(也要使用图标、文本或模式)

可访问性 (WCAG 2.1 AA)

每个组件都必须满足这些标准:

键盘导航

// 每个交互元素都必须可通过键盘访问
<button onClick={handleClick}>Click me</button>        // ✓ 默认可获得焦点
<div onClick={handleClick}>Click me</div>               // ✗ 不可获得焦点
<div role="button" tabIndex={0} onClick={handleClick}    // ✓ 但首选 <button>
     onKeyDown={e => {
       if (e.key === 'Enter') handleClick();
       if (e.key === ' ') e.preventDefault();
     }}
     onKeyUp={e => {
       if (e.key === ' ') handleClick();
     }}>
  Click me
</div>

ARIA 标签

// 为缺少可见文本的交互元素添加标签
<button aria-label="Close dialog"><XIcon /></button>

// 为表单输入添加标签
<label htmlFor="email">Email</label>
<input id="email" type="email" />

// 或者当没有可见标签时使用 aria-label
<input aria-label="Search tasks" type="search" />

焦点管理

// 当内容发生变化时移动焦点
function Dialog({ isOpen, onClose }: DialogProps) {
  const closeRef = useRef<HTMLButtonElement>(null);

  useEffect(() => {
    if (isOpen) closeRef.current?.focus();
  }, [isOpen]);

  // 打开时在对话框内 trap 焦点
  return (
    <dialog open={isOpen}>
      <button ref={closeRef} onClick={onClose}>Close</button>
      {/* dialog content */}
    </dialog>
  );
}

有意义的空状态和错误状态

// 不要显示空白屏幕
function TaskList({ tasks }: { tasks: Task[] }) {
  if (tasks.length === 0) {
    return (
      <div role="status" className="text-center py-12">
        <TasksEmptyIcon className="mx-auto h-12 w-12 text-muted" />
        <h3 className="mt-2 text-sm font-medium">No tasks</h3>
        <p className="mt-1 text-sm text-muted">Get started by creating a new task.</p>
        <Button className="mt-4" onClick={onCreateTask}>Create Task</Button>
      </div>
    );
  }

  return <ul role="list">...</ul>;
}

响应式设计

移动优先设计,然后扩展:

// Tailwind: 移动优先响应式
<div className="
  grid grid-cols-1      /* 移动端:单列 */
  sm:grid-cols-2        /* 小屏:2列 */
  lg:grid-cols-3        /* 大屏:3列 */
  gap-4
">

在这些断点处测试:320px, 768px, 1024px, 1440px。

加载与过渡

// 骨架屏加载(内容区域不使用旋转器)
function TaskListSkeleton() {
  return (
    <div className="space-y-3" aria-busy="true" aria-label="Loading tasks">
      {Array.from({ length: 3 }).map((_, i) => (
        <div key={i} className="h-12 bg-muted animate-pulse rounded" />
      ))}
    </div>
  );
}

// 乐观更新以提升感知速度
function useToggleTask() {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: toggleTask,
    onMutate: async (taskId) => {
      await queryClient.cancelQueries({ queryKey: ['tasks'] });
      const previous = queryClient.getQueryData(['tasks']);

      queryClient.setQueryData(['tasks'], (old: Task[]) =>
        old.map(t => t.id === taskId ? { ...t, done: !t.done } : t)
      );

      return { previous };
    },
    onError: (_err, _taskId, context) => {
      queryClient.setQueryData(['tasks'], context?.previous);
    },
  });
}

参见

有关详细的可访问性要求和测试工具,请参见 ../../references/accessibility-checklist.md。

常见借口

借口现实
“可访问性可有可无”在许多司法管辖区这是法律要求,也是工程质量标准。
“我们以后再做响应式”事后改造响应式设计比从一开始就构建要难三倍。
“设计还没最终定稿,所以我先跳过样式”使用设计系统默认值。未样式化的 UI 会给审查者留下糟糕的第一印象。
“这只是一个原型”原型会变成生产代码。从一开始就打好基础。
“AI 审美暂时没问题”它传达了低质量信号。从一开始就使用项目实际的设计系统。

警示标志

  • 超过200行的组件(拆分它们)
  • 内联样式或任意的像素值
  • 缺少错误状态、加载状态或空状态
  • 未进行键盘导航测试
  • 将颜色作为状态的唯一指示符(红色/绿色没有文字或图标)
  • 通用的“AI 外观”(紫色渐变、超大卡片、股票布局)

验证清单

构建 UI 后:

  • 组件渲染时无控制台错误
  • 所有交互元素均可通过键盘访问(使用 Tab 键浏览页面)
  • 屏幕阅读器可以传达页面的内容和结构
  • 响应式:在 320px、768px、1024px、1440px 下正常工作
  • 在适用时处理加载、空、错误、成功和权限状态
  • 遵循项目的设计系统(间距、颜色、排版)
  • 渲染结果通过最终的 UI 特定的“finish-gate”审查
  • 开发者工具或 axe-core 中没有可访问性警告

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相关技能