Skip to content

Commit

Permalink
feat(dark): make dark mode work with auto on SSR quasarframework#7530
Browse files Browse the repository at this point in the history
Not solved problems:
- vmColor in DialogPlugin
- classes in QStepper

Once these are solved isDark can be removed.
  • Loading branch information
pdanpdan committed Aug 4, 2020
1 parent d082c77 commit 2588451
Show file tree
Hide file tree
Showing 96 changed files with 614 additions and 126 deletions.
3 changes: 3 additions & 0 deletions ui/dev/quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = function (ctx) {
framework: {
// iconSet: 'svg-mdi-v4',
// config: { ripple: { early: true } },
config: {
dark: 'auto'
},
importStrategy: 'all'
},

Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/banner/QBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default Vue.extend({
class: {
'q-banner--top-padding': actions !== void 0 && !this.inlineActions,
'q-banner--dense': this.dense,
'q-banner--dark q-dark': this.isDark,
[`q-banner--${this.darkSuffix} q-${this.darkSuffix}`]: true,
'rounded-borders': this.rounded
},
attrs,
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/bar/QBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default Vue.extend({

computed: {
classes () {
return `q-bar--${this.dense === true ? 'dense' : 'standard'} ` +
`q-bar--${this.isDark === true ? 'dark' : 'light'}`
return `q-bar--${this.dense === true ? 'dense' : 'standard'} q-bar--${this.darkSuffix}`
}
},

Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/bar/QBar.sass
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

&--dark
background: rgba(255,255,255,.15)

@media (prefers-color-scheme: dark)
.q-bar--dark-auto
background: rgba(255,255,255,.15)
4 changes: 4 additions & 0 deletions ui/src/components/bar/QBar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@

&--dark
background: rgba(255,255,255,.15)

@media (prefers-color-scheme: dark)
.q-bar--dark-auto
background: rgba(255,255,255,.15)
3 changes: 1 addition & 2 deletions ui/src/components/card/QCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default Vue.extend({

computed: {
classes () {
return 'q-card' +
(this.isDark === true ? ' q-card--dark q-dark' : '') +
return `q-card q-card--${this.darkSuffix} q-${this.darkSuffix}` +
(this.bordered === true ? ' q-card--bordered' : '') +
(this.square === true ? ' q-card--square no-border-radius' : '') +
(this.flat === true ? ' q-card--flat no-shadow' : '')
Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/card/QCard.sass
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@
width: 100%
max-width: 100%
border: 0

@media (prefers-color-scheme: dark)
.q-card--dark-auto
border-color: $separator-dark-color
4 changes: 4 additions & 0 deletions ui/src/components/card/QCard.styl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@
width: 100%
max-width: 100%
border: 0

@media (prefers-color-scheme: dark)
.q-card--dark-auto
border-color: $separator-dark-color
3 changes: 1 addition & 2 deletions ui/src/components/carousel/QCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export default Vue.extend({
},

classes () {
return `q-carousel q-panel-parent q-carousel--with${this.padding === true ? '' : 'out'}-padding` +
return `q-carousel q-panel-parent q-carousel--with${this.padding === true ? '' : 'out'}-padding q-carousel--${this.darkSuffix} q-${this.darkSuffix}` +
(this.inFullscreen === true ? ' fullscreen' : '') +
(this.isDark === true ? ' q-carousel--dark q-dark' : '') +
(this.arrows === true ? ` q-carousel--arrows-${this.direction}` : '') +
(this.navigation === true ? ` q-carousel--navigation-${this.navigationPositionComputed}` : '')
},
Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/checkbox/QCheckbox.sass
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@ body.desktop
&:hover
.q-checkbox__inner:before
transform: scale3d(1.4, 1.4, 1)

@media (prefers-color-scheme: dark)
.q-checkbox--dark-auto
.q-checkbox__inner
color: rgba(255,255,255,.7)
&:before
opacity: .32 !important
&--truthy, &--indet
color: $primary
color: var(--q-color-primary)
10 changes: 10 additions & 0 deletions ui/src/components/checkbox/QCheckbox.styl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,13 @@ body.desktop
&:hover
.q-checkbox__inner:before
transform: scale3d(1.4, 1.4, 1)

@media (prefers-color-scheme: dark)
.q-checkbox--dark-auto
.q-checkbox__inner
color: rgba(255,255,255,.7)
&:before
opacity: .32 !important
&--truthy, &--indet
color: $primary
color: var(--q-color-primary)
2 changes: 1 addition & 1 deletion ui/src/components/chip/QChip.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default Vue.extend({
'q-chip--selected': this.selected,
'q-chip--clickable cursor-pointer non-selectable q-hoverable': this.isClickable,
'q-chip--square': this.square,
'q-chip--dark q-dark': this.isDark
[`q-chip--${this.darkSuffix} q-${this.darkSuffix}`]: true
}
},

Expand Down
5 changes: 5 additions & 0 deletions ui/src/components/chip/QChip.sass
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ $chip-height: 2em

body.desktop .q-chip--clickable:focus
box-shadow: $shadow-1

@media (prefers-color-scheme: dark)
.q-chip--dark-auto
.q-chip__icon
color: inherit
5 changes: 5 additions & 0 deletions ui/src/components/chip/QChip.styl
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ $chip-height = 2em

body.desktop .q-chip--clickable:focus
box-shadow: $shadow-1

@media (prefers-color-scheme: dark)
.q-chip--dark-auto
.q-chip__icon
color: inherit
13 changes: 6 additions & 7 deletions ui/src/components/color/QColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ export default Vue.extend({
},

classes () {
return 'q-color-picker' +
return `q-color-picker q-color-picker--${this.darkSuffix} q-${this.darkSuffix}` +
(this.bordered === true ? ' q-color-picker--bordered' : '') +
(this.square === true ? ' q-color-picker--square no-border-radius' : '') +
(this.flat === true ? ' q-color-picker--flat no-shadow' : '') +
(this.disable === true ? ' disabled' : '') +
(this.isDark === true ? ' q-color-picker--dark q-dark' : '')
(this.disable === true ? ' disabled' : '')
},

attrs () {
Expand Down Expand Up @@ -459,7 +458,7 @@ export default Vue.extend({
min: 0,
max: 255,
color: 'red',
dark: this.isDark,
dark: this.dark,
readonly: this.editable !== true
},
on: cache(this, 'rSlide', {
Expand Down Expand Up @@ -491,7 +490,7 @@ export default Vue.extend({
min: 0,
max: 255,
color: 'green',
dark: this.isDark,
dark: this.dark,
readonly: this.editable !== true
},
on: cache(this, 'gSlide', {
Expand Down Expand Up @@ -524,7 +523,7 @@ export default Vue.extend({
max: 255,
color: 'blue',
readonly: this.editable !== true,
dark: this.isDark
dark: this.dark
},
on: cache(this, 'bSlide', {
input: value => this.__onNumericChange(value, 'b', 255),
Expand Down Expand Up @@ -554,7 +553,7 @@ export default Vue.extend({
value: this.model.a,
color: 'grey',
readonly: this.editable !== true,
dark: this.isDark
dark: this.dark
},
on: cache(this, 'aSlide', {
input: value => this.__onNumericChange(value, 'a', 100),
Expand Down
7 changes: 7 additions & 0 deletions ui/src/components/color/QColor.sass
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@
background: inherit

&--dark
.q-color-picker__tune-tab input
border: 1px solid rgba(#fff, .3)

.q-slider
color: $grey-5

@media (prefers-color-scheme: dark)
.q-color-picker--dark-auto
.q-color-picker__tune-tab input
border: 1px solid rgba(#fff, .3)

Expand Down
7 changes: 7 additions & 0 deletions ui/src/components/color/QColor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@
background: inherit

&--dark
.q-color-picker__tune-tab input
border: 1px solid alpha(#fff, .3)

.q-slider
color: $grey-5

@media (prefers-color-scheme: dark)
.q-color-picker--dark-auto
.q-color-picker__tune-tab input
border: 1px solid alpha(#fff, .3)

Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/date/QDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ export default Vue.extend({
computed: {
classes () {
const type = this.landscape === true ? 'landscape' : 'portrait'
return `q-date q-date--${type} q-date--${type}-${this.minimal === true ? 'minimal' : 'standard'}` +
(this.isDark === true ? ' q-date--dark q-dark' : '') +
return `q-date q-date--${type} q-date--${type}-${this.minimal === true ? 'minimal' : 'standard'} q-date--${this.darkSuffix} q-${this.darkSuffix}` +
(this.bordered === true ? ` q-date--bordered` : '') +
(this.square === true ? ` q-date--square no-border-radius` : '') +
(this.flat === true ? ` q-date--flat no-shadow` : '') +
Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/date/QDate.sass
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,7 @@

&--dark
border-color: $separator-dark-color

@media (prefers-color-scheme: dark)
.q-date--dark-auto
border-color: $separator-dark-color
4 changes: 4 additions & 0 deletions ui/src/components/date/QDate.styl
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,7 @@

&--dark
border-color: $separator-dark-color

@media (prefers-color-scheme: dark)
.q-date--dark-auto
border-color: $separator-dark-color
8 changes: 4 additions & 4 deletions ui/src/components/dialog-bottom-sheet/BottomSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default Vue.extend({
return action.label === void 0
? h(QSeparator, {
staticClass: 'col-all',
props: { dark: this.isDark }
props: { dark: this.dark }
})
: h('div', {
staticClass: 'q-bottom-sheet__item q-hoverable q-focusable cursor-pointer relative-position',
Expand Down Expand Up @@ -100,14 +100,14 @@ export default Vue.extend({
const img = action.avatar || action.img

return action.label === void 0
? h(QSeparator, { props: { spaced: true, dark: this.isDark } })
? h(QSeparator, { props: { spaced: true, dark: this.dark } })
: h(QItem, {
staticClass: 'q-bottom-sheet__item',
class: action.classes,
props: {
tabindex: 0,
clickable: true,
dark: this.isDark
dark: this.dark
},
on: {
click: () => this.onOk(action),
Expand Down Expand Up @@ -168,7 +168,7 @@ export default Vue.extend({
}, [
h(QCard, {
staticClass: `q-bottom-sheet q-bottom-sheet--${this.grid === true ? 'grid' : 'list'}` +
(this.isDark === true ? ' q-bottom-sheet--dark q-dark' : ''),
` q-bottom-sheet--${this.darkSuffix} q-${this.darkSuffix}`,
style: this.cardStyle,
class: this.cardClass
}, child)
Expand Down
13 changes: 6 additions & 7 deletions ui/src/components/dialog-plugin/DialogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default Vue.extend({
color: this.vmColor,
dense: true,
autofocus: true,
dark: this.isDark
dark: this.dark
},
attrs: this.prompt.attrs,
on: cache(this, 'prompt', {
Expand Down Expand Up @@ -174,7 +174,7 @@ export default Vue.extend({
color: this.vmColor,
inline: this.options.inline,
options: this.options.items,
dark: this.isDark
dark: this.dark
},
on: cache(this, 'opts', {
input: v => { this.options.model = v }
Expand Down Expand Up @@ -256,13 +256,13 @@ export default Vue.extend({
}
else if (this.options !== void 0) {
child.push(
h(QSeparator, { props: { dark: this.isDark } }),
h(QSeparator, { props: { dark: this.dark } }),
h(
QCardSection,
{ staticClass: 'scroll q-dialog-plugin__form' },
this.getOptions(h)
),
h(QSeparator, { props: { dark: this.isDark } })
h(QSeparator, { props: { dark: this.dark } })
)
}

Expand All @@ -285,11 +285,10 @@ export default Vue.extend({
})
}, [
h(QCard, {
staticClass: 'q-dialog-plugin' +
(this.isDark === true ? ' q-dialog-plugin--dark q-dark' : ''),
staticClass: `q-dialog-plugin q-dialog-plugin--${this.darkSuffix} q-${this.darkSuffix}`,
style: this.cardStyle,
class: this.cardClass,
props: { dark: this.isDark }
props: { dark: this.dark }
}, child)
])
}
Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/drawer/QDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,8 @@ export default Vue.extend({
},

classes () {
return `q-drawer--${this.side}` +
return `q-drawer--${this.side} q-drawer--${this.darkSuffix} q-${this.darkSuffix}` +
(this.bordered === true ? ' q-drawer--bordered' : '') +
(this.isDark === true ? ' q-drawer--dark q-dark' : '') +
(this.showing !== true ? ' q-layout--prevent-focus' : '') +
(
this.belowBreakpoint === true
Expand Down
5 changes: 2 additions & 3 deletions ui/src/components/editor/QEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,12 @@ export default Vue.extend({
},

classes () {
return `q-editor q-editor--${this.isViewingSource === true ? 'source' : 'default'}` +
return `q-editor q-editor--${this.isViewingSource === true ? 'source' : 'default'} q-editor--${this.darkSuffix} q-${this.darkSuffix}` +
(this.disable === true ? ' disabled' : '') +
(this.inFullscreen === true ? ' fullscreen column' : '') +
(this.square === true ? ' q-editor--square no-border-radius' : '') +
(this.flat === true ? ' q-editor--flat' : '') +
(this.dense === true ? ' q-editor--dense' : '') +
(this.isDark === true ? ' q-editor--dark q-dark' : '')
(this.dense === true ? ' q-editor--dense' : '')
},

innerClass () {
Expand Down
13 changes: 13 additions & 0 deletions ui/src/components/editor/QEditor.sass
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@
border-color: $editor-border-dark-color

.q-editor
&__content hr
background: $editor-hr-dark-color

&__toolbar
border-color: $editor-border-dark-color

.q-editor__toolbar-group + .q-editor__toolbar-group:before
background: $editor-border-dark-color

@media (prefers-color-scheme: dark)
.q-editor--dark-auto
border-color: $editor-border-dark-color

.q-editor
&__content hr
background: $editor-hr-dark-color

Expand Down
13 changes: 13 additions & 0 deletions ui/src/components/editor/QEditor.styl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,20 @@
border-color: $editor-border-dark-color

.q-editor
&__content hr
background: $editor-hr-dark-color

&__toolbar
border-color: $editor-border-dark-color

.q-editor__toolbar-group + .q-editor__toolbar-group:before
background: $editor-border-dark-color

@media (prefers-color-scheme: dark)
.q-editor--dark-auto
border-color: $editor-border-dark-color

.q-editor
&__content hr
background: $editor-hr-dark-color

Expand Down
Loading

0 comments on commit 2588451

Please sign in to comment.