Shopping Cart
The cart lines beside a summary with a promo code and a free-delivery bar.
Install
npx ui8kit add shopping-cartPulls in: box, button, cart-list, cart-summary-card, compose, empty-state, group, kit-box, kit-button, kit-text, lucide-icon, media-frame, number-field, order-summary, section-frame, stack, text, utils
Preview
Your cart
Arc desk lamp
Brass
$89
$89
Field backpack
Olive
$129
$129
Desk mat
Charcoal
$35
$70
Order summary
3 products
Try:
WELCOME10FREESHIPDESK15Add $12 more for free express delivery
- Subtotal$288
- Shipping$12
- Tax$24
- Total$324
Taxes are calculated at checkout.
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 shopping-cart<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the
way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout
(split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { ShoppingCartLabels } from "./shopping-cart.types";
import type { CartLine, CartLabels } from "./cart-list.types";
import type { SummaryRow } from "./order-summary.types";
import type { Promo, CartSummaryLabels } from "../components/cart-summary-card.types";
export type ShoppingCartProps = {
id: string;
title: string;
lines: CartLine[];
rows: SummaryRow[];
promos: Promo[];
labels: CartLabels;
totals: CartSummaryLabels;
actions: ShoppingCartLabels;
layout?: "split" | "stacked";
promo?: "show" | "hide";
progress?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import Button from "../compose/Button.svelte";
import Group from "../compose/Group.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import Stack from "../compose/Stack.svelte";
import Text from "../compose/Text.svelte";
import CartSummaryCard from "../components/cart-summary-card.svelte";
import EmptyState from "../components/empty-state.svelte";
import MediaFrame from "../components/media-frame.svelte";
import NumberField from "../components/number-field.svelte";
import SectionFrame from "../components/section-frame.svelte";
import { fmtMoney, tpl } from "../utils";
let {
id,
title,
lines,
rows,
promos,
labels,
totals,
actions,
layout = "split",
promo = "show",
progress = "show",
tone = "default",
landmarkLabel,
}: ShoppingCartProps = $props();
</script>
<SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
<Box
class={
(layout as string) === "split" ? "grid grid-cols-1 items-start gap-8 lg:grid-cols-3"
: "grid grid-cols-1 gap-8"
}
>
<Stack
gap="4"
align="stretch"
class={(((layout as string) === "split") ? "lg:col-span-2" : "")}
data-slot="lines"
>
{#if ((lines?.length ?? 0) === 0)}
<EmptyState icon="shopping-cart" title={actions.empty} />
{/if}
{#each lines as line (line.id)}
<Group
gap="4"
align="center"
class="rounded bg-card inset-ring inset-ring-border flex-wrap p-4"
data-slot="item"
>
<MediaFrame alt={line.name} src={line.image} ratio="1/1" class="size-20 shrink-0" />
<Stack gap="0" class="min-w-40 flex-1">
<Text size="sm" weight="semibold">
{line.name}
</Text>
<Text size="xs" class="text-muted-foreground">
{line.variant}
</Text>
<Text size="sm">
{fmtMoney(line.price, line.currency)}
</Text>
</Stack>
<NumberField
value={(line.qty == null ? undefined : String(line.qty))}
name={tpl("{0}-qty-{1}", id, line.id)}
min="1"
label={labels.qty}
decrease={labels.decrease}
increase={labels.increase}
/>
<Text size="base" weight="bold" class="w-24 text-right">
{fmtMoney((line.price * line.qty), line.currency)}
</Text>
<Button variant="ghost" size="sm" layout="icon" aria-label={labels.remove}>
<LucideIcon name="trash" size={16} />
</Button>
</Group>
{/each}
<Group gap="4" justify="between" class="flex-wrap">
<Button variant="outline" size="default">
<LucideIcon name="arrow-left" size={16} />
{actions.back}
</Button>
<Button variant="ghost" size="default">
{actions.clear}
</Button>
</Group>
</Stack>
<Box class={(((layout as string) === "split") ? "lg:sticky lg:top-8" : "")} data-slot="aside">
<CartSummaryCard
field={tpl("{0}-promo", id)}
lines={lines}
rows={rows}
promos={promos}
labels={totals}
promo={promo}
progress={progress}
/>
</Box>
</Box>
</SectionFrame>
// 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 ShoppingCartLabels = {
back: string;
clear: 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 shopping-cart// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the
* way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout
* (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
*/
import { type ReactNode } from "react";
import { Box, Button, Group, Stack, Text } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { CartSummaryCard } from "../components/cart-summary-card";
import { EmptyState } from "../components/empty-state";
import { MediaFrame } from "../components/media-frame";
import { NumberField } from "../components/number-field";
import { SectionFrame } from "../components/section-frame";
import { fmtMoney, tpl } from "../utils";
import type { ShoppingCartLabels } from "./shopping-cart.types";
import type { CartLine, CartLabels } from "./cart-list.types";
import type { SummaryRow } from "./order-summary.types";
import type { Promo, CartSummaryLabels } from "../components/cart-summary-card.types";
export type ShoppingCartProps = {
id: string;
title: string;
lines: CartLine[];
rows: SummaryRow[];
promos: Promo[];
labels: CartLabels;
totals: CartSummaryLabels;
actions: ShoppingCartLabels;
layout?: "split" | "stacked";
promo?: "show" | "hide";
progress?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
};
export function ShoppingCart({
id,
title,
lines,
rows,
promos,
labels,
totals,
actions,
layout = "split",
promo = "show",
progress = "show",
tone = "default",
landmarkLabel,
}: ShoppingCartProps) {
return (
<SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
<Box
className={
(layout as string) === "split" ? "grid grid-cols-1 items-start gap-8 lg:grid-cols-3"
: "grid grid-cols-1 gap-8"
}
>
<Stack
gap="4"
align="stretch"
className={(((layout as string) === "split") ? "lg:col-span-2" : "")}
data-slot="lines"
>
{((lines?.length ?? 0) === 0) ? (
<EmptyState icon="shopping-cart" title={actions.empty} />
) : null}
{(lines ?? []).map((line) => (
<Group key={line.id}
gap="4"
align="center"
className="rounded bg-card inset-ring inset-ring-border flex-wrap p-4"
data-slot="item"
>
<MediaFrame alt={line.name} src={line.image} ratio="1/1" className="size-20 shrink-0" />
<Stack gap="0" className="min-w-40 flex-1">
<Text size="sm" weight="semibold">
{line.name}
</Text>
<Text size="xs" className="text-muted-foreground">
{line.variant}
</Text>
<Text size="sm">
{fmtMoney(line.price, line.currency)}
</Text>
</Stack>
<NumberField
value={(line.qty == null ? undefined : String(line.qty))}
name={tpl("{0}-qty-{1}", id, line.id)}
min="1"
label={labels.qty}
decrease={labels.decrease}
increase={labels.increase}
/>
<Text size="base" weight="bold" className="w-24 text-right">
{fmtMoney((line.price * line.qty), line.currency)}
</Text>
<Button variant="ghost" size="sm" layout="icon" aria-label={labels.remove}>
<LucideIcon name="trash" size={16} />
</Button>
</Group>
))}
<Group gap="4" justify="between" className="flex-wrap">
<Button variant="outline" size="default">
<LucideIcon name="arrow-left" size={16} />
{actions.back}
</Button>
<Button variant="ghost" size="default">
{actions.clear}
</Button>
</Group>
</Stack>
<Box className={(((layout as string) === "split") ? "lg:sticky lg:top-8" : "")} data-slot="aside">
<CartSummaryCard
field={tpl("{0}-promo", id)}
lines={lines}
rows={rows}
promos={promos}
labels={totals}
promo={promo}
progress={progress}
/>
</Box>
</Box>
</SectionFrame>
);
}
// 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 ShoppingCartLabels = {
back: string;
clear: 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 shopping-cart// 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 ShoppingCartLabels = {
back: string;
clear: 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. -->
<!--
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the
way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout
(split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
-->
<script lang="ts">
import type { ShoppingCartLabels } from "./shopping-cart.types";
import type { CartLine, CartLabels } from "./cart-list.types";
import type { SummaryRow } from "./order-summary.types";
import type { Promo, CartSummaryLabels } from "../components/cart-summary-card.types";
export type ShoppingCartProps = {
id: string;
title: string;
lines: CartLine[];
rows: SummaryRow[];
promos: Promo[];
labels: CartLabels;
totals: CartSummaryLabels;
actions: ShoppingCartLabels;
layout?: "split" | "stacked";
promo?: "show" | "hide";
progress?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
};
</script>
<script setup lang="ts">
import Box from "../compose/Box.vue";
import Button from "../compose/Button.vue";
import Group from "../compose/Group.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import Stack from "../compose/Stack.vue";
import Text from "../compose/Text.vue";
import CartSummaryCard from "../components/cart-summary-card.vue";
import EmptyState from "../components/empty-state.vue";
import MediaFrame from "../components/media-frame.vue";
import NumberField from "../components/number-field.vue";
import SectionFrame from "../components/section-frame.vue";
import { fmtMoney, tpl } from "../utils";
const {
id,
title,
lines,
rows,
promos,
labels,
totals,
actions,
layout = "split",
promo = "show",
progress = "show",
tone = "default",
landmarkLabel,
} = defineProps<ShoppingCartProps>();
</script>
<template>
<SectionFrame :id="id" :title="title" :tone="tone" :landmarkLabel="landmarkLabel">
<Box
:class="
(layout as string) === 'split' ? 'grid grid-cols-1 items-start gap-8 lg:grid-cols-3'
: 'grid grid-cols-1 gap-8'
"
>
<Stack
gap="4"
align="stretch"
:class="(((layout as string) === 'split') ? 'lg:col-span-2' : '')"
data-slot="lines"
>
<EmptyState v-if="((lines?.length ?? 0) === 0)" icon="shopping-cart" :title="actions.empty" />
<Group v-for="line in lines" :key="line.id"
gap="4"
align="center"
class="rounded bg-card inset-ring inset-ring-border flex-wrap p-4"
data-slot="item"
>
<MediaFrame :alt="line.name" :src="line.image" ratio="1/1" class="size-20 shrink-0" />
<Stack gap="0" class="min-w-40 flex-1">
<Text size="sm" weight="semibold">
{{ line.name }}
</Text>
<Text size="xs" class="text-muted-foreground">
{{ line.variant }}
</Text>
<Text size="sm">
{{ fmtMoney(line.price, line.currency) }}
</Text>
</Stack>
<NumberField
:value="(line.qty == null ? undefined : String(line.qty))"
:name="tpl('{0}-qty-{1}', id, line.id)"
min="1"
:label="labels.qty"
:decrease="labels.decrease"
:increase="labels.increase"
/>
<Text size="base" weight="bold" class="w-24 text-right">
{{ fmtMoney((line.price * line.qty), line.currency) }}
</Text>
<Button variant="ghost" size="sm" layout="icon" :aria-label="labels.remove">
<LucideIcon name="trash" :size="16" />
</Button>
</Group>
<Group gap="4" justify="between" class="flex-wrap">
<Button variant="outline" size="default">
<LucideIcon name="arrow-left" :size="16" />
{{ actions.back }}
</Button>
<Button variant="ghost" size="default">
{{ actions.clear }}
</Button>
</Group>
</Stack>
<Box :class="(((layout as string) === 'split') ? 'lg:sticky lg:top-8' : '')" data-slot="aside">
<CartSummaryCard
:field="tpl('{0}-promo', id)"
:lines="lines"
:rows="rows"
:promos="promos"
:labels="totals"
:promo="promo"
:progress="progress"
/>
</Box>
</Box>
</SectionFrame>
</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 shopping-cart// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the
* way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout
* (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
*/
import { For, type JSX } from "solid-js";
import { Box, Button, Group, Stack, Text } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { CartSummaryCard } from "../components/cart-summary-card";
import { EmptyState } from "../components/empty-state";
import { MediaFrame } from "../components/media-frame";
import { NumberField } from "../components/number-field";
import { SectionFrame } from "../components/section-frame";
import { fmtMoney, tpl } from "../utils";
import type { ShoppingCartLabels } from "./shopping-cart.types";
import type { CartLine, CartLabels } from "./cart-list.types";
import type { SummaryRow } from "./order-summary.types";
import type { Promo, CartSummaryLabels } from "../components/cart-summary-card.types";
export type ShoppingCartProps = {
id: string;
title: string;
lines: CartLine[];
rows: SummaryRow[];
promos: Promo[];
labels: CartLabels;
totals: CartSummaryLabels;
actions: ShoppingCartLabels;
layout?: "split" | "stacked";
promo?: "show" | "hide";
progress?: "show" | "hide";
tone?: "default" | "muted";
landmarkLabel?: string;
};
export function ShoppingCart({
id,
title,
lines,
rows,
promos,
labels,
totals,
actions,
layout = "split",
promo = "show",
progress = "show",
tone = "default",
landmarkLabel,
}: ShoppingCartProps) {
return (
<SectionFrame id={id} title={title} tone={tone} landmarkLabel={landmarkLabel}>
<Box
class={
(layout as string) === "split" ? "grid grid-cols-1 items-start gap-8 lg:grid-cols-3"
: "grid grid-cols-1 gap-8"
}
>
<Stack
gap="4"
align="stretch"
class={(((layout as string) === "split") ? "lg:col-span-2" : "")}
data-slot="lines"
>
{((lines?.length ?? 0) === 0) ? (
<EmptyState icon="shopping-cart" title={actions.empty} />
) : null}
<For each={lines ?? []}>{(line) => (
<Group
gap="4"
align="center"
class="rounded bg-card inset-ring inset-ring-border flex-wrap p-4"
data-slot="item"
>
<MediaFrame alt={line.name} src={line.image} ratio="1/1" class="size-20 shrink-0" />
<Stack gap="0" class="min-w-40 flex-1">
<Text size="sm" weight="semibold">
{line.name}
</Text>
<Text size="xs" class="text-muted-foreground">
{line.variant}
</Text>
<Text size="sm">
{fmtMoney(line.price, line.currency)}
</Text>
</Stack>
<NumberField
value={(line.qty == null ? undefined : String(line.qty))}
name={tpl("{0}-qty-{1}", id, line.id)}
min="1"
label={labels.qty}
decrease={labels.decrease}
increase={labels.increase}
/>
<Text size="base" weight="bold" class="w-24 text-right">
{fmtMoney((line.price * line.qty), line.currency)}
</Text>
<Button variant="ghost" size="sm" layout="icon" aria-label={labels.remove}>
<LucideIcon name="trash" size={16} />
</Button>
</Group>
)}</For>
<Group gap="4" justify="between" class="flex-wrap">
<Button variant="outline" size="default">
<LucideIcon name="arrow-left" size={16} />
{actions.back}
</Button>
<Button variant="ghost" size="default">
{actions.clear}
</Button>
</Group>
</Stack>
<Box class={(((layout as string) === "split") ? "lg:sticky lg:top-8" : "")} data-slot="aside">
<CartSummaryCard
field={tpl("{0}-promo", id)}
lines={lines}
rows={rows}
promos={promos}
labels={totals}
promo={promo}
progress={progress}
/>
</Box>
</Box>
</SectionFrame>
);
}
// 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 ShoppingCartLabels = {
back: string;
clear: 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 shopping-cart// 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/shopping-cart.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/icons"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// ShoppingCartProps are the props of ShoppingCart; the values are the JSON shapes of the TypeScript props.
type ShoppingCartProps struct {
Id any `json:"id"`
Title any `json:"title"`
Lines any `json:"lines"`
Rows any `json:"rows"`
Promos any `json:"promos"`
Labels any `json:"labels"`
Totals any `json:"totals"`
Actions any `json:"actions"`
Layout any `json:"layout"`
Promo any `json:"promo"`
Progress any `json:"progress"`
Tone any `json:"tone"`
LandmarkLabel any `json:"landmarkLabel"`
}
// The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
templ ShoppingCart(p ShoppingCartProps) {
{{ vId := p.Id }}
{{ vTitle := p.Title }}
{{ vLines := p.Lines }}
{{ vRows := p.Rows }}
{{ vPromos := p.Promos }}
{{ vLabels := p.Labels }}
{{ vTotals := p.Totals }}
{{ vActions := p.Actions }}
{{ vLayout := uiutils.Def(p.Layout, "split") }}
{{ vPromo := uiutils.Def(p.Promo, "show") }}
{{ vProgress := uiutils.Def(p.Progress, "show") }}
{{ vTone := uiutils.Def(p.Tone, "default") }}
{{ vLandmarkLabel := p.LandmarkLabel }}
@SectionFrame(SectionFrameProps{Id: vId, Title: vTitle, Tone: vTone, LandmarkLabel: vLandmarkLabel}) {
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "split")), "grid grid-cols-1 items-start gap-8 lg:grid-cols-3", "grid grid-cols-1 gap-8"))}}) {
@compose.Stack(compose.StackProps{Gap: "4", Align: "stretch", BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "split")), "lg:col-span-2", "")), Attrs: uiutils.Attrs("data-slot", "lines")}}) {
if uiutils.Eq(uiutils.Len(vLines), float64(0)) {
@EmptyState(EmptyStateProps{Icon: "shopping-cart", Title: uiutils.Get(vActions, "empty")})
}
for _, vLine := range uiutils.L(vLines) {
@compose.Group(compose.GroupProps{Gap: "4", Align: "center", BoxProps: box.BoxProps{Class: "rounded bg-card inset-ring inset-ring-border flex-wrap p-4", Attrs: uiutils.Attrs("data-slot", "item")}}) {
@MediaFrame(MediaFrameProps{Alt: uiutils.Get(vLine, "name"), Src: uiutils.Get(vLine, "image"), Ratio: "1/1", Class: uiutils.Cnv("size-20 shrink-0")})
@compose.Stack(compose.StackProps{Gap: "0", BoxProps: box.BoxProps{Class: "min-w-40 flex-1"}}) {
@compose.Text(compose.TextProps{Size: "sm", Weight: "semibold", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Get(vLine, "name")) }
}
@compose.Text(compose.TextProps{Size: "xs", TextProps: text.TextProps{Class: "text-muted-foreground"}}) {
{ uiutils.Text(uiutils.Get(vLine, "variant")) }
}
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Money(uiutils.Get(vLine, "price"), uiutils.Get(vLine, "currency"))) }
}
}
@NumberField(NumberFieldProps{Value: uiutils.Str(uiutils.Get(vLine, "qty")), Name: uiutils.Tpl("{0}-qty-{1}", vId, uiutils.Get(vLine, "id")), Min: "1", Label: uiutils.Get(vLabels, "qty"), Decrease: uiutils.Get(vLabels, "decrease"), Increase: uiutils.Get(vLabels, "increase")})
@compose.Text(compose.TextProps{Size: "base", Weight: "bold", TextProps: text.TextProps{Class: "w-24 text-right"}}) {
{ uiutils.Text(uiutils.Money(uiutils.Mul(uiutils.Get(vLine, "price"), uiutils.Get(vLine, "qty")), uiutils.Get(vLine, "currency"))) }
}
@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{AriaLabel: uiutils.S(uiutils.Get(vLabels, "remove"))}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "trash", Size: 16})
}
}
}
@compose.Group(compose.GroupProps{Gap: "4", Justify: "between", BoxProps: box.BoxProps{Class: "flex-wrap"}}) {
@compose.Button(compose.ButtonProps{Variant: "outline", Size: "default", ButtonProps: button.ButtonProps{}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "arrow-left", Size: 16})
{ uiutils.Text(uiutils.Get(vActions, "back")) }
}
@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "default", ButtonProps: button.ButtonProps{}}) {
{ uiutils.Text(uiutils.Get(vActions, "clear")) }
}
}
}
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cond(uiutils.T(uiutils.Eq(vLayout, "split")), "lg:sticky lg:top-8", "")), Attrs: uiutils.Attrs("data-slot", "aside")}}) {
@CartSummaryCard(CartSummaryCardProps{Field: uiutils.Tpl("{0}-promo", vId), Lines: vLines, Rows: vRows, Promos: vPromos, Labels: vTotals, Promo: vPromo, Progress: vProgress})
}
}
}
}
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 shopping-cart{#- 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/shopping-cart.json
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
Props (p): id, title, lines, rows, promos, labels, totals, actions, layout, promo, progress, tone, landmarkLabel. -#}
{%- set v_id = (p.id ?? null) -%}
{%- set v_title = (p.title ?? null) -%}
{%- set v_lines = (p.lines ?? null) -%}
{%- set v_rows = (p.rows ?? null) -%}
{%- set v_promos = (p.promos ?? null) -%}
{%- set v_labels = (p.labels ?? null) -%}
{%- set v_totals = (p.totals ?? null) -%}
{%- set v_actions = (p.actions ?? null) -%}
{%- set v_layout = (p.layout ?? 'split') -%}
{%- set v_promo = (p.promo ?? 'show') -%}
{%- set v_progress = (p.progress ?? 'show') -%}
{%- set v_tone = (p.tone ?? 'default') -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- set c_14 -%}
{%- set c_13 -%}
{%- set c_11 -%}
{%- if og_t(og_eq(og_len(v_lines), 0)) %}
{{ include('blocks/empty-state.html.twig', {'p': {'icon': 'shopping-cart', 'title': og_get(v_actions, ['empty'])}}, with_context = false) }}
{%- endif %}
{%- for v_line in og_l(v_lines) %}
{%- set c_7 -%}
{{ include('blocks/media-frame.html.twig', {'p': {'alt': og_get(v_line, ['name']), 'src': og_get(v_line, ['image']), 'ratio': '1/1', 'className': og_cnv(['size-20 shrink-0'])}}, with_context = false) }}
{%- set c_4 -%}
{%- set c_1 -%}
{{ og_text(og_get(v_line, ['name'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'weight': 'semibold', 'children': c_1}, with_context = false) }}
{%- set c_2 -%}
{{ og_text(og_get(v_line, ['variant'])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'xs', 'class': 'text-muted-foreground', 'children': c_2}, with_context = false) }}
{%- set c_3 -%}
{{ og_text(og_money(og_get(v_line, ['price']), og_get(v_line, ['currency']))) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'children': c_3}, with_context = false) }}
{%- endset -%}
{{ include('compose/Stack.html.twig', {'gap': '0', 'class': 'min-w-40 flex-1', 'children': c_4}, with_context = false) }}
{{ include('blocks/number-field.html.twig', {'p': {'value': og_str(og_get(v_line, ['qty'])), 'name': og_tpl('{0}-qty-{1}', [v_id, og_get(v_line, ['id'])]), 'min': '1', 'label': og_get(v_labels, ['qty']), 'decrease': og_get(v_labels, ['decrease']), 'increase': og_get(v_labels, ['increase'])}}, with_context = false) }}
{%- set c_5 -%}
{{ og_text(og_money(og_mul(og_get(v_line, ['price']), og_get(v_line, ['qty'])), og_get(v_line, ['currency']))) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'base', 'weight': 'bold', 'class': 'w-24 text-right', 'children': c_5}, with_context = false) }}
{%- set c_6 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'trash', 'size': 16}, with_context = false) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'sm', 'layout': 'icon', 'ariaLabel': og_s(og_get(v_labels, ['remove'])), 'children': c_6}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '4', 'align': 'center', 'class': 'rounded bg-card inset-ring inset-ring-border flex-wrap p-4', 'attrs': og_attrs(['data-slot', 'item']), 'children': c_7}, with_context = false) }}
{%- endfor %}
{%- set c_10 -%}
{%- set c_8 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'arrow-left', 'size': 16}, with_context = false) }}
{{ og_text(og_get(v_actions, ['back'])) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'outline', 'size': 'default', 'children': c_8}, with_context = false) }}
{%- set c_9 -%}
{{ og_text(og_get(v_actions, ['clear'])) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'default', 'children': c_9}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '4', 'justify': 'between', 'class': 'flex-wrap', 'children': c_10}, with_context = false) }}
{%- endset -%}
{{ include('compose/Stack.html.twig', {'gap': '4', 'align': 'stretch', 'class': og_s((og_t(og_eq(v_layout, 'split')) ? 'lg:col-span-2' : '')), 'attrs': og_attrs(['data-slot', 'lines']), 'children': c_11}, with_context = false) }}
{%- set c_12 -%}
{{ include('blocks/cart-summary-card.html.twig', {'p': {'field': og_tpl('{0}-promo', [v_id]), 'lines': v_lines, 'rows': v_rows, 'promos': v_promos, 'labels': v_totals, 'promo': v_promo, 'progress': v_progress}}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s((og_t(og_eq(v_layout, 'split')) ? 'lg:sticky lg:top-8' : '')), 'attrs': og_attrs(['data-slot', 'aside']), 'children': c_12}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s((og_t(og_eq(v_layout, 'split')) ? 'grid grid-cols-1 items-start gap-8 lg:grid-cols-3' : 'grid grid-cols-1 gap-8')), 'children': c_13}, with_context = false) }}
{%- endset -%}
{{ include('blocks/section-frame.html.twig', {'p': {'id': v_id, 'title': v_title, 'tone': v_tone, 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_14)}, 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 shopping-cart{* 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/shopping-cart.json
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
Props (p): id, title, lines, rows, promos, labels, totals, actions, layout, promo, progress, tone, landmarkLabel. *}
{var $v_id = ($p['id'] ?? null)}
{var $v_title = ($p['title'] ?? null)}
{var $v_lines = ($p['lines'] ?? null)}
{var $v_rows = ($p['rows'] ?? null)}
{var $v_promos = ($p['promos'] ?? null)}
{var $v_labels = ($p['labels'] ?? null)}
{var $v_totals = ($p['totals'] ?? null)}
{var $v_actions = ($p['actions'] ?? null)}
{var $v_layout = ($p['layout'] ?? 'split')}
{var $v_promo = ($p['promo'] ?? 'show')}
{var $v_progress = ($p['progress'] ?? 'show')}
{var $v_tone = ($p['tone'] ?? 'default')}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{capture $c_14}
{capture $c_13}
{capture $c_11}
{if og_t(og_eq(og_len($v_lines), 0))}
{=og_include('blocks/empty-state.latte', ['p' => ['icon' => 'shopping-cart', 'title' => og_get($v_actions, ['empty'])]])|noescape}
{/if}
{foreach og_l($v_lines) as $v_line}
{capture $c_7}
{=og_include('blocks/media-frame.latte', ['p' => ['alt' => og_get($v_line, ['name']), 'src' => og_get($v_line, ['image']), 'ratio' => '1/1', 'className' => og_cnv(['size-20 shrink-0'])]])|noescape}
{capture $c_4}
{capture $c_1}
{=og_text(og_get($v_line, ['name']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'weight' => 'semibold', 'children' => (string) $c_1])|noescape}
{capture $c_2}
{=og_text(og_get($v_line, ['variant']))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'xs', 'class' => 'text-muted-foreground', 'children' => (string) $c_2])|noescape}
{capture $c_3}
{=og_text(og_money(og_get($v_line, ['price']), og_get($v_line, ['currency'])))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'children' => (string) $c_3])|noescape}
{/capture}
{=og_include('compose/Stack.latte', ['gap' => '0', 'class' => 'min-w-40 flex-1', 'children' => (string) $c_4])|noescape}
{=og_include('blocks/number-field.latte', ['p' => ['value' => og_str(og_get($v_line, ['qty'])), 'name' => og_tpl('{0}-qty-{1}', [$v_id, og_get($v_line, ['id'])]), 'min' => '1', 'label' => og_get($v_labels, ['qty']), 'decrease' => og_get($v_labels, ['decrease']), 'increase' => og_get($v_labels, ['increase'])]])|noescape}
{capture $c_5}
{=og_text(og_money(og_mul(og_get($v_line, ['price']), og_get($v_line, ['qty'])), og_get($v_line, ['currency'])))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'base', 'weight' => 'bold', 'class' => 'w-24 text-right', 'children' => (string) $c_5])|noescape}
{capture $c_6}
{=og_include('icons/LucideIcon.latte', ['name' => 'trash', 'size' => 16])|noescape}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'sm', 'layout' => 'icon', 'ariaLabel' => og_s(og_get($v_labels, ['remove'])), 'children' => (string) $c_6])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '4', 'align' => 'center', 'class' => 'rounded bg-card inset-ring inset-ring-border flex-wrap p-4', 'attrs' => og_attrs(['data-slot', 'item']), 'children' => (string) $c_7])|noescape}
{/foreach}
{capture $c_10}
{capture $c_8}
{=og_include('icons/LucideIcon.latte', ['name' => 'arrow-left', 'size' => 16])|noescape}
{=og_text(og_get($v_actions, ['back']))}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'outline', 'size' => 'default', 'children' => (string) $c_8])|noescape}
{capture $c_9}
{=og_text(og_get($v_actions, ['clear']))}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'default', 'children' => (string) $c_9])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '4', 'justify' => 'between', 'class' => 'flex-wrap', 'children' => (string) $c_10])|noescape}
{/capture}
{=og_include('compose/Stack.latte', ['gap' => '4', 'align' => 'stretch', 'class' => og_s((og_t(og_eq($v_layout, 'split')) ? 'lg:col-span-2' : '')), 'attrs' => og_attrs(['data-slot', 'lines']), 'children' => (string) $c_11])|noescape}
{capture $c_12}
{=og_include('blocks/cart-summary-card.latte', ['p' => ['field' => og_tpl('{0}-promo', [$v_id]), 'lines' => $v_lines, 'rows' => $v_rows, 'promos' => $v_promos, 'labels' => $v_totals, 'promo' => $v_promo, 'progress' => $v_progress]])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s((og_t(og_eq($v_layout, 'split')) ? 'lg:sticky lg:top-8' : '')), 'attrs' => og_attrs(['data-slot', 'aside']), 'children' => (string) $c_12])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s((og_t(og_eq($v_layout, 'split')) ? 'grid grid-cols-1 items-start gap-8 lg:grid-cols-3' : 'grid grid-cols-1 gap-8')), 'children' => (string) $c_13])|noescape}
{/capture}
{=og_include('blocks/section-frame.latte', ['p' => ['id' => $v_id, 'title' => $v_title, 'tone' => $v_tone, 'landmarkLabel' => $v_landmarkLabel], 'children' => og_markup($c_14)])|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 shopping-cart{#- 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/shopping-cart.json
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
Props (p): id, title, lines, rows, promos, labels, totals, actions, layout, promo, progress, tone, landmarkLabel. -#}
{%- set v_id = og_def(p['id'], none) -%}
{%- set v_title = og_def(p['title'], none) -%}
{%- set v_lines = og_def(p['lines'], none) -%}
{%- set v_rows = og_def(p['rows'], none) -%}
{%- set v_promos = og_def(p['promos'], none) -%}
{%- set v_labels = og_def(p['labels'], none) -%}
{%- set v_totals = og_def(p['totals'], none) -%}
{%- set v_actions = og_def(p['actions'], none) -%}
{%- set v_layout = og_def(p['layout'], 'split') -%}
{%- set v_promo = og_def(p['promo'], 'show') -%}
{%- set v_progress = og_def(p['progress'], 'show') -%}
{%- set v_tone = og_def(p['tone'], 'default') -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- set c_14 -%}
{%- set c_13 -%}
{%- set c_11 -%}
{%- if og_t(og_eq(og_len(v_lines), 0)) %}
{{ og_include('blocks/empty-state.html.j2', {'p': {'icon': 'shopping-cart', 'title': og_get(v_actions, ['empty'])}}) }}
{%- endif %}
{%- for v_line in og_l(v_lines) %}
{%- set c_7 -%}
{{ og_include('blocks/media-frame.html.j2', {'p': {'alt': og_get(v_line, ['name']), 'src': og_get(v_line, ['image']), 'ratio': '1/1', 'className': og_cnv(['size-20 shrink-0'])}}) }}
{%- set c_4 -%}
{%- set c_1 -%}
{{ og_text(og_get(v_line, ['name'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm', 'Weight': 'semibold'}, 'children': c_1}) }}
{%- set c_2 -%}
{{ og_text(og_get(v_line, ['variant'])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'xs', 'Class': 'text-muted-foreground'}, 'children': c_2}) }}
{%- set c_3 -%}
{{ og_text(og_money(og_get(v_line, ['price']), og_get(v_line, ['currency']))) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm'}, 'children': c_3}) }}
{%- endset -%}
{{ og_include('compose/stack.html.j2', {'p': {'Gap': '0', 'Class': 'min-w-40 flex-1'}, 'children': c_4}) }}
{{ og_include('blocks/number-field.html.j2', {'p': {'value': og_str(og_get(v_line, ['qty'])), 'name': og_tpl('{0}-qty-{1}', [v_id, og_get(v_line, ['id'])]), 'min': '1', 'label': og_get(v_labels, ['qty']), 'decrease': og_get(v_labels, ['decrease']), 'increase': og_get(v_labels, ['increase'])}}) }}
{%- set c_5 -%}
{{ og_text(og_money(og_mul(og_get(v_line, ['price']), og_get(v_line, ['qty'])), og_get(v_line, ['currency']))) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'base', 'Weight': 'bold', 'Class': 'w-24 text-right'}, 'children': c_5}) }}
{%- set c_6 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'trash', 'Size': 16}}) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'sm', 'Layout': 'icon', 'AriaLabel': og_s(og_get(v_labels, ['remove']))}, 'children': c_6}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Align': 'center', 'Class': 'rounded bg-card inset-ring inset-ring-border flex-wrap p-4', 'Attrs': og_attrs(['data-slot', 'item'])}, 'children': c_7}) }}
{%- endfor %}
{%- set c_10 -%}
{%- set c_8 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'arrow-left', 'Size': 16}}) }}
{{ og_text(og_get(v_actions, ['back'])) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'outline', 'Size': 'default'}, 'children': c_8}) }}
{%- set c_9 -%}
{{ og_text(og_get(v_actions, ['clear'])) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'default'}, 'children': c_9}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Justify': 'between', 'Class': 'flex-wrap'}, 'children': c_10}) }}
{%- endset -%}
{{ og_include('compose/stack.html.j2', {'p': {'Gap': '4', 'Align': 'stretch', 'Class': og_s(('lg:col-span-2' if og_t(og_eq(v_layout, 'split')) else '')), 'Attrs': og_attrs(['data-slot', 'lines'])}, 'children': c_11}) }}
{%- set c_12 -%}
{{ og_include('blocks/cart-summary-card.html.j2', {'p': {'field': og_tpl('{0}-promo', [v_id]), 'lines': v_lines, 'rows': v_rows, 'promos': v_promos, 'labels': v_totals, 'promo': v_promo, 'progress': v_progress}}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(('lg:sticky lg:top-8' if og_t(og_eq(v_layout, 'split')) else '')), 'Attrs': og_attrs(['data-slot', 'aside'])}, 'children': c_12}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(('grid grid-cols-1 items-start gap-8 lg:grid-cols-3' if og_t(og_eq(v_layout, 'split')) else 'grid grid-cols-1 gap-8'))}, 'children': c_13}) }}
{%- endset -%}
{{ og_include('blocks/section-frame.html.j2', {'p': {'id': v_id, 'title': v_title, 'tone': v_tone, 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_14)}) }}
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.
The cart as a page: the lines as cards (picture, name, variant, price, quantity, line total, remove) with the way back, beside the order summary with a promo code and the free-delivery bar. Static markup. Axes: layout (split: the summary beside the lines, stacked: below them), promo (show, hide), progress (show, hide), tone.
| Prop | Type | Default | Description |
|---|---|---|---|
| id (required) | string | - | |
| title (required) | string | - | |
| lines (required) | CartLine[] | - | |
| rows (required) | SummaryRow[] | - | |
| promos (required) | Promo[] | - | |
| labels (required) | CartLabels | - | |
| totals (required) | CartSummaryLabels | - | labels of the order summary |
| actions (required) | ShoppingCartLabels | - | labels of the buttons under the lines, and the empty-cart title |
| layout | "split" | "stacked" | "split" | |
| promo | "show" | "hide" | "show" | |
| progress | "show" | "hide" | "show" | |
| tone | "default" | "muted" | "default" | |
| landmarkLabel | string | - | accessible name of the landmark of this component when the page shows it more than once (a variant); replaces the heading name of the root landmark, follows the name of a nested one |