默认
已选中
品牌色
成功
警告
错误
信息
小号
默认
大号
前端
设计
VIP
<div class="demo-row"> <span class="icen-tag">默认</span> <span class="icen-tag is-selected">已选中</span> <span class="icen-tag icen-tag--accent">品牌色</span> <span class="icen-tag icen-tag--success">成功</span> <span class="icen-tag icen-tag--warning">警告</span> <span class="icen-tag icen-tag--error">错误</span> <span class="icen-tag icen-tag--info">信息</span></div><div class="demo-row" style="margin-top:14px"> <span class="icen-tag icen-tag--sm">小号</span> <span class="icen-tag">默认</span> <span class="icen-tag icen-tag--lg">大号</span></div><div class="demo-row" style="margin-top:14px"> <span class="icen-tag"> <span class="icen-tag-label">前端</span> <button class="icen-tag-close" type="button" aria-label="移除"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M6 6l8 8M14 6l-8 8"></path></svg></button> </span> <span class="icen-tag"> <span class="icen-tag-label">设计</span> <button class="icen-tag-close" type="button" aria-label="移除"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M6 6l8 8M14 6l-8 8"></path></svg></button> </span> <span class="icen-tag icen-tag--accent"> <span class="icen-tag-label">VIP</span> <button class="icen-tag-close" type="button" aria-label="移除"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M6 6l8 8M14 6l-8 8"></path></svg></button> </span></div>
特性
- 结构:
icen-tag+icen-tag-label;移除钮icen-tag-close必须配aria-label - 状态:
is-selected选中态,适合筛选条件场景 - 配色:
icen-tag--accent/--success/--warning/--error/--info - 尺寸:
icen-tag--sm/ 默认 /icen-tag--lg
与徽章(pill)分工:tag 是中性展示与筛选载体,状态语义(正常 / 警告 / 异常)归 pill。
安装
bun add @icen.ai/ui pnpm add @icen.ai/ui npm install @icen.ai/ui yarn add @icen.ai/ui 一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):
import '@icen.ai/ui/kit/tag';
也可以用脚手架直接打印引入行:
bunx --bun @icen.ai/ui add tag
Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/tag.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。
用法
<span class="icen-tag">默认标签</span><span class="icen-tag is-selected">筛选条件</span><span class="icen-tag icen-tag--accent">品牌色</span><span class="icen-tag"> <span class="icen-tag-label">可移除</span> <button class="icen-tag-close" type="button" aria-label="移除"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M6 6l8 8M14 6l-8 8"></path></svg></button></span><!-- 语义色:tag--accent/success/warning/error/info;尺寸:tag--sm/lg -->