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

[docs] Remove last dependencies on makeStyles from @material-ui/core/styles #26246

Merged
merged 5 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 21 additions & 15 deletions benchmark/browser/scenarios/make-styles/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { createTheme } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles((theme) => ({
root: {
width: 200,
height: 200,
borderWidth: 3,
borderColor: 'white',
'&:hover': {
backgroundColor: theme.palette.secondary.dark,
},
[theme.breakpoints.up('sm')]: {
backgroundColor: theme.palette.primary.main,
borderStyle: 'dashed',
const defaultTheme = createTheme();

const useStyles = makeStyles(
(theme) => ({
root: {
width: 200,
height: 200,
borderWidth: 3,
borderColor: 'white',
'&:hover': {
backgroundColor: theme.palette.secondary.dark,
},
[theme.breakpoints.up('sm')]: {
backgroundColor: theme.palette.primary.main,
borderStyle: 'dashed',
},
},
},
}));
}),
{ defaultTheme },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where the code is not publicly visible on docs, or styles are too complicated, I used the defaultTheme prop.

);

const Div = React.forwardRef(function Div(props, ref) {
const classes = useStyles();
Expand Down
173 changes: 76 additions & 97 deletions docs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import { experimentalStyled as styled } from '@material-ui/core/styles';
import Box from '@material-ui/core/Box';
import Typography, { TypographyProps } from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import Container from '@material-ui/core/Container';
import Steps from 'docs/src/pages/landing/Steps';
Expand Down Expand Up @@ -32,82 +33,59 @@ function loadDependencies() {
loadScript('https://platform.twitter.com/widgets.js', document.querySelector('head'));
}

const useStyles = makeStyles(
(theme) => ({
root: {
flex: '1 0 100%',
},
hero: {
paddingTop: theme.spacing(8),
color: theme.palette.primary.main,
},
content: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
paddingTop: theme.spacing(4),
paddingBottom: theme.spacing(8),
[theme.breakpoints.up('md')]: {
paddingTop: theme.spacing(16),
paddingBottom: theme.spacing(16),
flexDirection: 'row',
alignItems: 'flex-start',
textAlign: 'left',
},
},
title: {
marginLeft: -12,
whiteSpace: 'nowrap',
letterSpacing: '.7rem',
textIndent: '.7rem',
fontWeight: theme.typography.fontWeightLight,
[theme.breakpoints.only('xs')]: {
fontSize: 28,
},
},
logo: {
flexShrink: 0,
width: 120,
height: 120,
marginBottom: theme.spacing(2),
[theme.breakpoints.up('md')]: {
marginRight: theme.spacing(8),
width: 195,
height: 175,
},
},
button: {
marginTop: theme.spacing(4),
},
social: {
padding: theme.spacing(2, 0),
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
minHeight: 21,
boxSizing: 'content-box',
'& a': {
color: theme.palette.background.paper,
},
},
github: {
width: 105,
display: 'flex',
justifyContent: 'flex-end',
marginRight: theme.spacing(1),
'& span': {
display: 'flex',
},
},
twitter: {
width: 160,
display: 'flex',
const Content = styled(Container)(({ theme }) => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page is going away, it would have been simpler to change the import only (it seems).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh well..

display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'center',
paddingTop: theme.spacing(4),
paddingBottom: theme.spacing(8),
[theme.breakpoints.up('md')]: {
paddingTop: theme.spacing(16),
paddingBottom: theme.spacing(16),
flexDirection: 'row',
alignItems: 'flex-start',
textAlign: 'left',
},
}));

const Title = styled(Typography)<TypographyProps & { component?: React.ElementType }>(
({ theme }) => ({
marginLeft: -12,
whiteSpace: 'nowrap',
letterSpacing: '.7rem',
textIndent: '.7rem',
fontWeight: theme.typography.fontWeightLight,
[theme.breakpoints.only('xs')]: {
fontSize: 28,
},
}),
{ name: 'LandingPage' },
);

const Logo = styled('img')(({ theme }) => ({
flexShrink: 0,
width: 120,
height: 120,
marginBottom: theme.spacing(2),
[theme.breakpoints.up('md')]: {
marginRight: theme.spacing(8),
width: 195,
height: 175,
},
}));

const Social = styled('div')(({ theme }) => ({
padding: theme.spacing(2, 0),
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
minHeight: 21,
boxSizing: 'content-box',
'& a': {
color: theme.palette.background.paper,
},
}));

interface LandingPageProps {
sponsorsProps: {
docs: object;
Expand All @@ -121,43 +99,44 @@ export default function LandingPage(props: LandingPageProps) {
loadDependencies();
}, []);
const t = useTranslate();
const classes = useStyles();

return (
<AppFrame>
<div className={classes.root}>
<Box sx={{ flex: '1 0 100%' }}>
<Head />
<main id="main-content" tabIndex={-1}>
<div className={classes.hero}>
<Container maxWidth="md" className={classes.content}>
<img src="/static/logo_raw.svg" alt="" className={classes.logo} />
<Box sx={{ pt: 8, color: 'primary.main' }}>
<Content maxWidth="md">
<Logo src="/static/logo_raw.svg" alt="" />
<div>
<Typography
variant="h3"
component="h1"
color="inherit"
gutterBottom
className={classes.title}
>
<Title variant="h3" component="h1" color="inherit" gutterBottom>
{'MATERIAL-UI'}
</Typography>
</Title>
<Typography variant="h5" component="p" color="inherit">
{t('strapline')}
</Typography>
<Button
component={Link}
noLinkStyle
href="/getting-started/installation"
className={classes.button}
sx={{ mt: 4 }}
variant="outlined"
>
{t('getStarted')}
</Button>
</div>
</Container>
</div>
<div className={classes.social}>
<div className={classes.github}>
</Content>
</Box>
<Social>
<Box
sx={{
width: 105,
display: 'flex',
justifyContent: 'flex-end',
mr: 1,
'& span': { display: 'flex' },
}}
>
<a
className="github-button"
href="https://github.com/mui-org/material-ui"
Expand All @@ -166,17 +145,17 @@ export default function LandingPage(props: LandingPageProps) {
>
Star
</a>
</div>
<div className={classes.twitter}>
</Box>
<Box sx={{ width: 160, display: 'flex' }}>
<a
className="twitter-follow-button"
href="https://twitter.com/@materialui"
data-show-screen-name="false"
>
Follow
</a>
</div>
</div>
</Box>
</Social>
<Pro />
<QuickWord />
<Steps />
Expand All @@ -186,7 +165,7 @@ export default function LandingPage(props: LandingPageProps) {
<Users />
</main>
<AppFooter />
</div>
</Box>
<script
type="application/ld+json"
// eslint-disable-next-line react/no-danger
Expand Down
7 changes: 4 additions & 3 deletions docs/src/modules/components/MarkdownElement.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
// TODO: fix import, test:regressions is failing as there is no theme in the context
import { makeStyles } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/styles';
import { createTheme } from '@material-ui/core/styles';

const styles = (theme) => ({
root: {
Expand Down Expand Up @@ -207,7 +207,8 @@ const styles = (theme) => ({
},
},
});
const useStyles = makeStyles(styles, { name: 'MarkdownElement', flip: false });
const defaultTheme = createTheme();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the dark mode and RTL toggle?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am setting only defaultTheme. If there is a ThemeProvider with different theme it will be picked up. Is there some scenario that is not working?

Copy link
Member

@oliviertassinari oliviertassinari May 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK my bad

const useStyles = makeStyles(styles, { name: 'MarkdownElement', flip: false, defaultTheme });

const MarkdownElement = React.forwardRef(function MarkdownElement(props, ref) {
const { className, renderedMarkdown, ...other } = props;
Expand Down
Loading