IconButton图标按钮
只含图标的原生按钮;必须提供 label 作为可访问名称。
关闭、更多、收藏等熟悉动作;不依赖图形猜测行为。
引入
import { IconButton } from "@cwa-design/react";
import "@cwa-design/react/styles.css"; // 应用入口引入一次当前通过源码 workspace 使用。查看有效安装步骤 →
交互示例
可切换示例主题、开启实色降级并重置状态。应用根部需要 CwaProvider。
IconButton 基础用法
可运行示例 · 与复制源码同源
正在准备交互示例…
icon-button-basic
查看与复制源码
import { IconButton } from "@cwa-design/react";
export function IconButtonBasic() {
return (
<IconButton label="关闭" variant="secondary" onClick={() => {}}>
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<path
d="M4 4l8 8M12 4l-8 8"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
fill="none"
/>
</svg>
</IconButton>
);
}
在应用根部引入 styles.css 并配置 CwaProvider。源码 SHA-256:02963b83165f
API
下表读取本版本组件契约。原生与 Base UI 继承属性的完整定义保留在 TypeScript 声明中。
类型:IconButtonProps · 继承 React.ButtonHTMLAttributes<HTMLButtonElement>;disabled/onClick/aria-* 等继承 · 候选源类型 ↗
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
label必填 | 见类型定义 | string | — |
variant | 见类型定义 | "primary" | "secondary" | "ghost" | "danger" | "secondary" |
size | 见类型定义 | "sm" | "md" | "lg" | "md" |
loading | 见类型定义 | boolean | false |
ref | React.Ref<HTMLButtonElement> | React.Ref<HTMLButtonElement> | — |
children | ReactNode;内容由调用方提供 | ReactNode;内容由调用方提供 | — |
type | 见类型定义 | "button" | "submit" | "reset" | "button" |
材质与状态
继承父级表面
材质规则来自源 metadata。覆盖玻璃区域的浮层按实际重叠关系选择较厚或实色材质。
图标按钮不独立创建 blur;label 不能只靠图标或 Tooltip 替代。
适用的状态与行为见示例及本页 API;系统减少透明与显式 solid 配置会启用回退。
阅读材质指南 →关联 Token
以下变量从组件源样式的实际引用生成。共享光学规则还使用全局玻璃 Token。
--cwa-design-font-family--cwa-design-motion-control--cwa-design-focus-width--cwa-design-color-focus--cwa-design-focus-offset--cwa-design-color-accent--cwa-design-color-on-accent--cwa-design-color-surface--cwa-design-color-glass-reflection--cwa-design-color-text--cwa-design-color-glass-rim-bottom--cwa-design-color-glass-rim-top--cwa-design-color-glass-inner-highlight--cwa-design-color-glass-inner-shade--cwa-design-color-danger--cwa-design-color-border-strong无障碍与使用约束
semantic-contentvisible-focus-for-interactive-partskeyboard-behavior-from-native-or-base-ui
这些是组件契约与使用要求。具体业务页面仍需验证标签、阅读顺序与实际背景下的对比度。
查看无障碍使用指南 →