Community程式設計與開發github.com

alfathafp/portofolio-web-design

建立可投入生產、易於存取、具備響應式設計且使用者可直接使用的前端 UI。適合在建置或修改使用者介面與頁面、建立元件、實作版面配置、滿足 WCAG 無障礙標準、管理狀態,或要求輸出成果具備專業品質而非 AI 生成感時使用。

portofolio-web-design 是什麼?

此技能將開發者引導為一名注重設計的工程師,專注於建立高品質前端使用者介面。其核心原則為避免常見的「AI 美感」陷阱,例如過度使用紫色、漸層、圓角及陰影,並強制使用專案的設計系統與語意化色彩 Token。技能涵蓋元件檔案結構的最佳實踐(如將相關檔案集中放置)、偏好組合而非設定的元件模式,以及將資料擷取與呈現邏輯分離的架構。為確保無障礙性,技能詳細說明了鍵盤導覽、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 工程化指南

概述

建立可投入生產、易於存取、高效能且視覺上精煉的使用者介面。目標是讓 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>任務</CardTitle>
  </CardHeader>
  <CardBody>
    <TaskList tasks={tasks} />
  </CardBody>
</Card>

// 避免:過度設定
<Card
  title="任務"
  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="無法載入任務" retry={refetch} />;
  if (tasks.length === 0) return <EmptyState message="尚無任務" />;

  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)  → 帶快取的遠端資料
全域 Store (Zustand, Redux)    → 應用程式共用的複雜客戶端狀態

避免 Props 傳遞深度超過 3 層。 如果你正將 props 傳遞給不直接使用它們的元件,請引入 context 或重構元件樹。

設計系統遵循

參考導向的 UI 品質

當產品需要獨特的視覺方向時,在選擇版面配置前先收集證據:

  1. 搜尋可信賴的參考目錄,或使用產品團隊提供的參考資料。
  2. 研究兩到三個相關的畫面。記錄關於層級、密度、導覽、控制項、響應式行為和互動狀態的決定。
  3. 在實作之前,將這些決定轉化為簡短的設計契約。命名該畫面的任務、主要操作、必要狀態、響應式規則以及應拒絕的模式。
  4. 使用產品自身的元件、Token、內容和視覺語言重建有用的結構。切勿拷貝其他產品的品牌標誌、專有文字、圖像或完全相同的版面配置。

將參考資料視為證據,而非模板。若無參考資料可用,請記錄假設,並根據產品現有的設計系統驗證結果。

避免 AI 美感

AI 生成的 UI 有可辨識的模式。請避免所有這些模式:

AI 預設值問題所在生產品質建議
全部用紫色/靛藍色模型預設使用視覺上「安全」的色板,導致每個應用程式看起來都一樣使用專案實際的色板
過度的漸層漸層增加視覺雜訊,並與大多數設計系統衝突使用與設計系統相符的平面或細微漸層
所有地方都圓角 (rounded-2xl)最大圓角代表「友善」,但忽略了真實設計中圓角半徑的層級使用設計系統中一致的邊框半徑
通用的英雄區塊模板驅動的版面配置,與實際內容或使用者需求無關以內容為優先的版面配置
Lorem ipsum 風格的佔位文字佔位文字隱藏了真實內容才會暴露的版面問題(長度、換行、溢出)使用擬真的佔位內容
到處都是過大的內距平等的巨大內距破壞了視覺層級,並浪費螢幕空間使用一致的間距規模
標準的卡片網格統一的網格是忽略資訊優先級和掃描模式的版面配置捷徑目的驅動的版面配置
重度陰影的設計多層陰影增加與內容競爭的深度,並在低階裝置上降低渲染速度除非設計系統指定,否則使用細微陰影或無陰影

間距與版面配置

使用一致的間距級別。不要創造自己的數值:

/* 使用級別:0.25rem 為增量(或專案使用的任何級別) */
/* 良好 */  padding: 1rem;      /* 16px */
/* 良好 */  gap: 0.75rem;       /* 12px */
/* 不良 */   padding: 13px;      /* 不在任何級別上 */
/* 不良 */   margin-top: 2.3rem; /* 不在任何級別上 */

字體排版

尊重字體層級:

h1 → 頁面標題(每頁一個)
h2 → 區塊標題
h3 → 子區塊標題
body → 預設文字
small → 次要/輔助文字

不要跳過標題層級。不要對非標題內容使用標題樣式。

顏色

  • 使用語意化顏色 Token:text-primary、bg-surface、border-default — 而非原始十六進位值
  • 確保足夠的對比度(一般文字 4.5:1,大字型 3:1)
  • 不要僅依賴顏色來傳達資訊(也使用圖示、文字或模式)

無障礙性 (WCAG 2.1 AA)

每個元件都必須滿足這些標準:

鍵盤導覽

// 每個可互動的元素都必須可透過鍵盤存取
<button onClick={handleClick}>按我</button>        // ✓ 預設可聚焦
<div onClick={handleClick}>按我</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();
     }}>
  按我
</div>

ARIA 標籤

// 為缺乏可見文字的互動元素加上標籤
<button aria-label="關閉對話框"><XIcon /></button>

// 為表單輸入加上標籤
<label htmlFor="email">電子郵件</label>
<input id="email" type="email" />

// 或當沒有可見標籤時使用 aria-label
<input aria-label="搜尋任務" type="search" />

焦點管理

// 內容變更時移動焦點
function Dialog({ isOpen, onClose }: DialogProps) {
  const closeRef = useRef<HTMLButtonElement>(null);

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

  // 對話框開啟時將焦點限制在內部
  return (
    <dialog open={isOpen}>
      <button ref={closeRef} onClick={onClose}>關閉</button>
      {/* 對話框內容 */}
    </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">尚無任務</h3>
        <p className="mt-1 text-sm text-muted">透過建立新任務開始使用。</p>
        <Button className="mt-4" onClick={onCreateTask}>建立任務</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="正在載入任務">
      {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。

常見的合理化藉口

合理化藉口現實情況
「無障礙性是有則更好」在許多司法管轄區這是法律要求,也是工程品質標準。
「我們以後再讓它變成響應式」為設計回溯加入響應式支援比一開始就建置還要困難 3 倍。
「設計還未最終定案,所以我先略過樣式」使用設計系統的預設值。未經樣式化的 UI 會給審查者留下壞的第一印象。
「這只是原型」原型會變成正式程式碼。從一開始就打下正確的基礎。
「AI 審美目前還可以」這傳達出低品質的訊號。從一開始就使用專案實際的設計系統。

紅旗警示

  • 超過 200 行的元件(請分割它們)
  • 行內樣式或任意的像素值
  • 缺少錯誤狀態、載入狀態或空狀態
  • 未測試鍵盤導覽
  • 只使用顏色作為狀態的單一指標(紅/綠而不帶文字或圖示)
  • 通用的「AI 外觀」(紫色漸層、過大的卡片、標準版面配置)

驗證清單

建置 UI 後:

  • 元件渲染時無 console 錯誤
  • 所有可互動元素都可透過鍵盤存取(使用 Tab 鍵瀏覽頁面)
  • 螢幕閱讀器能夠傳達頁面的內容與結構
  • 響應式:在 320px、768px、1024px、1440px 下運作正常
  • 適當時處理了載入、空狀態、錯誤、成功和權限狀態
  • 遵循專案的設計系統(間距、顏色、字體排版)
  • 渲染結果通過最終的 UI 特定完成閘門審查
  • 開發者工具或 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.

相關技能