product-card
delta-components/product-cardFreeComponent
delta-components publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by delta-components on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://deltacomponents.dev/r/product-card.jsonSource
1"use client"23import * as React from "react"45import { cn } from "@/lib/utils"67/* ------------------------------------------------------------------8 * Context for sharing state between compound components9 * ------------------------------------------------------------------ */1011type ProductCardVariant = "default" | "inner"12type ProductCardSize = "default" | "sm" | "small" | "lg" | "large"1314interface ProductCardContextValue {15 variant: ProductCardVariant16 size: ProductCardSize17 animated: boolean18}1920const ProductCardContext = React.createContext<ProductCardContextValue | null>(21 null22)2324function useProductCardContext() {25 const context = React.useContext(ProductCardContext)26 if (!context) {27 throw new Error(28 "ProductCard compound components must be used within <ProductCard>"29 )30 }31 return context32}3334function normalizeSize(size: ProductCardSize): "default" | "sm" | "lg" {35 if (size === "small") return "sm"36 if (size === "large") return "lg"37 return size as "default" | "sm" | "lg"38}3940/* ------------------------------------------------------------------41 * ProductCard (root)42 * ------------------------------------------------------------------ */4344interface ProductCardProps extends React.HTMLAttributes<HTMLDivElement> {45 /** Card variant - "default" shows content below image, "inner" shows content inside */46 variant?: ProductCardVariant47 /** Card size - "sm" | "small", "default", or "lg" | "large" */48 size?: ProductCardSize49 /** Enable hover/active animation on image - defaults to true */50 animated?: boolean51 /** Callback when the card is clicked */52 onCardClick?: () => void53}5455const ProductCard = React.forwardRef<HTMLDivElement, ProductCardProps>(56 (57 {58 className,59 variant = "default",60 size = "default",61 animated = true,62 onCardClick,63 children,64 ...props65 },66 ref67 ) => {68 return (69 <ProductCardContext.Provider value={{ variant, size, animated }}>70 <div71 ref={ref}72 className={cn("cursor-pointer overflow-hidden rounded-lg", className)}73 onClick={onCardClick}74 {...props}75 >76 {children}77 </div>78 </ProductCardContext.Provider>79 )80 }81)82ProductCard.displayName = "ProductCard"8384/* ------------------------------------------------------------------85 * ProductCardImage86 * ------------------------------------------------------------------ */8788// … truncated
Files it writes
More from delta-components
All 93 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| admonitionadmonition | delta-components | Components | Free | 1 dep | |
| cambio-imagecambio-image | delta-components | Components | Free | 2 deps | |
| card-deckcard-deck | delta-components | Components | Free | 3 deps | |
| chatchat | delta-components | Components | Free | 3 deps | |
| code-blockcode-block | delta-components | Components | Free | 3 deps | |
| code-block-iconscode-block-icons | delta-components | Components | Free | no deps | |
| copy-buttoncopy-button | delta-components | Components | Free | 1 dep | |
| input-otpinput-otp | delta-components | Components | Free | 1 dep |
