跳到内容

快速开始

本指南会帮助你在 Preact 项目中开始使用 YCloud Icons。 请确保已经准备好 Preact 开发环境。如果还没有,可以使用 Create Preact App、Vite 或其他你偏好的 Preact 脚手架创建新项目。

版本要求

@ycloud-web/icons-preact 的最低版本要求:Preact ^10.27.2

安装

sh
pnpm add @ycloud-web/icons-preact@latest
sh
yarn add @ycloud-web/icons-preact@latest
sh
npm install @ycloud-web/icons-preact@latest
sh
bun add @ycloud-web/icons-preact@latest

导入第一个图标

YCloud Icons 基于 ES Modules 构建,因此可以完整支持 tree-shaking。

每个图标都可以作为 Preact component 导入,并渲染为内联 SVG 元素。这样最终产物只会包含你实际导入的图标,其余未使用的图标会被构建工具移除。

jsx
import { Camera } from '@ycloud-web/icons-preact';

// 使用
const App = () => {
  return <Camera />;
};

export default App;

属性

你可以通过以下 props 调整图标外观:

名称类型默认值
sizenumber24
colorstringcurrentColor
strokeWidthnumber2
absoluteStrokeWidthbooleanfalse

由于图标最终会渲染为 SVG 元素,所有标准 SVG 属性也可以作为 props 传入。可参考 MDN 上的 SVG Presentation Attributes 列表

jsx
// 使用
const App = () => {
  return (
    <Camera
      size={48}
      color="red"
      strokeWidth={1}
    />
  );
};

继续阅读下面的内容,了解更多 props 用法和示例:

基于 ISC 许可证发布。