Skip to content

Commit

Permalink
Invert header icons on bright preset backgrounds
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Oct 19, 2022
1 parent b125e10 commit dcb0fd0
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 60 deletions.
22 changes: 0 additions & 22 deletions apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ import isMobile from './mixins/isMobile.js'
const panels = loadState('dashboard', 'panels')
const firstRun = loadState('dashboard', 'firstRun')
const background = loadState('theming', 'background')
const themingDefaultBackground = loadState('theming', 'themingDefaultBackground')
const shippedBackgroundList = loadState('theming', 'shippedBackgrounds')
const statusInfo = {
weather: {
text: t('dashboard', 'Weather'),
Expand Down Expand Up @@ -148,8 +144,6 @@ export default {
modal: false,
appStoreUrl: generateUrl('/settings/apps/dashboard'),
statuses: {},
background,
themingDefaultBackground,
}
},
computed: {
Expand Down Expand Up @@ -240,7 +234,6 @@ export default {
},
mounted() {
this.updateGlobalStyles()
this.updateSkipLink()
window.addEventListener('scroll', this.handleScroll)
Expand All @@ -257,21 +250,6 @@ export default {
},
methods: {
updateGlobalStyles() {
// Override primary-invert-if-bright and color-primary-text if background is set
const isBackgroundBright = shippedBackgroundList[this.background]?.theming === 'dark'
if (isBackgroundBright) {
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'invert(100%)')
document.querySelector('#header').style.setProperty('--color-primary-text', '#000000')
// document.body.removeAttribute('data-theme-dark')
// document.body.setAttribute('data-theme-light', 'true')
} else {
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'no')
document.querySelector('#header').style.setProperty('--color-primary-text', '#ffffff')
// document.body.removeAttribute('data-theme-light')
// document.body.setAttribute('data-theme-dark', 'true')
}
},
/**
* Method to register panels that will be called by the integrating apps
*
Expand Down
1 change: 1 addition & 0 deletions apps/theming/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
--primary-invert-if-bright: no;
--background-invert-if-dark: no;
--background-invert-if-bright: invert(100%);
--invert-if-background-bright: no;
--image-main-background: url('/core/img/app-background.jpg');
--color-primary: #00639a;
--color-primary-default: #0082c9;
Expand Down
1 change: 1 addition & 0 deletions apps/theming/lib/Themes/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public function getCSSVariables(): array {
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkToRouteAbsolute('theming.userTheme.getBackground') . "?v=$cacheBuster')";
} elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground])) {
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
$variables['--invert-if-background-bright'] = BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['theming'] ?? null === BackgroundService::THEMING_MODE_DARK ? 'invert(100%)' : 'no';
} elseif (substr($themingBackground, 0, 1) === '#') {
unset($variables['--image-main-background']);
$variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
Expand Down
28 changes: 7 additions & 21 deletions apps/theming/src/UserThemes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ const shortcutsDisabled = loadState('theming', 'shortcutsDisabled', false)

const background = loadState('theming', 'background')
const themingDefaultBackground = loadState('theming', 'themingDefaultBackground')
const shippedBackgroundList = loadState('theming', 'shippedBackgrounds')

console.debug('Available themes', availableThemes)

export default {
name: 'UserThemes',

components: {
ItemPreview,
NcCheckboxRadioSwitch,
Expand All @@ -116,6 +116,7 @@ export default {
themes() {
return this.availableThemes.filter(theme => theme.type === 1)
},

fonts() {
return this.availableThemes.filter(theme => theme.type === 2)
},
Expand All @@ -134,9 +135,11 @@ export default {
.replace('{guidelines}', this.guidelinesLink)
.replace('{linkend}', '</a>')
},

guidelinesLink() {
return '<a target="_blank" href="https://www.w3.org/WAI/standards-guidelines/wcag/" rel="noreferrer nofollow">'
},

descriptionDetail() {
return t(
'theming',
Expand All @@ -146,9 +149,11 @@ export default {
.replace('{designteam}', this.designteamLink)
.replace(/\{linkend\}/g, '</a>')
},

issuetrackerLink() {
return '<a target="_blank" href="https://github.com/nextcloud/server/issues/" rel="noreferrer nofollow">'
},

designteamLink() {
return '<a target="_blank" href="https://nextcloud.com/design" rel="noreferrer nofollow">'
},
Expand All @@ -160,32 +165,12 @@ export default {
},
},

mounted() {
this.updateGlobalStyles()
},

methods: {
updateBackground(data) {
this.background = (data.type === 'custom' || data.type === 'default') ? data.type : data.value
this.updateGlobalStyles()
this.$emit('update:background')
},

updateGlobalStyles() {
// Override primary-invert-if-bright and color-primary-text if background is set
const isBackgroundBright = shippedBackgroundList[this.background]?.theming === 'dark'
if (isBackgroundBright) {
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'invert(100%)')
document.querySelector('#header').style.setProperty('--color-primary-text', '#000000')
// document.body.removeAttribute('data-theme-dark')
// document.body.setAttribute('data-theme-light', 'true')
} else {
document.querySelector('#header').style.setProperty('--primary-invert-if-bright', 'no')
document.querySelector('#header').style.setProperty('--color-primary-text', '#ffffff')
// document.body.removeAttribute('data-theme-light')
// document.body.setAttribute('data-theme-dark', 'true')
}
},
changeTheme({ enabled, id }) {
// Reset selected and select new one
this.themes.forEach(theme => {
Expand All @@ -199,6 +184,7 @@ export default {
this.updateBodyAttributes()
this.selectItem(enabled, id)
},

changeFont({ enabled, id }) {
// Reset selected and select new one
this.fonts.forEach(font => {
Expand Down
2 changes: 1 addition & 1 deletion core/css/server.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/css/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ span.ui-icon {
content: ' ';
// Force white
background-image: var(--original-icon-contacts-white);
filter: var(--primary-invert-if-bright);
filter: var(--invert-if-background-bright);
}

&:hover,
Expand Down
3 changes: 1 addition & 2 deletions core/src/components/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ $header-icon-size: 20px;
position: relative;
display: flex;
opacity: .7;
filter: var(--invert-if-background-bright);

&.app-menu-entry__active {
opacity: 1;
Expand Down Expand Up @@ -183,7 +184,6 @@ $header-icon-size: 20px;
width: $header-icon-size;
height: $header-icon-size;
padding: calc((100% - $header-icon-size) / 2);
filter: var(--primary-invert-if-bright);
}

.app-menu-entry--label {
Expand Down Expand Up @@ -269,7 +269,6 @@ $header-icon-size: 20px;
}

img {
filter: var(--background-invert-if-bright);
width: $header-icon-size;
height: $header-icon-size;
padding: calc((50px - $header-icon-size) / 2);
Expand Down
4 changes: 4 additions & 0 deletions core/src/views/UnifiedSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ $input-height: 34px;
$input-padding: 6px;

.unified-search {
&__trigger {
filter: var(--invert-if-background-bright);
}

&__input-wrapper {
position: sticky;
// above search results
Expand Down
4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-unified-search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unified-search.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/dashboard-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dashboard-main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/theming-theming-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/theming-theming-settings.js.map

Large diffs are not rendered by default.

0 comments on commit dcb0fd0

Please sign in to comment.