Skip to content

Commit

Permalink
fix: accent color style override
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Oct 4, 2023
1 parent 433563b commit 8e4808d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/providers/root/accent-color-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,27 @@ const accentColorDark = [
'#838BC6',
]

const STEP = 60
const INTERVAL = 300
export const AccentColorProvider = ({ children }: PropsWithChildren) => {
const { light, dark } =
useAppConfigSelector((config) => config.color) || (noopObj as AccentColor)

const Length = Math.max(light?.length ?? 0, dark?.length ?? 0)
const randomSeedRef = useRef((Math.random() * Length) | 0)

const lightColors = light ?? accentColorLight
const darkColors = dark ?? accentColorDark

const Length = Math.max(lightColors.length ?? 0, darkColors.length ?? 0)
const randomSeedRef = useRef((Math.random() * Length) | 0)
const currentAccentColorLRef = useRef(lightColors[randomSeedRef.current])
const currentAccentColorDRef = useRef(darkColors[randomSeedRef.current])

const [u, update] = useState(0)
useEffect(() => {
const $style = document.createElement('style')

const $originColor = document.getElementById('accent-color-style')

const nextSeed = (randomSeedRef.current + 1) % Length
const nextColorD = darkColors[nextSeed]
const nextColorL = lightColors[nextSeed]
const STEP = 60
const INTERVAL = 100
const colorsD = generateTransitionColors(
currentAccentColorDRef.current,
nextColorD,
Expand Down Expand Up @@ -81,25 +79,24 @@ export const AccentColorProvider = ({ children }: PropsWithChildren) => {
const [hl, sl, ll] = lightHsl
const [hd, sd, ld] = darkHsl

$style.innerHTML = `html[data-theme='light'] {
$style.innerHTML = `:root[data-theme='light'] {
--a: ${`${hl} ${sl}% ${ll}%`};
--af: ${`${hl} ${sl}% ${ll + 6}%`};
}
html[data-theme='dark'] {
:root[data-theme='dark'] {
--a: ${`${hd} ${sd}% ${ld}%`};
--af: ${`${hd} ${sd}% ${ld - 6}%`};
}
`
}, INTERVAL)

document.head.appendChild($style)
// FIXME should remove origin color, if not will not override origin color
$originColor?.remove()
return () => {
clearTimeout(timer)

setTimeout(() => {
document.head.removeChild($style)
}, 1000)
}, INTERVAL)
}
}, [Length, darkColors, lightColors, u])

Expand Down

1 comment on commit 8e4808d

@vercel
Copy link

@vercel vercel bot commented on 8e4808d Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

shiro – ./

shiro-git-main-innei.vercel.app
springtide.vercel.app
shiro-innei.vercel.app
innei.in

Please sign in to comment.