Product Card
Product Card block
Install
npx ui8kit add product-cardPulls in: badge, block, box, button, card-content, compose, group, inline, kit-box, kit-button, kit-link, kit-text, link, media-frame, rating, text, title, utils
Preview
Gift card
19 reviews
Delivered by email, never expires.
$50
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add product-card<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck
through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image,
none), ratio, rating (show, hide), action (button, none), density.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { Product, ProductLabels } from "./product-card.types";
export type ProductCardProps = {
product: Product;
labels: ProductLabels;
badges: Record<string, string>;
layout?: "vertical" | "horizontal";
media?: "image" | "none";
ratio?: "4/3" | "1/1" | "3/4";
rating?: "show" | "hide";
action?: "button" | "none";
density?: "default" | "compact";
onadd?: (id: string) => void;
};
</script>
<script lang="ts">
import Badge from "../compose/Badge.svelte";
import Block from "../compose/Block.svelte";
import Box from "../compose/Box.svelte";
import Button from "../compose/Button.svelte";
import CardContent from "../compose/CardContent.svelte";
import Group from "../compose/Group.svelte";
import Inline from "../compose/Inline.svelte";
import Link from "../compose/Link.svelte";
import Text from "../compose/Text.svelte";
import Title from "../compose/Title.svelte";
import MediaFrame from "../components/media-frame.svelte";
import Rating from "../components/rating.svelte";
import { at, cn, fmtMoney, tpl, urlOf } from "../utils";
let {
product,
labels,
badges,
layout = "vertical",
media = "image",
ratio = "4/3",
rating = "show",
action = "button",
density = "default",
onadd,
}: ProductCardProps = $props();
</script>
<Block
tag="article"
class={cn(
"flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded",
"h-full gap-4 overflow-hidden",
(((layout as string) === "horizontal") ? "flex flex-col sm:flex-row" : "flex flex-col")
)}
data-slot="card"
data-layout={layout}
>
{#if ((media as string) === "image")}
<Box class={cn("relative shrink-0", (((layout as string) === "horizontal") ? "sm:w-48" : ""))}>
<MediaFrame alt={product.name} src={product.image} ratio={ratio} class="h-full" />
{#if product.badge}
<Badge variant="default" size="default" class="absolute left-4 top-4">
{at(badges, product.badge)}
</Badge>
{/if}
</Box>
{/if}
<CardContent class="flex flex-1 flex-col gap-2">
<Text size="xs" class="uppercase tracking-wide text-muted-foreground">
{product.category}
</Text>
<Title as={3} size="base" weight="bold">
{#if product.href}
<Link href={urlOf(product.href)} variant="default" data-slot="open">
{product.name}
</Link>
{:else}
{product.name}
{/if}
</Title>
{#if ((rating as string) === "show")}
<Group gap="2">
<Rating value={product.rating} label={tpl(labels.ratingLabel, product.rating)} />
<Text size="xs" class="text-muted-foreground">
{tpl(labels.reviews, product.reviews)}
</Text>
</Group>
{/if}
{#if ((density as string) === "default")}
<Text size="sm" class="text-muted-foreground">
{product.summary}
</Text>
{/if}
<Group gap="4" justify="between" class="mt-auto pt-2">
<Group gap="2" align="baseline" class="flex-wrap">
<Text size="xl" weight="bold">
{fmtMoney(product.price, product.currency)}
</Text>
{#if (product.compareAt && (product.compareAt > product.price))}
<Text tag="del" size="sm" class="relative text-muted-foreground" data-slot="compare-at">
<Inline class="sr-only">
{labels.was}
</Inline>
{fmtMoney(product.compareAt, product.currency)}
</Text>
{/if}
</Group>
{#if ((action as string) === "button")}
<Button
variant={(product.inStock ? "default" : "outline")}
size="sm"
disabled={!product.inStock}
onclick={() => onadd?.(product.id)}
>
{(product.inStock ? labels.add : labels.soldOut)}
</Button>
{/if}
</Group>
</CardContent>
</Block>
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type Product = {
id: string;
name: string;
summary: string;
price: number;
currency: string;
rating: number;
reviews: number;
badge?: string;
category: string;
inStock: boolean;
compareAt?: number;
href?: string;
image?: string;
};
export type ProductLabels = {
add: string;
soldOut: string;
reviews: string;
ratingLabel: string;
was: string;
empty: string;
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add product-card// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck
* through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image,
* none), ratio, rating (show, hide), action (button, none), density.
*/
import { type ReactNode } from "react";
import { Badge, Block, Box, Button, CardContent, Group, Inline, Link, Text, Title } from "../compose";
import { MediaFrame } from "../components/media-frame";
import { Rating } from "../components/rating";
import { at, cn, fmtMoney, tpl, urlOf } from "../utils";
import type { Product, ProductLabels } from "./product-card.types";
export type ProductCardProps = {
product: Product;
labels: ProductLabels;
badges: Record<string, string>;
layout?: "vertical" | "horizontal";
media?: "image" | "none";
ratio?: "4/3" | "1/1" | "3/4";
rating?: "show" | "hide";
action?: "button" | "none";
density?: "default" | "compact";
onAdd?: (id: string) => void;
};
export function ProductCard({
product,
labels,
badges,
layout = "vertical",
media = "image",
ratio = "4/3",
rating = "show",
action = "button",
density = "default",
onAdd,
}: ProductCardProps) {
return (
<Block
tag="article"
className={cn(
"flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded",
"h-full gap-4 overflow-hidden",
(((layout as string) === "horizontal") ? "flex flex-col sm:flex-row" : "flex flex-col")
)}
data-slot="card"
data-layout={layout}
>
{((media as string) === "image") ? (
<Box className={cn("relative shrink-0", (((layout as string) === "horizontal") ? "sm:w-48" : ""))}>
<MediaFrame alt={product.name} src={product.image} ratio={ratio} className="h-full" />
{product.badge ? (
<Badge variant="default" size="default" className="absolute left-4 top-4">
{at(badges, product.badge)}
</Badge>
) : null}
</Box>
) : null}
<CardContent className="flex flex-1 flex-col gap-2">
<Text size="xs" className="uppercase tracking-wide text-muted-foreground">
{product.category}
</Text>
<Title as={3} size="base" weight="bold">
{product.href ? (
<Link href={urlOf(product.href)} variant="default" data-slot="open">
{product.name}
</Link>
) : (
<>
{product.name}
</>
)}
</Title>
{((rating as string) === "show") ? (
<Group gap="2">
<Rating value={product.rating} label={tpl(labels.ratingLabel, product.rating)} />
<Text size="xs" className="text-muted-foreground">
{tpl(labels.reviews, product.reviews)}
</Text>
</Group>
) : null}
{((density as string) === "default") ? (
<Text size="sm" className="text-muted-foreground">
{product.summary}
</Text>
) : null}
<Group gap="4" justify="between" className="mt-auto pt-2">
<Group gap="2" align="baseline" className="flex-wrap">
<Text size="xl" weight="bold">
{fmtMoney(product.price, product.currency)}
</Text>
{(product.compareAt && (product.compareAt > product.price)) ? (
<Text tag="del" size="sm" className="relative text-muted-foreground" data-slot="compare-at">
<Inline className="sr-only">
{labels.was}
</Inline>
{fmtMoney(product.compareAt, product.currency)}
</Text>
) : null}
</Group>
{((action as string) === "button") ? (
<Button
variant={(product.inStock ? "default" : "outline")}
size="sm"
disabled={!product.inStock}
onClick={() => onAdd?.(product.id)}
>
{(product.inStock ? labels.add : labels.soldOut)}
</Button>
) : null}
</Group>
</CardContent>
</Block>
);
}
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type Product = {
id: string;
name: string;
summary: string;
price: number;
currency: string;
rating: number;
reviews: number;
badge?: string;
category: string;
inStock: boolean;
compareAt?: number;
href?: string;
image?: string;
};
export type ProductLabels = {
add: string;
soldOut: string;
reviews: string;
ratingLabel: string;
was: string;
empty: string;
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add product-card// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type Product = {
id: string;
name: string;
summary: string;
price: number;
currency: string;
rating: number;
reviews: number;
badge?: string;
category: string;
inStock: boolean;
compareAt?: number;
href?: string;
image?: string;
};
export type ProductLabels = {
add: string;
soldOut: string;
reviews: string;
ratingLabel: string;
was: string;
empty: string;
};
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck
through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image,
none), ratio, rating (show, hide), action (button, none), density.
-->
<script lang="ts">
import type { Product, ProductLabels } from "./product-card.types";
export type ProductCardProps = {
product: Product;
labels: ProductLabels;
badges: Record<string, string>;
layout?: "vertical" | "horizontal";
media?: "image" | "none";
ratio?: "4/3" | "1/1" | "3/4";
rating?: "show" | "hide";
action?: "button" | "none";
density?: "default" | "compact";
};
</script>
<script setup lang="ts">
import Badge from "../compose/Badge.vue";
import Block from "../compose/Block.vue";
import Box from "../compose/Box.vue";
import Button from "../compose/Button.vue";
import CardContent from "../compose/CardContent.vue";
import Group from "../compose/Group.vue";
import Inline from "../compose/Inline.vue";
import Link from "../compose/Link.vue";
import Text from "../compose/Text.vue";
import Title from "../compose/Title.vue";
import MediaFrame from "../components/media-frame.vue";
import Rating from "../components/rating.vue";
import { at, cn, fmtMoney, tpl, urlOf } from "../utils";
const {
product,
labels,
badges,
layout = "vertical",
media = "image",
ratio = "4/3",
rating = "show",
action = "button",
density = "default",
} = defineProps<ProductCardProps>();
const emit = defineEmits<{ add: [id: string] }>();
</script>
<template>
<Block
tag="article"
:class="cn(
'flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded',
'h-full gap-4 overflow-hidden',
(((layout as string) === 'horizontal') ? 'flex flex-col sm:flex-row' : 'flex flex-col')
)"
data-slot="card"
:data-layout="layout"
>
<Box
v-if="((media as string) === 'image')"
:class="cn('relative shrink-0', (((layout as string) === 'horizontal') ? 'sm:w-48' : ''))"
>
<MediaFrame :alt="product.name" :src="product.image" :ratio="ratio" class="h-full" />
<Badge v-if="product.badge" variant="default" size="default" class="absolute left-4 top-4">
{{ at(badges, product.badge) }}
</Badge>
</Box>
<CardContent class="flex flex-1 flex-col gap-2">
<Text size="xs" class="uppercase tracking-wide text-muted-foreground">
{{ product.category }}
</Text>
<Title :as="3" size="base" weight="bold">
<Link v-if="product.href" :href="urlOf(product.href)" variant="default" data-slot="open">
{{ product.name }}
</Link>
<template v-else>
{{ product.name }}
</template>
</Title>
<Group v-if="((rating as string) === 'show')" gap="2">
<Rating :value="product.rating" :label="tpl(labels.ratingLabel, product.rating)" />
<Text size="xs" class="text-muted-foreground">
{{ tpl(labels.reviews, product.reviews) }}
</Text>
</Group>
<Text v-if="((density as string) === 'default')" size="sm" class="text-muted-foreground">
{{ product.summary }}
</Text>
<Group gap="4" justify="between" class="mt-auto pt-2">
<Group gap="2" align="baseline" class="flex-wrap">
<Text size="xl" weight="bold">
{{ fmtMoney(product.price, product.currency) }}
</Text>
<Text
v-if="(product.compareAt && (product.compareAt > product.price))"
tag="del"
size="sm"
class="relative text-muted-foreground"
data-slot="compare-at"
>
<Inline class="sr-only">
{{ labels.was }}
</Inline>
{{ fmtMoney(product.compareAt, product.currency) }}
</Text>
</Group>
<Button v-if="((action as string) === 'button')"
:variant="(product.inStock ? 'default' : 'outline')"
size="sm"
:disabled="!product.inStock"
@click="() => emit('add', product.id)"
>
{{ (product.inStock ? labels.add : labels.soldOut) }}
</Button>
</Group>
</CardContent>
</Block>
</template>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add product-card// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck
* through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image,
* none), ratio, rating (show, hide), action (button, none), density.
*/
import { type JSX } from "solid-js";
import { Badge, Block, Box, Button, CardContent, Group, Inline, Link, Text, Title } from "../compose";
import { MediaFrame } from "../components/media-frame";
import { Rating } from "../components/rating";
import { at, cn, fmtMoney, tpl, urlOf } from "../utils";
import type { Product, ProductLabels } from "./product-card.types";
export type ProductCardProps = {
product: Product;
labels: ProductLabels;
badges: Record<string, string>;
layout?: "vertical" | "horizontal";
media?: "image" | "none";
ratio?: "4/3" | "1/1" | "3/4";
rating?: "show" | "hide";
action?: "button" | "none";
density?: "default" | "compact";
onAdd?: (id: string) => void;
};
export function ProductCard({
product,
labels,
badges,
layout = "vertical",
media = "image",
ratio = "4/3",
rating = "show",
action = "button",
density = "default",
onAdd,
}: ProductCardProps) {
return (
<Block
tag="article"
class={cn(
"flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded",
"h-full gap-4 overflow-hidden",
(((layout as string) === "horizontal") ? "flex flex-col sm:flex-row" : "flex flex-col")
)}
data-slot="card"
data-layout={layout}
>
{((media as string) === "image") ? (
<Box class={cn("relative shrink-0", (((layout as string) === "horizontal") ? "sm:w-48" : ""))}>
<MediaFrame alt={product.name} src={product.image} ratio={ratio} class="h-full" />
{product.badge ? (
<Badge variant="default" size="default" class="absolute left-4 top-4">
{at(badges, product.badge)}
</Badge>
) : null}
</Box>
) : null}
<CardContent class="flex flex-1 flex-col gap-2">
<Text size="xs" class="uppercase tracking-wide text-muted-foreground">
{product.category}
</Text>
<Title as={3} size="base" weight="bold">
{product.href ? (
<Link href={urlOf(product.href)} variant="default" data-slot="open">
{product.name}
</Link>
) : (
<>
{product.name}
</>
)}
</Title>
{((rating as string) === "show") ? (
<Group gap="2">
<Rating value={product.rating} label={tpl(labels.ratingLabel, product.rating)} />
<Text size="xs" class="text-muted-foreground">
{tpl(labels.reviews, product.reviews)}
</Text>
</Group>
) : null}
{((density as string) === "default") ? (
<Text size="sm" class="text-muted-foreground">
{product.summary}
</Text>
) : null}
<Group gap="4" justify="between" class="mt-auto pt-2">
<Group gap="2" align="baseline" class="flex-wrap">
<Text size="xl" weight="bold">
{fmtMoney(product.price, product.currency)}
</Text>
{(product.compareAt && (product.compareAt > product.price)) ? (
<Text tag="del" size="sm" class="relative text-muted-foreground" data-slot="compare-at">
<Inline class="sr-only">
{labels.was}
</Inline>
{fmtMoney(product.compareAt, product.currency)}
</Text>
) : null}
</Group>
{((action as string) === "button") ? (
<Button
variant={(product.inStock ? "default" : "outline")}
size="sm"
disabled={!product.inStock}
onClick={() => onAdd?.(product.id)}
>
{(product.inStock ? labels.add : labels.soldOut)}
</Button>
) : null}
</Group>
</CardContent>
</Block>
);
}
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
export type Product = {
id: string;
name: string;
summary: string;
price: number;
currency: string;
rating: number;
reviews: number;
badge?: string;
category: string;
inStock: boolean;
compareAt?: number;
href?: string;
image?: string;
};
export type ProductLabels = {
add: string;
soldOut: string;
reviews: string;
ratingLabel: string;
was: string;
empty: string;
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add product-card// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/product-card.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/ui/button"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/ui/link"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// ProductCardProps are the props of ProductCard; the values are the JSON shapes of the TypeScript props.
type ProductCardProps struct {
Product any `json:"product"`
Labels any `json:"labels"`
Badges any `json:"badges"`
Layout any `json:"layout"`
Media any `json:"media"`
Ratio any `json:"ratio"`
Rating any `json:"rating"`
Action any `json:"action"`
Density any `json:"density"`
}
// A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image, none), ratio, rating (show, hide), action (button, none), density.
templ ProductCard(p ProductCardProps) {
{{ vProduct := p.Product }}
{{ vLabels := p.Labels }}
{{ vBadges := p.Badges }}
{{ vLayout := uiutils.Def(p.Layout, "vertical") }}
{{ vMedia := uiutils.Def(p.Media, "image") }}
{{ vRatio := uiutils.Def(p.Ratio, "4/3") }}
{{ vRating := uiutils.Def(p.Rating, "show") }}
{{ vAction := uiutils.Def(p.Action, "button") }}
{{ vDensity := uiutils.Def(p.Density, "default") }}
@compose.Block(compose.BlockProps{BoxProps: box.BoxProps{Tag: "article", Class: uiutils.S(uiutils.Cnv("flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded", "h-full gap-4 overflow-hidden", uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "horizontal")), "flex flex-col sm:flex-row", "flex flex-col"))), Attrs: uiutils.Attrs("data-slot", "card", "data-layout", vLayout)}}) {
if uiutils.Eq(vMedia, "image") {
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("relative shrink-0", uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "horizontal")), "sm:w-48", "")))}}) {
@MediaFrame(MediaFrameProps{Alt: uiutils.Get(vProduct, "name"), Src: uiutils.Get(vProduct, "image"), Ratio: vRatio, Class: uiutils.Cnv("h-full")})
if uiutils.T(uiutils.Get(vProduct, "badge")) {
@compose.Badge(compose.BadgeProps{Variant: "default", Size: "default", TextProps: text.TextProps{Class: "absolute left-4 top-4"}}) {
{ uiutils.Text(uiutils.At(vBadges, uiutils.Get(vProduct, "badge"))) }
}
}
}
}
@compose.CardContent(compose.CardContentProps{BoxProps: box.BoxProps{Class: "flex flex-1 flex-col gap-2"}}) {
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "uppercase tracking-wide text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Get(vProduct, "category")) }
}
@compose.Title(compose.TitleProps{As: "3", Size: "base", Weight: "bold", TextProps: text.TextProps{}}) {
if uiutils.T(uiutils.Get(vProduct, "href")) {
@compose.Link(compose.LinkProps{Variant: "default", LinkProps: link.LinkProps{Href: uiutils.URL(uiutils.Get(vProduct, "href"), false), Attrs: uiutils.Attrs("data-slot", "open")}}) {
{ uiutils.Text(uiutils.Get(vProduct, "name")) }
}
} else {
{ uiutils.Text(uiutils.Get(vProduct, "name")) }
}
}
if uiutils.Eq(vRating, "show") {
@compose.Group(compose.GroupProps{Gap: "2", BoxProps: box.BoxProps{}}) {
@Rating(RatingProps{Value: uiutils.Get(vProduct, "rating"), Label: uiutils.Tpl(uiutils.Get(vLabels, "ratingLabel"), uiutils.Get(vProduct, "rating"))})
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vLabels, "reviews"), uiutils.Get(vProduct, "reviews"))) }
}
}
}
if uiutils.Eq(vDensity, "default") {
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Get(vProduct, "summary")) }
}
}
@compose.Group(compose.GroupProps{Gap: "4", Justify: "between", BoxProps: box.BoxProps{Class: "mt-auto pt-2"}}) {
@compose.Group(compose.GroupProps{Gap: "2", Align: "baseline", BoxProps: box.BoxProps{Class: "flex-wrap"}}) {
@compose.Text(compose.TextProps{Size: "xl", Weight: "bold", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Money(uiutils.Get(vProduct, "price"), uiutils.Get(vProduct, "currency"))) }
}
if uiutils.T(uiutils.And(uiutils.Get(vProduct, "compareAt"), uiutils.Gt(uiutils.Get(vProduct, "compareAt"), uiutils.Get(vProduct, "price")))) {
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{Tag: "del", Class: "relative text-muted-foreground", Attrs: uiutils.Attrs("data-slot", "compare-at")}}) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "sr-only"}}) {
{ uiutils.Text(uiutils.Get(vLabels, "was")) }
}
{ uiutils.Text(uiutils.Money(uiutils.Get(vProduct, "compareAt"), uiutils.Get(vProduct, "currency"))) }
}
}
}
if uiutils.Eq(vAction, "button") {
@compose.Button(compose.ButtonProps{Variant: uiutils.S(uiutils.Cond(uiutils.T(uiutils.Get(vProduct, "inStock")), "default", "outline")), Size: "sm", ButtonProps: button.ButtonProps{Disabled: uiutils.T(!uiutils.T(uiutils.Get(vProduct, "inStock")))}}) {
{ uiutils.Text(uiutils.Cond(uiutils.T(uiutils.Get(vProduct, "inStock")), uiutils.Get(vLabels, "add"), uiutils.Get(vLabels, "soldOut"))) }
}
}
}
}
}
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add product-card{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/product-card.json
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image, none), ratio, rating (show, hide), action (button, none), density.
Props (p): product, labels, badges, layout, media, ratio, rating, action, density. -#}
{%- set v_product = (p.product ?? null) -%}
{%- set v_labels = (p.labels ?? null) -%}
{%- set v_badges = (p.badges ?? null) -%}
{%- set v_layout = (p.layout ?? 'vertical') -%}
{%- set v_media = (p.media ?? 'image') -%}
{%- set v_ratio = (p.ratio ?? '4/3') -%}
{%- set v_rating = (p.rating ?? 'show') -%}
{%- set v_action = (p.action ?? 'button') -%}
{%- set v_density = (p.density ?? 'default') -%}
{%- set c_16 -%}
{%- if og_t(og_eq(v_media, 'image')) %}
{%- set c_2 -%}
{{ include('blocks/media-frame.html.twig', {'p': {'alt': og_get(v_product, ['name']), 'src': og_get(v_product, ['image']), 'ratio': v_ratio, 'className': og_cnv(['h-full'])}}, with_context = false) }}
{%- if og_t(og_get(v_product, ['badge'])) %}
{%- set c_1 -%}
{{ og_text(og_at(v_badges, og_get(v_product, ['badge']))) }}
{%- endset -%}
{{ include('compose/Badge.html.twig', {'variant': 'default', 'size': 'default', 'class': 'absolute left-4 top-4', 'children': c_1}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv(['relative shrink-0', (og_t(og_eq(v_layout, 'horizontal')) ? 'sm:w-48' : '')])), 'children': c_2}, with_context = false) }}
{%- endif %}
{%- set c_15 -%}
{%- set c_3 -%}
{{ og_text(og_get(v_product, ['category'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'uppercase tracking-wide text-muted-foreground', 'children': c_3}, with_context = false) }}
{%- set c_5 -%}
{%- if og_t(og_get(v_product, ['href'])) %}
{%- set c_4 -%}
{{ og_text(og_get(v_product, ['name'])) }}
{%- endset -%}
{{ include('compose/Link.html.twig', {'href': og_url(og_s(og_get(v_product, ['href']))), 'variant': 'default', 'attrs': og_attrs(['data-slot', 'open']), 'children': c_4}, with_context = false) }}
{%- else %}
{{ og_text(og_get(v_product, ['name'])) }}
{%- endif %}
{%- endset -%}
{{ include('compose/Title.html.twig', {'as': 3, 'size': 'base', 'weight': 'bold', 'children': c_5}, with_context = false) }}
{%- if og_t(og_eq(v_rating, 'show')) %}
{%- set c_7 -%}
{{ include('blocks/rating.html.twig', {'p': {'value': og_get(v_product, ['rating']), 'label': og_tpl(og_get(v_labels, ['ratingLabel']), [og_get(v_product, ['rating'])])}}, with_context = false) }}
{%- set c_6 -%}
{{ og_text(og_tpl(og_get(v_labels, ['reviews']), [og_get(v_product, ['reviews'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_6}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'children': c_7}, with_context = false) }}
{%- endif %}
{%- if og_t(og_eq(v_density, 'default')) %}
{%- set c_8 -%}
{{ og_text(og_get(v_product, ['summary'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'class': 'text-muted-foreground', 'children': c_8}, with_context = false) }}
{%- endif %}
{%- set c_14 -%}
{%- set c_12 -%}
{%- set c_9 -%}
{{ og_text(og_money(og_get(v_product, ['price']), og_get(v_product, ['currency']))) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xl', 'weight': 'bold', 'children': c_9}, with_context = false) }}
{%- if og_t(og_and([og_get(v_product, ['compareAt']), og_gt(og_get(v_product, ['compareAt']), og_get(v_product, ['price']))])) %}
{%- set c_11 -%}
{%- set c_10 -%}
{{ og_text(og_get(v_labels, ['was'])) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'sr-only', 'children': c_10}, with_context = false) }}
{{ og_text(og_money(og_get(v_product, ['compareAt']), og_get(v_product, ['currency']))) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'tag': 'del', 'size': 'sm', 'class': 'relative text-muted-foreground', 'attrs': og_attrs(['data-slot', 'compare-at']), 'children': c_11}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'baseline', 'class': 'flex-wrap', 'children': c_12}, with_context = false) }}
{%- if og_t(og_eq(v_action, 'button')) %}
{%- set c_13 -%}
{{ og_text((og_t(og_get(v_product, ['inStock'])) ? og_get(v_labels, ['add']) : og_get(v_labels, ['soldOut']))) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': og_s((og_t(og_get(v_product, ['inStock'])) ? 'default' : 'outline')), 'size': 'sm', 'disabled': og_t(not (og_t(og_get(v_product, ['inStock'])))), 'children': c_13}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '4', 'justify': 'between', 'class': 'mt-auto pt-2', 'children': c_14}, with_context = false) }}
{%- endset -%}
{{ include('compose/CardContent.html.twig', {'class': 'flex flex-1 flex-col gap-2', 'children': c_15}, with_context = false) }}
{%- endset -%}
{{ include('compose/Block.html.twig', {'tag': 'article', 'class': og_s(og_cnv(['flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded', 'h-full gap-4 overflow-hidden', (og_t(og_eq(v_layout, 'horizontal')) ? 'flex flex-col sm:flex-row' : 'flex flex-col')])), 'attrs': og_attrs(['data-slot', 'card', 'data-layout', v_layout]), 'children': c_16}, with_context = false) }}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add product-card{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/product-card.json
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image, none), ratio, rating (show, hide), action (button, none), density.
Props (p): product, labels, badges, layout, media, ratio, rating, action, density. *}
{var $v_product = ($p['product'] ?? null)}
{var $v_labels = ($p['labels'] ?? null)}
{var $v_badges = ($p['badges'] ?? null)}
{var $v_layout = ($p['layout'] ?? 'vertical')}
{var $v_media = ($p['media'] ?? 'image')}
{var $v_ratio = ($p['ratio'] ?? '4/3')}
{var $v_rating = ($p['rating'] ?? 'show')}
{var $v_action = ($p['action'] ?? 'button')}
{var $v_density = ($p['density'] ?? 'default')}
{capture $c_16}
{if og_t(og_eq($v_media, 'image'))}
{capture $c_2}
{=og_include('blocks/media-frame.latte', ['p' => ['alt' => og_get($v_product, ['name']), 'src' => og_get($v_product, ['image']), 'ratio' => $v_ratio, 'className' => og_cnv(['h-full'])]])|noescape}
{if og_t(og_get($v_product, ['badge']))}
{capture $c_1}
{=og_text(og_at($v_badges, og_get($v_product, ['badge'])))}
{/capture}
{=og_include('compose/Badge.latte', ['variant' => 'default', 'size' => 'default', 'class' => 'absolute left-4 top-4', 'children' => (string) $c_1])|noescape}
{/if}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv(['relative shrink-0', (og_t(og_eq($v_layout, 'horizontal')) ? 'sm:w-48' : '')])), 'children' => (string) $c_2])|noescape}
{/if}
{capture $c_15}
{capture $c_3}
{=og_text(og_get($v_product, ['category']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'uppercase tracking-wide text-muted-foreground', 'children' => (string) $c_3])|noescape}
{capture $c_5}
{if og_t(og_get($v_product, ['href']))}
{capture $c_4}
{=og_text(og_get($v_product, ['name']))}
{/capture}
{=og_include('compose/Link.latte', ['href' => og_url(og_s(og_get($v_product, ['href']))), 'variant' => 'default', 'attrs' => og_attrs(['data-slot', 'open']), 'children' => (string) $c_4])|noescape}
{else}
{=og_text(og_get($v_product, ['name']))}
{/if}
{/capture}
{=og_include('compose/Title.latte', ['as' => 3, 'size' => 'base', 'weight' => 'bold', 'children' => (string) $c_5])|noescape}
{if og_t(og_eq($v_rating, 'show'))}
{capture $c_7}
{=og_include('blocks/rating.latte', ['p' => ['value' => og_get($v_product, ['rating']), 'label' => og_tpl(og_get($v_labels, ['ratingLabel']), [og_get($v_product, ['rating'])])]])|noescape}
{capture $c_6}
{=og_text(og_tpl(og_get($v_labels, ['reviews']), [og_get($v_product, ['reviews'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_6])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'children' => (string) $c_7])|noescape}
{/if}
{if og_t(og_eq($v_density, 'default'))}
{capture $c_8}
{=og_text(og_get($v_product, ['summary']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'class' => 'text-muted-foreground', 'children' => (string) $c_8])|noescape}
{/if}
{capture $c_14}
{capture $c_12}
{capture $c_9}
{=og_text(og_money(og_get($v_product, ['price']), og_get($v_product, ['currency'])))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xl', 'weight' => 'bold', 'children' => (string) $c_9])|noescape}
{if og_t(og_and([og_get($v_product, ['compareAt']), og_gt(og_get($v_product, ['compareAt']), og_get($v_product, ['price']))]))}
{capture $c_11}
{capture $c_10}
{=og_text(og_get($v_labels, ['was']))}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'sr-only', 'children' => (string) $c_10])|noescape}
{=og_text(og_money(og_get($v_product, ['compareAt']), og_get($v_product, ['currency'])))}
{/capture}
{=og_include('compose/Text.latte', ['tag' => 'del', 'size' => 'sm', 'class' => 'relative text-muted-foreground', 'attrs' => og_attrs(['data-slot', 'compare-at']), 'children' => (string) $c_11])|noescape}
{/if}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'baseline', 'class' => 'flex-wrap', 'children' => (string) $c_12])|noescape}
{if og_t(og_eq($v_action, 'button'))}
{capture $c_13}
{=og_text((og_t(og_get($v_product, ['inStock'])) ? og_get($v_labels, ['add']) : og_get($v_labels, ['soldOut'])))}
{/capture}
{=og_include('compose/Button.latte', ['variant' => og_s((og_t(og_get($v_product, ['inStock'])) ? 'default' : 'outline')), 'size' => 'sm', 'disabled' => og_t(!(og_t(og_get($v_product, ['inStock'])))), 'children' => (string) $c_13])|noescape}
{/if}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '4', 'justify' => 'between', 'class' => 'mt-auto pt-2', 'children' => (string) $c_14])|noescape}
{/capture}
{=og_include('compose/CardContent.latte', ['class' => 'flex flex-1 flex-col gap-2', 'children' => (string) $c_15])|noescape}
{/capture}
{=og_include('compose/Block.latte', ['tag' => 'article', 'class' => og_s(og_cnv(['flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded', 'h-full gap-4 overflow-hidden', (og_t(og_eq($v_layout, 'horizontal')) ? 'flex flex-col sm:flex-row' : 'flex flex-col')])), 'attrs' => og_attrs(['data-slot', 'card', 'data-layout', $v_layout]), 'children' => (string) $c_16])|noescape}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add product-card{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/product-card.json
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image, none), ratio, rating (show, hide), action (button, none), density.
Props (p): product, labels, badges, layout, media, ratio, rating, action, density. -#}
{%- set v_product = og_def(p['product'], none) -%}
{%- set v_labels = og_def(p['labels'], none) -%}
{%- set v_badges = og_def(p['badges'], none) -%}
{%- set v_layout = og_def(p['layout'], 'vertical') -%}
{%- set v_media = og_def(p['media'], 'image') -%}
{%- set v_ratio = og_def(p['ratio'], '4/3') -%}
{%- set v_rating = og_def(p['rating'], 'show') -%}
{%- set v_action = og_def(p['action'], 'button') -%}
{%- set v_density = og_def(p['density'], 'default') -%}
{%- set c_16 -%}
{%- if og_t(og_eq(v_media, 'image')) %}
{%- set c_2 -%}
{{ og_include('blocks/media-frame.html.j2', {'p': {'alt': og_get(v_product, ['name']), 'src': og_get(v_product, ['image']), 'ratio': v_ratio, 'className': og_cnv(['h-full'])}}) }}
{%- if og_t(og_get(v_product, ['badge'])) %}
{%- set c_1 -%}
{{ og_text(og_at(v_badges, og_get(v_product, ['badge']))) }}
{%- endset -%}
{{ og_include('compose/badge.html.j2', {'p': {'Variant': 'default', 'Size': 'default', 'Class': 'absolute left-4 top-4'}, 'children': c_1}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv(['relative shrink-0', ('sm:w-48' if og_t(og_eq(v_layout, 'horizontal')) else '')]))}, 'children': c_2}) }}
{%- endif %}
{%- set c_15 -%}
{%- set c_3 -%}
{{ og_text(og_get(v_product, ['category'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'uppercase tracking-wide text-muted-foreground'}, 'children': c_3}) }}
{%- set c_5 -%}
{%- if og_t(og_get(v_product, ['href'])) %}
{%- set c_4 -%}
{{ og_text(og_get(v_product, ['name'])) }}
{%- endset -%}
{{ og_include('compose/link.html.j2', {'p': {'Href': og_url(og_s(og_get(v_product, ['href']))), 'Variant': 'default', 'Attrs': og_attrs(['data-slot', 'open'])}, 'children': c_4}) }}
{%- else %}
{{ og_text(og_get(v_product, ['name'])) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/title.html.j2', {'p': {'As': 3, 'Size': 'base', 'Weight': 'bold'}, 'children': c_5}) }}
{%- if og_t(og_eq(v_rating, 'show')) %}
{%- set c_7 -%}
{{ og_include('blocks/rating.html.j2', {'p': {'value': og_get(v_product, ['rating']), 'label': og_tpl(og_get(v_labels, ['ratingLabel']), [og_get(v_product, ['rating'])])}}) }}
{%- set c_6 -%}
{{ og_text(og_tpl(og_get(v_labels, ['reviews']), [og_get(v_product, ['reviews'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_6}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2'}, 'children': c_7}) }}
{%- endif %}
{%- if og_t(og_eq(v_density, 'default')) %}
{%- set c_8 -%}
{{ og_text(og_get(v_product, ['summary'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm', 'Class': 'text-muted-foreground'}, 'children': c_8}) }}
{%- endif %}
{%- set c_14 -%}
{%- set c_12 -%}
{%- set c_9 -%}
{{ og_text(og_money(og_get(v_product, ['price']), og_get(v_product, ['currency']))) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xl', 'Weight': 'bold'}, 'children': c_9}) }}
{%- if og_t(og_and([og_get(v_product, ['compareAt']), og_gt(og_get(v_product, ['compareAt']), og_get(v_product, ['price']))])) %}
{%- set c_11 -%}
{%- set c_10 -%}
{{ og_text(og_get(v_labels, ['was'])) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'sr-only'}, 'children': c_10}) }}
{{ og_text(og_money(og_get(v_product, ['compareAt']), og_get(v_product, ['currency']))) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Tag': 'del', 'Size': 'sm', 'Class': 'relative text-muted-foreground', 'Attrs': og_attrs(['data-slot', 'compare-at'])}, 'children': c_11}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'baseline', 'Class': 'flex-wrap'}, 'children': c_12}) }}
{%- if og_t(og_eq(v_action, 'button')) %}
{%- set c_13 -%}
{{ og_text((og_get(v_labels, ['add']) if og_t(og_get(v_product, ['inStock'])) else og_get(v_labels, ['soldOut']))) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': og_s(('default' if og_t(og_get(v_product, ['inStock'])) else 'outline')), 'Size': 'sm', 'Disabled': og_t(not (og_t(og_get(v_product, ['inStock']))))}, 'children': c_13}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Justify': 'between', 'Class': 'mt-auto pt-2'}, 'children': c_14}) }}
{%- endset -%}
{{ og_include('compose/card-content.html.j2', {'p': {'Class': 'flex flex-1 flex-col gap-2'}, 'children': c_15}) }}
{%- endset -%}
{{ og_include('compose/block.html.j2', {'p': {'Tag': 'article', 'Class': og_s(og_cnv(['flex flex-col gap-8 bg-card p-6 text-card-foreground inset-ring inset-ring-border rounded', 'h-full gap-4 overflow-hidden', ('flex flex-col sm:flex-row' if og_t(og_eq(v_layout, 'horizontal')) else 'flex flex-col')])), 'Attrs': og_attrs(['data-slot', 'card', 'data-layout', v_layout])}, 'children': c_16}) }}
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
A product as a card: picture, optional badge, category, name, rating, summary, price (and the old price struck through when `compareAt` is higher) and an add button. Axes: layout (vertical, horizontal), media (image, none), ratio, rating (show, hide), action (button, none), density.
| Prop | Type | Default | Description |
|---|---|---|---|
| product (required) | Product | - | |
| labels (required) | ProductLabels | - | |
| badges (required) | Record<string, string> | - | badge word by product badge (new, sale) |
| layout | "vertical" | "horizontal" | "vertical" | |
| media | "image" | "none" | "image" | |
| ratio | "4/3" | "1/1" | "3/4" | "4/3" | |
| rating | "show" | "hide" | "show" | |
| action | "button" | "none" | "button" | |
| density | "default" | "compact" | "default" |