fix: better theme color changing

This commit is contained in:
Mateusz Pstrucha committed 2021-09-13 21:38:12 +02:00
1 parent 50a4db0fbf
commit ac034b2bc4
3 files changed
+31 -2

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
import FastAverageColor from 'fast-average-color'
var fac = new FastAverageColor(),
def = document.documentElement.style.getPropertyValue('--deg')
function setColor(target, lvl) {
fac
.getColorAsync(target)
.then(({ value: [r, g, b] }) => {
let color =
Math.atan2(1.732050808 * (g - b), 2 * r - g - b) * 57.295779513
return color
})
.catch((err) => {
return def
})
.then((color) => {
document.documentElement.style.setProperty('--deg', color + 'deg')
})
}
export { setColor }
+7 -1
View File
@@ -1,11 +1,13 @@
import { useContext, useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
import { setColor } from '../../Color'
import PlayingContext from '../../contexts/Playing'
import './Status.css'
function Status({ progress, paused, onEnd }) {
function Status({ progress, paused }) {
const {
id,
title = '-',
@@ -18,6 +20,10 @@ function Status({ progress, paused, onEnd }) {
const step = 500,
tread = step / duration
useEffect(() => {
if (album.art) setColor(album.art, 1)
}, [album.art])
useEffect(() => {
setElapsed(progress ? progress / duration : 0)
}, [progress, duration])
+1 -1
View File
@@ -8,7 +8,7 @@ body {
}
:root {
--deg: 200deg;
--deg: 0deg;
--white: hsl(0, 0%, 100%);
--light: hsl(var(--deg) 50% 88%);
--main: hsl(var(--deg), 57%, 52%);