Update swatch

This commit is contained in:
cond0r 2021-05-28 10:54:48 +03:00
parent ca703ad2a0
commit 1d33b6a0cd
4 changed files with 25 additions and 11 deletions

View File

@ -1,8 +1,10 @@
.root { .root {
composes: root from 'components/ui/Button/Button.module.css'; composes: root from 'components/ui/Button/Button.module.css';
@apply h-12 w-12 bg-primary text-primary rounded-full mr-3 inline-flex @apply h-12 p-0 bg-primary text-primary rounded-full mr-3 inline-flex
items-center justify-center cursor-pointer transition duration-150 ease-in-out items-center justify-center cursor-pointer transition duration-150 ease-in-out
p-0 shadow-none border-gray-200 border box-border; shadow-none border-gray-200 border box-border;
min-width: 3em;
& > span { & > span {
@apply absolute; @apply absolute;
@ -13,6 +15,10 @@
} }
} }
.size {
@apply px-3;
}
.color { .color {
@apply text-black transition duration-150 ease-in-out; @apply text-black transition duration-150 ease-in-out;

View File

@ -21,14 +21,14 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
active, active,
...props ...props
}) => { }) => {
variant = variant?.toLowerCase()
label = label?.toLowerCase() label = label?.toLowerCase()
const isColor = color !== ''
const rootClassName = cn( const rootClassName = cn(
s.root, s.root,
{ {
[s.active]: active, [s.active]: active,
[s.size]: variant === 'size', [s.size]: !isColor,
[s.color]: color, [s.color]: color,
[s.dark]: color ? isDark(color) : false, [s.dark]: color ? isDark(color) : false,
}, },
@ -38,16 +38,18 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
return ( return (
<Button <Button
className={rootClassName} className={rootClassName}
style={color ? { backgroundColor: color } : {}} style={isColor ? { backgroundColor: color } : {}}
aria-label="Variant Swatch" aria-label="Variant Swatch"
{...(isColor && { title: label })}
{...props} {...props}
> >
{variant === 'color' && active && ( {isColor ? (
<span> <span>
<Check /> <Check />
</span> </span>
) : (
label
)} )}
{variant !== 'color' ? label : null}
</Button> </Button>
) )
} }

View File

@ -16,6 +16,7 @@ import {
import type { Cart, LineItem } from '../types' import type { Cart, LineItem } from '../types'
import type { Page } from '../common/get-all-pages' import type { Page } from '../common/get-all-pages'
import { colorMap } from '@lib/colors'
const money = ({ amount, currencyCode }: MoneyV2) => { const money = ({ amount, currencyCode }: MoneyV2) => {
return { return {
@ -38,9 +39,12 @@ const normalizeProductOption = ({
label: value, label: value,
} }
if (displayName.match(/colou?r/gi)) { if (displayName.match(/colou?r/gi)) {
const mapedColor = colorMap[value]
if (mapedColor) {
output = { output = {
...output, ...output,
hexColors: [value], hexColors: [mapedColor],
}
} }
} }

View File

@ -42,7 +42,7 @@ function hexToRgb(hex: string = '') {
return [r, g, b] return [r, g, b]
} }
const colorMap: Record<string, string> = { export const colorMap: Record<string, string> = {
aliceblue: '#F0F8FF', aliceblue: '#F0F8FF',
antiquewhite: '#FAEBD7', antiquewhite: '#FAEBD7',
aqua: '#00FFFF', aqua: '#00FFFF',
@ -56,6 +56,8 @@ const colorMap: Record<string, string> = {
blueviolet: '#8A2BE2', blueviolet: '#8A2BE2',
brown: '#A52A2A', brown: '#A52A2A',
burlywood: '#DEB887', burlywood: '#DEB887',
burgandy: '#800020',
burgundy: '#800020',
cadetblue: '#5F9EA0', cadetblue: '#5F9EA0',
chartreuse: '#7FFF00', chartreuse: '#7FFF00',
chocolate: '#D2691E', chocolate: '#D2691E',