mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
completing SKU page design
This commit is contained in:
parent
decb61bee3
commit
3a1d89e9ed
@ -1,24 +1,49 @@
|
||||
'use client'
|
||||
|
||||
import clsx from "clsx";
|
||||
import { createProductSKUs } from "lib/helpers/skus";
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
export function ProductSKUs(productInfo: {productTitle: string}) {
|
||||
const SKUs = createProductSKUs(productInfo.productTitle)
|
||||
const [copyMessageState, setCopyMessageState] = useState< number | null >(null);
|
||||
|
||||
const triggerCopyMessage = async (e: MouseEvent<HTMLButtonElement>, i: number) => {
|
||||
copyText(e.target.value)
|
||||
|
||||
console.log("copyMessageState", copyMessageState);
|
||||
setCopyMessageState(i);
|
||||
console.log("copyMessageState", copyMessageState);
|
||||
|
||||
setTimeout(() => setCopyMessageState(null), 2500)
|
||||
}
|
||||
|
||||
function copyText(e) {
|
||||
navigator.clipboard.writeText(e.target.value);
|
||||
function copyText(text: string) {
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mx-auto max-w-screen-2xl px-4">
|
||||
<div className="rounded-lg border border-neutral-200 bg-white p-8 px-4 dark:border-neutral-800 dark:bg-black md:p-12 lg:grid lg:grid-cols-6">
|
||||
<div className="lg:col-span-3">
|
||||
{SKUs?.map(SKU => {
|
||||
<div className="rounded-lg border border-neutral-200 bg-white p-8 px-4 dark:border-neutral-800 dark:bg-black md:p-12 lg:grid lg:grid-cols-12">
|
||||
<div className="lg:col-span-6 lg:col-start-4">
|
||||
<h3 className="font-bold text-xl pb-4">{productInfo.productTitle}</h3>
|
||||
{/* {copyMessageState} */}
|
||||
{SKUs?.map((SKU, index) => {
|
||||
return (
|
||||
<div className="my-4 w-full">
|
||||
<input type="text" value={SKU} onClick={copyText} className="cursor-pointer w-full border py-2 px-2" />
|
||||
<div className="my-4 w-full" key={`${SKU}-${index}`}>
|
||||
<div
|
||||
onClick={(e) => triggerCopyMessage(e, index)}
|
||||
className={clsx(
|
||||
[
|
||||
"cursor-pointer w-full border py-2 px-2 rounded",
|
||||
{ 'border-green-500': (copyMessageState === index) },
|
||||
]
|
||||
)}
|
||||
>
|
||||
{SKU}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
@ -58,6 +58,7 @@ export const customisationSKUs = {
|
||||
};
|
||||
|
||||
export const sizeSKUs = {
|
||||
xxs: 'XXS',
|
||||
xs: 'XS',
|
||||
s: 'S',
|
||||
m: 'M',
|
||||
|
Loading…
x
Reference in New Issue
Block a user