Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 8447ab1

Browse files
Fix: Update getContrast so that it will support transparent
If colour is transparent the color will be set to initial which should get the default browser colour.
1 parent c3ea921 commit 8447ab1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/styled-system/src/functions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ export const getContrast = (hexstring: string, colors?: ColorsType): string => {
171171
// eslint-disable-next-line prefer-const
172172
let r, g, b;
173173

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

0 commit comments

Comments
 (0)