AppBarAPI
React AppBar 组件的 API 参考文档。了解此导出模块的属性、CSS 和其他 API。
演示
导入
import AppBar from '@mui/material/AppBar';
// or
import { AppBar } from '@mui/material';
通过阅读本关于最小化捆绑包大小的指南,了解两者之间的区别。
Paper 组件的属性也可用。
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
children | node | - | 组件的内容。 |
classes | object | - | 覆盖或扩展应用于组件的样式。 有关更多详细信息,请参阅下面的 CSS 类 API。 |
color | 'default' | 'inherit' | 'primary' | 'secondary' | 'transparent' | 'error' | 'info' | 'success' | 'warning' | string | 'primary' | 组件的颜色。它支持默认主题颜色和自定义主题颜色,可以按照调色板自定义指南中所示的方式添加。 |
enableColorOnDark | bool | false | 如果为 true,则在暗黑模式下应用 |
position | 'absolute' | 'fixed' | 'relative' | 'static' | 'sticky' | 'fixed' | 定位类型。不同选项的行为在 MDN web 文档中描述。注意: |
sx | Array<func | object | bool> | func | object | - | 允许定义系统覆盖以及其他 CSS 样式的系统属性。 有关更多详细信息,请参阅 `sx` 页面。 |
ref
被转发到根元素。继承
虽然上面没有明确记录,但 Paper 组件的属性在 AppBar 中也可用。您可以利用这一点来定位嵌套组件。
主题默认属性
您可以使用 MuiAppBar
通过主题更改此组件的默认属性。
这些类名对于使用 CSS 进行样式设置很有用。当触发特定状态时,它们将应用于组件的插槽。
类名 | 规则名称 | 描述 |
---|---|---|
.MuiAppBar-colorDefault | colorDefault | 如果 color="default" ,则应用于根元素的样式。 |
.MuiAppBar-colorError | colorError | 如果 color="error" ,则应用于根元素的样式。 |
.MuiAppBar-colorInfo | colorInfo | 如果 color="info" ,则应用于根元素的样式。 |
.MuiAppBar-colorInherit | colorInherit | 如果 color="inherit" ,则应用于根元素的样式。 |
.MuiAppBar-colorPrimary | colorPrimary | 如果 color="primary" ,则应用于根元素的样式。 |
.MuiAppBar-colorSecondary | colorSecondary | 如果 color="secondary" ,则应用于根元素的样式。 |
.MuiAppBar-colorSuccess | colorSuccess | 如果 color="success" ,则应用于根元素的样式。 |
.MuiAppBar-colorTransparent | colorTransparent | 如果 color="transparent" ,则应用于根元素的样式。 |
.MuiAppBar-colorWarning | colorWarning | 如果 color="warning" ,则应用于根元素的样式。 |
.MuiAppBar-positionAbsolute | positionAbsolute | 如果 position="absolute" ,则应用于根元素的样式。 |
.MuiAppBar-positionFixed | positionFixed | 如果 position="fixed" ,则应用于根元素的样式。 |
.MuiAppBar-positionRelative | positionRelative | 如果 position="relative" ,则应用于根元素的样式。 |
.MuiAppBar-positionStatic | positionStatic | 如果 position="static" ,则应用于根元素的样式。 |
.MuiAppBar-positionSticky | positionSticky | 如果 position="sticky" ,则应用于根元素的样式。 |
.MuiAppBar-root | root | 应用于根元素的样式。 |
您可以使用以下自定义选项之一覆盖组件的样式
- 使用全局类名。
- 使用作为自定义主题中组件的
styleOverrides
属性一部分的规则名称。
源代码
如果您在此页面中没有找到信息,请考虑查看组件的实现以获取更多详细信息。