Skip to content

Commit

Permalink
Fix: Update getContrast so that it will support transparent
Browse files Browse the repository at this point in the history
If colour is transparent the color will be set to initial which should get the default browser colour.
  • Loading branch information
The-Code-Monkey authored Jul 16, 2024
1 parent c3ea921 commit 8447ab1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/styled-system/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ export const getContrast = (hexstring: string, colors?: ColorsType): string => {
// eslint-disable-next-line prefer-const
let r, g, b;

// Check if the hexstring is transparent.
if (hexstring === 'transparent') {
return 'initial';
// Check the format of the color, HEX or RGB?
if (hexstring.match(/^rgb/)) {
} else if (hexstring.match(/^rgb/)) {
// If RGB --> store the red, green, blue values in separate variables
const color = hexstring.match(
/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/
Expand Down

0 comments on commit 8447ab1

Please sign in to comment.