跳到主要內容
+

使用圖示庫

了解如何在 Joy UI 中使用您最愛的圖示庫。

Material UI 圖示

@mui/icons-material 包含 2,100 多個官方 Material Icons,已轉換為 SVG 圖示 組件。

安裝

本節假設您已在您的應用程式中安裝 Joy UI — 請參閱安裝以取得說明。

yarn

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

npm

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

使用方法

預設情況下,當 Joy UI 組件的大小或變體變更時,能夠控制圖示的顏色、字體大小和邊距。

Hello World

Hello World

Hello World

Hello World

尺寸

要控制圖示的大小,請使用 fontSize 屬性。值可以是 theme.fontSize 中的其中一個鍵(預設值為 "xl")。

按下 Enter 以開始編輯

第三方圖示

若要在 Joy UI 中使用其他圖示庫、網頁字型圖示或純 SVG 圖示,請套用具有特定 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 Icons

Font Awesome Icons

Iconify

Lucide