卡片與網格
像素風介面組
像素風介面三件組:步進鋸齒邊框卡片、按下會下沉的像素按鈕、逐格填滿的像素進度條,全部以 box-shadow 與 CSS 繪製。
一個元件、三個子元件:PixelUiKit 是容器,負責尺寸與主色(寫入 --wb-pixel-accent),底下以靜態屬性掛上 PixelUiKit.Card、PixelUiKit.Button 與 PixelUiKit.Progress。所有像素邊框都不用圖片,而是用多重 box-shadow 往四邊各推一格、四角留空,形成步進的鋸齒圓角;卡片滑過會「跳一格」,按鈕按下會硬切下沉,進度條則一格一格亮起。字型交給你的站決定,元件只用 font-mono。
把這個效果裝進你的專案
在專案資料夾執行指令,CLI 會加入原始碼與依賴套件,再依下方使用範例引用元件。
npx webberui@latest add pixel-ui-kitPlayground
即時調整 props、程式碼片段同步更新——直接試出你要的樣子再複製。
20
4
編輯中的呼叫預設屬性
<PixelUiKit/>
完整範例包含預覽的排版與資料。先安裝元件,再把範例檔貼入你的專案。
安裝
npx webberui@latest add https://webberui.com/r/pixel-ui-kit.json或在 components.json 設定 registries 後,改用 @webberui/pixel-ui-kit 安裝。
使用
import { PixelUiKit } from "@/components/ui/pixel-ui-kit";
const [days, setDays] = React.useState(3);
<PixelUiKit size="md" accent="#22c55e">
<PixelUiKit.Card title="第 1 關">
<p>每日簽到 {days}/5</p>
<PixelUiKit.Progress value={(days / 5) * 100} label="簽到進度" striped />
<PixelUiKit.Button variant="secondary" onClick={() => setDays((d) => Math.min(5, d + 1))}>
+1
</PixelUiKit.Button>
<PixelUiKit.Button variant="primary" disabled={days < 5}>
領取獎勵
</PixelUiKit.Button>
</PixelUiKit.Card>
</PixelUiKit>Props
PixelUiKit
| Prop | 型別 | 預設值 | 說明 |
|---|---|---|---|
size | "sm" | "md" | "md" | 介面組尺寸:影響字級、內距與進度條高度 |
accent | string | "#22c55e" | 主色,寫入 --wb-pixel-accent;用於主要按鈕與進度條填色 |
children | ReactNode | — | 子元件(Card/Button/Progress 或任意內容) |
className | string | — | 透傳到最外層容器 |
PixelUiKit.Card
| 欄位 | 型別 | 預設值 | 說明 |
|---|---|---|---|
title | ReactNode | — | 標題列文字;不提供則不顯示標題列 |
icon | ReactNode | — | 標題列左側的可選圖示,套用 image-rendering: pixelated |
children | ReactNode | — | 卡片內容 |
className | string | — | 透傳到卡片根元素 |
PixelUiKit.Button
| 欄位 | 型別 | 預設值 | 說明 |
|---|---|---|---|
variant | "primary" | "secondary" | "danger" | "primary" | 外觀:主要(主色)、次要(中性色)、危險(紅色) |
children | ReactNode | — | 按鈕內容 |
onClick | (event: MouseEvent) => void | — | 點擊回呼 |
disabled | boolean | false | 停用按鈕 |
type | "button" | "submit" | "reset" | "button" | 原生 button type |
className | string | — | 透傳到 button 元素 |
PixelUiKit.Progress
| 欄位 | 型別 | 預設值 | 說明 |
|---|---|---|---|
value | number | — | 受控進度值(0–100);未提供時使用 defaultValue |
defaultValue | number | 0 | 非受控模式的初始進度值(0–100) |
segments | number | 20 | 分成幾格 |
striped | boolean | false | 已填格是否顯示循環移動的條紋 |
label | string | "進度" | 進度條名稱,同時作為 aria-label 並顯示於上方 |
className | string | — | 透傳到進度條根元素 |
CSS 變數
| 欄位 | 型別 | 預設值 | 說明 |
|---|---|---|---|
--wb-pixel-size | length | 4px | 一格像素的邊長;可在任一祖先元素覆寫 |
--wb-pixel-accent | color | #22c55e | 主色(由 accent prop 寫入) |
--wb-pixel-step | time | 40ms | 進度條每格亮起的間隔 |
--wb-pixel-press | time | 60ms | 按鈕下沉與卡片跳格的時長 |
細節
- 步進邊框:上下左右四道
box-shadow各推出一格--wb-pixel-size,四角刻意留空,就成了像素遊戲常見的缺角外框;卡片另加一層往右下偏兩格的深色投影。 - 卡片滑過時以
steps(2)往上位移一格——瞬間跳格而不是平滑滑動;按住時回到原位。 - 按鈕底部有兩格厚的底邊;按下時以
steps(1)硬切:整顆下沉兩格、底邊厚度歸零,上緣位置不變,看起來像按鍵被壓進去。 - 進度條把 0–100 分成
segments格,每格以「0 秒過渡+遞增延遲」逐格亮起或熄滅,間隔為--wb-pixel-step;striped開啟時已填格會有steps(4)循環的條紋。 - 線條、底色與投影色以 CSS 變數在容器上依亮暗色設定,子元件自動跟上主題。
可及性
PixelUiKit.Button是真正的<button>,預設type="button";鍵盤 focus 時顯示 2px 像素虛線外框- 卡片有標題時以
aria-labelledby關聯標題列 PixelUiKit.Progress為role="progressbar",帶aria-label、aria-valuenow、aria-valuemin、aria-valuemax與aria-valuetext;色彩之外另顯示文字百分比- 使用者系統開啟「減少動態效果」時,卡片滑過不跳格、進度條直接填到目標值、不播放條紋動畫