Merge pull request #54515 from nextcloud/fix/theming-parsing

fix(theming): correctly parse CSS colors for user primary color picker
This commit is contained in:
Ferdinand Thiessen 2025-08-19 17:43:18 +02:00 committed by GitHub
commit 9fd80b2aa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View file

@ -76,13 +76,23 @@ export default defineComponent({
methods: {
t,
numberToHex(numeric: string) {
const parsed = Number.parseInt(numeric)
return parsed.toString(16).padStart(2, '0')
},
/**
* Global styles are reloaded so we might need to update the current value
*/
reload() {
const trigger = this.$refs.trigger as HTMLButtonElement
const newColor = window.getComputedStyle(trigger).backgroundColor
if (newColor.toLowerCase() !== this.primaryColor) {
let newColor = window.getComputedStyle(trigger).backgroundColor
// sometimes the browser returns the color in the "rgb(255, 132, 234)" format
const rgbMatch = newColor.replaceAll(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+)/)
if (rgbMatch) {
newColor = `#${this.numberToHex(rgbMatch[1])}${this.numberToHex(rgbMatch[2])}${this.numberToHex(rgbMatch[3])}`
}
if (newColor.toLowerCase() !== this.primaryColor.toLowerCase()) {
this.primaryColor = newColor
}
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long