导航

v1.0.5
框架

Astro

在 Astro 中渲染动态或固定的光学尺寸图标。

本页内容

#动态图标

Astro 是必需的对等依赖。请在应用中安装 Astro 7,并安装 @master/icons-astro。

---import { SearchIcon } from '@master/icons-astro';---<SearchIcon size={20} corner="rounded" label="搜索" />

从动态入口导入的每个图标都包含九种光学尺寸与边角样式的组合,以及每种组合支持的线宽变体。各框架与 SVG 使用相同的图形数据。size 会选择最接近的光学图稿;corner 默认为 soft。

#固定图标

---import { SearchIcon } from '@master/icons-astro/16/soft';---<button aria-label="搜索"><SearchIcon /></button>

固定入口只包含一种光学尺寸和边角样式的组合。可将 16/soft 换成 16、20、24 与 sharp、soft、rounded 的任意组合。固定组件不接受 corner 或 opticalSize;size 只会缩放所选图稿。

#框架特性

原生 .astro 组件会输出内联 SVG,不需要浏览器端图标 JavaScript,也不需要框架集成或 client:* 指令。支持 SVG 属性、class:list 与默认插槽。Node.js 版本须符合 Astro 的要求。

没有标签的图标会被视为装饰。对于需要表达含义的图标,可以使用 label、aria-label 或 aria-labelledby,也可以为外层按钮命名,详见无障碍。

#自定义线宽

动态与固定入口都接受 strokeWidth,以原图坐标为单位,步长为 0.25。它会根据线宽选择单独绘制的图稿。

---import { SearchIcon } from '@master/icons-astro/24/soft';---<SearchIcon size={48} strokeWidth={2} />

各光学尺寸支持的线宽范围和绘制方法,参见线宽。