Skip to content

Commit 745c6a3

Browse files
n-batalhaoliviertassinari
authored andcommitted
[docs] Add examples of global class names (#14563)
* Add global CSS examples * good for me
1 parent ebd0d1f commit 745c6a3

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { makeStyles } from '@material-ui/styles';
3+
4+
const useStyles = makeStyles({
5+
'@global': {
6+
'.cssjss-advanced-global-root': {
7+
height: 100,
8+
width: 100,
9+
backgroundColor: 'blue',
10+
},
11+
'.cssjss-advanced-global-child': {
12+
height: 8,
13+
backgroundColor: 'red',
14+
},
15+
},
16+
});
17+
18+
function GlobalCss() {
19+
useStyles();
20+
21+
return (
22+
<div className="cssjss-advanced-global-root">
23+
<div className="cssjss-advanced-global-child" />
24+
</div>
25+
);
26+
}
27+
28+
export default GlobalCss;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import { makeStyles } from '@material-ui/styles';
4+
5+
const useStyles = makeStyles({
6+
root: {
7+
'&.root': {
8+
height: 100,
9+
width: 100,
10+
backgroundColor: 'blue',
11+
},
12+
'& .child': {
13+
height: 8,
14+
backgroundColor: 'red',
15+
},
16+
},
17+
});
18+
19+
function HybridCss() {
20+
const classes = useStyles();
21+
22+
return (
23+
<div className={clsx(classes.root, 'root')}>
24+
<div className="child" />
25+
</div>
26+
);
27+
}
28+
29+
export default HybridCss;

docs/src/pages/css-in-js/advanced/advanced.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ JSS relies on the concept of [class name generator](https://cssinjs.org/jss-api/
253253

254254
## Global CSS
255255

256+
### `jss-plugin-global`
257+
258+
The [`jss-plugin-global`](#jss-plugins) plugin is installed in the default preset, you can use it to define global class names.
259+
260+
{{"demo": "pages/css-in-js/advanced/GlobalCss.js"}}
261+
262+
### Hybrid
263+
264+
You can also combine JSS generated class names with global ones.
265+
266+
{{"demo": "pages/css-in-js/advanced/HybridGlobalCss.js"}}
267+
268+
### Deterministic class names
269+
256270
We provide an option to make the class names **deterministic** with the [`dangerouslyUseGlobalCSS`](/css-in-js/api/#creategenerateclassname-options-class-name-generator) option. When turned on, the class names will look like this:
257271

258272
- development: `.AppBar-root`

0 commit comments

Comments
 (0)