Skip to content

Commit

Permalink
fix(utils): formatColor match alpha empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Jan 12, 2023
1 parent 9151482 commit 2ae596e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const formatRGBA = (colors: string[]) => {
? colors[3].startsWith('.')
? `0${colors[3]}`
: colors[3]
: '1'
return `rgba(${colors[0]},${colors[1]},${colors[2]},${alpha})`
: undefined
return alpha === undefined
? `rgb(${colors[0]},${colors[1]},${colors[2]})`
: `rgba(${colors[0]},${colors[1]},${colors[2]},${alpha})`
}

export const formatColor = (
Expand All @@ -35,7 +37,7 @@ export const formatColor = (
? match[4].startsWith('.')
? `0${match[4]}`
: match[4]
: '1'
: ''
const colors = [match[1], match[2], match[3], alpha]
return hex ? `#${rbg2hex(formatRGBA(colors))}` : formatRGBA(colors)
}
Expand Down

0 comments on commit 2ae596e

Please sign in to comment.