-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AppBar] Hide and Elevate on Scroll (#15522)
* [AppBar] Hide an Elevate on Scroll * [useSCrollTrigger] Fix test * [useScrollTrigger] Fix test * [useScrollTrigger] Add tests and set default values * [useScrollTrigger] Add test error message info * [useScrollTrigger] Add clock to tests * Update docs/src/pages/demos/app-bar/app-bar.md Co-Authored-By: cvanem <chris@greenlinkservices.com> * Update docs/src/pages/demos/app-bar/app-bar.md Co-Authored-By: cvanem <chris@greenlinkservices.com> * [Docuementation] Remove duplicate App Bar elevate demo * [Documentiation] Remove unused props * [Documentation] Polish comments * [useScrollTrigger,Documentation] Update demos and prop names * Remove typescript demos * [AppBar] Revert PaperProps property addition * [AppBar] Revert typescript PaperProp changes * [Documentation] Revert PaperProps changes * [useScrollTrigger] Fixing tests * Tests * [useScrollTrigger] Filter Chrome OS X browser tests * [useScrollTrigger] Seperate onTrigger event * Update prop types and typings * Remove setTarget useEffect dependency * Move trigger options to state, update typings * Update typings * Simplify demo * Update scrollTrigger state logic and typings * Update typings * Simplify getScrollY * Fix typing * Fix getScrollY * change the API * Typos
- Loading branch information
1 parent
4516caf
commit 9b1bb8a
Showing
38 changed files
with
639 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable prefer-spread */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import useScrollTrigger from '@material-ui/core/useScrollTrigger'; | ||
import Box from '@material-ui/core/Box'; | ||
import Container from '@material-ui/core/Container'; | ||
|
||
function ElevationScroll(props) { | ||
const { children, window } = props; | ||
// Note that you normally won't need to set the window ref as useScrollTrigger | ||
// will default to window. | ||
// This is only being set here because the demo is in an iframe. | ||
const trigger = useScrollTrigger({ | ||
disableHysteresis: true, | ||
threshold: 0, | ||
target: window ? window() : undefined, | ||
}); | ||
|
||
return React.cloneElement(children, { | ||
elevation: trigger ? 4 : 0, | ||
}); | ||
} | ||
|
||
ElevationScroll.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
// Injected by the documentation to work in an iframe. | ||
// You won't need it on your project. | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default function ElevateAppBar(props) { | ||
return ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<ElevationScroll {...props}> | ||
<AppBar> | ||
<Toolbar> | ||
<Typography variant="h6">Scroll to Elevate App Bar</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
</ElevationScroll> | ||
<Toolbar /> | ||
<Container> | ||
<Box my={2}> | ||
{Array.apply(null, Array(12)) | ||
.map( | ||
() => `Cras mattis consectetur purus sit amet fermentum. | ||
Cras justo odio, dapibus ac facilisis in, egestas eget quam. | ||
Morbi leo risus, porta ac consectetur ac, vestibulum at eros. | ||
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.`, | ||
) | ||
.join('\n')} | ||
</Box> | ||
</Container> | ||
</React.Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable prefer-spread */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import useScrollTrigger from '@material-ui/core/useScrollTrigger'; | ||
import Box from '@material-ui/core/Box'; | ||
import Container from '@material-ui/core/Container'; | ||
|
||
interface Props { | ||
window?: () => Window; | ||
children: React.ReactElement; | ||
} | ||
|
||
function ElevationScroll(props: Props) { | ||
const { children, window } = props; | ||
// Note that you normally won't need to set the window ref as useScrollTrigger | ||
// will default to window. | ||
// This is only being set here because the demo is in an iframe. | ||
const trigger = useScrollTrigger({ | ||
disableHysteresis: true, | ||
threshold: 0, | ||
target: window ? window() : undefined, | ||
}); | ||
|
||
return React.cloneElement(children, { | ||
elevation: trigger ? 4 : 0, | ||
}); | ||
} | ||
|
||
ElevationScroll.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
// Injected by the documentation to work in an iframe. | ||
// You won't need it on your project. | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default function ElevateAppBar(props: Props) { | ||
return ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<ElevationScroll {...props}> | ||
<AppBar> | ||
<Toolbar> | ||
<Typography variant="h6">Scroll to Elevate App Bar</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
</ElevationScroll> | ||
<Toolbar /> | ||
<Container> | ||
<Box my={2}> | ||
{Array.apply(null, Array(12)) | ||
.map( | ||
() => `Cras mattis consectetur purus sit amet fermentum. | ||
Cras justo odio, dapibus ac facilisis in, egestas eget quam. | ||
Morbi leo risus, porta ac consectetur ac, vestibulum at eros. | ||
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.`, | ||
) | ||
.join('\n')} | ||
</Box> | ||
</Container> | ||
</React.Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable prefer-spread */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import useScrollTrigger from '@material-ui/core/useScrollTrigger'; | ||
import Box from '@material-ui/core/Box'; | ||
import Container from '@material-ui/core/Container'; | ||
import Slide from '@material-ui/core/Slide'; | ||
|
||
function HideOnScroll(props) { | ||
const { children, window } = props; | ||
// Note that you normally won't need to set the window ref as useScrollTrigger | ||
// will default to window. | ||
// This is only being set here because the demo is in an iframe. | ||
const trigger = useScrollTrigger({ target: window ? window() : undefined }); | ||
|
||
return ( | ||
<Slide appear={false} direction="down" in={!trigger}> | ||
{children} | ||
</Slide> | ||
); | ||
} | ||
|
||
HideOnScroll.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
// Injected by the documentation to work in an iframe. | ||
// You won't need it on your project. | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default function HideAppBar(props) { | ||
return ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<HideOnScroll {...props}> | ||
<AppBar> | ||
<Toolbar> | ||
<Typography variant="h6">Scroll to Hide App Bar</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
</HideOnScroll> | ||
<Toolbar /> | ||
<Container> | ||
<Box my={2}> | ||
{Array.apply(null, Array(12)) | ||
.map( | ||
() => `Cras mattis consectetur purus sit amet fermentum. | ||
Cras justo odio, dapibus ac facilisis in, egestas eget quam. | ||
Morbi leo risus, porta ac consectetur ac, vestibulum at eros. | ||
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.`, | ||
) | ||
.join('\n')} | ||
</Box> | ||
</Container> | ||
</React.Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable prefer-spread */ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AppBar from '@material-ui/core/AppBar'; | ||
import Toolbar from '@material-ui/core/Toolbar'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import CssBaseline from '@material-ui/core/CssBaseline'; | ||
import useScrollTrigger from '@material-ui/core/useScrollTrigger'; | ||
import Box from '@material-ui/core/Box'; | ||
import Container from '@material-ui/core/Container'; | ||
import Slide from '@material-ui/core/Slide'; | ||
|
||
interface Props { | ||
window?: () => Window; | ||
children: React.ReactElement; | ||
} | ||
|
||
function HideOnScroll(props: Props) { | ||
const { children, window } = props; | ||
// Note that you normally won't need to set the window ref as useScrollTrigger | ||
// will default to window. | ||
// This is only being set here because the demo is in an iframe. | ||
const trigger = useScrollTrigger({ target: window ? window() : undefined }); | ||
|
||
return ( | ||
<Slide appear={false} direction="down" in={!trigger}> | ||
{children} | ||
</Slide> | ||
); | ||
} | ||
|
||
HideOnScroll.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
// Injected by the documentation to work in an iframe. | ||
// You won't need it on your project. | ||
window: PropTypes.func, | ||
}; | ||
|
||
export default function HideAppBar(props: Props) { | ||
return ( | ||
<React.Fragment> | ||
<CssBaseline /> | ||
<HideOnScroll {...props}> | ||
<AppBar> | ||
<Toolbar> | ||
<Typography variant="h6">Scroll to Hide App Bar</Typography> | ||
</Toolbar> | ||
</AppBar> | ||
</HideOnScroll> | ||
<Toolbar /> | ||
<Container> | ||
<Box my={2}> | ||
{Array.apply(null, Array(12)) | ||
.map( | ||
() => `Cras mattis consectetur purus sit amet fermentum. | ||
Cras justo odio, dapibus ac facilisis in, egestas eget quam. | ||
Morbi leo risus, porta ac consectetur ac, vestibulum at eros. | ||
Praesent commodo cursus magna, vel scelerisque nisl consectetur et.`, | ||
) | ||
.join('\n')} | ||
</Box> | ||
</Container> | ||
</React.Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.