Skip to content
Open
Show file tree
Hide file tree
Changes from 13 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
20 changes: 20 additions & 0 deletions docs/pages/system/global-classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import { prepareMarkdown } from 'docs/src/modules/utils/parseMarkdown';

const pageFilename = 'system/global-classes';
const requireDemo = require.context('docs/src/pages/system/global-classes', false, /\.(js|tsx)$/);
const requireRaw = require.context(
'!raw-loader!../../src/pages/system/global-classes',
false,
/\.(js|md|tsx)$/,
);

export default function Page({ demos, docs }) {
return <MarkdownDocs demos={demos} docs={docs} requireDemo={requireDemo} />;
}

Page.getInitialProps = () => {
const { demos, docs } = prepareMarkdown({ pageFilename, requireRaw });
return { demos, docs };
};
1 change: 1 addition & 0 deletions docs/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const pages = [
{ pathname: '/system/screen-readers' },
{ pathname: '/system/typography' },
{ pathname: '/system/api', title: 'API' },
{ pathname: '/system/global-classes' },

Choose a reason for hiding this comment

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

Seeing the structure makes me think of how we don't explain well the value proposition of the helpers on the /basics page. http://material-ui.com/system/basics#real-world-use-case should be at the top like they did on https://tailwindcss.com/docs/utility-first. Or even https://chakra-ui.com/ on the homepage 😆

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was missing explanation a bit too to be honest..

],
},
{
Expand Down
24 changes: 24 additions & 0 deletions docs/src/pages/system/global-classes/Basics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import GlobalCss from './GlobalCss';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': {
border: '1px dashed grey',
},
},
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.debug}>
<GlobalCss />
<div className="m-2 p-4">
<div className="m-4 p-2"></div>
</div>
</div>
);
}
24 changes: 24 additions & 0 deletions docs/src/pages/system/global-classes/Basics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import GlobalCss from './GlobalCss';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': {
border: '1px dashed grey',
},
},
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.debug}>
<GlobalCss />
<div className="m-2 p-4">
<div className="m-4 p-2"></div>
</div>
</div>
);
}
27 changes: 27 additions & 0 deletions docs/src/pages/system/global-classes/ColorsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import Button from '@material-ui/core/Button';

export default function App() {
return (
<div>
<Button
variant="contained"
className="m-1 bg-warning-main hover-bg-warning-dark text-warning-contrastText"
>
Warning
</Button>
<Button
variant="contained"
className="m-1 bg-error-main hover-bg-error-dark text-error-contrastText"
>
Error
</Button>
<Button
variant="contained"
className="m-1 bg-success-main hover-bg-success-dark text-success-contrastText"
>
Success
</Button>
</div>
);
}
27 changes: 27 additions & 0 deletions docs/src/pages/system/global-classes/ColorsExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import Button from '@material-ui/core/Button';

export default function App() {
return (
<div>
<Button
variant="contained"
className="m-1 bg-warning-main hover-bg-warning-dark text-warning-contrastText"
>
Warning
</Button>
<Button
variant="contained"
className="m-1 bg-error-main hover-bg-error-dark text-error-contrastText"
>
Error
</Button>
<Button
variant="contained"
className="m-1 bg-success-main hover-bg-success-dark text-success-contrastText"
>
Success
</Button>
</div>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/global-classes/DisplaysExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': {
border: '1px dashed grey',
},
},
});

export default function App() {
const classes = useStyles();
return (
<div className={classes.debug}>
<div className="d-inline mr-1 p-2">div.d-inline</div>
<div className="d-inline d-print-none p-2">Hidden when printed</div>
</div>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/global-classes/DisplaysExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': {
border: '1px dashed grey',
},
},
});

export default function App() {
const classes = useStyles();
return (
<div className={classes.debug}>
<div className="d-inline mr-1 p-2">div.d-inline</div>
<div className="d-inline d-print-none p-2">Hidden when printed</div>
</div>
);
}
21 changes: 21 additions & 0 deletions docs/src/pages/system/global-classes/ElevationsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& > *': { border: '1px dashed grey' },
},
});

export default function App() {
const classes = useStyles();
return (
<div className={classes.debug}>
{Array.from(Array(24).keys()).map((val) => (
<div className={`m-2 p-1 elevation-${val}`} key={val}>
Elevation {val}
</div>
))}
</div>
);
}
21 changes: 21 additions & 0 deletions docs/src/pages/system/global-classes/ElevationsExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& > *': { border: '1px dashed grey' },
},
});

export default function App() {
const classes = useStyles();
return (
<div className={classes.debug}>
{Array.from(Array(24).keys()).map((val) => (
<div className={`m-2 p-1 elevation-${val}`} key={val}>
Elevation {val}
</div>
))}
</div>
);
}
1 change: 1 addition & 0 deletions docs/src/pages/system/global-classes/GlobalCss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (): JSX.Element;
32 changes: 32 additions & 0 deletions docs/src/pages/system/global-classes/GlobalCss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { withStyles } from '@material-ui/styles';
import spacings from './spacings';
import colors from './colors';
import elevations from './elevations';
import texts from './texts';
import positions from './positions';
import {
displays,
overflows,
textOverflows,
visibilities,
whiteSpaces,
} from './displays';

const GlobalCss = withStyles((theme) => {

Choose a reason for hiding this comment

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

I think that we will need to look at

  1. the time it takes to build the styles
  2. how we can handle server-side rendering, if we trust https://tailwindcss.com/docs/controlling-file-size/, 144.5kb gzipped is no way for inlining critical CSS. In our current experimentation, we are at 4kb gzipped. https://www.nytimes.com/ is 210kB gzipped. Youtube.com is 56kb gzipped. Amazon.com is at 93kb gzipped. So I would say 40kB gzipped isn't too far from our limit.

Choose a reason for hiding this comment

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

Actually, for 2. I remember emotion having some sort of critical extraction tool, to only include the required class names. Tailwind has something similar, if it's fast enough to be run at each server-side query, it could move the limitation to 1. only. On the server 1. can be cached.

Choose a reason for hiding this comment

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

For 1. I measure 1ms to build the object and 12ms for JSS to process the object before injection in the page. I have no idea how it scales. They might be way to bypass the plugins, speeding things up. We would also need to look at how long it makes with styled-components and emotion.

return {
'@global': {
...spacings(theme),
...colors(theme),
...elevations(theme),
...texts(theme),
...positions(theme),
...displays,
...overflows,
...textOverflows,
...visibilities,
...whiteSpaces,
},
};
})(() => null);

export default GlobalCss;
23 changes: 23 additions & 0 deletions docs/src/pages/system/global-classes/PositionsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
root: { width: '100%' },
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.root}>
<div className="position-relative p-4 mb-14">
<div className="position-absolute p-4 top-4 left-0 bg-grey-700 text-common-white">
position-absolute
</div>
<div className="position-absolute py-4 px-6 top-10 left-5 zIndex-tooltip bg-primary-light text-common-white">
zIndex-tooltip
</div>
</div>
</div>
);
}
23 changes: 23 additions & 0 deletions docs/src/pages/system/global-classes/PositionsExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
root: { width: '100%' },
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.root}>
<div className="position-relative p-4 mb-14">
<div className="position-absolute p-4 top-4 left-0 bg-grey-700 text-common-white">
position-absolute
</div>
<div className="position-absolute py-4 px-6 top-10 left-5 zIndex-tooltip bg-primary-light text-common-white">
zIndex-tooltip
</div>
</div>
</div>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/global-classes/SpacingsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': { border: '1px dashed grey' },
},
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.debug}>
<div className="m-4 p-4">
<div className="px-10 py-4"></div>
</div>
</div>
);
}
20 changes: 20 additions & 0 deletions docs/src/pages/system/global-classes/SpacingsExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { makeStyles } from '@material-ui/styles';

const useStyles = makeStyles({
debug: {
'& *': { border: '1px dashed grey' },
},
});

export default function App() {
const classes = useStyles();

return (
<div className={classes.debug}>
<div className="m-4 p-4">
<div className="px-10 py-4"></div>
</div>
</div>
);
}
27 changes: 27 additions & 0 deletions docs/src/pages/system/global-classes/TextsExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';

export default function App() {
return (
<div>
{[
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'subtitle1',
'subtitle2',
'body1',
'body2',
'button',
'caption',
'overline',
].map((val) => (
<div className={`m-2 p-1 text-${val}`} key={val}>
Text {val}
</div>
))}
</div>
);
}
Loading