@@ -3,6 +3,7 @@ import { makeStyles } from '@material-ui/core/styles'
33import { AppBar as MUIAppBar , Toolbar , useScrollTrigger , Slide } from '@material-ui/core'
44import PropTypes from 'prop-types'
55import PWAContext from './PWAContext'
6+ import clsx from 'clsx'
67
78const useStyles = makeStyles ( theme => ( {
89 /**
@@ -19,6 +20,9 @@ const useStyles = makeStyles(theme => ({
1920 flexDirection : 'column' ,
2021 alignItems : 'stretch' ,
2122 } ,
23+ relative : {
24+ position : 'relative' ,
25+ } ,
2226 /**
2327 * Styles applied to the spacer that fills the height behind the floating toolbar.
2428 */
@@ -46,15 +50,22 @@ const useStyles = makeStyles(theme => ({
4650 } ,
4751} ) )
4852
49- export default function AppBar ( { children, style, fixed, offlineWarning, classes } ) {
53+ export default function AppBar ( { children, style, variant, fixed, offlineWarning, classes } ) {
54+ if ( fixed ) {
55+ variant = 'fixed'
56+ }
57+
5058 const trigger = useScrollTrigger ( )
5159 classes = useStyles ( { classes } )
5260
5361 const { offline } = useContext ( PWAContext )
5462
5563 let appBar = (
5664 < MUIAppBar
57- className = { classes . root }
65+ className = { clsx ( {
66+ [ classes . root ] : true ,
67+ [ classes . relative ] : variant === 'relative' ,
68+ } ) }
5869 style = { {
5970 ...style ,
6071 } }
@@ -65,7 +76,7 @@ export default function AppBar({ children, style, fixed, offlineWarning, classes
6576 </ MUIAppBar >
6677 )
6778
68- if ( ! fixed ) {
79+ if ( variant === 'hide' ) {
6980 appBar = (
7081 < Slide appear = { false } in = { ! trigger } >
7182 { appBar }
@@ -75,7 +86,7 @@ export default function AppBar({ children, style, fixed, offlineWarning, classes
7586
7687 return (
7788 < >
78- < div className = { classes . spacer } />
89+ { ( variant === 'hide' || variant === 'fixed' ) && < div className = { classes . spacer } /> }
7990 { offline && < div className = { classes . offline } > { offlineWarning } </ div > }
8091 { appBar }
8192 </ >
@@ -89,17 +100,27 @@ AppBar.propTypes = {
89100 classes : PropTypes . object ,
90101
91102 /**
92- * Set as `true` if the AppBar should be fixed position.
103+ * Affixes the AppBar to the top of the viewport. This prop is deprecated.
104+ * Use `variant="fixed"` instead.
105+ * @deprecated
93106 */
94107 fixed : PropTypes . bool ,
95108
96109 /**
97110 * String or Element to render within the offline warning container at the top of the app.
98111 */
99112 offlineWarning : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . element ] ) ,
113+
114+ /**
115+ * * relative - The AppBar stays at the top of the page.
116+ * * fixed - The AppBar stays at the top of the viewport.
117+ * * hide - The same as fixed, but the app bar automatically hides when the user scrolls down.
118+ */
119+ variant : PropTypes . oneOf ( [ 'relative' , 'fixed' , 'hide' ] ) ,
100120}
101121
102122AppBar . defaultProps = {
103123 offlineWarning : 'Your device lost its internet connection.' ,
124+ variant : 'hide' ,
104125 fixed : false ,
105126}
0 commit comments