diff --git a/components/icon/ArrowLeft.tsx b/components/icon/ArrowLeft.tsx
index ed80ca7a7..8cc1e1294 100644
--- a/components/icon/ArrowLeft.tsx
+++ b/components/icon/ArrowLeft.tsx
@@ -10,15 +10,15 @@ const ArrowLeft = ({ ...props }) => {
>
)
diff --git a/components/icon/Check.tsx b/components/icon/Check.tsx
index ce37027f4..89c91a1e3 100644
--- a/components/icon/Check.tsx
+++ b/components/icon/Check.tsx
@@ -10,9 +10,9 @@ const Check = ({ ...props }) => {
>
)
diff --git a/components/icon/Minus.tsx b/components/icon/Minus.tsx
index f41aa3cf0..1e9411dda 100644
--- a/components/icon/Minus.tsx
+++ b/components/icon/Minus.tsx
@@ -4,9 +4,9 @@ const Minus = ({ ...props }) => {
)
diff --git a/components/icon/Plus.tsx b/components/icon/Plus.tsx
index 1fca1ac9d..ad030b92e 100644
--- a/components/icon/Plus.tsx
+++ b/components/icon/Plus.tsx
@@ -4,16 +4,16 @@ const Plus = ({ ...props }) => {
)
diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx
index 71d874a25..a0016365f 100644
--- a/components/product/ProductView/ProductView.tsx
+++ b/components/product/ProductView/ProductView.tsx
@@ -110,6 +110,7 @@ const ProductView: FC = ({ product, className }) => {
label={v.label}
onClick={() => {
setChoices((choices) => {
+ console.log(choices)
return {
...choices,
[opt.displayName]: v.label,
diff --git a/components/product/Swatch/Swatch.module.css b/components/product/Swatch/Swatch.module.css
index cb35c0b71..137f23749 100644
--- a/components/product/Swatch/Swatch.module.css
+++ b/components/product/Swatch/Swatch.module.css
@@ -1,7 +1,7 @@
.root {
@apply h-12 w-12 bg-primary text-primary rounded-full mr-3 inline-flex
items-center justify-center cursor-pointer transition duration-100 ease-in-out
- p-0 shadow-none border-gray-200 border box-border;
+ p-0 shadow-none border-gray-200 border box-border text-black;
}
.active.size {
diff --git a/components/product/Swatch/Swatch.tsx b/components/product/Swatch/Swatch.tsx
index 6d8a7dfb2..49befcd28 100644
--- a/components/product/Swatch/Swatch.tsx
+++ b/components/product/Swatch/Swatch.tsx
@@ -1,10 +1,9 @@
import cn from 'classnames'
import { FC } from 'react'
import s from './Swatch.module.css'
-import { Colors } from '@components/ui/types'
import { Check } from '@components/icon'
import Button, { ButtonProps } from '@components/ui/Button'
-
+import { isDark } from '@lib/colors'
interface Props {
active?: boolean
children?: any
@@ -24,6 +23,7 @@ const Swatch: FC = ({
}) => {
variant = variant?.toLowerCase()
label = label?.toLowerCase()
+ const isDarkBg = isDark(color)
const rootClassName = cn(
s.root,
@@ -43,8 +43,7 @@ const Swatch: FC = ({
{variant === 'color' && active && (
diff --git a/lib/colors.ts b/lib/colors.ts
index 2d4ca14cc..fbd1443ea 100644
--- a/lib/colors.ts
+++ b/lib/colors.ts
@@ -14,3 +14,36 @@ export function getRandomPairOfColors() {
// Returns a pair of colors
return [colors[idx], colors[idx2]]
}
+
+function hexToRgb(hex: string = '') {
+ const match = hex.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i)
+
+ if (!match) {
+ return [0, 0, 0]
+ }
+
+ let colorString = match[0]
+
+ if (match[0].length === 3) {
+ colorString = colorString
+ .split('')
+ .map((char: string) => {
+ return char + char
+ })
+ .join('')
+ }
+
+ const integer = parseInt(colorString, 16)
+ const r = (integer >> 16) & 0xff
+ const g = (integer >> 8) & 0xff
+ const b = integer & 0xff
+
+ return [r, g, b]
+}
+
+export function isDark(color = '') {
+ // Equation from http://24ways.org/2010/calculating-color-contrast
+ const rgb = hexToRgb(color)
+ const res = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000
+ return res < 128
+}