圖示按鈕API
React IconButton 元件的 API 參考文件。了解此匯出模組的 props、CSS 和其他 API。
範例
匯入
import IconButton from '@mui/material/IconButton';
// or
import { IconButton } from '@mui/material';
閱讀這篇關於最小化套件大小的指南,以了解差異。
請參考文件中關於可用圖示選項的圖示章節。
ButtonBase 元件的屬性也適用。
名稱 | 類型 | 預設 | 描述 |
---|---|---|---|
children | node | - | 要顯示的圖示。 |
類別 | object | - | 覆寫或擴展應用於元件的樣式。 詳情請參閱下方的CSS 類別 API。 |
color | 'inherit' | 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string | 'default' | 元件的顏色。它同時支援預設和自訂主題色彩,這些色彩可以按照調色盤自訂指南中所示的方式新增。 |
disabled | bool | false | 若為 |
disableFocusRipple | bool | false | 若為 |
disableRipple | bool | false | 若為 |
edge | 'end' | 'start' | false | false | 如果提供此屬性,則會使用負邊距來抵消一側的 padding(這通常有助於將圖示的左側或右側與上方或下方的內容對齊,而不會破壞邊框大小和形狀)。 |
loading | bool | null | 若為 |
loadingIndicator | node | <CircularProgress color="inherit" size={16} /> | 如果按鈕處於載入狀態,則此元素會放置在子項之前。節點應包含具有 |
size | 'small' | 'medium' | 'large' | string | 'medium' | 元件的大小。 |
sx | Array<func | object | bool> | func | object | - | 系統屬性,可讓您定義系統覆寫以及額外的 CSS 樣式。 詳情請參閱 `sx` 頁面。 |
ref
會轉發到根元素。繼承
雖然上方未明確說明,但 ButtonBase 元件的屬性也適用於 IconButton。您可以利用此功能來鎖定巢狀元件。
主題預設屬性
您可以使用 MuiIconButton
來透過主題變更此元件的預設屬性。
這些類別名稱對於使用 CSS 設定樣式很有用。當觸發特定狀態時,它們會套用至元件的插槽。
類別名稱 | 規則名稱 | 描述 |
---|---|---|
.Mui-disabled | 如果 disabled={true} ,則套用至根元素的狀態類別。 | |
.MuiIconButton-colorError | colorError | 如果 color="error" ,則套用至根元素的樣式。 |
.MuiIconButton-colorInfo | colorInfo | 如果 color="info" ,則套用至根元素的樣式。 |
.MuiIconButton-colorInherit | colorInherit | 如果 color="inherit" ,則套用至根元素的樣式。 |
.MuiIconButton-colorPrimary | colorPrimary | 如果 color="primary" ,則套用至根元素的樣式。 |
.MuiIconButton-colorSecondary | colorSecondary | 如果 color="secondary" ,則套用至根元素的樣式。 |
.MuiIconButton-colorSuccess | colorSuccess | 如果 color="success" ,則套用至根元素的樣式。 |
.MuiIconButton-colorWarning | colorWarning | 如果 color="warning" ,則套用至根元素的樣式。 |
.MuiIconButton-edgeEnd | edgeEnd | 如果 edge="end" ,則套用至根元素的樣式。 |
.MuiIconButton-edgeStart | edgeStart | 如果 edge="start" ,則套用至根元素的樣式。 |
.MuiIconButton-loading | loading | 如果 loading={true} ,則套用至根元素的樣式。 |
.MuiIconButton-loadingIndicator | loadingIndicator | 套用至 loadingIndicator 元素的樣式。 |
.MuiIconButton-loadingWrapper | loadingWrapper | 套用至 loadingWrapper 元素的樣式。 |
.MuiIconButton-root | root | 套用至根元素的樣式。 |
.MuiIconButton-sizeLarge | sizeLarge | 如果 size="large" ,則套用至根元素的樣式。 |
.MuiIconButton-sizeMedium | sizeMedium | 如果 size="medium" ,則套用至根元素的樣式。 |
.MuiIconButton-sizeSmall | sizeSmall | 如果 size="small" ,則套用至根元素的樣式。 |
您可以使用以下其中一種客製化選項來覆寫元件的樣式
原始碼
如果您在此頁面中找不到所需資訊,請考慮查看 元件的實作 以取得更多詳細資訊。