| 1 |
import { Dialog, DialogPanel, DialogTitle } from '@headlessui/react'; |
| 2 |
import { createInterpolateElement } from '@wordpress/element'; |
| 3 |
import { check, Icon } from '@wordpress/icons'; |
| 4 |
import { Cta } from '../Cta'; |
| 5 |
import { cardVariables, colorsOf } from '../colors'; |
| 6 |
import { DismissButton } from '../DismissButton'; |
| 7 |
|
| 8 |
export const Pricing = ({ |
| 9 |
notification, |
| 10 |
href, |
| 11 |
external, |
| 12 |
dismissible, |
| 13 |
onDismiss, |
| 14 |
onClick, |
| 15 |
}) => { |
| 16 |
const { title, content } = notification; |
| 17 |
const { |
| 18 |
price, |
| 19 |
'price-detail': priceDetail, |
| 20 |
description, |
| 21 |
items, |
| 22 |
} = notification.offer ?? {}; |
| 23 |
const colors = colorsOf(notification); |
| 24 |
|
| 25 |
return ( |
| 26 |
// Dialog portals to the body, so the prefix scope has to travel with it. |
| 27 |
<Dialog |
| 28 |
open |
| 29 |
static |
| 30 |
className="extendify-notifications" |
| 31 |
onClose={dismissible ? onDismiss : () => undefined} |
| 32 |
> |
| 33 |
{/* The agent loading rail in Skeleton.php sits at 1000001, over z-higher. */} |
| 34 |
<div className="fixed inset-0 z-max-1 flex items-center justify-center p-4"> |
| 35 |
<div className="fixed inset-0 bg-black/60" aria-hidden="true" /> |
| 36 |
<DialogPanel |
| 37 |
className="relative w-full max-w-lg rounded-xl bg-(--ext-notification-card-main,#ffffff) p-8 text-base text-(--ext-notification-card-text,#1e1e1e) shadow-2xl" |
| 38 |
style={cardVariables(colors)} |
| 39 |
data-test="notification-pricing" |
| 40 |
> |
| 41 |
{dismissible && ( |
| 42 |
<DismissButton |
| 43 |
onClick={onDismiss} |
| 44 |
size={24} |
| 45 |
className="absolute right-3 top-3 flex size-8 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 text-current opacity-60 hover:opacity-100 rtl:left-3 rtl:right-auto" |
| 46 |
/> |
| 47 |
)} |
| 48 |
{/* An <h2> would pick up the theme's heading font and casing on the front end. */} |
| 49 |
<DialogTitle |
| 50 |
as="div" |
| 51 |
className="m-0 text-3xl font-bold leading-tight" |
| 52 |
> |
| 53 |
{title} |
| 54 |
</DialogTitle> |
| 55 |
<p className="mt-3 text-sm leading-relaxed">{content}</p> |
| 56 |
{(price || priceDetail || description) && ( |
| 57 |
<div |
| 58 |
className="mt-6 flex flex-col gap-2" |
| 59 |
data-test="notification-pricing-price" |
| 60 |
> |
| 61 |
{(price || priceDetail) && ( |
| 62 |
<div className="flex items-baseline gap-1.5"> |
| 63 |
{price && <span className="text-4xl font-bold">{price}</span>} |
| 64 |
{priceDetail && ( |
| 65 |
<span className="text-sm">{priceDetail}</span> |
| 66 |
)} |
| 67 |
</div> |
| 68 |
)} |
| 69 |
{description && ( |
| 70 |
<p className="m-0 text-sm font-bold">{description}</p> |
| 71 |
)} |
| 72 |
</div> |
| 73 |
)} |
| 74 |
{items?.length > 0 && ( |
| 75 |
<ul |
| 76 |
className="my-6 list-none border-0 border-t border-solid border-[#e5e7eb] p-0 pt-6 text-sm" |
| 77 |
data-test="notification-pricing-items" |
| 78 |
> |
| 79 |
{items.map((item) => ( |
| 80 |
<li key={item} className="mb-4 flex items-center gap-3"> |
| 81 |
<span |
| 82 |
className="flex size-6 shrink-0 items-center justify-center rounded-full bg-[#dcfce7] text-[#16a34a]" |
| 83 |
data-test="notification-pricing-check" |
| 84 |
> |
| 85 |
<Icon icon={check} size={18} className="fill-current" /> |
| 86 |
</span> |
| 87 |
<span> |
| 88 |
{createInterpolateElement(item, { strong: <strong /> })} |
| 89 |
</span> |
| 90 |
</li> |
| 91 |
))} |
| 92 |
</ul> |
| 93 |
)} |
| 94 |
<Cta |
| 95 |
notification={notification} |
| 96 |
href={href} |
| 97 |
external={external} |
| 98 |
onClick={onClick} |
| 99 |
surface="design" |
| 100 |
className="flex h-12 w-full cursor-pointer items-center justify-center rounded-md bg-design-main px-4 text-sm font-semibold text-design-text no-underline" |
| 101 |
/> |
| 102 |
</DialogPanel> |
| 103 |
</div> |
| 104 |
</Dialog> |
| 105 |
); |
| 106 |
}; |
| 107 |
|