跳到内容
+

使用图标库

了解如何在 Joy UI 中使用您最喜欢的图标库。

Material UI 图标

@mui/icons-material 包括 2,100 多个官方 Material 图标 转换为 SVG 图标 组件。

安装

本节假设您已在您的应用程序中安装了 Joy UI — 有关说明,请参阅安装

yarn

yarn add @mui/icons-material @mui/material

npm

npm install @mui/icons-material @mui/material

用法

默认情况下,当 Joy UI 组件的尺寸或变体更改时,它们能够控制图标的颜色、字体大小和边距。

你好,世界

你好,世界

你好,世界

你好,世界

尺寸

要控制图标的大小,请使用 fontSize 属性。该值可以是 theme.fontSize 中的键之一(默认值为 "xl")。

Enter 开始编辑

第三方图标

要将其他图标库、Web 字体图标或纯 SVG 图标与 Joy UI 一起使用,请应用具有特定 CSS 变量的样式,如下例所示

import { CssVarsProvider } from '@mui/joy/styles';
import GlobalStyles from '@mui/joy/GlobalStyles';
// The `GlobalStyles` component is used to create a global style sheet.
// You can replace it with your preferred CSS solution.

function App() {
  return (
    <CssVarsProvider>
      <GlobalStyles styles={{
        // The {selector} is the CSS selector to target the icon.
        // We recommend using a class over a tag if possible.
        '{selector}': {
          color: "var(--Icon-color)",
          margin: "var(--Icon-margin)",
          fontSize: "var(--Icon-fontSize, 20px)",
          width: "1em",
          height: "1em"
        }
      }}>
    </CssVarsProvider>
  )
}

Joy UI 组件可以根据其尺寸和变体控制这些变量,以使图标完美契合。


以下是您可以与 Joy UI 一起使用的知名图标库的集合。

react-icons

Ionicons

Heroicons

Bootstrap 图标

Font Awesome 图标

Iconify

Lucide