IconButton
Square icon-only button. Requires aria-label. Common in toolbars, table column actions, and input suffixes.
Basic usage
Three variants (default / primary / danger), three sizes (sm / md / lg), and shapes square / round.
pressed drives toggle behavior (pin / bookmark) and automatically sets aria-pressed.
背景
<script setup lang="ts">
import { CfIconButton } from '@chufix-design/vue';
</script>
<template>
<div class="demo-row">
<CfIconButton aria-label="刷新">
<svg viewBox="0 0 16 16" fill="none"><path d="M3 8a5 5 0 1 1 1.5 3.5M3 8V5m0 3h3" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
</CfIconButton>
<CfIconButton variant="primary" aria-label="保存">
<svg viewBox="0 0 16 16" fill="none"><path d="M3 8.5l3.2 3.2L13 5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
</CfIconButton>
<CfIconButton variant="danger" aria-label="删除">
<svg viewBox="0 0 16 16" fill="none"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
</CfIconButton>
<CfIconButton :pressed="true" aria-label="固定">
<svg viewBox="0 0 16 16" fill="none"><path d="M8 2v8m0 4v.01M5 5h6" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>
</CfIconButton>
</div>
</template>
<CfIconButton aria-label="Save" variant="primary"><Icon /></CfIconButton>
<CfIconButton aria-label="Delete" variant="danger"><Icon /></CfIconButton>
<CfIconButton aria-label="Pin" pressed><Icon /></CfIconButton> Sizes and shapes
Three sizes (sm 26 / md 32 / lg 38 px). shape="round" switches to a circular pill.
背景
<script setup lang="ts">
import { CfIconButton } from '@chufix-design/vue';
const star = `<svg viewBox="0 0 16 16" fill="none"><path d="M8 2l1.9 4 4.4.4-3.3 3 .9 4.3L8 11.5 4.1 13.7l.9-4.3-3.3-3 4.4-.4z" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/></svg>`;
</script>
<template>
<div class="demo-row" style="align-items: center; gap: 16px;">
<CfIconButton size="sm" aria-label="星标 (sm)"><span v-html="star" style="display: contents;"/></CfIconButton>
<CfIconButton size="md" aria-label="星标 (md)"><span v-html="star" style="display: contents;"/></CfIconButton>
<CfIconButton size="lg" aria-label="星标 (lg)"><span v-html="star" style="display: contents;"/></CfIconButton>
<span style="width: 1px; height: 24px; background: var(--line-1); margin: 0 8px;" />
<CfIconButton size="md" shape="round" aria-label="圆形"><span v-html="star" style="display: contents;"/></CfIconButton>
<CfIconButton size="lg" shape="round" aria-label="圆形 lg"><span v-html="star" style="display: contents;"/></CfIconButton>
</div>
</template>
<CfIconButton size="sm" aria-label="Star" />
<CfIconButton size="md" aria-label="Star" />
<CfIconButton size="lg" aria-label="Star" />
<CfIconButton shape="round" aria-label="Round" /> States
pressed toggles selected state (auto-sets aria-pressed); loading and disabled show a spinner and disabled style respectively.
背景
已固定
<script setup lang="ts">
import { ref } from 'vue';
import { CfIconButton } from '@chufix-design/vue';
const pinned = ref(true);
const liked = ref(false);
const star = `<svg viewBox="0 0 16 16" fill="none"><path d="M8 2l1.9 4 4.4.4-3.3 3 .9 4.3L8 11.5 4.1 13.7l.9-4.3-3.3-3 4.4-.4z" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/></svg>`;
</script>
<template>
<div class="demo-row" style="align-items: center; gap: 16px;">
<CfIconButton :pressed="pinned" aria-label="固定" @click="pinned = !pinned">
<span v-html="star" style="display: contents;"/>
</CfIconButton>
<CfIconButton :pressed="liked" variant="danger" aria-label="收藏" @click="liked = !liked">
<span v-html="star" style="display: contents;"/>
</CfIconButton>
<CfIconButton loading aria-label="加载中">
<span v-html="star" style="display: contents;"/>
</CfIconButton>
<CfIconButton disabled aria-label="禁用">
<span v-html="star" style="display: contents;"/>
</CfIconButton>
<span v-if="pinned" style="font-size: 12px; color: var(--accent-1); font-family: var(--font-mono);">已固定</span>
<span v-if="liked" style="font-size: 12px; color: var(--status-error); font-family: var(--font-mono);">已收藏</span>
</div>
</template>
<CfIconButton pressed aria-label="Pin" />
<CfIconButton variant="danger" pressed aria-label="Favorite" />
<CfIconButton loading aria-label="Loading" />
<CfIconButton disabled aria-label="Disabled" /> API
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'primary' | 'danger' | 'default' | Visual variant |
size | 'sm' | 'md' | 'lg' | 'md' | Size |
shape | 'square' | 'round' | 'square' | Shape |
pressed | boolean | false | Toggle state, outputs aria-pressed |
loading | boolean | false | Show spinner |
disabled | boolean | false | Disabled |
Default slot / children | — | — | Icon content |
badge slot / badge prop | — | — | Top-right badge |
a11y:
aria-labelis required, otherwise screen readers cannot announce the button’s purpose.
反馈与讨论
IconButton · Discussion