Skip to content

Commit 6d73cb9

Browse files
committed
perf(Screen): Only add screen-* body classes if enabled through framework: { config: { screen: { bodyClasses: true } } } quasarframework#5757
1 parent a01dcb9 commit 6d73cb9

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

docs/src/pages/options/screen-plugin.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ import { Screen } from 'quasar'
4444
// Screen.name ('xs', 'sm', ...; Quasar v1.5.2+)
4545
```
4646

47-
## CSS helper
47+
## Body classes
4848

49-
<q-badge label="v1.5.2+" />
49+
<q-badge label="v1.5.3+" />
5050

51-
You can also style your content based on a particular set of CSS classes applied to document.body: `screen--xs`, `screen--sm`, ..., `screen-xl`.
51+
**If you enable it (see how to do it after the examples below)**, you can also style your content based on a particular set of CSS classes applied to document.body: `screen--xs`, `screen--sm`, ..., `screen-xl`.
5252

5353
```css
5454
body.screen--xs {
@@ -74,6 +74,23 @@ Or a sexy variant in Sass or Stylus:
7474
color: #fff
7575
```
7676

77+
### How to enable body classes
78+
79+
In order to enable the behavior above, edit your /quasar.conf.js file like below. Please note that this will increase a bit the time for First Meaningful Paint.
80+
81+
```js
82+
// file: /quasar.conf.js
83+
// with Quasar v1.5.3+
84+
85+
framework: {
86+
config: {
87+
screen: {
88+
bodyClasses: true // <<< add this
89+
}
90+
}
91+
}
92+
```
93+
7794
## Configuration
7895
There are a few methods that can be used to tweak how Screen plugin works:
7996

docs/src/pages/style/body-classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ Quasar attaches some very useful helper CSS classes to document.body which you c
1919
| electron | When client is on an [Electron](/quasar-cli/developing-electron-apps/introduction) app |
2020
| bex | When app runs from a browser extension |
2121
| within-iframe | When app runs from an iframe |
22-
| `screen--*` | Tells current window breakpoint (`screen--xs`, `screen--sm`, ..., `screen--xl`) (**Quasar v1.5.2+**) |
22+
| `screen--*` | If [enabled (only)](/options/screen-plugin#How-to-enable-body-classes), tells current window breakpoint (`screen--xs`, `screen--sm`, ..., `screen--xl`) (**Quasar v1.5.3+**) |

docs/src/pages/style/breakpoints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ $sizes.<breakpoint>
4040
// replace <breakpoint> with xs, sm, md, lg or xl
4141
```
4242

43-
Starting with **Quasar v1.5.2+**, you can also style your content based on a particular set of CSS classes applied to document.body: `screen--xs`, `screen--sm`, ..., `screen-xl`.
43+
Starting with **Quasar v1.5.3+**, [if enabled (only)](/options/screen-plugin#How-to-enable-body-classes), you can also style your content based on a particular set of CSS classes applied to document.body: `screen--xs`, `screen--sm`, ..., `screen-xl`.
4444

4545
```css
46-
// v1.5.2+
46+
// v1.5.3+
4747

4848
.my-div
4949
body.screen-xs &

ui/src/body.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ export default {
8080
cls = getBodyClasses(q.platform, cfg),
8181
fn = ctx.ssr.setBodyClasses
8282

83-
cls.push('screen--xs')
83+
if (cfg.screen !== void 0 && cfg.screen.bodyClass === true) {
84+
cls.push('screen--xs')
85+
}
8486

8587
if (typeof fn === 'function') {
8688
fn(cls)

ui/src/install.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function (Vue, opts = {}) {
3030
Platform.install($q, queues)
3131
Body.install(queues, cfg)
3232
Dark.install($q, queues, cfg)
33-
Screen.install($q, queues)
33+
Screen.install($q, queues, cfg)
3434
History.install($q, cfg)
3535
Lang.install($q, queues, opts.lang)
3636
IconSet.install($q, opts.iconSet)

ui/src/plugins/Screen.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ export default {
4040
setSizes () {},
4141
setDebounce () {},
4242

43-
install ($q, queues) {
43+
install ($q, queues, cfg) {
4444
if (isSSR === true) {
4545
$q.screen = this
4646
return
4747
}
4848

49+
const classes = cfg.screen !== void 0 && cfg.screen.bodyClasses === true
50+
4951
const update = force => {
5052
const
5153
w = window.innerWidth,
@@ -86,8 +88,10 @@ export default {
8688

8789
if (s !== this.name) {
8890
this.name = s
89-
document.body.classList.remove(`screen--${this.__oldName}`)
90-
document.body.classList.add(`screen--${s}`)
91+
if (classes === true) {
92+
document.body.classList.remove(`screen--${this.__oldName}`)
93+
document.body.classList.add(`screen--${s}`)
94+
}
9195
this.__oldName = s
9296
}
9397
}

0 commit comments

Comments
 (0)