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

گالری تصاویر، امتیاز، قیمت، انتخاب رنگ و تعداد، افزودن به سبد، مشخصات و معرفی.

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

این بلاک از ۱۲ آیتم دیگ استفاده می‌کند: add-to-cartbadgebuttonchipcolor-swatch-pickercontrol-sizeiconslabelpersianproduct-cardtabstoggle-group

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/add-to-cart.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/color-swatch-picker.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/product-card.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toggle-group.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/add-to-cart.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/color-swatch-picker.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/product-card.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toggle-group.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/add-to-cart.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/color-swatch-picker.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/product-card.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toggle-group.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/add-to-cart.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/color-swatch-picker.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/product-card.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toggle-group.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework vue
pnpm dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework vue
yarn dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework vue
bunx --bun digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --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 add-to-cart badge button chip color-swatch-picker control-size icons label persian product-card tabs toggle-group --framework angular
pnpm dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size icons label persian product-card tabs toggle-group --framework angular
yarn dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size icons label persian product-card tabs toggle-group --framework angular
bunx --bun digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size icons label persian product-card tabs toggle-group --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework android
pnpm dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework android
yarn dlx digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework android
bunx --bun digdesign@latest add add-to-cart badge button chip color-swatch-picker control-size label persian product-card tabs toggle-group --framework android

۲. کد صفحه

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

product-detail.tsx
"use client"

import * as React from "react"

import { HeartIcon, RefreshIcon, ShieldCheckIcon, StarIcon, TruckIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
import { AddToCart } from "@/components/ui/add-to-cart"
import { Button } from "@/components/ui/button"
import { Chip } from "@/components/ui/chip"
import { ColorSwatchPicker, ColorSwatchPickerItem } from "@/components/ui/color-swatch-picker"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Label } from "@/components/ui/label"
import { ProductCard, ProductCardBody, ProductCardMedia, ProductCardPrice, ProductCardTitle } from "@/components/ui/product-card"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { stockImages, type StockImageName } from "@/lib/stock-images"
import { formatCurrency } from "@/lib/persian"

const VIEWS: { label: string; image: StockImageName }[] = [
  { label: "نمای روبه‌رو", image: "headphonesLight" },
  { label: "در دست", image: "headphonesHand" },
  { label: "روی پایه", image: "headphonesStand" },
  { label: "زمینهٔ تیره", image: "headphonesDark" },
]
// رنگِ واقعی کالا داده است، نه توکنِ رابط؛ از پالتِ پایهٔ دیگ می‌آید تا hex خام نباشد.
const COLORS = [
  { value: "black", label: "مشکی", swatch: "var(--dig-graphite-900)" },
  { value: "white", label: "سفید", swatch: "var(--dig-neutral-50)" },
  { value: "blue", label: "سرمه‌ای", swatch: "var(--dig-blue-900)" },
  { value: "sage", label: "سبزِ مریمی", swatch: "var(--dig-green-300)" },
]
const FEATURES = ["حذفِ نویزِ فعال", "۳۰ ساعت شارژ", "بلوتوث ۵٫۳", "ضدِ تعریق"]
const SPECS = [
  ["اتصال", "بلوتوث ۵٫۳"],
  ["شارژدهی", "تا ۳۰ ساعت"],
  ["وزن", "۲۵۰ گرم"],
  ["گارانتی", "۱۸ ماه"],
]
const PROMISES = [
  { icon: <TruckIcon />, title: "ارسالِ رایگان", detail: "تحویلِ ۲ روزه" },
  { icon: <ShieldCheckIcon />, title: "۱۸ ماه گارانتی", detail: "اصالت و سلامت" },
  { icon: <RefreshIcon />, title: "۷ روز بازگشت", detail: "بدونِ پرسش" },
]
const RELATED: { id: string; title: string; price: number; image: StockImageName }[] = [
  { id: "r1", title: "پایهٔ رومیزیِ چوبیِ هدفون", price: 690_000, image: "headphonesWoodStand" },
  { id: "r2", title: "کابلِ شارژِ تایپ‌سیِ بافته‌شده", price: 180_000, image: "cableUsbC" },
  { id: "r3", title: "پاوربانکِ ۲۰ هزار با سه کابل", price: 1_890_000, image: "powerBank" },
  { id: "r4", title: "ایربادِ بی‌سیم با کیفِ شارژ", price: 1_250_000, image: "earbuds" },
]

export default function ProductDetailBlock() {
  const [view, setView] = React.useState(VIEWS[0].label)
  const current = VIEWS.find((item) => item.label === view) ?? VIEWS[0]
  const [color, setColor] = React.useState("black")
  const [liked, setLiked] = React.useState(false)

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-6xl flex-col gap-12 p-4 sm:p-6">
        <div className="grid grid-cols-1 gap-8 md:grid-cols-2 lg:gap-12">
          {/* گالری: تصویرِ اصلی با برچسب‌های روی تصویر، زیرش بندانگشتی‌ها. */}
          <section aria-label="تصاویر محصول" className="flex flex-col gap-3 self-start">
            <div className="relative aspect-square overflow-hidden rounded-xl bg-muted">
              {/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
              <img src={stockImages[current.image].src} alt={`هدفون بی‌سیم دیگ پرو، ${current.label}`} className="size-full object-cover" />
              <span className="absolute start-4 top-4 rounded-full bg-background px-3 py-1 text-xs font-semibold">تازه رسید</span>
              <span className="absolute end-4 top-4 flex items-center gap-1 rounded-full bg-background px-2.5 py-1 text-xs font-semibold">
                <StarIcon className="size-3.5 text-warning-subtle-foreground" />
                ۴٫۴
              </span>
            </div>
            <ToggleGroup
              type="single"
              value={view}
              onValueChange={(next) => next && setView(next as string)}
              aria-label="انتخاب تصویر"
              className="grid w-full grid-cols-4 gap-3"
            >
              {VIEWS.map((item) => (
                <ToggleGroupItem
                  key={item.label}
                  value={item.label}
                  aria-label={item.label}
                  className="aspect-square h-auto w-full overflow-hidden rounded-lg! bg-muted p-0 data-[state=on]:bg-muted data-[state=on]:ring-2 data-[state=on]:ring-foreground data-[state=on]:ring-offset-2 data-[state=on]:ring-offset-background"
                >
                  {/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
                  <img src={stockImages[item.image].src} alt="" className="size-full object-cover" />
                </ToggleGroupItem>
              ))}
            </ToggleGroup>
          </section>

          {/* سلسله‌مراتب: معرفی، قیمت، ویژگی‌ها، انتخاب‌ها، خرید، تعهدها؛ هر گروه با فاصلهٔ بیشتر از قبلی. */}
          <section aria-label="جزئیات محصول" className="flex flex-col">
            <div className="flex flex-col gap-3">
              <span className="text-sm font-medium text-brand-secondary">صوتی / هدفون بی‌سیم</span>
              <h1 className="text-3xl leading-snug font-bold">هدفون بی‌سیم دیگ پرو</h1>
              <p className="leading-7 text-muted-foreground">
                حذفِ نویزِ فعال و باتری سی‌ساعته برای رفت‌وآمدِ روزانه و کار در فضای شلوغ؛ سبک، تاشو و همراهِ هر روز.
              </p>
            </div>

            <div className="mt-6 flex flex-col gap-1.5">
              <div className="flex flex-wrap items-center gap-3">
                <span className="text-3xl font-bold">{formatCurrency(3_490_000)}</span>
                <Badge variant="soft" color="success">
                  ارسالِ رایگان
                </Badge>
              </div>
              <div className="flex items-center gap-2 text-sm text-muted-foreground">
                <s>{formatCurrency(4_100_000)}</s>
                <Badge color="destructive" size="sm">
                  ٪۱۵
                </Badge>
                <span>· قیمت با مالیات</span>
              </div>
            </div>

            <ul aria-label="ویژگی‌ها" className="mt-6 flex flex-wrap gap-2">
              {FEATURES.map((feature) => (
                <li key={feature}>
                  <Chip variant="soft">{feature}</Chip>
                </li>
              ))}
            </ul>

            <ControlSizeProvider size="xl">
              <div className="mt-8 flex flex-col gap-3">
                <Label id="color-label" className="gap-1">
                  رنگ:
                  <span className="font-normal text-muted-foreground">{COLORS.find((item) => item.value === color)?.label}</span>
                </Label>
                <ColorSwatchPicker
                  value={color}
                  onValueChange={setColor}
                  aria-labelledby="color-label"
                  size="md"
                  radius="full"
                  indicator="ring"
                  className="gap-3 p-1"
                >
                  {COLORS.map((item) => (
                    <ColorSwatchPickerItem key={item.value} value={item.value} color={item.swatch} label={item.label} />
                  ))}
                </ColorSwatchPicker>
              </div>

              {/* تعداد بعد از افزودن روی همین دکمه انتخاب می‌شود؛ فیلدِ جدا لازم نیست. */}
              <div className="mt-8 flex gap-3">
                <AddToCart variant="default" fullWidth label="افزودن به سبد خرید" itemName="هدفون" max={7} className="flex-1" />
                <Button
                  variant="outline"
                  size="icon"
                  aria-pressed={liked}
                  aria-label={liked ? "حذف از علاقه‌مندی‌ها" : "افزودن به علاقه‌مندی‌ها"}
                  onClick={() => setLiked((value) => !value)}
                  className={liked ? "text-destructive hover:text-destructive" : undefined}
                >
                  <HeartIcon filled={liked} />
                </Button>
              </div>
            </ControlSizeProvider>

            <ul aria-label="تعهدهای فروشگاه" className="mt-8 grid grid-cols-3 gap-3">
              {PROMISES.map((item) => (
                <li key={item.title} className="flex flex-col items-center gap-2 rounded-xl border border-border p-3 text-center">
                  <span aria-hidden className="text-muted-foreground [&_svg]:size-5">
                    {item.icon}
                  </span>
                  <span className="flex flex-col gap-0.5">
                    <span className="text-sm font-semibold">{item.title}</span>
                    <span className="text-xs text-muted-foreground">{item.detail}</span>
                  </span>
                </li>
              ))}
            </ul>
          </section>
        </div>

        <Tabs defaultValue="specs" className="gap-4">
          <TabsList>
            <TabsTrigger value="specs">مشخصات</TabsTrigger>
            <TabsTrigger value="about">معرفی</TabsTrigger>
          </TabsList>
          <TabsContent value="specs">
            <dl className="grid grid-cols-1 gap-x-8 text-sm sm:grid-cols-2">
              {SPECS.map(([key, value]) => (
                <div key={key} className="flex justify-between gap-4 border-b border-border py-3">
                  <dt className="text-muted-foreground">{key}</dt>
                  <dd className="font-medium">{value}</dd>
                </div>
              ))}
            </dl>
          </TabsContent>
          <TabsContent value="about">
            <p className="max-w-3xl text-sm leading-7 text-muted-foreground">
              هدفون دیگ پرو با حذف نویز فعال و باتری سی‌ساعته برای رفت‌وآمد روزانه و کار در فضای شلوغ ساخته شده است.
            </p>
          </TabsContent>
        </Tabs>

        <section aria-labelledby="related-title" className="flex flex-col gap-4">
          <h2 id="related-title" className="text-xl font-bold">
            معمولاً با هم خریده می‌شوند
          </h2>
          <div className="flex gap-3 overflow-x-auto pb-2">
            {RELATED.map((item) => (
              <ProductCard key={item.id} size="sm">
                <ProductCardMedia>
                  {/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
                  <img src={stockImages[item.image].src} alt={stockImages[item.image].alt} loading="lazy" />
                </ProductCardMedia>
                <ProductCardBody>
                  <ProductCardTitle>{item.title}</ProductCardTitle>
                  <ProductCardPrice amount={formatCurrency(item.price)} />
                </ProductCardBody>
              </ProductCard>
            ))}
          </div>
        </section>
      </main>
    </ControlSizeProvider>
  )
}
product-detail.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import AddToCart from "@/components/ui/AddToCart.vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import Chip from "@/components/ui/Chip.vue"
import ColorSwatchPicker from "@/components/ui/ColorSwatchPicker.vue"
import ColorSwatchPickerItem from "@/components/ui/ColorSwatchPickerItem.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Label from "@/components/ui/Label.vue"
import ProductCard from "@/components/ui/ProductCard.vue"
import ProductCardBody from "@/components/ui/ProductCardBody.vue"
import ProductCardMedia from "@/components/ui/ProductCardMedia.vue"
import ProductCardPrice from "@/components/ui/ProductCardPrice.vue"
import ProductCardTitle from "@/components/ui/ProductCardTitle.vue"
import Tabs from "@/components/ui/Tabs.vue"
import TabsContent from "@/components/ui/TabsContent.vue"
import TabsList from "@/components/ui/TabsList.vue"
import TabsTrigger from "@/components/ui/TabsTrigger.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency } from "@/lib/persian"

// stock-images:begin
/** تصویرهای کتابخانهٔ دیگ (همان آدرس‌های `stockImages` نسخهٔ React). */
const stockImages = {
  headphonesLight: { src: "https://docs.digdesign.ir/images/headphones-light.webp", alt: "هدفونِ بی‌سیمِ مشکی روی میزِ سفید" },
  headphonesHand: { src: "https://docs.digdesign.ir/images/headphones-hand.webp", alt: "دستی که هدفونِ مشکی را گرفته" },
  headphonesStand: { src: "https://docs.digdesign.ir/images/headphones-stand.webp", alt: "هدفونِ مشکی روی پایهٔ چوبی" },
  headphonesDark: { src: "https://docs.digdesign.ir/images/headphones-dark.webp", alt: "هدفونِ مشکی روی زمینهٔ تیره" },
  headphonesWoodStand: { src: "https://docs.digdesign.ir/images/headphones-wood-stand.webp", alt: "هدفون روی پایهٔ چوبیِ رومیزی کنارِ گیاه" },
  cableUsbC: { src: "https://docs.digdesign.ir/images/cable-usb-c.webp", alt: "کابلِ مشکیِ بافته با سرِ تایپ‌سی" },
  powerBank: { src: "https://docs.digdesign.ir/images/power-bank.webp", alt: "پاوربانکِ سفید با سه کابلِ شارژ" },
  earbuds: { src: "https://docs.digdesign.ir/images/earbuds.webp", alt: "دو جفت ایربادِ بی‌سیم با کیف روی زمینهٔ یاسی" },
}
// stock-images:end
type StockImageName = keyof typeof stockImages

const VIEWS: { label: string; image: StockImageName }[] = [
  { label: "نمای روبه‌رو", image: "headphonesLight" },
  { label: "در دست", image: "headphonesHand" },
  { label: "روی پایه", image: "headphonesStand" },
  { label: "زمینهٔ تیره", image: "headphonesDark" },
]
// رنگِ واقعی کالا داده است، نه توکنِ رابط؛ از پالتِ پایهٔ دیگ می‌آید تا hex خام نباشد.
const COLORS = [
  { value: "black", label: "مشکی", swatch: "var(--dig-graphite-900)" },
  { value: "white", label: "سفید", swatch: "var(--dig-neutral-50)" },
  { value: "blue", label: "سرمه‌ای", swatch: "var(--dig-blue-900)" },
  { value: "sage", label: "سبزِ مریمی", swatch: "var(--dig-green-300)" },
]
const FEATURES = ["حذفِ نویزِ فعال", "۳۰ ساعت شارژ", "بلوتوث ۵٫۳", "ضدِ تعریق"]
const SPECS = [
  ["اتصال", "بلوتوث ۵٫۳"],
  ["شارژدهی", "تا ۳۰ ساعت"],
  ["وزن", "۲۵۰ گرم"],
  ["گارانتی", "۱۸ ماه"],
]
const PROMISES = [
  { icon: "truck", title: "ارسالِ رایگان", detail: "تحویلِ ۲ روزه" },
  { icon: "shield-check", title: "۱۸ ماه گارانتی", detail: "اصالت و سلامت" },
  { icon: "refresh", title: "۷ روز بازگشت", detail: "بدونِ پرسش" },
] as const
const RELATED: { id: string; title: string; price: number; image: StockImageName }[] = [
  { id: "r1", title: "پایهٔ رومیزیِ چوبیِ هدفون", price: 690_000, image: "headphonesWoodStand" },
  { id: "r2", title: "کابلِ شارژِ تایپ‌سیِ بافته‌شده", price: 180_000, image: "cableUsbC" },
  { id: "r3", title: "پاوربانکِ ۲۰ هزار با سه کابل", price: 1_890_000, image: "powerBank" },
  { id: "r4", title: "ایربادِ بی‌سیم با کیفِ شارژ", price: 1_250_000, image: "earbuds" },
]

const view = ref(VIEWS[0].label)
const current = computed(() => VIEWS.find((item) => item.label === view.value) ?? VIEWS[0])
const color = ref("black")
const liked = ref(false)

function onViewChange(next: string | string[] | undefined) {
  if (next) view.value = next as string
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full max-w-6xl flex-col gap-12 p-4 sm:p-6">
      <div class="grid grid-cols-1 gap-8 md:grid-cols-2 lg:gap-12">
        <!-- گالری: تصویرِ اصلی با برچسب‌های روی تصویر، زیرش بندانگشتی‌ها. -->
        <section aria-label="تصاویر محصول" class="flex flex-col gap-3 self-start">
          <div class="relative aspect-square overflow-hidden rounded-xl bg-muted">
            <img :src="stockImages[current.image].src" :alt="`هدفون بی‌سیم دیگ پرو، ${current.label}`" class="size-full object-cover" />
            <span class="absolute start-4 top-4 rounded-full bg-background px-3 py-1 text-xs font-semibold">تازه رسید</span>
            <span class="absolute end-4 top-4 flex items-center gap-1 rounded-full bg-background px-2.5 py-1 text-xs font-semibold">
              <DigIcon name="star" class="size-3.5 text-warning-subtle-foreground" />
              ۴٫۴
            </span>
          </div>
          <ToggleGroup type="single" :value="view" aria-label="انتخاب تصویر" class="grid w-full grid-cols-4 gap-3" @update:value="onViewChange">
            <ToggleGroupItem
              v-for="item in VIEWS"
              :key="item.label"
              :value="item.label"
              :aria-label="item.label"
              class="aspect-square h-auto w-full overflow-hidden rounded-lg! bg-muted p-0 data-[state=on]:bg-muted data-[state=on]:ring-2 data-[state=on]:ring-foreground data-[state=on]:ring-offset-2 data-[state=on]:ring-offset-background"
            >
              <img :src="stockImages[item.image].src" alt="" class="size-full object-cover" />
            </ToggleGroupItem>
          </ToggleGroup>
        </section>

        <!-- سلسله‌مراتب: معرفی، قیمت، ویژگی‌ها، انتخاب‌ها، خرید، تعهدها؛ هر گروه با فاصلهٔ بیشتر از قبلی. -->
        <section aria-label="جزئیات محصول" class="flex flex-col">
          <div class="flex flex-col gap-3">
            <span class="text-sm font-medium text-brand-secondary">صوتی / هدفون بی‌سیم</span>
            <h1 class="text-3xl leading-snug font-bold">هدفون بی‌سیم دیگ پرو</h1>
            <p class="leading-7 text-muted-foreground">
              حذفِ نویزِ فعال و باتری سی‌ساعته برای رفت‌وآمدِ روزانه و کار در فضای شلوغ؛ سبک، تاشو و همراهِ هر روز.
            </p>
          </div>

          <div class="mt-6 flex flex-col gap-1.5">
            <div class="flex flex-wrap items-center gap-3">
              <span class="text-3xl font-bold">{{ formatCurrency(3_490_000) }}</span>
              <Badge variant="soft" color="success">ارسالِ رایگان</Badge>
            </div>
            <div class="flex items-center gap-2 text-sm text-muted-foreground">
              <s>{{ formatCurrency(4_100_000) }}</s>
              <Badge color="destructive" size="sm">٪۱۵</Badge>
              <span>· قیمت با مالیات</span>
            </div>
          </div>

          <ul aria-label="ویژگی‌ها" class="mt-6 flex flex-wrap gap-2">
            <li v-for="feature in FEATURES" :key="feature">
              <Chip variant="soft">{{ feature }}</Chip>
            </li>
          </ul>

          <ControlSize size="xl">
            <div class="mt-8 flex flex-col gap-3">
              <Label id="color-label" class="gap-1">
                رنگ:
                <span class="font-normal text-muted-foreground">{{ COLORS.find((item) => item.value === color)?.label }}</span>
              </Label>
              <ColorSwatchPicker v-model:value="color" aria-labelledby="color-label" size="md" radius="full" indicator="ring" class="gap-3 p-1">
                <ColorSwatchPickerItem v-for="item in COLORS" :key="item.value" :value="item.value" :color="item.swatch" :label="item.label" />
              </ColorSwatchPicker>
            </div>

            <!-- تعداد بعد از افزودن روی همین دکمه انتخاب می‌شود؛ فیلدِ جدا لازم نیست. -->
            <div class="mt-8 flex gap-3">
              <AddToCart variant="default" full-width label="افزودن به سبد خرید" item-name="هدفون" :max="7" class="flex-1" />
              <Button
                variant="outline"
                size="icon"
                :aria-pressed="liked"
                :aria-label="liked ? 'حذف از علاقه‌مندی‌ها' : 'افزودن به علاقه‌مندی‌ها'"
                :class="liked ? 'text-destructive hover:text-destructive' : undefined"
                @click="liked = !liked"
              >
                <DigIcon :name="liked ? 'heart-filled' : 'heart'" />
              </Button>
            </div>
          </ControlSize>

          <ul aria-label="تعهدهای فروشگاه" class="mt-8 grid grid-cols-3 gap-3">
            <li v-for="item in PROMISES" :key="item.title" class="flex flex-col items-center gap-2 rounded-xl border border-border p-3 text-center">
              <span aria-hidden="true" class="text-muted-foreground [&_svg]:size-5">
                <DigIcon :name="item.icon" />
              </span>
              <span class="flex flex-col gap-0.5">
                <span class="text-sm font-semibold">{{ item.title }}</span>
                <span class="text-xs text-muted-foreground">{{ item.detail }}</span>
              </span>
            </li>
          </ul>
        </section>
      </div>

      <Tabs default-value="specs" class="gap-4">
        <TabsList>
          <TabsTrigger value="specs">مشخصات</TabsTrigger>
          <TabsTrigger value="about">معرفی</TabsTrigger>
        </TabsList>
        <TabsContent value="specs">
          <dl class="grid grid-cols-1 gap-x-8 text-sm sm:grid-cols-2">
            <div v-for="[key, value] in SPECS" :key="key" class="flex justify-between gap-4 border-b border-border py-3">
              <dt class="text-muted-foreground">{{ key }}</dt>
              <dd class="font-medium">{{ value }}</dd>
            </div>
          </dl>
        </TabsContent>
        <TabsContent value="about">
          <p class="max-w-3xl text-sm leading-7 text-muted-foreground">
            هدفون دیگ پرو با حذف نویز فعال و باتری سی‌ساعته برای رفت‌وآمد روزانه و کار در فضای شلوغ ساخته شده است.
          </p>
        </TabsContent>
      </Tabs>

      <section aria-labelledby="related-title" class="flex flex-col gap-4">
        <h2 id="related-title" class="text-xl font-bold">معمولاً با هم خریده می‌شوند</h2>
        <div class="flex gap-3 overflow-x-auto pb-2">
          <ProductCard v-for="item in RELATED" :key="item.id" size="sm">
            <ProductCardMedia>
              <img :src="stockImages[item.image].src" :alt="stockImages[item.image].alt" loading="lazy" />
            </ProductCardMedia>
            <ProductCardBody>
              <ProductCardTitle>{{ item.title }}</ProductCardTitle>
              <ProductCardPrice :amount="formatCurrency(item.price)" />
            </ProductCardBody>
          </ProductCard>
        </div>
      </section>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: add-to-cartbadgechipcolor-swatch-pickercontrol-sizelabelpersianproduct-cardtabstoggle-groupآیکون heartآیکون refreshآیکون shield-checkآیکون starآیکون truck

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

product-detail.ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  signal,
} from "@angular/core"

import { DigIcon } from "@/lib/icons"
import { formatCurrency } from "@/lib/persian"
import { DigAddToCart } from "@/components/ui/add-to-cart"
import { DigBadge } from "@/components/ui/badge"
import { DigButton } from "@/components/ui/button"
import { DigChip } from "@/components/ui/chip"
import {
  DigColorSwatchPicker,
  DigColorSwatchPickerItem,
} from "@/components/ui/color-swatch-picker"
import { DigControlSize } from "@/components/ui/control-size"
import { DigLabel } from "@/components/ui/label"
import {
  DigProductCard,
  DigProductCardBody,
  DigProductCardMedia,
  DigProductCardPrice,
  DigProductCardTitle,
} from "@/components/ui/product-card"
import {
  DigTabs,
  DigTabsContent,
  DigTabsList,
  DigTabsTrigger,
} from "@/components/ui/tabs"
import {
  DigToggleGroup,
  DigToggleGroupItem,
} from "@/components/ui/toggle-group"

const stockImages = {
  headphonesLight: {
    src: "https://docs.digdesign.ir/images/headphones-light.webp",
    alt: "هدفونِ بی‌سیمِ مشکی روی میزِ سفید",
  },
  headphonesHand: {
    src: "https://docs.digdesign.ir/images/headphones-hand.webp",
    alt: "دستی که هدفونِ مشکی را گرفته",
  },
  headphonesStand: {
    src: "https://docs.digdesign.ir/images/headphones-stand.webp",
    alt: "هدفونِ مشکی روی پایهٔ چوبی",
  },
  headphonesDark: {
    src: "https://docs.digdesign.ir/images/headphones-dark.webp",
    alt: "هدفونِ مشکی روی زمینهٔ تیره",
  },
  headphonesWoodStand: {
    src: "https://docs.digdesign.ir/images/headphones-wood-stand.webp",
    alt: "هدفون روی پایهٔ چوبیِ رومیزی کنارِ گیاه",
  },
  cableUsbC: {
    src: "https://docs.digdesign.ir/images/cable-usb-c.webp",
    alt: "کابلِ مشکیِ بافته با سرِ تایپ‌سی",
  },
  powerBank: {
    src: "https://docs.digdesign.ir/images/power-bank.webp",
    alt: "پاوربانکِ سفید با سه کابلِ شارژ",
  },
  earbuds: {
    src: "https://docs.digdesign.ir/images/earbuds.webp",
    alt: "دو جفت ایربادِ بی‌سیم با کیف روی زمینهٔ یاسی",
  },
}

type StockImageName = keyof typeof stockImages

const VIEWS: { label: string; image: StockImageName }[] = [
  { label: "نمای روبه‌رو", image: "headphonesLight" },
  { label: "در دست", image: "headphonesHand" },
  { label: "روی پایه", image: "headphonesStand" },
  { label: "زمینهٔ تیره", image: "headphonesDark" },
]

const COLORS = [
  { value: "black", label: "مشکی", swatch: "var(--dig-graphite-900)" },
  { value: "white", label: "سفید", swatch: "var(--dig-neutral-50)" },
  { value: "blue", label: "سرمه‌ای", swatch: "var(--dig-blue-900)" },
  { value: "sage", label: "سبزِ مریمی", swatch: "var(--dig-green-300)" },
]
const FEATURES = ["حذفِ نویزِ فعال", "۳۰ ساعت شارژ", "بلوتوث ۵٫۳", "ضدِ تعریق"]
const SPECS = [
  ["اتصال", "بلوتوث ۵٫۳"],
  ["شارژدهی", "تا ۳۰ ساعت"],
  ["وزن", "۲۵۰ گرم"],
  ["گارانتی", "۱۸ ماه"],
]
const PROMISES = [
  { icon: "truck", title: "ارسالِ رایگان", detail: "تحویلِ ۲ روزه" },
  { icon: "shield-check", title: "۱۸ ماه گارانتی", detail: "اصالت و سلامت" },
  { icon: "refresh", title: "۷ روز بازگشت", detail: "بدونِ پرسش" },
] as const
const RELATED: {
  id: string
  title: string
  price: number
  image: StockImageName
}[] = [
  {
    id: "r1",
    title: "پایهٔ رومیزیِ چوبیِ هدفون",
    price: 690_000,
    image: "headphonesWoodStand",
  },
  {
    id: "r2",
    title: "کابلِ شارژِ تایپ‌سیِ بافته‌شده",
    price: 180_000,
    image: "cableUsbC",
  },
  {
    id: "r3",
    title: "پاوربانکِ ۲۰ هزار با سه کابل",
    price: 1_890_000,
    image: "powerBank",
  },
  {
    id: "r4",
    title: "ایربادِ بی‌سیم با کیفِ شارژ",
    price: 1_250_000,
    image: "earbuds",
  },
]

@Component({
  selector: "dig-block-product-detail",
  imports: [
    DigAddToCart,
    DigBadge,
    DigButton,
    DigChip,
    DigColorSwatchPicker,
    DigColorSwatchPickerItem,
    DigControlSize,
    DigIcon,
    DigLabel,
    DigProductCard,
    DigProductCardBody,
    DigProductCardMedia,
    DigProductCardPrice,
    DigProductCardTitle,
    DigTabs,
    DigTabsContent,
    DigTabsList,
    DigTabsTrigger,
    DigToggleGroup,
    DigToggleGroupItem,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main
      digControlSize="xl"
      class="mx-auto flex w-full max-w-6xl flex-col gap-12 p-4 sm:p-6"
    >
      <div class="grid grid-cols-1 gap-8 md:grid-cols-2 lg:gap-12">
        <!-- گالری: تصویرِ اصلی با برچسب‌های روی تصویر، زیرش بندانگشتی‌ها. -->
        <section
          aria-label="تصاویر محصول"
          class="flex flex-col gap-3 self-start"
        >
          <div
            class="relative aspect-square overflow-hidden rounded-xl bg-muted"
          >
            <img
              [src]="stockImages[current().image].src"
              [alt]="'هدفون بی‌سیم دیگ پرو، ' + current().label"
              class="size-full object-cover"
            />
            <span
              class="absolute start-4 top-4 rounded-full bg-background px-3 py-1 text-xs font-semibold"
              >تازه رسید</span
            >
            <span
              class="absolute end-4 top-4 flex items-center gap-1 rounded-full bg-background px-2.5 py-1 text-xs font-semibold"
            >
              <svg
                digIcon="star"
                class="size-3.5 text-warning-subtle-foreground"
              ></svg>
              ۴٫۴
            </span>
          </div>
          <div
            digToggleGroup
            type="single"
            [value]="view()"
            aria-label="انتخاب تصویر"
            class="grid w-full grid-cols-4 gap-3"
            (valueChange)="onViewChange($event)"
          >
            @for (item of VIEWS; track item.label) {
              <button
                digToggleGroupItem
                type="button"
                [value]="item.label"
                [attr.aria-label]="item.label"
                class="aspect-square h-auto w-full overflow-hidden rounded-lg! bg-muted p-0 data-[state=on]:bg-muted data-[state=on]:ring-2 data-[state=on]:ring-foreground data-[state=on]:ring-offset-2 data-[state=on]:ring-offset-background"
              >
                <img
                  [src]="stockImages[item.image].src"
                  alt=""
                  class="size-full object-cover"
                />
              </button>
            }
          </div>
        </section>

        <!-- سلسله‌مراتب: معرفی، قیمت، ویژگی‌ها، انتخاب‌ها، خرید، تعهدها؛ هر گروه با فاصلهٔ بیشتر از قبلی. -->
        <section aria-label="جزئیات محصول" class="flex flex-col">
          <div class="flex flex-col gap-3">
            <span class="text-sm font-medium text-brand-secondary"
              >صوتی / هدفون بی‌سیم</span
            >
            <h1 class="text-3xl leading-snug font-bold">
              هدفون بی‌سیم دیگ پرو
            </h1>
            <p class="leading-7 text-muted-foreground">
              حذفِ نویزِ فعال و باتری سی‌ساعته برای رفت‌وآمدِ روزانه و کار در
              فضای شلوغ؛ سبک، تاشو و همراهِ هر روز.
            </p>
          </div>

          <div class="mt-6 flex flex-col gap-1.5">
            <div class="flex flex-wrap items-center gap-3">
              <span class="text-3xl font-bold">{{
                formatCurrency(3_490_000)
              }}</span>
              <span digBadge variant="soft" color="success">ارسالِ رایگان</span>
            </div>
            <div class="flex items-center gap-2 text-sm text-muted-foreground">
              <s>{{ formatCurrency(4_100_000) }}</s>
              <span digBadge color="destructive" size="sm">٪۱۵</span>
              <span>· قیمت با مالیات</span>
            </div>
          </div>

          <ul aria-label="ویژگی‌ها" class="mt-6 flex flex-wrap gap-2">
            @for (feature of FEATURES; track feature) {
              <li>
                <span digChip variant="soft">{{ feature }}</span>
              </li>
            }
          </ul>

          <div digControlSize="xl">
            <div class="mt-8 flex flex-col gap-3">
              <label digLabel id="color-label" class="gap-1">
                رنگ:
                <span
                  class="font-normal text-muted-foreground"
                  >{{ COLORS.find((item) => item.value === color())?.label }}</span
                >
              </label>
              <div
                digColorSwatchPicker
                [value]="color()"
                (valueChange)="color.set($event ?? color())"
                aria-labelledby="color-label"
                size="md"
                radius="full"
                indicator="ring"
                class="gap-3 p-1"
              >
                @for (item of COLORS; track item.value) {
                  <button
                    digColorSwatchPickerItem
                    type="button"
                    [value]="item.value"
                    [color]="item.swatch"
                    [label]="item.label"
                  ></button>
                }
              </div>
            </div>

            <!-- تعداد بعد از افزودن روی همین دکمه انتخاب می‌شود؛ فیلدِ جدا لازم نیست. -->
            <div class="mt-8 flex gap-3">
              <div
                digAddToCart
                variant="default"
                fullWidth
                label="افزودن به سبد خرید"
                itemName="هدفون"
                [max]="7"
                class="flex-1"
              ></div>
              <button
                digButton
                type="button"
                variant="outline"
                size="icon"
                [attr.aria-pressed]="liked()"
                [attr.aria-label]="
                  liked() ? 'حذف از علاقه‌مندی‌ها' : 'افزودن به علاقه‌مندی‌ها'
                "
                [class]="
                  liked() ? 'text-destructive hover:text-destructive' : ''
                "
                (click)="liked.set(!liked())"
              >
                <svg [digIcon]="liked() ? 'heart-filled' : 'heart'"></svg>
              </button>
            </div>
          </div>

          <ul aria-label="تعهدهای فروشگاه" class="mt-8 grid grid-cols-3 gap-3">
            @for (item of PROMISES; track item.title) {
              <li
                class="flex flex-col items-center gap-2 rounded-xl border border-border p-3 text-center"
              >
                <span
                  aria-hidden="true"
                  class="text-muted-foreground [&_svg]:size-5"
                >
                  <svg [digIcon]="item.icon"></svg>
                </span>
                <span class="flex flex-col gap-0.5">
                  <span class="text-sm font-semibold">{{ item.title }}</span>
                  <span class="text-xs text-muted-foreground">{{
                    item.detail
                  }}</span>
                </span>
              </li>
            }
          </ul>
        </section>
      </div>

      <div digTabs value="specs" class="gap-4">
        <div digTabsList>
          <button digTabsTrigger type="button" value="specs">مشخصات</button>
          <button digTabsTrigger type="button" value="about">معرفی</button>
        </div>
        <div digTabsContent value="specs">
          <dl class="grid grid-cols-1 gap-x-8 text-sm sm:grid-cols-2">
            @for (entry of SPECS; track entry[0]) {
              @let key = entry[0];
              @let value = entry[1];
              <div
                class="flex justify-between gap-4 border-b border-border py-3"
              >
                <dt class="text-muted-foreground">{{ key }}</dt>
                <dd class="font-medium">{{ value }}</dd>
              </div>
            }
          </dl>
        </div>
        <div digTabsContent value="about">
          <p class="max-w-3xl text-sm leading-7 text-muted-foreground">
            هدفون دیگ پرو با حذف نویز فعال و باتری سی‌ساعته برای رفت‌وآمد روزانه
            و کار در فضای شلوغ ساخته شده است.
          </p>
        </div>
      </div>

      <section aria-labelledby="related-title" class="flex flex-col gap-4">
        <h2 id="related-title" class="text-xl font-bold">
          معمولاً با هم خریده می‌شوند
        </h2>
        <div class="flex gap-3 overflow-x-auto pb-2">
          @for (item of RELATED; track item.id) {
            <article digProductCard size="sm">
              <div digProductCardMedia>
                <img
                  [src]="stockImages[item.image].src"
                  [alt]="stockImages[item.image].alt"
                  loading="lazy"
                />
              </div>
              <div digProductCardBody>
                <h3 digProductCardTitle>{{ item.title }}</h3>
                <div
                  digProductCardPrice
                  [amount]="formatCurrency(item.price)"
                ></div>
              </div>
            </article>
          }
        </div>
      </section>
    </main>
  `,
})
export class ProductDetailBlock {
  readonly stockImages = stockImages
  readonly VIEWS = VIEWS
  readonly COLORS = COLORS
  readonly FEATURES = FEATURES
  readonly SPECS = SPECS
  readonly PROMISES = PROMISES
  readonly RELATED = RELATED
  readonly formatCurrency = formatCurrency

  readonly view = signal(VIEWS[0].label)
  readonly current = computed(
    () => VIEWS.find((item) => item.label === this.view()) ?? VIEWS[0]
  )
  readonly color = signal("black")
  readonly liked = signal(false)

  onViewChange(value: string | string[] | undefined) {
    if (typeof value === "string" && value) this.view.set(value)
  }
}

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

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

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