Skip to contentSkip to content

AppBarAPI

React AppBar 元件的 API 參考文件。瞭解此匯出模組的 props、CSS 和其他 API。

示範

匯入

import AppBar from '@mui/material/AppBar';
// or
import { AppBar } from '@mui/material';

閱讀這份關於最小化 bundle size 的指南,以瞭解差異。

Props

Paper 元件的 props 也可使用。

名稱類型預設值描述
childrennode-

元件的內容。

classesobject-

覆寫或擴充套用至元件的樣式。

請參閱下方CSS classes API 以取得更多詳細資訊。

color'default'
| 'inherit'
| 'primary'
| 'secondary'
| 'transparent'
| 'error'
| 'info'
| 'success'
| 'warning'
| string
'primary'

元件的色彩。它同時支援預設和自訂主題色彩,可以如調色盤自訂指南中所示新增。

enableColorOnDarkboolfalse

若為 true,則 color prop 會套用在深色模式中。

position'absolute'
| 'fixed'
| 'relative'
| 'static'
| 'sticky'
'fixed'

定位類型。不同選項的行為在 MDN web docs 中說明。注意:sticky 並非普遍支援,在無法使用時將會回退為 static

sxArray<func
| object
| bool>
| func
| object
-

系統 prop,可讓您定義系統覆寫以及額外的 CSS 樣式。

請參閱 `sx` 頁面 以取得更多詳細資訊。

ref 會轉發到根元素。

繼承

雖然上方未明確記錄,但 Paper 元件的 props 也可在 AppBar 中使用。您可以利用此優勢來鎖定巢狀元件

主題預設 props

您可以使用 MuiAppBar透過主題變更此元件的預設 props。

CSS 類別

這些類別名稱對於使用 CSS 設定樣式很有用。當觸發特定狀態時,它們會套用至元件的 slot。

類別名稱規則名稱描述
.MuiAppBar-colorDefaultcolorDefaultcolor="default",則套用至根元素的樣式。
.MuiAppBar-colorErrorcolorErrorcolor="error",則套用至根元素的樣式。
.MuiAppBar-colorInfocolorInfocolor="info",則套用至根元素的樣式。
.MuiAppBar-colorInheritcolorInheritcolor="inherit",則套用至根元素的樣式。
.MuiAppBar-colorPrimarycolorPrimarycolor="primary",則套用至根元素的樣式。
.MuiAppBar-colorSecondarycolorSecondarycolor="secondary",則套用至根元素的樣式。
.MuiAppBar-colorSuccesscolorSuccesscolor="success",則套用至根元素的樣式。
.MuiAppBar-colorTransparentcolorTransparentcolor="transparent",則套用至根元素的樣式。
.MuiAppBar-colorWarningcolorWarningcolor="warning",則套用至根元素的樣式。
.MuiAppBar-positionAbsolutepositionAbsoluteposition="absolute",則套用至根元素的樣式。
.MuiAppBar-positionFixedpositionFixedposition="fixed",則套用至根元素的樣式。
.MuiAppBar-positionRelativepositionRelativeposition="relative",則套用至根元素的樣式。
.MuiAppBar-positionStaticpositionStaticposition="static",則套用至根元素的樣式。
.MuiAppBar-positionStickypositionStickyposition="sticky",則套用至根元素的樣式。
.MuiAppBar-rootroot套用至根元素的樣式。

您可以使用以下其中一種自訂選項來覆寫元件的樣式

原始碼

如果您在此頁面中找不到資訊,請考慮查看元件的實作以取得更多詳細資訊。