Skip to content

Commit

Permalink
fixes to prevent crash on empty color (#1003)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Jul 9, 2024
1 parent 3656457 commit 9a5a422
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ const hexHasChanged = (hex: string, prevColor?: string) => {
if (prevColor === undefined) {
return ''
}
const prevHex = toHex(
`${getComputedStyle(document.documentElement).getPropertyValue(`--${prevColor}`)}`.replace(/ /g, ''),
const prevHexProperty = `${getComputedStyle(document.documentElement).getPropertyValue(`--${prevColor}`)}`.replace(
/ /g,
'',
)
if (prevHexProperty === undefined || prevHexProperty === '') {
return ''
}

const prevHex = toHex(prevHexProperty)

return prevHex !== hex
}
Expand All @@ -31,10 +37,10 @@ export const CSSTokenSwatch = ({color, prevColor, shadow}: CSSTokenSwatchProps)

const style = getComputedStyle(ref.current)
const rgb = style.getPropertyValue('background-color')
setHex(toHex(rgb))
setHex(rgb && rgb !== '' ? toHex(rgb) : null)
}, [color])

if (color === undefined) {
if (color === undefined || color === '') {
return null
}
return (
Expand Down

0 comments on commit 9a5a422

Please sign in to comment.