diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 4117027aa..fccdab80c 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -1,5 +1,5 @@ import cn from 'classnames' -import { FC } from 'react' +import { FC, useState } from 'react' import s from './ProductView.module.css' import { Button } from '@components/ui' import { Swatch } from '@components/product' @@ -24,11 +24,22 @@ interface Props { product: Product } +interface Choices { + size?: string | null + color?: string | null +} + const COLORS: Colors[] = ['pink', 'black', 'white'] +const SIZES = ['s', 'm', 'l', 'xl', 'xxl'] const ProductView: FC = ({ product, productData, className }) => { const addItem = useAddItem() const { openSidebar } = useUI() + const [choices, setChoices] = useState({ + size: null, + color: null, + }) + const addToCart = async () => { // TODO: loading state by awating the promise await addItem({ @@ -38,6 +49,9 @@ const ProductView: FC = ({ product, productData, className }) => { openSidebar() } + const activeSize = choices.size + const activeColor = choices.color + return (
@@ -48,26 +62,44 @@ const ProductView: FC = ({ product, productData, className }) => { {productData.prices}
-
-
+
+

Color

- {COLORS.map((c) => ( - + {COLORS.map((color) => ( + + setChoices((choices) => { + return { ...choices, color } + }) + } + /> ))}

Size

- - - - - + {SIZES.map((size) => { + return ( + + setChoices((choices) => { + return { ...choices, size } + }) + } + /> + ) + })}
diff --git a/components/product/Swatch/Swatch.module.css b/components/product/Swatch/Swatch.module.css index 8eb96e58a..3a795139e 100644 --- a/components/product/Swatch/Swatch.module.css +++ b/components/product/Swatch/Swatch.module.css @@ -1,25 +1,29 @@ .root { - @apply h-12 w-12 bg-white rounded-full mr-3 border border-gray-200 inline-flex items-center justify-center cursor-pointer transition duration-75 ease-in-out; + @apply h-12 w-12 bg-white text-black rounded-full mr-3 inline-flex items-center justify-center cursor-pointer transition duration-75 ease-in-out p-0 shadow-none; +} + +.active.size { + @apply border-black; } -.active, .root:hover { - @apply border-gray-700; + @apply transform scale-110; } .colorViolet { - @apply bg-violet; + @apply bg-violet !important; } .colorPink { - @apply bg-pink; + @apply bg-pink !important; } .colorBlack { - @apply bg-black; + @apply bg-black !important; } .colorWhite, .size { - @apply bg-white; + @apply bg-white !important; + @apply border border-gray-200; } diff --git a/components/product/Swatch/Swatch.tsx b/components/product/Swatch/Swatch.tsx index ad80373af..ea2fcbced 100644 --- a/components/product/Swatch/Swatch.tsx +++ b/components/product/Swatch/Swatch.tsx @@ -2,8 +2,9 @@ import cn from 'classnames' import { FC } from 'react' import s from './Swatch.module.css' import { Colors } from '@components/ui/types' +import Button, { ButtonProps } from '@components/ui/Button' -interface Props { +interface Props extends ButtonProps { className?: string children?: any active?: boolean @@ -11,7 +12,7 @@ interface Props { size?: string } -const Swatch: FC = ({ className, size, color, active }) => { +const Swatch: FC = ({ className, size, color, active, ...props }) => { const rootClassName = cn( s.root, { @@ -24,7 +25,41 @@ const Swatch: FC = ({ className, size, color, active }) => { }, className ) - return {size ? size : null} + + // TODO: technically this is a radio + + return ( + + ) } export default Swatch + +const Check = ( + + + +) diff --git a/components/ui/Button/Button.module.css b/components/ui/Button/Button.module.css index 02ea8edd1..fb72eebe2 100644 --- a/components/ui/Button/Button.module.css +++ b/components/ui/Button/Button.module.css @@ -1,17 +1,17 @@ .root { - @apply cursor-pointer inline-flex px-10 rounded-sm border border-transparent leading-6 text-white bg-black transition ease-in-out duration-150 shadow-sm font-semibold text-center justify-center uppercase py-4 uppercase text-center; + @apply cursor-pointer inline-flex px-10 rounded-sm leading-6 text-white bg-black transition ease-in-out duration-150 shadow-sm font-semibold text-center justify-center uppercase py-4 uppercase text-center focus:outline-none; } .root:hover { - @apply bg-white text-black border-black; + @apply bg-gray-800; } .root:focus { - @apply border-gray-700 shadow-outline; + @apply shadow-outline; } .root[data-active] { - @apply bg-gray-200; + @apply bg-gray-600; } s.filled { diff --git a/components/ui/Button/Button.tsx b/components/ui/Button/Button.tsx index 4a3e3cc66..55c9a157d 100644 --- a/components/ui/Button/Button.tsx +++ b/components/ui/Button/Button.tsx @@ -9,7 +9,7 @@ import mergeRefs from 'react-merge-refs' import { useButton } from 'react-aria' import s from './Button.module.css' -interface Props extends ButtonHTMLAttributes { +export interface ButtonProps extends ButtonHTMLAttributes { href?: string className?: string variant?: 'filled' | 'outlined' | 'flat' | 'none' @@ -18,7 +18,7 @@ interface Props extends ButtonHTMLAttributes { Component?: string | JSXElementConstructor } -const Button: React.FC = forwardRef((props, buttonRef) => { +const Button: React.FC = forwardRef((props, buttonRef) => { const { className, variant = 'filled', diff --git a/components/ui/Button/index.ts b/components/ui/Button/index.ts index 3389ecb83..aa076c58e 100644 --- a/components/ui/Button/index.ts +++ b/components/ui/Button/index.ts @@ -1 +1,2 @@ export { default } from './Button' +export * from './Button'