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

فروشگاه موبایل

پیش‌نمایش تمام‌صفحه

کارت محصول موبایل با علاقه‌مندی و افزودن به سبد، چیپ‌های دسته و باتم‌شیتِ فیلتر و مرتب‌سازی.

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

این بلاک از ۱۴ آیتم دیگ استفاده می‌کند: add-to-cartapp-barbadgebottom-navigationbuttoncheckboxcontrol-sizedrawericonslabelpersianproduct-cardradio-grouprating

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

۲. کد صفحه

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

mobile-shop.tsx
"use client"

import * as React from "react"

import { FilterIcon, HeartIcon, MenuIcon, SearchIcon, ShopIcon, ShoppingCartIcon, UserIcon } from "@/components/icons"
import { AppBar, AppBarActions, AppBarLeading, AppBarTitle } from "@/components/ui/app-bar"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Badge } from "@/components/ui/badge"
import { BottomNavigation, BottomNavigationItem } from "@/components/ui/bottom-navigation"
import { AddToCart } from "@/components/ui/add-to-cart"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { Drawer, DrawerClose, DrawerContent, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
import { ProductCard, ProductCardAction, ProductCardBody, ProductCardFooter, ProductCardGrid, ProductCardMedia, ProductCardPrice, ProductCardTitle } from "@/components/ui/product-card"
import { Rating } from "@/components/ui/rating"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = ["همه", "هدفون", "اسپیکر", "ساعت هوشمند", "لوازم جانبی"]
const PRODUCTS = [
  { id: 1, title: "هدفون بی‌سیم دیگ پرو", price: 3_490_000, oldPrice: 4_100_000, rating: 4.6, category: "هدفون" },
  { id: 2, title: "اسپیکر آوا بوم", price: 2_300_000, rating: 4.2, category: "اسپیکر" },
  { id: 3, title: "ساعت هوشمند دیگ فیت", price: 5_750_000, rating: 4.8, category: "ساعت هوشمند" },
  { id: 4, title: "کابل شارژ تایپ‌سی", price: 180_000, rating: 4.1, category: "لوازم جانبی" },
  { id: 5, title: "ایربادز سونیک لایت", price: 1_250_000, oldPrice: 1_490_000, rating: 4.3, category: "هدفون" },
  { id: 6, title: "پاوربانک ۲۰ هزار", price: 1_890_000, rating: 4.5, category: "لوازم جانبی" },
]
const SORTS = [
  { value: "popular", label: "محبوب‌ترین" },
  { value: "cheap", label: "ارزان‌ترین" },
  { value: "expensive", label: "گران‌ترین" },
]

export default function MobileShopBlock() {
  const [category, setCategory] = React.useState("همه")
  const [sort, setSort] = React.useState("popular")
  const [discountOnly, setDiscountOnly] = React.useState(false)
  const [liked, setLiked] = React.useState<number[]>([])
  const [cart, setCart] = React.useState<Record<number, number>>({})
  const cartCount = Object.values(cart).reduce((sum, qty) => sum + qty, 0)
  const changeQty = (id: number, delta: number) =>
    setCart((current) => {
      const next = { ...current, [id]: Math.max(0, (current[id] ?? 0) + delta) }
      if (next[id] === 0) delete next[id]
      return next
    })
  const [tab, setTab] = React.useState("shop")

  const items = PRODUCTS.filter((item) => category === "همه" || item.category === category)
    .filter((item) => !discountOnly || item.oldPrice)
    .sort((a, b) => (sort === "cheap" ? a.price - b.price : sort === "expensive" ? b.price - a.price : b.rating - a.rating))

  return (
    <ControlSizeProvider size="xl" asChild>
    <div className="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <AppBar sticky>
        <AppBarLeading>
          <Button variant="ghost" size="icon" aria-label="منو">
            <MenuIcon />
          </Button>
        </AppBarLeading>
        <AppBarTitle>فروشگاه دیگ</AppBarTitle>
        <AppBarActions>
          <Button variant="ghost" size="icon" aria-label="جست‌وجو">
            <SearchIcon />
          </Button>
        </AppBarActions>
      </AppBar>

      <main className="flex flex-1 flex-col gap-4 p-4">
        <div className="flex items-center gap-2">
          {/* چیپ‌های دسته در یک ردیفِ پیمایشی؛ در موبایل جا برای پیچیدن نیست. */}
          <div className="-ms-4 flex min-w-0 flex-1 gap-2 overflow-x-auto ps-4 [scrollbar-width:none]" role="tablist" aria-label="دسته‌ها">
            {CATEGORIES.map((item) => (
              <Button
                key={item}
                variant={category === item ? "default" : "outline"}
                role="tab"
                aria-selected={category === item}
                onClick={() => setCategory(item)}
                className="shrink-0 rounded-full"
              >
                {item}
              </Button>
            ))}
          </div>

          {/* باتم‌شیت: فیلتر و مرتب‌سازی از پایینِ صفحه، جایی که شست می‌رسد. */}
          <Drawer>
            <DrawerTrigger asChild>
              <Button variant="outline" size="icon" aria-label="فیلتر و مرتب‌سازی" className="relative shrink-0">
                <FilterIcon />
                {discountOnly && <span aria-hidden className="absolute end-1.5 top-1.5 size-2 rounded-full bg-primary" />}
              </Button>
            </DrawerTrigger>
            <ControlSizeProvider size="xl" asChild>
              <DrawerContent>
                <DrawerHeader>
                  <DrawerTitle>فیلتر و مرتب‌سازی</DrawerTitle>
                </DrawerHeader>
                <div className="flex flex-col gap-5 px-4">
                  <div className="flex flex-col gap-3">
                    <Label id="sort-label">مرتب‌سازی</Label>
                    <RadioGroup value={sort} onValueChange={setSort} aria-labelledby="sort-label" className="gap-3">
                      {SORTS.map((item) => (
                        <div key={item.value} className="flex items-center gap-2">
                          <RadioGroupItem id={`sort-${item.value}`} value={item.value} />
                          <Label htmlFor={`sort-${item.value}`} className="font-normal">
                            {item.label}
                          </Label>
                        </div>
                      ))}
                    </RadioGroup>
                  </div>
                  <div className="flex items-center gap-2">
                    <Checkbox id="discount" checked={discountOnly} onCheckedChange={(on) => setDiscountOnly(on === true)} />
                    <Label htmlFor="discount" className="font-normal">
                      فقط کالاهای تخفیف‌دار
                    </Label>
                  </div>
                </div>
                <DrawerFooter>
                  <DrawerClose asChild>
                    <Button fullWidth>نمایش {toFaDigits(items.length)} کالا</Button>
                  </DrawerClose>
                </DrawerFooter>
              </DrawerContent>
            </ControlSizeProvider>
          </Drawer>
        </div>

        <ProductCardGrid size="sm">
          {items.map((item) => {
            const isLiked = liked.includes(item.id)
            return (
              <ProductCard key={item.id} size="sm">
                <ProductCardMedia>
                  <ProductCardAction>
                  <Button
                    variant="outline"
                    size="icon"
                    aria-label={isLiked ? `حذف ${item.title} از علاقه‌مندی‌ها` : `افزودن ${item.title} به علاقه‌مندی‌ها`}
                    aria-pressed={isLiked}
                    onClick={() => setLiked((list) => (isLiked ? list.filter((id) => id !== item.id) : [...list, item.id]))}
                    className={isLiked ? "rounded-full bg-background text-destructive" : "rounded-full bg-background"}
                  >
                    <HeartIcon filled={isLiked} />
                  </Button>
                  </ProductCardAction>
                </ProductCardMedia>
                <ProductCardBody>
                  <ProductCardTitle>{item.title}</ProductCardTitle>
                  <Rating value={Math.round(item.rating)} readOnly size="sm" aria-label={`امتیاز ${toFaDigits(item.rating)}`} />
                  <ProductCardPrice
                    amount={formatCurrency(item.price)}
                    originalAmount={item.oldPrice ? formatCurrency(item.oldPrice) : undefined}
                    discount={item.oldPrice ? `٪${toFaDigits(Math.round((1 - item.price / item.oldPrice) * 100))}` : undefined}
                  />
                </ProductCardBody>
                {/* دکمهٔ تمام‌عرضِ ۴۰ پیکسلی (ناحیهٔ لمسِ کافی)؛ بعد از افزودن به شمارنده تبدیل می‌شود. */}
                <ProductCardFooter>
                  <AddToCart
                    fullWidth
                    variant="default"
                    itemName={item.title}
                    quantity={cart[item.id] ?? 0}
                    onQuantityChange={(next) => changeQty(item.id, next - (cart[item.id] ?? 0))}
                  />
                </ProductCardFooter>
              </ProductCard>
            )
          })}
        </ProductCardGrid>
      </main>

      <BottomNavigation value={tab} onValueChange={setTab} indicator="pill" fixed={false} className="sticky bottom-0">
        <BottomNavigationItem value="shop" icon={<ShopIcon />} label="فروشگاه" />
        <BottomNavigationItem value="likes" icon={<HeartIcon />} label="علاقه‌مندی" badge={liked.length ? toFaDigits(liked.length) : undefined} />
        <BottomNavigationItem
          value="cart"
          icon={<ShoppingCartIcon />}
          label="سبد خرید"
          badge={
            cartCount ? (
              <Badge color="destructive">{toFaDigits(cartCount)}</Badge>
            ) : undefined
          }
        />
        <BottomNavigationItem value="profile" icon={<UserIcon />} label="حساب" />
      </BottomNavigation>
    </div>
    </ControlSizeProvider>
  )
}
mobile-shop.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import AddToCart from "@/components/ui/AddToCart.vue"
import AppBar from "@/components/ui/AppBar.vue"
import AppBarActions from "@/components/ui/AppBarActions.vue"
import AppBarLeading from "@/components/ui/AppBarLeading.vue"
import AppBarTitle from "@/components/ui/AppBarTitle.vue"
import Badge from "@/components/ui/Badge.vue"
import BottomNavigation from "@/components/ui/BottomNavigation.vue"
import BottomNavigationItem from "@/components/ui/BottomNavigationItem.vue"
import Button from "@/components/ui/Button.vue"
import Checkbox from "@/components/ui/Checkbox.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Drawer from "@/components/ui/Drawer.vue"
import DrawerClose from "@/components/ui/DrawerClose.vue"
import DrawerContent from "@/components/ui/DrawerContent.vue"
import DrawerFooter from "@/components/ui/DrawerFooter.vue"
import DrawerHeader from "@/components/ui/DrawerHeader.vue"
import DrawerTitle from "@/components/ui/DrawerTitle.vue"
import DrawerTrigger from "@/components/ui/DrawerTrigger.vue"
import Label from "@/components/ui/Label.vue"
import ProductCard from "@/components/ui/ProductCard.vue"
import ProductCardAction from "@/components/ui/ProductCardAction.vue"
import ProductCardBody from "@/components/ui/ProductCardBody.vue"
import ProductCardFooter from "@/components/ui/ProductCardFooter.vue"
import ProductCardGrid from "@/components/ui/ProductCardGrid.vue"
import ProductCardMedia from "@/components/ui/ProductCardMedia.vue"
import ProductCardPrice from "@/components/ui/ProductCardPrice.vue"
import ProductCardTitle from "@/components/ui/ProductCardTitle.vue"
import RadioGroup from "@/components/ui/RadioGroup.vue"
import RadioGroupItem from "@/components/ui/RadioGroupItem.vue"
import Rating from "@/components/ui/Rating.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = ["همه", "هدفون", "اسپیکر", "ساعت هوشمند", "لوازم جانبی"]
const PRODUCTS: { id: number; title: string; price: number; oldPrice?: number; rating: number; category: string }[] = [
  { id: 1, title: "هدفون بی‌سیم دیگ پرو", price: 3_490_000, oldPrice: 4_100_000, rating: 4.6, category: "هدفون" },
  { id: 2, title: "اسپیکر آوا بوم", price: 2_300_000, rating: 4.2, category: "اسپیکر" },
  { id: 3, title: "ساعت هوشمند دیگ فیت", price: 5_750_000, rating: 4.8, category: "ساعت هوشمند" },
  { id: 4, title: "کابل شارژ تایپ‌سی", price: 180_000, rating: 4.1, category: "لوازم جانبی" },
  { id: 5, title: "ایربادز سونیک لایت", price: 1_250_000, oldPrice: 1_490_000, rating: 4.3, category: "هدفون" },
  { id: 6, title: "پاوربانک ۲۰ هزار", price: 1_890_000, rating: 4.5, category: "لوازم جانبی" },
]
const SORTS = [
  { value: "popular", label: "محبوب‌ترین" },
  { value: "cheap", label: "ارزان‌ترین" },
  { value: "expensive", label: "گران‌ترین" },
]

/** همان صفحهٔ `mobile-shop` نسخهٔ React: فروشگاه موبایل با دسته‌ها، فیلتر و مرتب‌سازی در باتم‌شیت و سبدِ خرید. */
const category = ref("همه")
const sort = ref("popular")
const discountOnly = ref(false)
const liked = ref<number[]>([])
const cart = ref<Record<number, number>>({})
const tab = ref("shop")

const cartCount = computed(() => Object.values(cart.value).reduce((sum, qty) => sum + qty, 0))
function changeQty(id: number, delta: number) {
  const next = { ...cart.value, [id]: Math.max(0, (cart.value[id] ?? 0) + delta) }
  if (next[id] === 0) delete next[id]
  cart.value = next
}
function toggleLiked(id: number) {
  liked.value = liked.value.includes(id) ? liked.value.filter((item) => item !== id) : [...liked.value, id]
}

const items = computed(() =>
  PRODUCTS.filter((item) => category.value === "همه" || item.category === category.value)
    .filter((item) => !discountOnly.value || item.oldPrice)
    .sort((a, b) => (sort.value === "cheap" ? a.price - b.price : sort.value === "expensive" ? b.price - a.price : b.rating - a.rating))
)
</script>

<template>
  <ControlSize size="xl" as-child>
    <div class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <AppBar sticky>
        <AppBarLeading>
          <Button variant="ghost" size="icon" aria-label="منو">
            <DigIcon name="menu" />
          </Button>
        </AppBarLeading>
        <AppBarTitle>فروشگاه دیگ</AppBarTitle>
        <AppBarActions>
          <Button variant="ghost" size="icon" aria-label="جست‌وجو">
            <DigIcon name="search" />
          </Button>
        </AppBarActions>
      </AppBar>

      <main class="flex flex-1 flex-col gap-4 p-4">
        <div class="flex items-center gap-2">
          <!-- چیپ‌های دسته در یک ردیفِ پیمایشی؛ در موبایل جا برای پیچیدن نیست. -->
          <div class="-ms-4 flex min-w-0 flex-1 gap-2 overflow-x-auto ps-4 [scrollbar-width:none]" role="tablist" aria-label="دسته‌ها">
            <Button
              v-for="item in CATEGORIES"
              :key="item"
              :variant="category === item ? 'default' : 'outline'"
              role="tab"
              :aria-selected="category === item"
              class="shrink-0 rounded-full"
              @click="category = item"
            >
              {{ item }}
            </Button>
          </div>

          <!-- باتم‌شیت: فیلتر و مرتب‌سازی از پایینِ صفحه، جایی که شست می‌رسد. -->
          <Drawer>
            <DrawerTrigger as-child>
              <Button variant="outline" size="icon" aria-label="فیلتر و مرتب‌سازی" class="relative shrink-0">
                <DigIcon name="filter" />
                <span v-if="discountOnly" aria-hidden="true" class="absolute end-1.5 top-1.5 size-2 rounded-full bg-primary" />
              </Button>
            </DrawerTrigger>
            <ControlSize size="xl" as-child>
              <DrawerContent>
                <DrawerHeader>
                  <DrawerTitle>فیلتر و مرتب‌سازی</DrawerTitle>
                </DrawerHeader>
                <div class="flex flex-col gap-5 px-4">
                  <div class="flex flex-col gap-3">
                    <Label id="sort-label">مرتب‌سازی</Label>
                    <RadioGroup v-model:value="sort" aria-labelledby="sort-label" class="gap-3">
                      <div v-for="item in SORTS" :key="item.value" class="flex items-center gap-2">
                        <RadioGroupItem :id="`sort-${item.value}`" :value="item.value" />
                        <Label :for="`sort-${item.value}`" class="font-normal">{{ item.label }}</Label>
                      </div>
                    </RadioGroup>
                  </div>
                  <div class="flex items-center gap-2">
                    <Checkbox id="discount" :checked="discountOnly" @update:checked="(on) => (discountOnly = on === true)" />
                    <Label for="discount" class="font-normal">فقط کالاهای تخفیف‌دار</Label>
                  </div>
                </div>
                <DrawerFooter>
                  <DrawerClose as-child>
                    <Button full-width>نمایش {{ toFaDigits(items.length) }} کالا</Button>
                  </DrawerClose>
                </DrawerFooter>
              </DrawerContent>
            </ControlSize>
          </Drawer>
        </div>

        <ProductCardGrid size="sm">
          <ProductCard v-for="item in items" :key="item.id" size="sm">
            <ProductCardMedia>
              <ProductCardAction>
                <Button
                  variant="outline"
                  size="icon"
                  :aria-label="liked.includes(item.id) ? `حذف ${item.title} از علاقه‌مندی‌ها` : `افزودن ${item.title} به علاقه‌مندی‌ها`"
                  :aria-pressed="liked.includes(item.id)"
                  :class="liked.includes(item.id) ? 'rounded-full bg-background text-destructive' : 'rounded-full bg-background'"
                  @click="toggleLiked(item.id)"
                >
                  <DigIcon :name="liked.includes(item.id) ? 'heart-filled' : 'heart'" />
                </Button>
              </ProductCardAction>
            </ProductCardMedia>
            <ProductCardBody>
              <ProductCardTitle>{{ item.title }}</ProductCardTitle>
              <Rating :value="Math.round(item.rating)" read-only size="sm" :aria-label="`امتیاز ${toFaDigits(item.rating)}`" />
              <ProductCardPrice
                :amount="formatCurrency(item.price)"
                :original-amount="item.oldPrice ? formatCurrency(item.oldPrice) : undefined"
                :discount="item.oldPrice ? `٪${toFaDigits(Math.round((1 - item.price / item.oldPrice) * 100))}` : undefined"
              />
            </ProductCardBody>
            <!-- دکمهٔ تمام‌عرضِ ۴۰ پیکسلی (ناحیهٔ لمسِ کافی)؛ بعد از افزودن به شمارنده تبدیل می‌شود. -->
            <ProductCardFooter>
              <AddToCart
                full-width
                variant="default"
                :item-name="item.title"
                :quantity="cart[item.id] ?? 0"
                @update:quantity="(next) => changeQty(item.id, next - (cart[item.id] ?? 0))"
              />
            </ProductCardFooter>
          </ProductCard>
        </ProductCardGrid>
      </main>

      <BottomNavigation v-model:value="tab" indicator="pill" :fixed="false" class="sticky bottom-0">
        <BottomNavigationItem value="shop" label="فروشگاه">
          <template #icon><DigIcon name="shop" /></template>
        </BottomNavigationItem>
        <BottomNavigationItem value="likes" label="علاقه‌مندی">
          <template #icon><DigIcon name="heart" /></template>
          <template v-if="liked.length" #badge>{{ toFaDigits(liked.length) }}</template>
        </BottomNavigationItem>
        <BottomNavigationItem value="cart" label="سبد خرید">
          <template #icon><DigIcon name="shopping-cart" /></template>
          <template v-if="cartCount" #badge><Badge color="destructive">{{ toFaDigits(cartCount) }}</Badge></template>
        </BottomNavigationItem>
        <BottomNavigationItem value="profile" label="حساب">
          <template #icon><DigIcon name="user" /></template>
        </BottomNavigationItem>
      </BottomNavigation>
    </div>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: add-to-cartapp-barbadgebottom-navigationcheckboxcontrol-sizedrawerlabelpersianproduct-cardradio-groupratingآیکون filterآیکون heartآیکون menuآیکون searchآیکون shopآیکون shopping-cartآیکون user

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

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

import { DigControlSize } from "@/components/ui/control-size"
import { DigAppBar, DigAppBarLeading, DigAppBarTitle, DigAppBarActions } from "@/components/ui/app-bar"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import {
  DigDrawer,
  DigDrawerTrigger,
  DigDrawerContent,
  DigDrawerHeader,
  DigDrawerTitle,
  DigDrawerFooter,
  DigDrawerClose,
} from "@/components/ui/drawer"
import { DigLabel } from "@/components/ui/label"
import { DigRadioGroup, DigRadioGroupItem } from "@/components/ui/radio-group"
import { DigCheckbox } from "@/components/ui/checkbox"
import {
  DigProductCardGrid,
  DigProductCard,
  DigProductCardMedia,
  DigProductCardAction,
  DigProductCardBody,
  DigProductCardTitle,
  DigProductCardPrice,
  DigProductCardFooter,
} from "@/components/ui/product-card"
import { DigRating } from "@/components/ui/rating"
import { DigAddToCart } from "@/components/ui/add-to-cart"
import {
  DigBottomNavigation,
  DigBottomNavigationItem,
  DigBottomNavigationActiveIcon,
  DigBottomNavigationBadge,
} from "@/components/ui/bottom-navigation"
import { DigBadge } from "@/components/ui/badge"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = ["همه", "هدفون", "اسپیکر", "ساعت هوشمند", "لوازم جانبی"]

const PRODUCTS: { id: number; title: string; price: number; oldPrice?: number; rating: number; category: string }[] = [
  { id: 1, title: "هدفون بی‌سیم دیگ پرو", price: 3_490_000, oldPrice: 4_100_000, rating: 4.6, category: "هدفون" },
  { id: 2, title: "اسپیکر آوا بوم", price: 2_300_000, rating: 4.2, category: "اسپیکر" },
  { id: 3, title: "ساعت هوشمند دیگ فیت", price: 5_750_000, rating: 4.8, category: "ساعت هوشمند" },
  { id: 4, title: "کابل شارژ تایپ‌سی", price: 180_000, rating: 4.1, category: "لوازم جانبی" },
  { id: 5, title: "ایربادز سونیک لایت", price: 1_250_000, oldPrice: 1_490_000, rating: 4.3, category: "هدفون" },
  { id: 6, title: "پاوربانک ۲۰ هزار", price: 1_890_000, rating: 4.5, category: "لوازم جانبی" },
]

const SORTS = [
  { value: "popular", label: "محبوب‌ترین" },
  { value: "cheap", label: "ارزان‌ترین" },
  { value: "expensive", label: "گران‌ترین" },
]

@Component({
  selector: "dig-block-mobile-shop",
  imports: [
    DigControlSize,
    DigAppBar,
    DigAppBarLeading,
    DigAppBarTitle,
    DigAppBarActions,
    DigButton,
    DigIcon,
    DigDrawer,
    DigDrawerTrigger,
    DigDrawerContent,
    DigDrawerHeader,
    DigDrawerTitle,
    DigDrawerFooter,
    DigDrawerClose,
    DigLabel,
    DigRadioGroup,
    DigRadioGroupItem,
    DigCheckbox,
    DigProductCardGrid,
    DigProductCard,
    DigProductCardMedia,
    DigProductCardAction,
    DigProductCardBody,
    DigProductCardTitle,
    DigProductCardPrice,
    DigProductCardFooter,
    DigRating,
    DigAddToCart,
    DigBottomNavigation,
    DigBottomNavigationItem,
    DigBottomNavigationActiveIcon,
    DigBottomNavigationBadge,
    DigBadge,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div digControlSize="xl" class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <header digAppBar sticky>
        <div digAppBarLeading>
          <button digButton type="button" variant="ghost" size="icon" aria-label="منو">
            <svg digIcon="menu"></svg>
          </button>
        </div>
        <h1 digAppBarTitle>فروشگاه دیگ</h1>
        <div digAppBarActions>
          <button digButton type="button" variant="ghost" size="icon" aria-label="جست‌وجو">
            <svg digIcon="search"></svg>
          </button>
        </div>
      </header>

      <main class="flex flex-1 flex-col gap-4 p-4">
        <div class="flex items-center gap-2">
          <!-- چیپ‌های دسته در یک ردیفِ پیمایشی؛ در موبایل جا برای پیچیدن نیست. -->
          <div
            class="-ms-4 flex min-w-0 flex-1 gap-2 overflow-x-auto ps-4 [scrollbar-width:none]"
            role="tablist"
            aria-label="دسته‌ها"
          >
            @for (item of CATEGORIES; track item) {
              <button
                digButton
                type="button"
                [variant]="category() === item ? 'default' : 'outline'"
                role="tab"
                [attr.aria-selected]="category() === item"
                class="shrink-0 rounded-full"
                (click)="category.set(item)"
              >
                {{ item }}
              </button>
            }
          </div>

          <!-- باتم‌شیت: فیلتر و مرتب‌سازی از پایینِ صفحه، جایی که شست می‌رسد. -->
          <ng-container digDrawer
            ><button
              digDrawerTrigger
              digButton
              type="button"
              variant="outline"
              size="icon"
              aria-label="فیلتر و مرتب‌سازی"
              class="relative shrink-0"
            >
              <svg digIcon="filter"></svg>
              @if (discountOnly()) {
                <span aria-hidden="true" class="absolute end-1.5 top-1.5 size-2 rounded-full bg-primary"></span>
              }
            </button>
            <div digControlSize="xl" digDrawerContent>
              <div digDrawerHeader><h2 digDrawerTitle>فیلتر و مرتب‌سازی</h2></div>
              <div class="flex flex-col gap-5 px-4">
                <div class="flex flex-col gap-3">
                  <label digLabel id="sort-label">مرتب‌سازی</label>
                  <div
                    digRadioGroup
                    [value]="sort()"
                    (valueChange)="typeof $event === 'string' && sort.set($event)"
                    aria-labelledby="sort-label"
                    class="gap-3"
                  >
                    @for (item of SORTS; track item.value) {
                      <div class="flex items-center gap-2">
                        <button digRadioGroupItem [id]="\`sort-\${item.value}\`" [value]="item.value"></button>
                        <label digLabel [htmlFor]="\`sort-\${item.value}\`" class="font-normal">{{ item.label }}</label>
                      </div>
                    }
                  </div>
                </div>
                <div class="flex items-center gap-2">
                  <button
                    digCheckbox
                    id="discount"
                    [checked]="discountOnly()"
                    (checkedChange)="discountOnly.set($event === true)"
                  ></button>
                  <label digLabel for="discount" class="font-normal">فقط کالاهای تخفیف‌دار</label>
                </div>
              </div>
              <div digDrawerFooter>
                <button digDrawerClose digButton type="button" fullWidth>
                  نمایش {{ toFaDigits(items().length) }} کالا
                </button>
              </div>
            </div></ng-container
          >
        </div>

        <div digProductCardGrid size="sm">
          @for (item of items(); track item.id) {
            <article digProductCard size="sm">
              <div digProductCardMedia>
                <div digProductCardAction>
                  <button
                    digButton
                    type="button"
                    variant="outline"
                    size="icon"
                    [attr.aria-label]="
                      liked().includes(item.id)
                        ? \`حذف \${item.title} از علاقه‌مندی‌ها\`
                        : \`افزودن \${item.title} به علاقه‌مندی‌ها\`
                    "
                    [attr.aria-pressed]="liked().includes(item.id)"
                    [class]="
                      liked().includes(item.id)
                        ? 'rounded-full bg-background text-destructive'
                        : 'rounded-full bg-background'
                    "
                    (click)="toggleLiked(item.id)"
                  >
                    <svg [digIcon]="liked().includes(item.id) ? 'heart-filled' : 'heart'"></svg>
                  </button>
                </div>
              </div>
              <div digProductCardBody>
                <h3 digProductCardTitle>{{ item.title }}</h3>
                <div
                  digRating
                  [value]="math.round(item.rating)"
                  readOnly
                  size="sm"
                  [attr.aria-label]="\`امتیاز \${toFaDigits(item.rating)}\`"
                ></div>
                <div
                  digProductCardPrice
                  [amount]="formatCurrency(item.price)"
                  [originalAmount]="item.oldPrice ? formatCurrency(item.oldPrice) : undefined"
                  [discount]="
                    item.oldPrice ? \`٪\${toFaDigits(math.round((1 - item.price / item.oldPrice) * 100))}\` : undefined
                  "
                ></div>
              </div>
              <!-- دکمهٔ تمام‌عرضِ ۴۰ پیکسلی (ناحیهٔ لمسِ کافی)؛ بعد از افزودن به شمارنده تبدیل می‌شود. -->
              <div digProductCardFooter>
                <div
                  digAddToCart
                  fullWidth
                  variant="default"
                  [itemName]="item.title"
                  [quantity]="cart()[item.id] ?? 0"
                  (quantityChange)="changeQty(item.id, ($event ?? 0) - (cart()[item.id] ?? 0))"
                ></div>
              </div>
            </article>
          }
        </div>
      </main>

      <nav
        digBottomNavigation
        [value]="tab()"
        (valueChange)="typeof $event === 'string' && tab.set($event)"
        indicator="pill"
        [fixed]="false"
        class="sticky bottom-0"
      >
        <button digBottomNavigationItem value="shop" label="فروشگاه"><svg digIcon="shop"></svg></button>
        <button digBottomNavigationItem value="likes" label="علاقه‌مندی">
          <svg digIcon="heart"></svg><span digBottomNavigationBadge>{{ toFaDigits(liked().length) }}</span>
        </button>
        <button digBottomNavigationItem value="cart" label="سبد خرید">
          <svg digIcon="shopping-cart"></svg
          ><span digBottomNavigationBadge
            ><span digBadge color="destructive">{{ toFaDigits(cartCount()) }}</span></span
          >
        </button>
        <button digBottomNavigationItem value="profile" label="حساب"><svg digIcon="user"></svg></button>
      </nav>
    </div>
  `,
})
export class MobileShopBlock {
  readonly math = Math

  readonly toFaDigits = toFaDigits

  readonly formatCurrency = formatCurrency

  readonly SORTS = SORTS

  readonly CATEGORIES = CATEGORIES

  readonly category = signal("همه")

  readonly sort = signal("popular")

  readonly discountOnly = signal(false)

  readonly liked = signal<number[]>([])

  readonly cart = signal<Record<number, number>>({})

  readonly tab = signal("shop")

  readonly cartCount = computed(() => Object.values(this.cart()).reduce((sum, qty) => sum + qty, 0))

  changeQty(id: number, delta: number) {
    const next = { ...this.cart(), [id]: Math.max(0, (this.cart()[id] ?? 0) + delta) }
    if (next[id] === 0) delete next[id]
    this.cart.set(next)
  }

  toggleLiked(id: number) {
    this.liked.set(this.liked().includes(id) ? this.liked().filter((item) => item !== id) : [...this.liked(), id])
  }

  readonly items = computed(() =>
    PRODUCTS.filter((item) => this.category() === "همه" || item.category === this.category())
      .filter((item) => !this.discountOnly() || item.oldPrice)
      .sort((a, b) =>
        this.sort() === "cheap"
          ? a.price - b.price
          : this.sort() === "expensive"
            ? b.price - a.price
            : b.rating - a.rating
      )
  )
}
MobileShopScreen.kt
package ir.digdesign.compose.demo.blocks

// sync: src/blocks/mobile-shop.tsx

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import ir.digdesign.compose.AddToCart
import ir.digdesign.compose.AddToCartVariant
import ir.digdesign.compose.Button
import ir.digdesign.compose.ButtonRadius
import ir.digdesign.compose.ButtonSize
import ir.digdesign.compose.ButtonVariant
import ir.digdesign.compose.Checkbox
import ir.digdesign.compose.ChoiceChips
import ir.digdesign.compose.ControlSize
import ir.digdesign.compose.ControlSizeProvider
import ir.digdesign.compose.DigBottomSheet
import ir.digdesign.compose.DigIcon
import ir.digdesign.compose.DigIcons
import ir.digdesign.compose.DigNavigationBadge
import ir.digdesign.compose.DigNavigationBar
import ir.digdesign.compose.DigNavigationIndicator
import ir.digdesign.compose.DigNavigationItem
import ir.digdesign.compose.DigSpacing
import ir.digdesign.compose.DigTheme
import ir.digdesign.compose.DigTopAppBar
import ir.digdesign.compose.Label
import ir.digdesign.compose.ProductCard
import ir.digdesign.compose.ProductCardSize
import ir.digdesign.compose.RadioGroup
import ir.digdesign.compose.Rating
import ir.digdesign.compose.RatingSize
import ir.digdesign.compose.TypographyLarge
import ir.digdesign.compose.formatCurrency
import ir.digdesign.compose.toFaDigits
import kotlin.math.roundToInt

private val Categories = listOf("همه", "هدفون", "اسپیکر", "ساعت هوشمند", "لوازم جانبی")

private class Product(val id: Int, val title: String, val price: Long, val rating: Float, val category: String, val oldPrice: Long? = null)

private val Products = listOf(
    Product(1, "هدفون بی‌سیم دیگ پرو", 3_490_000, 4.6f, "هدفون", oldPrice = 4_100_000),
    Product(2, "اسپیکر آوا بوم", 2_300_000, 4.2f, "اسپیکر"),
    Product(3, "ساعت هوشمند دیگ فیت", 5_750_000, 4.8f, "ساعت هوشمند"),
    Product(4, "کابل شارژ تایپ‌سی", 180_000, 4.1f, "لوازم جانبی"),
    Product(5, "ایربادز سونیک لایت", 1_250_000, 4.3f, "هدفون", oldPrice = 1_490_000),
    Product(6, "پاوربانک ۲۰ هزار", 1_890_000, 4.5f, "لوازم جانبی"),
)

private val Sorts = listOf("popular" to "محبوب‌ترین", "cheap" to "ارزان‌ترین", "expensive" to "گران‌ترین")

/** فروشگاهِ موبایل: چیپ‌های دسته، فیلتر و مرتب‌سازی در باتم‌شیت، شبکهٔ دوستونهٔ محصول با افزودن به سبد و ناوبریِ پایین. */
@Composable
fun MobileShopScreen() {
    var category by remember { mutableStateOf<String?>("همه") }
    var sort by remember { mutableStateOf<String?>("popular") }
    var discountOnly by remember { mutableStateOf(false) }
    var filterOpen by remember { mutableStateOf(false) }
    var liked by remember { mutableStateOf(setOf<Int>()) }
    var cart by remember { mutableStateOf(mapOf<Int, Int>()) }
    var tab by remember { mutableStateOf("shop") }
    val colors = DigTheme.colors

    val items = Products
        .filter { category == "همه" || it.category == category }
        .filter { !discountOnly || it.oldPrice != null }
        .let { list ->
            when (sort) {
                "cheap" -> list.sortedBy { it.price }
                "expensive" -> list.sortedByDescending { it.price }
                else -> list.sortedByDescending { it.rating }
            }
        }

    Box(
        Modifier.fillMaxSize().background(colors.background).safeDrawingPadding(),
        contentAlignment = Alignment.TopCenter,
    ) {
        ControlSizeProvider(ControlSize.Xl) {
            Column(Modifier.widthIn(max = 480.dp).fillMaxWidth().fillMaxHeight()) {
                DigTopAppBar(
                    title = "فروشگاه دیگ",
                    windowInsets = WindowInsets(),
                    actions = {
                        Button(onClick = {}, variant = ButtonVariant.Ghost, size = ButtonSize.Icon, contentDescription = "جست‌وجو") {
                            DigIcon(DigIcons.Search, contentDescription = null)
                        }
                    },
                )
                Column(
                    Modifier.weight(1f).verticalScroll(rememberScrollState()).padding(DigSpacing * 4),
                    verticalArrangement = Arrangement.spacedBy(DigSpacing * 4),
                ) {
                    Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(DigSpacing * 2)) {
                        ChoiceChips(value = category, onValueChange = { if (it != null) category = it }, modifier = Modifier.weight(1f), wrap = false) {
                            Categories.forEach { chip(it, it) }
                        }
                        Button(
                            onClick = { filterOpen = true },
                            variant = ButtonVariant.Outline,
                            size = ButtonSize.Icon,
                            contentDescription = "فیلتر و مرتب‌سازی${if (discountOnly) "، فیلتر فعال است" else ""}",
                        ) { DigIcon(DigIcons.AccountSettings, contentDescription = null) }
                    }

                    items.chunked(2).forEach { pair ->
                        Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
                            pair.forEach { item ->
                                val isLiked = item.id in liked
                                ProductCard(
                                    title = item.title,
                                    amount = formatCurrency(item.price),
                                    modifier = Modifier.weight(1f),
                                    size = ProductCardSize.Sm,
                                    originalAmount = item.oldPrice?.let { formatCurrency(it) },
                                    discount = item.oldPrice?.let { "٪${toFaDigits(((1 - item.price.toDouble() / it) * 100).roundToInt())}" },
                                    media = { Box(Modifier.fillMaxSize().background(colors.muted)) },
                                    action = {
                                        Button(
                                            onClick = { liked = if (isLiked) liked - item.id else liked + item.id },
                                            variant = if (isLiked) ButtonVariant.Default else ButtonVariant.Outline,
                                            size = ButtonSize.Icon,
                                            radius = ButtonRadius.Full,
                                            contentDescription = "${if (isLiked) "حذف" else "افزودن"} ${item.title} ${if (isLiked) "از" else "به"} علاقه‌مندی‌ها",
                                        ) { DigIcon(DigIcons.BadgeStar, contentDescription = null) }
                                    },
                                    body = {
                                        Rating(item.rating, onValueChange = {}, readOnly = true, size = RatingSize.Sm, contentDescription = "امتیاز ${toFaDigits(item.rating)}")
                                    },
                                    footer = {
                                        AddToCart(
                                            quantity = cart[item.id] ?: 0,
                                            onQuantityChange = { next -> cart = if (next <= 0) cart - item.id else cart + (item.id to next) },
                                            itemName = item.title,
                                            variant = AddToCartVariant.Default,
                                            fullWidth = true,
                                        )
                                    },
                                )
                            }
                            if (pair.size == 1) Spacer(Modifier.weight(1f))
                        }
                    }
                }
                val cartCount = cart.values.sum()
                DigNavigationBar(indicator = DigNavigationIndicator.Pill, windowInsets = WindowInsets()) {
                    DigNavigationItem(tab == "shop", { tab = "shop" }, { DigIcon(DigIcons.Search, contentDescription = null) }, "فروشگاه")
                    DigNavigationItem(
                        tab == "likes", { tab = "likes" }, { DigIcon(DigIcons.BadgeStar, contentDescription = null) }, "علاقه‌مندی",
                        badge = if (liked.isNotEmpty()) DigNavigationBadge.Count(liked.size) else null,
                    )
                    DigNavigationItem(
                        tab == "cart", { tab = "cart" }, { DigIcon(DigIcons.CreditCard, contentDescription = null) }, "سبد خرید",
                        badge = if (cartCount > 0) DigNavigationBadge.Count(cartCount) else null,
                    )
                    DigNavigationItem(tab == "profile", { tab = "profile" }, { DigIcon(DigIcons.User, contentDescription = null) }, "حساب")
                }
            }
        }

        DigBottomSheet(visible = filterOpen, onDismissRequest = { filterOpen = false }) {
            Column(Modifier.fillMaxWidth().padding(horizontal = DigSpacing * 4).padding(bottom = DigSpacing * 4), verticalArrangement = Arrangement.spacedBy(DigSpacing * 5)) {
                TypographyLarge("فیلتر و مرتب‌سازی", Modifier.semantics { heading() })
                Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
                    Label("مرتب‌سازی")
                    RadioGroup(value = sort, onValueChange = { sort = it }) {
                        Sorts.forEach { (value, label) -> RadioGroupItem(value, label = label) }
                    }
                }
                Checkbox(checked = discountOnly, onCheckedChange = { discountOnly = it }, label = "فقط کالاهای تخفیف‌دار")
                Button("نمایش ${toFaDigits(items.size)} کالا", onClick = { filterOpen = false }, fullWidth = true)
            }
        }
    }
}