ecommerce / components / shopping-carts
Drawer
04-drawer.jsx
'use client'
import { useState } from 'react'
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle } from '@headlessui/react'
import { XMarkIcon } from '@heroicons/react/24/outline'
const products = [
{
id: 1,
name: 'Throwback Hip Bag',
href: '#',
color: 'Salmon',
price: '$90.00',
quantity: 1,
imageSrc: 'https://tailwindcss.com/plus-assets/img/ecommerce-images/shopping-cart-page-04-product-01.jpg',
imageAlt: 'Salmon orange fabric pouch with match zipper, gray zipper pull, and adjustable hip belt.',
},
{
id: 2,
name: 'Medium Stuff Satchel',
href: '#',
color: 'Blue',
price: '$32.00',
quantity: 1,
imageSrc: 'https://tailwindcss.com/plus-assets/img/ecommerce-images/shopping-cart-page-04-product-02.jpg',
imageAlt:
'Front of satchel with blue canvas body, black straps and handle, drawstring top, and front zipper pouch.',
},
{
id: 3,
name: 'Zip Tote Basket',
href: '#',
color: 'White and black',
price: '$140.00',
quantity: 1,
imageSrc: 'https://tailwindcss.com/plus-assets/img/ecommerce-images/shopping-cart-page-04-product-03.jpg',
imageAlt: 'Front of zip tote bag with white canvas, black canvas straps and handle, and black zipper pulls.',
},
]
export default function Example() {
const [open, setOpen] = useState(true)
return (
<div>
<button
onClick={() => setOpen(true)}
className="rounded-md bg-gray-950/5 px-2.5 py-1.5 text-sm font-semibold text-gray-900 hover:bg-gray-950/10"
>
Open drawer
</button>
<Dialog open={open} onClose={setOpen} className="relative z-10">
<DialogBackdrop
transition
className="fixed inset-0 bg-gray-500/75 transition-opacity duration-500 ease-in-out data-closed:opacity-0"
/>
<div className="fixed inset-0 overflow-hidden">
<div className="absolute inset-0 overflow-hidden">
<div className="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10 sm:pl-16">
<DialogPanel
transition
className="pointer-events-auto w-screen max-w-md transform transition duration-500 ease-in-out data-closed:translate-x-full sm:duration-700"
>
<div className="flex h-full flex-col overflow-y-auto bg-white shadow-xl">
<div className="flex-1 overflow-y-auto px-4 py-6 sm:px-6">
<div className="flex items-start justify-between">
<DialogTitle className="text-lg font-medium text-gray-900">Shopping cart</DialogTitle>
<div className="ml-3 flex h-7 items-center">
<button
type="button"
onClick={() => setOpen(false)}
className="relative -m-2 p-2 text-gray-400 hover:text-gray-500"
>
<span className="absolute -inset-0.5" />
<span className="sr-only">Close panel</span>
<XMarkIcon aria-hidden="true" className="size-6" />
</button>
</div>
</div>
<div className="mt-8">
<div className="flow-root">
<ul role="list" className="-my-6 divide-y divide-gray-200">
{products.map((product) => (
<li key={product.id} className="flex py-6">
<div className="size-24 shrink-0 overflow-hidden rounded-md border border-gray-200">
<img alt={product.imageAlt} src={product.imageSrc} className="size-full object-cover" />
</div>
<div className="ml-4 flex flex-1 flex-col">
<div>
<div className="flex justify-between text-base font-medium text-gray-900">
<h3>
<a href={product.href}>{product.name}</a>
</h3>
<p className="ml-4">{product.price}</p>
</div>
<p className="mt-1 text-sm text-gray-500">{product.color}</p>
</div>
<div className="flex flex-1 items-end justify-between text-sm">
<p className="text-gray-500">Qty {product.quantity}</p>
<div className="flex">
<button type="button" className="font-medium text-indigo-600 hover:text-indigo-500">
Remove
</button>
</div>
</div>
</div>
</li>
))}
</ul>
</div>
</div>
</div>
<div className="border-t border-gray-200 px-4 py-6 sm:px-6">
<div className="flex justify-between text-base font-medium text-gray-900">
<p>Subtotal</p>
<p>$262.00</p>
</div>
<p className="mt-0.5 text-sm text-gray-500">Shipping and taxes calculated at checkout.</p>
<div className="mt-6">
<a
href="#"
className="flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-6 py-3 text-base font-medium text-white shadow-xs hover:bg-indigo-700"
>
Checkout
</a>
</div>
<div className="mt-6 flex justify-center text-center text-sm text-gray-500">
<p>
or{' '}
<button
type="button"
onClick={() => setOpen(false)}
className="font-medium text-indigo-600 hover:text-indigo-500"
>
Continue Shopping
<span aria-hidden="true"> →</span>
</button>
</p>
</div>
</div>
</div>
</DialogPanel>
</div>
</div>
</div>
</Dialog>
</div>
)
}