mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(theming): correctly parse CSS colors for user primary color picker
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
6404a9925c
commit
d0012e5672
1 changed files with 12 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue