Skip to content

Commit 62e439b

Browse files
lexskiroliviertassinari
andauthored
[AppBar] Add color transparent support (#19393)
* Fix `AppBar color='inherit'` * Update docs * [AppBar] Add color transparent support Co-authored-by: Olivier Tassinari <[email protected]>
1 parent f05d9a2 commit 62e439b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

docs/pages/api/app-bar.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
2626
|:-----|:-----|:--------|:------------|
2727
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | The content of the component. |
2828
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
29-
| <span class="prop-name">color</span> | <span class="prop-type">'default'<br>&#124;&nbsp;'inherit'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'</span> | <span class="prop-default">'primary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
29+
| <span class="prop-name">color</span> | <span class="prop-type">'default'<br>&#124;&nbsp;'inherit'<br>&#124;&nbsp;'primary'<br>&#124;&nbsp;'secondary'<br>&#124;&nbsp;'transparent'</span> | <span class="prop-default">'primary'</span> | The color of the component. It supports those theme colors that make sense for this component. |
3030
| <span class="prop-name">position</span> | <span class="prop-type">'absolute'<br>&#124;&nbsp;'fixed'<br>&#124;&nbsp;'relative'<br>&#124;&nbsp;'static'<br>&#124;&nbsp;'sticky'</span> | <span class="prop-default">'fixed'</span> | The positioning type. The behavior of the different options is described [in the MDN web docs](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning). Note: `sticky` is not universally supported and will fall back to `static` when unavailable. |
3131

3232
The `ref` is forwarded to the root element.
@@ -49,6 +49,8 @@ Any other props supplied will be provided to the root element ([Paper](/api/pape
4949
| <span class="prop-name">colorDefault</span> | <span class="prop-name">.MuiAppBar-colorDefault</span> | Styles applied to the root element if `color="default"`.
5050
| <span class="prop-name">colorPrimary</span> | <span class="prop-name">.MuiAppBar-colorPrimary</span> | Styles applied to the root element if `color="primary"`.
5151
| <span class="prop-name">colorSecondary</span> | <span class="prop-name">.MuiAppBar-colorSecondary</span> | Styles applied to the root element if `color="secondary"`.
52+
| <span class="prop-name">colorInherit</span> | <span class="prop-name">.MuiAppBar-colorInherit</span> | Styles applied to the root element if `color="inherit"`.
53+
| <span class="prop-name">colorTransparent</span> | <span class="prop-name">.MuiAppBar-colorTransparent</span> | Styles applied to the root element if `color="transparent"`.
5254

5355
You can override the style of the component thanks to one of these customization points:
5456

packages/material-ui/src/AppBar/AppBar.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface AppBarProps extends StandardProps<PaperProps, AppBarClassKey> {
55
/**
66
* The color of the component. It supports those theme colors that make sense for this component.
77
*/
8-
color?: PropTypes.Color;
8+
color?: PropTypes.Color | 'transparent';
99
/**
1010
* The positioning type. The behavior of the different options is described
1111
* [in the MDN web docs](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).

packages/material-ui/src/AppBar/AppBar.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ export const styles = theme => {
6969
backgroundColor: theme.palette.secondary.main,
7070
color: theme.palette.secondary.contrastText,
7171
},
72+
/* Styles applied to the root element if `color="inherit"`. */
73+
colorInherit: {
74+
color: 'inherit',
75+
},
76+
/* Styles applied to the root element if `color="transparent"`. */
77+
colorTransparent: {
78+
backgroundColor: 'transparent',
79+
color: 'inherit',
80+
},
7281
};
7382
};
7483

@@ -83,8 +92,8 @@ const AppBar = React.forwardRef(function AppBar(props, ref) {
8392
className={clsx(
8493
classes.root,
8594
classes[`position${capitalize(position)}`],
95+
classes[`color${capitalize(color)}`],
8696
{
87-
[classes[`color${capitalize(color)}`]]: color !== 'inherit',
8897
'mui-fixed': position === 'fixed', // Useful for the Dialog
8998
},
9099
className,
@@ -116,7 +125,7 @@ AppBar.propTypes = {
116125
/**
117126
* The color of the component. It supports those theme colors that make sense for this component.
118127
*/
119-
color: PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary']),
128+
color: PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary', 'transparent']),
120129
/**
121130
* The positioning type. The behavior of the different options is described
122131
* [in the MDN web docs](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).

0 commit comments

Comments
 (0)