Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(theming): change color button contrast #43347

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion apps/theming/src/AdminTheming.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
:default-value="colorPickerField.defaultValue"
:display-name="colorPickerField.displayName"
:value.sync="colorPickerField.value"
data-admin-theming-setting-primary-color
@update:theming="$emit('update:theming')" />

<!-- Default background picker -->
Expand Down
37 changes: 22 additions & 15 deletions apps/theming/src/components/BackgroundSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@
</button>

<!-- Custom color picker -->
<NcColorPicker v-model="Theming.color" @input="debouncePickColor">
<button class="background background__color"
:data-color="Theming.color"
:data-color-bright="invertTextColor(Theming.color)"
:style="{ backgroundColor: Theming.color, '--border-color': Theming.color}"
data-user-theming-background-color
tabindex="0">
{{ t('theming', 'Change color') }}
</button>
</NcColorPicker>
<div class="background-color"
data-user-theming-background-color>
<NcColorPicker v-model="Theming.color"
@input="debouncePickColor">
<NcButton type="ternary">
{{ t('theming', 'Change color') }}
</NcButton>
</NcColorPicker>
</div>

<!-- Remove background -->
<button :aria-pressed="isBackgroundDisabled"
Expand Down Expand Up @@ -113,6 +112,7 @@ import { Palette } from 'node-vibrant/lib/color.js'
import axios from '@nextcloud/axios'
import debounce from 'debounce'
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import Vibrant from 'node-vibrant'

import Check from 'vue-material-design-icons/Check.vue'
Expand All @@ -133,6 +133,7 @@ export default {
Check,
Close,
ImageEdit,
NcButton,
NcColorPicker,
},

Expand Down Expand Up @@ -341,6 +342,17 @@ export default {
flex-wrap: wrap;
justify-content: center;

.background-color {
display: flex;
justify-content: center;
align-items: center;
width: 176px;
height: 96px;
margin: 8px;
border-radius: var(--border-radius-large);
background-color: var(--color-primary);
}

.background {
overflow: hidden;
width: 176px;
Expand Down Expand Up @@ -368,11 +380,6 @@ export default {
border-color: var(--color-border);
}

&__color {
color: var(--color-primary-text);
background-color: var(--color-primary-default);
}

// Over a background image
&__default,
&__shipped {
Expand Down
42 changes: 14 additions & 28 deletions apps/theming/src/components/admin/ColorPickerField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
<div class="field__row">
<NcColorPicker :value.sync="localValue"
:advanced-fields="true"
data-admin-theming-setting-primary-color-picker
@update:value="debounceSave">
<NcButton class="field__button"
type="primary"
:id="id"
:aria-label="t('theming', 'Select a custom color')"
data-admin-theming-setting-primary-color-picker>
{{ value }}
<NcButton type="secondary"
:id="id">
<template #icon>
<Palette :size="20" />
</template>
{{ t('theming', 'Change color') }}
</NcButton>
</NcColorPicker>
<div class="field__color-preview" data-admin-theming-setting-primary-color />
<NcButton v-if="value !== defaultValue"
type="tertiary"
:aria-label="t('theming', 'Reset to default')"
Expand All @@ -60,6 +62,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcColorPicker from '@nextcloud/vue/dist/Components/NcColorPicker.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import Undo from 'vue-material-design-icons/UndoVariant.vue'
import Palette from 'vue-material-design-icons/Palette.vue'

import TextValueMixin from '../../mixins/admin/TextValueMixin.js'

Expand All @@ -71,6 +74,7 @@ export default {
NcColorPicker,
NcNoteCard,
Undo,
Palette,
},

mixins: [
Expand Down Expand Up @@ -108,28 +112,10 @@ export default {
@import './shared/field.scss';

.field {
// Override default NcButton styles
&__button {
width: 230px !important;
border-radius: var(--border-radius-large) !important;
background-color: var(--color-primary-default) !important;

// emulated hover state because it would not make sense
// to create a dedicated global variable for the color-primary-default
&:hover::after {
background-color: white;
content: "";
position: absolute;
width: 100%;
height: 100%;
opacity: .2;
filter: var(--primary-invert-if-bright);
}

// Above the ::after
&::v-deep * {
z-index: 1;
}
&__color-preview {
width: var(--default-clickable-area);
border-radius: var(--border-radius-large);
background-color: var(--color-primary-default);
}
}
</style>
11 changes: 4 additions & 7 deletions cypress/e2e/theming/admin-settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Admin theming settings visibility check', function() {
})

it('See the default settings', function() {
cy.get('[data-admin-theming-setting-primary-color-picker]').should('contain.text', defaultPrimary)
cy.get('[data-admin-theming-setting-primary-color-picker]').should('exist')
cy.get('[data-admin-theming-setting-primary-color-reset]').should('not.exist')
cy.get('[data-admin-theming-setting-file-reset]').should('not.exist')
cy.get('[data-admin-theming-setting-file-remove]').should('be.visible')
Expand All @@ -66,8 +66,7 @@ describe('Change the primary color and reset it', function() {
it('Change the primary color', function() {
cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')

pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
.then(color => { selectedColor = color })
pickRandomColor().then(color => { selectedColor = color })

cy.wait('@setColor')
cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
Expand Down Expand Up @@ -151,8 +150,7 @@ describe('Remove the default background with a custom primary color', function()
it('Change the primary color', function() {
cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')

pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
.then((color) => { selectedColor = color })
pickRandomColor().then(color => { selectedColor = color })

cy.wait('@setColor')
cy.waitUntil(() => validateBodyThemingCss(selectedColor, defaultBackground))
Expand Down Expand Up @@ -372,8 +370,7 @@ describe('The user default background settings reflect the admin theming setting
it('Change the primary color', function() {
cy.intercept('*/apps/theming/ajax/updateStylesheet').as('setColor')

pickRandomColor('[data-admin-theming-setting-primary-color-picker]')
.then(color => { selectedColor = color })
pickRandomColor().then(color => { selectedColor = color })

cy.wait('@setColor')
cy.waitUntil(() => cy.window().then(($window) => {
Expand Down
29 changes: 19 additions & 10 deletions cypress/e2e/theming/themingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ export const validateBodyThemingCss = function(expectedColor = defaultPrimary, e
*/
export const validateUserThemingDefaultCss = function(expectedColor = defaultPrimary, expectedBackground: string|null = defaultBackground) {
const defaultSelectButton = Cypress.$('[data-user-theming-background-default]')
const customColorSelectButton = Cypress.$('[data-user-theming-background-color]')
if (defaultSelectButton.length === 0 || customColorSelectButton.length === 0) {
if (defaultSelectButton.length === 0) {
return false
}

const defaultOptionBackground = defaultSelectButton.css('background-image')
const colorPickerOptionColor = customColorSelectButton.css('background-color')
const colorPickerOptionColor = defaultSelectButton.css('background-color')

const isValidBackgroundImage = !expectedBackground
? defaultOptionBackground === 'none'
Expand All @@ -71,16 +70,26 @@ export const validateUserThemingDefaultCss = function(expectedColor = defaultPri
return isValidBackgroundImage && colord(colorPickerOptionColor).isEqual(expectedColor)
}

export const pickRandomColor = function(pickerSelector: string): Cypress.Chainable<string> {
export const pickRandomColor = function(): Cypress.Chainable<string> {
// Pick one of the first 8 options
const randColour = Math.floor(Math.random() * 8)

// Open picker
cy.get(pickerSelector).click()
const colorPreviewSelector = '[data-user-theming-background-color],[data-admin-theming-setting-primary-color]'

// Return selected colour
return cy.get(pickerSelector).get('.color-picker__simple-color-circle').eq(randColour).then(($el) => {
$el.trigger('click')
return $el.css('background-color')
let oldColor = ''
cy.get(colorPreviewSelector).then(($el) => {
oldColor = $el.css('background-color')
})

// Open picker
cy.contains('button', 'Change color').click()

// Click on random color
cy.get('.color-picker__simple-color-circle').eq(randColour).click()

// Wait for color change
cy.waitUntil(() => Cypress.$(colorPreviewSelector).css('background-color') !== oldColor)

// Get the selected color from the color preview block
return cy.get(colorPreviewSelector).then(($el) => $el.css('background-color'))
}
6 changes: 3 additions & 3 deletions cypress/e2e/theming/user-background.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('User select a custom color', function() {
it('Select a custom color', function() {
cy.intercept('*/apps/theming/background/color').as('setColor')

pickRandomColor('[data-user-theming-background-color]')
pickRandomColor()

// Validate custom colour change
cy.wait('@setColor')
Expand Down Expand Up @@ -168,7 +168,7 @@ describe('User select a bright custom color and remove background', function() {
cy.intercept('*/apps/theming/background/color').as('setColor')

// Pick one of the bright color preset
cy.get('[data-user-theming-background-color]').click()
cy.contains('button', 'Change color').click()
cy.get('.color-picker__simple-color-circle:eq(4)').click()

// Validate custom colour change
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('User changes settings and reload the page', function() {
it('Select a custom color', function() {
cy.intercept('*/apps/theming/background/color').as('setColor')

cy.get('[data-user-theming-background-color]').click()
cy.contains('button', 'Change color').click()
cy.get('.color-picker__simple-color-circle:eq(5)').click()

// Validate clear background
Expand Down
4 changes: 2 additions & 2 deletions dist/theming-admin-theming.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading