Rarity
五档稀有度,沿用游戏中为战利品分级的做法:普通、优秀、稀有、史诗、传说,每档各有专属颜色。
安装
# once per project: where @zzzui items come frompnpm dlx shadcn@latest registry add @zzzui=https://zzzui.catforest.dev/r/{name}.jsonpnpm dlx shadcn@latest add @zzzui/rarity示例
按稀有度分级的战利品
Rail pass
One ride across the yards.
common
Canal key
Opens the lock at Tower 9.
uncommon
Night permit
Work past 22:00 without a fine.
rare
Sealed crate
Do not open it.
epic
North gate seal
Signs any job, anywhere.
legendary
North gate seal
Found in the rail yards
Legendary
Signs any job, anywhere. Only one is known.
import { Badge } from "@/components/zero/badge";import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle,} from "@/components/zero/card";import { LockIcon } from "@/components/zero/icons";import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, ItemTitle,} from "@/components/zero/item";const loot = [ { name: "Rail pass", line: "One ride across the yards.", rarity: "common" }, { name: "Canal key", line: "Opens the lock at Tower 9.", rarity: "uncommon" }, { name: "Night permit", line: "Work past 22:00 without a fine.", rarity: "rare", }, { name: "Sealed crate", line: "Do not open it.", rarity: "epic" }, { name: "North gate seal", line: "Signs any job, anywhere.", rarity: "legendary", },] as const;export default function RarityLoot() { return ( <div className="grid w-full max-w-3xl gap-6 md:grid-cols-[minmax(0,1fr)_16rem]"> <ItemGroup className="gap-1"> {loot.map(({ name, line, rarity }) => ( <Item key={name} variant="muted" size="sm" rarity={rarity}> <ItemMedia variant="icon"> <LockIcon /> </ItemMedia> <ItemContent> <ItemTitle>{name}</ItemTitle> <ItemDescription>{line}</ItemDescription> </ItemContent> <ItemActions> <Badge rarity={rarity}>{rarity}</Badge> </ItemActions> </Item> ))} </ItemGroup> <Card rarity="legendary" className="self-start"> <CardHeader> <CardTitle>North gate seal</CardTitle> <CardDescription>Found in the rail yards</CardDescription> <CardAction> <Badge rarity="legendary">Legendary</Badge> </CardAction> </CardHeader> <CardContent> <p className="text-zero-text-2"> Signs any job, anywhere. Only one is known. </p> </CardContent> </Card> </div> );}行为
颜色以设计 token 提供,从 --color-zero-rarity-common 到 --color-zero-rarity-legendary,与强调色、焦点框的黄色和危险色都有明显区分;用作文字时,在 zzzUI 的各种底色上也都清晰可读。
有三个组件接受 rarity:Badge 以该档颜色填充,Card 的顶边使用该颜色,Item 则像游戏物品栏那样为标题着色,并在起始一侧加一道色条。其他场合可直接使用设计 token(text-zero-rarity-epic、bg-zero-rarity-rare)。
属性
Badge, Card, Item
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| rarity | "common" | "uncommon" | "rare" | "epic" | "legendary" | — | 稀有度档位,颜色随之确定。 |