بلاک‌ها · فروشگاهی
ری‌اکت ۱۹ و Next.js با پیاده‌سازی دسترس‌پذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده

مراحل خرید، روش ارسال، روش پرداخت و خلاصهٔ سفارش.

۱. نصب کامپوننت‌ها

این بلاک از ۱۱ آیتم دیگ استفاده می‌کند: buttoncardcontrol-sizeiconspersianradio-cardradio-groupseparatorsteppertext-fieldtoast

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/radio-card.json https://docs.digdesign.ir/r/radio-group.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/radio-card.json https://docs.digdesign.ir/r/radio-group.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/radio-card.json https://docs.digdesign.ir/r/radio-group.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/radio-card.json https://docs.digdesign.ir/r/radio-group.json https://docs.digdesign.ir/r/separator.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework vue
pnpm dlx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework vue
yarn dlx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework vue
bunx --bun digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework vue
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button --framework svelte
pnpm dlx digdesign@latest add button --framework svelte
yarn dlx digdesign@latest add button --framework svelte
bunx --bun digdesign@latest add button --framework svelte
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button card control-size icons input persian radio-card radio-group separator stepper text-field toast --framework angular
pnpm dlx digdesign@latest add button card control-size icons input persian radio-card radio-group separator stepper text-field toast --framework angular
yarn dlx digdesign@latest add button card control-size icons input persian radio-card radio-group separator stepper text-field toast --framework angular
bunx --bun digdesign@latest add button card control-size icons input persian radio-card radio-group separator stepper text-field toast --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework android
pnpm dlx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework android
yarn dlx digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework android
bunx --bun digdesign@latest add button card control-size persian radio-card radio-group separator stepper text-field toast --framework android

۲. کد صفحه

کد را در صفحهٔ پروژه‌تان بگذارید (React: app/<route>/page.tsx) و متن‌ها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریم‌ورک کدِ همین صفحه در فریم‌ورک دیگر را ببینید.

checkout.tsx
"use client"

import * as React from "react"

import { CheckIcon, CreditCardIcon, ExpressIcon, TruckIcon, WalletIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { RadioCard } from "@/components/ui/radio-card"
import { RadioGroup } from "@/components/ui/radio-group"
import { Separator } from "@/components/ui/separator"
import { TextField } from "@/components/ui/text-field"
import { toast } from "@/components/ui/toast"
import { Stepper, StepperItem, StepperTitle } from "@/components/ui/stepper"
import { formatCurrency, toFaDigits } from "@/lib/persian"
import { stockImages, type StockImageName } from "@/lib/stock-images"

const ITEMS: { id: string; title: string; quantity: number; price: number; image: StockImageName }[] = [
  { id: "1", title: "گلدانِ سرامیکی دوقلو", quantity: 1, price: 3_490_000, image: "productVase" },
  { id: "2", title: "دفترِ یادداشتِ جلدسخت", quantity: 2, price: 180_000, image: "coverNotebook" },
]
const WALLET_BALANCE = 1_345_000
const SHIPPING = [
  { value: "post", label: "پست پیشتاز", note: "۳ تا ۵ روز کاری", price: 45_000, icon: <TruckIcon /> },
  { value: "express", label: "پیک سریع", note: "همان روز در تهران", price: 90_000, icon: <ExpressIcon /> },
]

/**
 * تسویه‌حساب: مراحل، نشانی انتخاب‌شده با «تغییر»، روشِ ارسال و پرداخت با کارت‌های رادیویی
 * (کیف پولِ ناکافی غیرفعال با دلیل)، و خلاصهٔ چسبان با عکسِ اقلام و کدِ تخفیف. نتیجهٔ
 * پرداخت صفحهٔ خودش را دارد.
 */
export default function CheckoutBlock() {
  const [shipping, setShipping] = React.useState("post")
  const [payment, setPayment] = React.useState("card")
  const [paying, setPaying] = React.useState(false)
  const [paid, setPaid] = React.useState(false)
  const subtotal = ITEMS.reduce((sum, item) => sum + item.price * item.quantity, 0)
  const shippingItem = SHIPPING.find((item) => item.value === shipping)!
  const total = subtotal + shippingItem.price
  // کیف پولی که موجودی‌اش به مبلغِ سفارش نمی‌رسد قابل انتخاب نیست، نه این‌که پرداخت بعداً خطا بدهد.
  const walletShort = WALLET_BALANCE < total
  const payments = [
    { value: "card", label: "درگاه بانکی", note: "همهٔ کارت‌های عضو شتاب", icon: <CreditCardIcon />, disabled: false },
    {
      value: "wallet",
      label: "کیف پول",
      note: walletShort
        ? `موجودی ${formatCurrency(WALLET_BALANCE)}؛ برای این سفارش کافی نیست`
        : `موجودی ${formatCurrency(WALLET_BALANCE)}`,
      icon: <WalletIcon />,
      disabled: walletShort,
    },
  ]

  async function pay() {
    setPaying(true)
    await new Promise((resolve) => setTimeout(resolve, 900))
    setPaying(false)
    // نتیجهٔ پرداخت صفحهٔ خودش را می‌خواهد؛ اعلانِ گوشهٔ صفحه ممکن است دیده نشود.
    setPaid(true)
    window.scrollTo({ top: 0 })
  }

  if (paid) {
    return (
      <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-lg flex-col items-center gap-6 p-4 py-12 text-center sm:p-6">
        <span
          aria-hidden
          className="flex size-16 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-8"
        >
          <CheckIcon />
        </span>
        <div className="flex flex-col gap-2" role="status">
          <h1 className="text-2xl font-bold">پرداخت موفق بود</h1>
          <p className="text-muted-foreground">سفارش شما ثبت شد و پیامکِ تأیید برایتان ارسال شد.</p>
        </div>
        <Card className="w-full text-start">
          <CardContent className="flex flex-col gap-3 text-sm">
            <div className="flex justify-between gap-2">
              <span className="text-muted-foreground">کد پیگیری</span>
              <bdi dir="ltr" className="font-semibold tracking-wider">
                {toFaDigits("8821042")}
              </bdi>
            </div>
            <div className="flex justify-between gap-2">
              <span className="text-muted-foreground">مبلغ پرداخت‌شده</span>
              <span className="font-semibold">{formatCurrency(total)}</span>
            </div>
            <div className="flex justify-between gap-2">
              <span className="text-muted-foreground">روش ارسال</span>
              <span>
                {shippingItem.label} · {shippingItem.note}
              </span>
            </div>
          </CardContent>
        </Card>
        <div className="flex w-full flex-col gap-2 sm:flex-row">
          <Button className="flex-1">پیگیری سفارش</Button>
          <Button variant="outline" className="flex-1" onClick={() => setPaid(false)}>
            بازگشت به فروشگاه
          </Button>
        </div>
      </main>
      </ControlSizeProvider>
    )
  }

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6">
        <h1 className="sr-only">تسویه‌حساب</h1>
        <Stepper value={2} className="mx-auto w-full max-w-xl">
          <StepperItem>
            <StepperTitle>سبد خرید</StepperTitle>
          </StepperItem>
          <StepperItem>
            <StepperTitle>آدرس</StepperTitle>
          </StepperItem>
          <StepperItem>
            <StepperTitle>پرداخت</StepperTitle>
          </StepperItem>
        </Stepper>

        <div className="grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_22rem]">
          <div className="flex flex-col gap-6">
            <Card>
              <CardContent className="flex items-start gap-4">
                <div className="flex flex-1 flex-col gap-1">
                  <span className="text-sm text-muted-foreground">ارسال به</span>
                  <span className="font-semibold">خانه · مهسا کریمی</span>
                  <span className="text-sm leading-6 text-muted-foreground">تهران، خیابان ولیعصر، کوچهٔ نسترن، پلاک ۱۲، واحد ۴</span>
                </div>
                <Button variant="outline">تغییر</Button>
              </CardContent>
            </Card>
            <Card>
              <CardHeader>
                <CardTitle className="text-base">روش ارسال</CardTitle>
              </CardHeader>
              <CardContent>
                <RadioGroup name="shipping" value={shipping} onValueChange={setShipping} className="gap-3" aria-label="روش ارسال">
                  {SHIPPING.map((item) => (
                    <RadioCard key={item.value} value={item.value} media={<OptionIcon>{item.icon}</OptionIcon>} title={item.label} description={item.note} aside={<span className="tabular-nums">{formatCurrency(item.price)}</span>} />
                  ))}
                </RadioGroup>
              </CardContent>
            </Card>
            <Card>
              <CardHeader>
                <CardTitle className="text-base">روش پرداخت</CardTitle>
              </CardHeader>
              <CardContent>
                <RadioGroup name="payment" value={payment} onValueChange={setPayment} className="gap-3" aria-label="روش پرداخت">
                  {payments.map((item) => (
                    <RadioCard
                      key={item.value}
                      value={item.value}
                      disabled={item.disabled}
                      media={<OptionIcon>{item.icon}</OptionIcon>}
                      title={item.label}
                      description={item.disabled ? <span className="text-destructive-subtle-foreground">{item.note}</span> : item.note}
                    />
                  ))}
                </RadioGroup>
              </CardContent>
            </Card>
          </div>

          <section aria-labelledby="checkout-summary" className="flex flex-col gap-5 rounded-xl bg-subtle p-6 lg:sticky lg:top-6">
            <h2 id="checkout-summary" className="font-bold">
              خلاصهٔ سفارش
            </h2>
            <ul className="flex flex-col gap-4">
              {ITEMS.map((item) => (
                <li key={item.id} className="flex items-center gap-3 text-sm">
                  {/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
                  <img src={stockImages[item.image].src} alt={stockImages[item.image].alt} className="size-14 rounded-lg object-cover" />
                  <span className="flex flex-1 flex-col gap-0.5">
                    <span className="font-medium">{item.title}</span>
                    <span className="text-muted-foreground">{toFaDigits(item.quantity)} عدد</span>
                  </span>
                  <span className="tabular-nums">{formatCurrency(item.price * item.quantity)}</span>
                </li>
              ))}
            </ul>
            <form
              className="flex items-end gap-2"
              onSubmit={(event) => {
                event.preventDefault()
                toast.error("این کد تخفیف معتبر نیست.")
              }}
            >
              <TextField label="کد تخفیف" name="coupon" dir="ltr" className="flex-1" />
              <Button type="submit" variant="outline">
                اعمال
              </Button>
            </form>
            <Separator />
            <dl className="flex flex-col gap-3 text-sm">
              <div className="flex justify-between gap-2 text-muted-foreground">
                <dt>جمع اقلام</dt>
                <dd className="tabular-nums">{formatCurrency(subtotal)}</dd>
              </div>
              <div className="flex justify-between gap-2 text-muted-foreground">
                <dt>هزینهٔ ارسال</dt>
                <dd className="tabular-nums">{formatCurrency(shippingItem.price)}</dd>
              </div>
              <div className="flex items-baseline justify-between gap-2">
                <dt className="font-semibold">مبلغ قابل پرداخت</dt>
                <dd className="text-xl font-black tabular-nums">{formatCurrency(total)}</dd>
              </div>
            </dl>
            <Button fullWidth loading={paying} onClick={pay} className="mt-3">
              پرداخت {formatCurrency(total)}
            </Button>
          </section>
        </div>
      </main>
    </ControlSizeProvider>
  )
}

function OptionIcon({ children }: { children: React.ReactNode }) {
  return (
    <span
      aria-hidden
      className="flex size-10 shrink-0 items-center justify-center rounded-lg bg-subtle text-foreground group-has-[[data-state=checked]]/radio-card:bg-background [&_svg]:size-5"
    >
      {children}
    </span>
  )
}
checkout.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import Button from "@/components/ui/Button.vue"
import Card from "@/components/ui/Card.vue"
import CardContent from "@/components/ui/CardContent.vue"
import CardHeader from "@/components/ui/CardHeader.vue"
import CardTitle from "@/components/ui/CardTitle.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import RadioCard from "@/components/ui/RadioCard.vue"
import RadioGroup from "@/components/ui/RadioGroup.vue"
import Separator from "@/components/ui/Separator.vue"
import Stepper from "@/components/ui/Stepper.vue"
import StepperItem from "@/components/ui/StepperItem.vue"
import StepperTitle from "@/components/ui/StepperTitle.vue"
import TextField from "@/components/ui/TextField.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"

// تصویرهای کتابخانهٔ تصویرِ دیگ (همان فایل‌های stock-images نسخهٔ React).
const stockImages = {
  productVase: { src: "https://docs.digdesign.ir/images/product-vase.webp", alt: "دو گلدانِ سرامیکیِ سفید کنارِ پارچهٔ کرم" },
  coverNotebook: { src: "https://docs.digdesign.ir/images/cover-notebook.webp", alt: "دفترچه، خودکار، صفحه‌کلید و عینک روی میزِ سفید" },
}
type StockImageName = keyof typeof stockImages

const ITEMS: { id: string; title: string; quantity: number; price: number; image: StockImageName }[] = [
  { id: "1", title: "گلدانِ سرامیکی دوقلو", quantity: 1, price: 3_490_000, image: "productVase" },
  { id: "2", title: "دفترِ یادداشتِ جلدسخت", quantity: 2, price: 180_000, image: "coverNotebook" },
]
const WALLET_BALANCE = 1_345_000
const SHIPPING = [
  { value: "post", label: "پست پیشتاز", note: "۳ تا ۵ روز کاری", price: 45_000, icon: "truck" },
  { value: "express", label: "پیک سریع", note: "همان روز در تهران", price: 90_000, icon: "express" },
]

/**
 * تسویه‌حساب: مراحل، نشانی انتخاب‌شده با «تغییر»، روشِ ارسال و پرداخت با کارت‌های رادیویی
 * (کیف پولِ ناکافی غیرفعال با دلیل)، و خلاصهٔ چسبان با عکسِ اقلام و کدِ تخفیف. نتیجهٔ
 * پرداخت صفحهٔ خودش را دارد.
 */
const shipping = ref("post")
const payment = ref("card")
const paying = ref(false)
const paid = ref(false)
const subtotal = ITEMS.reduce((sum, item) => sum + item.price * item.quantity, 0)
const shippingItem = computed(() => SHIPPING.find((item) => item.value === shipping.value)!)
const total = computed(() => subtotal + shippingItem.value.price)
// کیف پولی که موجودی‌اش به مبلغِ سفارش نمی‌رسد قابل انتخاب نیست، نه این‌که پرداخت بعداً خطا بدهد.
const walletShort = computed(() => WALLET_BALANCE < total.value)
const payments = computed(() => [
  { value: "card", label: "درگاه بانکی", note: "همهٔ کارت‌های عضو شتاب", icon: "credit-card", disabled: false },
  {
    value: "wallet",
    label: "کیف پول",
    note: walletShort.value ? `موجودی ${formatCurrency(WALLET_BALANCE)}؛ برای این سفارش کافی نیست` : `موجودی ${formatCurrency(WALLET_BALANCE)}`,
    icon: "wallet",
    disabled: walletShort.value,
  },
])

async function pay() {
  paying.value = true
  await new Promise((resolve) => setTimeout(resolve, 900))
  paying.value = false
  // نتیجهٔ پرداخت صفحهٔ خودش را می‌خواهد؛ اعلانِ گوشهٔ صفحه ممکن است دیده نشود.
  paid.value = true
  window.scrollTo({ top: 0 })
}

function applyCoupon() {
  toast.error("این کد تخفیف معتبر نیست.")
}
</script>

<template>
  <ControlSize v-if="paid" size="xl" as-child>
    <main class="mx-auto flex w-full max-w-lg flex-col items-center gap-6 p-4 py-12 text-center sm:p-6">
      <span aria-hidden="true" class="flex size-16 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-8">
        <DigIcon name="check" />
      </span>
      <div class="flex flex-col gap-2" role="status">
        <h1 class="text-2xl font-bold">پرداخت موفق بود</h1>
        <p class="text-muted-foreground">سفارش شما ثبت شد و پیامکِ تأیید برایتان ارسال شد.</p>
      </div>
      <Card class="w-full text-start">
        <CardContent class="flex flex-col gap-3 text-sm">
          <div class="flex justify-between gap-2">
            <span class="text-muted-foreground">کد پیگیری</span>
            <bdi dir="ltr" class="font-semibold tracking-wider">{{ toFaDigits("8821042") }}</bdi>
          </div>
          <div class="flex justify-between gap-2">
            <span class="text-muted-foreground">مبلغ پرداخت‌شده</span>
            <span class="font-semibold">{{ formatCurrency(total) }}</span>
          </div>
          <div class="flex justify-between gap-2">
            <span class="text-muted-foreground">روش ارسال</span>
            <span>{{ shippingItem.label }} · {{ shippingItem.note }}</span>
          </div>
        </CardContent>
      </Card>
      <div class="flex w-full flex-col gap-2 sm:flex-row">
        <Button class="flex-1">پیگیری سفارش</Button>
        <Button variant="outline" class="flex-1" @click="paid = false">بازگشت به فروشگاه</Button>
      </div>
    </main>
  </ControlSize>

  <ControlSize v-else size="xl" as-child>
    <main class="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6">
      <h1 class="sr-only">تسویه‌حساب</h1>
      <Stepper :value="2" class="mx-auto w-full max-w-xl">
        <StepperItem>
          <StepperTitle>سبد خرید</StepperTitle>
        </StepperItem>
        <StepperItem>
          <StepperTitle>آدرس</StepperTitle>
        </StepperItem>
        <StepperItem>
          <StepperTitle>پرداخت</StepperTitle>
        </StepperItem>
      </Stepper>

      <div class="grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_22rem]">
        <div class="flex flex-col gap-6">
          <Card>
            <CardContent class="flex items-start gap-4">
              <div class="flex flex-1 flex-col gap-1">
                <span class="text-sm text-muted-foreground">ارسال به</span>
                <span class="font-semibold">خانه · مهسا کریمی</span>
                <span class="text-sm leading-6 text-muted-foreground">تهران، خیابان ولیعصر، کوچهٔ نسترن، پلاک ۱۲، واحد ۴</span>
              </div>
              <Button variant="outline">تغییر</Button>
            </CardContent>
          </Card>
          <Card>
            <CardHeader>
              <CardTitle class="text-base">روش ارسال</CardTitle>
            </CardHeader>
            <CardContent>
              <RadioGroup v-model:value="shipping" name="shipping" class="gap-3" aria-label="روش ارسال">
                <RadioCard v-for="item in SHIPPING" :key="item.value" :value="item.value" :title="item.label" :description="item.note">
                  <template #media>
                    <span aria-hidden="true" class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-subtle text-foreground group-has-[[data-state=checked]]/radio-card:bg-background [&_svg]:size-5">
                      <DigIcon :name="item.icon" />
                    </span>
                  </template>
                  <template #aside>
                    <span class="tabular-nums">{{ formatCurrency(item.price) }}</span>
                  </template>
                </RadioCard>
              </RadioGroup>
            </CardContent>
          </Card>
          <Card>
            <CardHeader>
              <CardTitle class="text-base">روش پرداخت</CardTitle>
            </CardHeader>
            <CardContent>
              <RadioGroup v-model:value="payment" name="payment" class="gap-3" aria-label="روش پرداخت">
                <RadioCard v-for="item in payments" :key="item.value" :value="item.value" :disabled="item.disabled" :title="item.label">
                  <template #media>
                    <span aria-hidden="true" class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-subtle text-foreground group-has-[[data-state=checked]]/radio-card:bg-background [&_svg]:size-5">
                      <DigIcon :name="item.icon" />
                    </span>
                  </template>
                  <template #description>
                    <span v-if="item.disabled" class="text-destructive-subtle-foreground">{{ item.note }}</span>
                    <template v-else>{{ item.note }}</template>
                  </template>
                </RadioCard>
              </RadioGroup>
            </CardContent>
          </Card>
        </div>

        <section aria-labelledby="checkout-summary" class="flex flex-col gap-5 rounded-xl bg-subtle p-6 lg:sticky lg:top-6">
          <h2 id="checkout-summary" class="font-bold">خلاصهٔ سفارش</h2>
          <ul class="flex flex-col gap-4">
            <li v-for="item in ITEMS" :key="item.id" class="flex items-center gap-3 text-sm">
              <img :src="stockImages[item.image].src" :alt="stockImages[item.image].alt" class="size-14 rounded-lg object-cover" />
              <span class="flex flex-1 flex-col gap-0.5">
                <span class="font-medium">{{ item.title }}</span>
                <span class="text-muted-foreground">{{ toFaDigits(item.quantity) }} عدد</span>
              </span>
              <span class="tabular-nums">{{ formatCurrency(item.price * item.quantity) }}</span>
            </li>
          </ul>
          <form class="flex items-end gap-2" @submit.prevent="applyCoupon">
            <TextField label="کد تخفیف" name="coupon" dir="ltr" class="flex-1" />
            <Button type="submit" variant="outline">اعمال</Button>
          </form>
          <Separator />
          <dl class="flex flex-col gap-3 text-sm">
            <div class="flex justify-between gap-2 text-muted-foreground">
              <dt>جمع اقلام</dt>
              <dd class="tabular-nums">{{ formatCurrency(subtotal) }}</dd>
            </div>
            <div class="flex justify-between gap-2 text-muted-foreground">
              <dt>هزینهٔ ارسال</dt>
              <dd class="tabular-nums">{{ formatCurrency(shippingItem.price) }}</dd>
            </div>
            <div class="flex items-baseline justify-between gap-2">
              <dt class="font-semibold">مبلغ قابل پرداخت</dt>
              <dd class="text-xl font-black tabular-nums">{{ formatCurrency(total) }}</dd>
            </div>
          </dl>
          <Button full-width :loading="paying" class="mt-3" @click="pay">پرداخت {{ formatCurrency(total) }}</Button>
        </section>
      </div>
    </main>
  </ControlSize>
</template>

کدِ این بلاک هنوز برای Svelte نوشته نشده است.

این موارد هنوز برای Svelte آماده نیستند: cardcontrol-sizepersianradio-cardradio-groupseparatorsteppertext-fieldtoastآیکون checkآیکون credit-cardآیکون expressآیکون truckآیکون wallet

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننت‌های Svelte می‌سازد.

checkout.ts
import {
  ChangeDetectionStrategy,
  Component,
  DestroyRef,
  computed,
  inject,
  signal,
} from "@angular/core"

import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"
import { DigButton } from "@/components/ui/button"
import {
  DigCard,
  DigCardContent,
  DigCardHeader,
  DigCardTitle,
} from "@/components/ui/card"
import { DigControlSize } from "@/components/ui/control-size"
import { DigInput, DigInputField } from "@/components/ui/input"
import {
  DigRadioCard,
  DigRadioCardAside,
  DigRadioCardMedia,
} from "@/components/ui/radio-card"
import { DigRadioGroup } from "@/components/ui/radio-group"
import { DigSeparator } from "@/components/ui/separator"
import {
  DigStepper,
  DigStepperItem,
  DigStepperTitle,
} from "@/components/ui/stepper"
import { DigTextField } from "@/components/ui/text-field"
import { toast } from "@/components/ui/toast"

const stockImages = {
  productVase: {
    src: "https://docs.digdesign.ir/images/product-vase.webp",
    alt: "دو گلدانِ سرامیکیِ سفید کنارِ پارچهٔ کرم",
  },
  coverNotebook: {
    src: "https://docs.digdesign.ir/images/cover-notebook.webp",
    alt: "دفترچه، خودکار، صفحه‌کلید و عینک روی میزِ سفید",
  },
}
type StockImageName = keyof typeof stockImages

const ITEMS: {
  id: string
  title: string
  quantity: number
  price: number
  image: StockImageName
}[] = [
  {
    id: "1",
    title: "گلدانِ سرامیکی دوقلو",
    quantity: 1,
    price: 3_490_000,
    image: "productVase",
  },
  {
    id: "2",
    title: "دفترِ یادداشتِ جلدسخت",
    quantity: 2,
    price: 180_000,
    image: "coverNotebook",
  },
]
const WALLET_BALANCE = 1_345_000
const SHIPPING = [
  {
    value: "post",
    label: "پست پیشتاز",
    note: "۳ تا ۵ روز کاری",
    price: 45_000,
    icon: "truck",
  },
  {
    value: "express",
    label: "پیک سریع",
    note: "همان روز در تهران",
    price: 90_000,
    icon: "express",
  },
] as const

const subtotal = ITEMS.reduce(
  (sum, item) => sum + item.price * item.quantity,
  0
)

@Component({
  selector: "dig-block-checkout",
  imports: [
    DigButton,
    DigCard,
    DigCardContent,
    DigCardHeader,
    DigCardTitle,
    DigControlSize,
    DigIcon,
    DigInput,
    DigInputField,
    DigRadioCard,
    DigRadioCardAside,
    DigRadioCardMedia,
    DigRadioGroup,
    DigSeparator,
    DigStepper,
    DigStepperItem,
    DigStepperTitle,
    DigTextField,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    @if (paid()) {
      <main
        digControlSize="xl"
        class="mx-auto flex w-full max-w-lg flex-col items-center gap-6 p-4 py-12 text-center sm:p-6"
      >
        <span
          aria-hidden="true"
          class="flex size-16 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-8"
        >
          <svg digIcon="check"></svg>
        </span>
        <div class="flex flex-col gap-2" role="status">
          <h1 class="text-2xl font-bold">پرداخت موفق بود</h1>
          <p class="text-muted-foreground">
            سفارش شما ثبت شد و پیامکِ تأیید برایتان ارسال شد.
          </p>
        </div>
        <section digCard class="w-full text-start">
          <div digCardContent class="flex flex-col gap-3 text-sm">
            <div class="flex justify-between gap-2">
              <span class="text-muted-foreground">کد پیگیری</span>
              <bdi dir="ltr" class="font-semibold tracking-wider">{{
                toFaDigits("8821042")
              }}</bdi>
            </div>
            <div class="flex justify-between gap-2">
              <span class="text-muted-foreground">مبلغ پرداخت‌شده</span>
              <span class="font-semibold">{{ formatCurrency(total()) }}</span>
            </div>
            <div class="flex justify-between gap-2">
              <span class="text-muted-foreground">روش ارسال</span>
              <span
                >{{ shippingItem().label }} · {{ shippingItem().note }}</span
              >
            </div>
          </div>
        </section>
        <div class="flex w-full flex-col gap-2 sm:flex-row">
          <button digButton type="button" class="flex-1">پیگیری سفارش</button>
          <button
            digButton
            type="button"
            variant="outline"
            class="flex-1"
            (click)="paid.set(false)"
          >
            بازگشت به فروشگاه
          </button>
        </div>
      </main>

    } @else {
      <main
        digControlSize="xl"
        class="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6"
      >
        <h1 class="sr-only">تسویه‌حساب</h1>
        <ol digStepper [value]="2" class="mx-auto w-full max-w-xl">
          <li digStepperItem>
            <span digStepperTitle>سبد خرید</span>
          </li>
          <li digStepperItem>
            <span digStepperTitle>آدرس</span>
          </li>
          <li digStepperItem>
            <span digStepperTitle>پرداخت</span>
          </li>
        </ol>

        <div
          class="grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_22rem]"
        >
          <div class="flex flex-col gap-6">
            <section digCard>
              <div digCardContent class="flex items-start gap-4">
                <div class="flex flex-1 flex-col gap-1">
                  <span class="text-sm text-muted-foreground">ارسال به</span>
                  <span class="font-semibold">خانه · مهسا کریمی</span>
                  <span class="text-sm leading-6 text-muted-foreground"
                    >تهران، خیابان ولیعصر، کوچهٔ نسترن، پلاک ۱۲، واحد ۴</span
                  >
                </div>
                <button digButton type="button" variant="outline">تغییر</button>
              </div>
            </section>
            <section digCard>
              <div digCardHeader>
                <h2 digCardTitle class="text-base">روش ارسال</h2>
              </div>
              <div digCardContent>
                <div
                  digRadioGroup
                  [value]="shipping()"
                  (valueChange)="shipping.set($event ?? shipping())"
                  name="shipping"
                  class="gap-3"
                  aria-label="روش ارسال"
                >
                  @for (item of SHIPPING; track item.value) {
                    <label
                      digRadioCard
                      [value]="item.value"
                      [title]="item.label"
                      [description]="item.note"
                    >
                      <span digRadioCardMedia>
                        <span
                          aria-hidden="true"
                          class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-subtle text-foreground group-has-[[data-state=checked]]/radio-card:bg-background [&_svg]:size-5"
                        >
                          <svg [digIcon]="item.icon"></svg>
                        </span>
                      </span>
                      <span
                        digRadioCardAside
                        class="inline-flex items-center gap-2"
                      >
                        <span class="tabular-nums">{{
                          formatCurrency(item.price)
                        }}</span>
                      </span>
                    </label>
                  }
                </div>
              </div>
            </section>
            <section digCard>
              <div digCardHeader>
                <h2 digCardTitle class="text-base">روش پرداخت</h2>
              </div>
              <div digCardContent>
                <div
                  digRadioGroup
                  [value]="payment()"
                  (valueChange)="payment.set($event ?? payment())"
                  name="payment"
                  class="gap-3"
                  aria-label="روش پرداخت"
                >
                  @for (item of payments(); track item.value) {
                    <label
                      digRadioCard
                      [value]="item.value"
                      [disabled]="item.disabled"
                      [title]="item.label"
                      [description]="item.note"
                      [class]="
                        item.disabled
                          ? '[&_[data-slot=radio-card-description]]:text-destructive-subtle-foreground'
                          : ''
                      "
                    >
                      <span digRadioCardMedia>
                        <span
                          aria-hidden="true"
                          class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-subtle text-foreground group-has-[[data-state=checked]]/radio-card:bg-background [&_svg]:size-5"
                        >
                          <svg [digIcon]="item.icon"></svg>
                        </span>
                      </span>
                    </label>
                  }
                </div>
              </div>
            </section>
          </div>

          <section
            aria-labelledby="checkout-summary"
            class="flex flex-col gap-5 rounded-xl bg-subtle p-6 lg:sticky lg:top-6"
          >
            <h2 id="checkout-summary" class="font-bold">خلاصهٔ سفارش</h2>
            <ul class="flex flex-col gap-4">
              @for (item of ITEMS; track item.id) {
                <li class="flex items-center gap-3 text-sm">
                  <img
                    [src]="stockImages[item.image].src"
                    [alt]="stockImages[item.image].alt"
                    class="size-14 rounded-lg object-cover"
                  />
                  <span class="flex flex-1 flex-col gap-0.5">
                    <span class="font-medium">{{ item.title }}</span>
                    <span class="text-muted-foreground"
                      >{{ toFaDigits(item.quantity) }} عدد</span
                    >
                  </span>
                  <span class="tabular-nums">{{
                    formatCurrency(item.price * item.quantity)
                  }}</span>
                </li>
              }
            </ul>
            <form
              class="flex items-end gap-2"
              (submit)="$event.preventDefault(); applyCoupon()"
            >
              <div digTextField label="کد تخفیف" class="flex-1">
                <dig-input
                  ><input digInput name="coupon" dir="ltr"
                /></dig-input>
              </div>
              <button digButton type="submit" variant="outline">اعمال</button>
            </form>
            <div digSeparator></div>
            <dl class="flex flex-col gap-3 text-sm">
              <div class="flex justify-between gap-2 text-muted-foreground">
                <dt>جمع اقلام</dt>
                <dd class="tabular-nums">{{ formatCurrency(subtotal) }}</dd>
              </div>
              <div class="flex justify-between gap-2 text-muted-foreground">
                <dt>هزینهٔ ارسال</dt>
                <dd class="tabular-nums">
                  {{ formatCurrency(shippingItem().price) }}
                </dd>
              </div>
              <div class="flex items-baseline justify-between gap-2">
                <dt class="font-semibold">مبلغ قابل پرداخت</dt>
                <dd class="text-xl font-black tabular-nums">
                  {{ formatCurrency(total()) }}
                </dd>
              </div>
            </dl>
            <button
              digButton
              type="button"
              fullWidth
              [loading]="paying()"
              class="mt-3"
              (click)="pay()"
            >
              پرداخت {{ formatCurrency(total()) }}
            </button>
          </section>
        </div>
      </main>
    }
  `,
})
export class CheckoutBlock {
  readonly stockImages = stockImages
  readonly ITEMS = ITEMS
  readonly SHIPPING = SHIPPING
  readonly subtotal = subtotal
  readonly formatCurrency = formatCurrency
  readonly toFaDigits = toFaDigits

  readonly shipping = signal("post")
  readonly payment = signal("card")
  readonly paying = signal(false)
  readonly paid = signal(false)
  readonly shippingItem = computed(
    () => SHIPPING.find((item) => item.value === this.shipping()) ?? SHIPPING[0]
  )
  readonly total = computed(() => subtotal + this.shippingItem().price)
  readonly walletShort = computed(() => WALLET_BALANCE < this.total())
  readonly payments = computed(
    () =>
      [
        {
          value: "card",
          label: "درگاه بانکی",
          note: "همهٔ کارت‌های عضو شتاب",
          icon: "credit-card",
          disabled: false,
        },
        {
          value: "wallet",
          label: "کیف پول",
          note: this.walletShort()
            ? `موجودی ${formatCurrency(WALLET_BALANCE)}؛ برای این سفارش کافی نیست`
            : `موجودی ${formatCurrency(WALLET_BALANCE)}`,
          icon: "wallet",
          disabled: this.walletShort(),
        },
      ] as const
  )

  private payTimer?: ReturnType<typeof setTimeout>

  constructor() {
    inject(DestroyRef).onDestroy(() => clearTimeout(this.payTimer))
  }

  pay() {
    if (this.paying()) return
    this.paying.set(true)
    this.payTimer = setTimeout(() => {
      this.paying.set(false)
      this.paid.set(true)
      window.scrollTo({ top: 0 })
    }, 900)
  }

  applyCoupon() {
    toast.error("این کد تخفیف معتبر نیست.")
  }
}

کدِ این بلاک هنوز برای Android نوشته نشده است.

همهٔ کامپوننت‌های لازم برای Android آماده‌اند؛ با MCP می‌توانید همین صفحه را از روی نسخهٔ React بسازید.

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننت‌های Android می‌سازد.