Skip to content

Commit d0012e5

Browse files
committed
fix(theming): correctly parse CSS colors for user primary color picker
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 6404a99 commit d0012e5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/theming/src/components/UserPrimaryColor.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,23 @@ export default defineComponent({
7676
methods: {
7777
t,
7878
79+
numberToHex(numeric: string) {
80+
const parsed = Number.parseInt(numeric)
81+
return parsed.toString(16).padStart(2, '0')
82+
},
83+
7984
/**
8085
* Global styles are reloaded so we might need to update the current value
8186
*/
8287
reload() {
8388
const trigger = this.$refs.trigger as HTMLButtonElement
84-
const newColor = window.getComputedStyle(trigger).backgroundColor
85-
if (newColor.toLowerCase() !== this.primaryColor) {
89+
let newColor = window.getComputedStyle(trigger).backgroundColor
90+
// sometimes the browser returns the color in the "rgb(255, 132, 234)" format
91+
const rgbMatch = newColor.replaceAll(/\s/g, '').match(/^rgba?\((\d+),(\d+),(\d+)/)
92+
if (rgbMatch) {
93+
newColor = `#${this.numberToHex(rgbMatch[1])}${this.numberToHex(rgbMatch[2])}${this.numberToHex(rgbMatch[3])}`
94+
}
95+
if (newColor.toLowerCase() !== this.primaryColor.toLowerCase()) {
8696
this.primaryColor = newColor
8797
}
8898
},

0 commit comments

Comments
 (0)