Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppBar] Hide and Elevate on Scroll #15522

Merged
merged 32 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ad43639
[AppBar] Hide an Elevate on Scroll
cvanem Apr 30, 2019
bf7653b
[useSCrollTrigger] Fix test
cvanem Apr 30, 2019
c03512a
[useScrollTrigger] Fix test
cvanem Apr 30, 2019
9923c32
[useScrollTrigger] Add tests and set default values
cvanem Apr 30, 2019
1154b2a
[useScrollTrigger] Add test error message info
cvanem Apr 30, 2019
887ebed
[useScrollTrigger] Add clock to tests
cvanem Apr 30, 2019
c8cb13c
Update docs/src/pages/demos/app-bar/app-bar.md
mbrookes Apr 30, 2019
7f07ba7
Update docs/src/pages/demos/app-bar/app-bar.md
mbrookes Apr 30, 2019
3340dab
[Docuementation] Remove duplicate App Bar elevate demo
cvanem Apr 30, 2019
df3d7a3
[Documentiation] Remove unused props
cvanem Apr 30, 2019
4e2a9b1
[Documentation] Polish comments
cvanem Apr 30, 2019
f422c68
[useScrollTrigger,Documentation] Update demos and prop names
cvanem May 1, 2019
a31a1a5
Remove typescript demos
cvanem May 1, 2019
7bef4e3
[AppBar] Revert PaperProps property addition
cvanem May 1, 2019
a288a79
[AppBar] Revert typescript PaperProp changes
cvanem May 1, 2019
8bb2338
[Documentation] Revert PaperProps changes
cvanem May 1, 2019
26c8e35
[useScrollTrigger] Fixing tests
cvanem May 1, 2019
fdb4c27
Tests
cvanem May 1, 2019
5809e8e
[useScrollTrigger] Filter Chrome OS X browser tests
cvanem May 1, 2019
40d5e46
[useScrollTrigger] Seperate onTrigger event
cvanem May 1, 2019
6df4c27
Update prop types and typings
cvanem May 1, 2019
9244a4c
Remove setTarget useEffect dependency
cvanem May 1, 2019
388baff
Move trigger options to state, update typings
cvanem May 1, 2019
aa7a67c
Update typings
cvanem May 1, 2019
7cbb5a5
Simplify demo
oliviertassinari May 1, 2019
c817b5b
Update scrollTrigger state logic and typings
cvanem May 2, 2019
ddde09e
Update typings
cvanem May 2, 2019
62fa887
Simplify getScrollY
cvanem May 2, 2019
da97d11
Fix typing
cvanem May 2, 2019
87ed6d2
Fix getScrollY
cvanem May 2, 2019
fba87db
change the API
oliviertassinari May 2, 2019
76171b8
Typos
joshwooding May 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class AppFrame extends React.Component {
<MenuIcon />
</IconButton>
{title !== null && (
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
<Typography className={classes.title} variant="h6" noWrap>
{title}
</Typography>
)}
Expand Down
1 change: 0 additions & 1 deletion docs/src/modules/components/AppTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const styles = theme => ({
flexShrink: 0,
order: 2,
position: 'sticky',
wordBreak: 'break-all',
height: 'calc(100vh - 70px - 29px)',
overflowY: 'auto',
padding: theme.spacing(2, 2, 2, 0),
Expand Down
2 changes: 2 additions & 0 deletions docs/src/modules/components/DemoFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DemoFrame extends React.Component {
}),
sheetsManager: new Map(),
container: this.contentDocument.body,
window: () => this.contentWindow,
});
};

Expand All @@ -60,6 +61,7 @@ class DemoFrame extends React.Component {
<StylesProvider jss={this.state.jss} sheetsManager={this.state.sheetsManager}>
{React.cloneElement(children, {
container: this.state.container,
window: this.state.window,
})}
</StylesProvider>
) : null}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/ButtonAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function ButtonAppBar() {
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.title}>
<Typography variant="h6" className={classes.title}>
News
</Typography>
<Button color="inherit">Login</Button>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/ButtonAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ButtonAppBar() {
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.title}>
<Typography variant="h6" className={classes.title}>
News
</Typography>
<Button color="inherit">Login</Button>
Expand Down
62 changes: 62 additions & 0 deletions docs/src/pages/demos/app-bar/ElevateAppBar.js
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>
);
}
67 changes: 67 additions & 0 deletions docs/src/pages/demos/app-bar/ElevateAppBar.tsx
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>
);
}
61 changes: 61 additions & 0 deletions docs/src/pages/demos/app-bar/HideAppBar.js
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>
);
}
66 changes: 66 additions & 0 deletions docs/src/pages/demos/app-bar/HideAppBar.tsx
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>
);
}
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/MenuAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function MenuAppBar() {
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.title}>
<Typography variant="h6" className={classes.title}>
Photos
</Typography>
{auth && (
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/MenuAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function MenuAppBar() {
<IconButton edge="start" className={classes.menuButton} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.title}>
<Typography variant="h6" className={classes.title}>
Photos
</Typography>
{auth && (
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/PrimarySearchAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function PrimarySearchAppBar() {
>
<MenuIcon />
</IconButton>
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
<Typography className={classes.title} variant="h6" noWrap>
Material-UI
</Typography>
<div className={classes.search}>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/PrimarySearchAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function PrimarySearchAppBar() {
>
<MenuIcon />
</IconButton>
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
<Typography className={classes.title} variant="h6" noWrap>
Material-UI
</Typography>
<div className={classes.search}>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/SearchAppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function SearchAppBar() {
>
<MenuIcon />
</IconButton>
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
<Typography className={classes.title} variant="h6" noWrap>
Material-UI
</Typography>
<div className={classes.search}>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/demos/app-bar/SearchAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function SearchAppBar() {
>
<MenuIcon />
</IconButton>
<Typography className={classes.title} variant="h6" color="inherit" noWrap>
<Typography className={classes.title} variant="h6" noWrap>
Material-UI
</Typography>
<div className={classes.search}>
Expand Down
Loading