import React, { ReactNode } from "react"; import { CheckIcon, DashIcon, XMarkIcon } from "@sparkle/icons/app"; import { classNames } from "@sparkle/lib/utils"; import { Icon } from "./Icon"; interface PriceTableProps { title: string; price: string; priceLabel?: string; color?: "pink" | "sky" | "emerald" | "amber" | "blue"; size?: "xs" | "sm"; className?: string; children: ReactNode; magnified?: boolean; } const colorTable = { pink: "s-bg-brand-pink-rose", amber: "s-bg-brand-sunshine-golden ", sky: "s-bg-brand-sky-blue", blue: "s-bg-brand-electric-blue", emerald: "s-bg-brand-tea-green", }; const textColorTable = { pink: " s-text-brand-red-rose", amber: "s-text-brand-orange-golden", sky: "s-text-brand-electric-blue", blue: "s-text-brand-sky-blue", emerald: "s-text-brand-hunter-green", }; const sizeTable = { sm: "s-rounded-2xl s-p-px s-shadow-2xl", xs: "s-rounded-2xl s-p-px s-shadow-xl", }; export function PriceTable({ title, price, color = "pink", size = "xs", priceLabel = "", className = "", magnified = true, children, // Use children instead of tableItems }: PriceTableProps) { // Pass size prop to all PriceTable.Item children const childrenWithProps = React.Children.map(children, (child) => { // Checking isValidElement is the safe way and avoids a typescript error too if (React.isValidElement(child)) { if ( child.type === PriceTable.Item || child.type === PriceTable.ActionContainer ) { return React.cloneElement(child, { size: size }); } } return child; }); return (
{title}
{price} {priceLabel}
{childrenWithProps}
); } const iconTable = { check: CheckIcon, dash: DashIcon, xmark: XMarkIcon, }; const iconColorTable = { check: "s-text-green-500", dash: "s-text-golden-500", xmark: "s-text-rose-500", }; interface PriceTableItemProps { label: ReactNode; size?: "xs" | "sm"; variant?: "check" | "dash" | "xmark"; className?: string; } PriceTable.Item = function ({ label, variant = "check", size = "xs", className = "", }: PriceTableItemProps) { return (
{label}
); }; interface PriceTableActionContainerProps { children: ReactNode; size?: "xs" | "sm"; position?: "top" | "bottom"; } PriceTable.ActionContainer = function ({ children, size = "xs", position = "bottom", }: PriceTableActionContainerProps) { return ( <> {position === "bottom" ?
: null}
{children}
); }; interface PriceTableContainerProps { children: ReactNode; } PriceTable.Container = function ({ children }: PriceTableContainerProps) { return (
{children}
); };