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

گزارش‌ها و نمودارها

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

کارت‌های آمارِ hi-fi با بازهٔ ۷/۳۰/۹۰ روز: نمودار خطی، نوار تا هدف، سهم‌ها، دونات کانال‌ها، قیف خرید و عقربهٔ اعتبار.

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

این بلاک از ۵ آیتم دیگ استفاده می‌کند: control-sizeiconspersianstat-tiletoggle-group

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add 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/stat-tile.json https://docs.digdesign.ir/r/toggle-group.json
pnpm dlx digdesign@latest add 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/stat-tile.json https://docs.digdesign.ir/r/toggle-group.json
yarn dlx digdesign@latest add 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/stat-tile.json https://docs.digdesign.ir/r/toggle-group.json
bunx --bun digdesign@latest add 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/stat-tile.json https://docs.digdesign.ir/r/toggle-group.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add control-size persian stat-tile toggle-group --framework vue
pnpm dlx digdesign@latest add control-size persian stat-tile toggle-group --framework vue
yarn dlx digdesign@latest add control-size persian stat-tile toggle-group --framework vue
bunx --bun digdesign@latest add control-size persian stat-tile toggle-group --framework vue

هیچ‌کدام از کامپوننت‌های این بلاک هنوز برای Svelte پورت نشده است.

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add control-size icons persian stat-tile toggle-group --framework angular
pnpm dlx digdesign@latest add control-size icons persian stat-tile toggle-group --framework angular
yarn dlx digdesign@latest add control-size icons persian stat-tile toggle-group --framework angular
bunx --bun digdesign@latest add control-size icons persian stat-tile toggle-group --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add control-size persian stat-tile toggle-group --framework android
pnpm dlx digdesign@latest add control-size persian stat-tile toggle-group --framework android
yarn dlx digdesign@latest add control-size persian stat-tile toggle-group --framework android
bunx --bun digdesign@latest add control-size persian stat-tile toggle-group --framework android

۲. کد صفحه

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

analytics.tsx
"use client"

import * as React from "react"

import { UsersIcon, WalletIcon } from "@/components/icons"
import {
  StatTile,
  StatTileAction,
  StatTileBar,
  StatTileChart,
  StatTileContent,
  StatTileDescription,
  StatTileGauge,
  StatTileHeader,
  StatTileIcon,
  StatTileLabel,
  StatTileList,
  StatTileMeter,
  StatTileRing,
  StatTileSegments,
  StatTileSparkline,
  StatTileTrend,
  StatTileUnit,
  StatTileValue,
} from "@/components/ui/stat-tile"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { formatNumber } from "@/lib/persian"

/** دادهٔ نمونه برای هر بازه؛ در پروژهٔ واقعی همین‌ها پاسخِ API هستند. */
const DATA = {
  "7": { visits: [42, 48, 45, 52, 61, 58, 66], revenue: 186, orders: 820, conversion: 3.4 },
  "30": { visits: [38, 41, 47, 44, 52, 49, 58, 55, 63, 60, 68, 72], revenue: 824, orders: 3_285, conversion: 3.9 },
  "90": { visits: [30, 34, 33, 41, 39, 45, 50, 47, 55, 58, 61, 66, 70], revenue: 2_410, orders: 9_870, conversion: 4.2 },
} as const

const CHANNELS = [
  { label: "فروشگاه آنلاین", value: 45, color: "var(--chart-1)" },
  { label: "اپلیکیشن", value: 35, color: "var(--chart-2)" },
  { label: "فروش حضوری", value: 20, color: "var(--chart-4)" },
]

export default function AnalyticsBlock() {
  const [period, setPeriod] = React.useState<keyof typeof DATA>("30")
  const data = DATA[period]

  return (
    <ControlSizeProvider size="xl" asChild>
    <main className="mx-auto flex w-full min-w-0 max-w-6xl flex-col gap-6 bg-muted p-4 sm:p-6">
      <header className="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div className="flex flex-col gap-1">
          <h1 className="text-2xl font-bold">گزارش‌ها</h1>
          <p className="text-sm text-muted-foreground">نمای کلی فروش، بازدید و مشتریان در بازهٔ انتخابی.</p>
        </div>
        <ControlSizeProvider size="lg" mobileSize="default" asChild>
          <ToggleGroup type="single" variant="segmented" value={period} onValueChange={(value) => value && setPeriod(value as keyof typeof DATA)} aria-label="بازهٔ زمانی">
            <ToggleGroupItem value="7" className="px-4">۷ روز</ToggleGroupItem>
            <ToggleGroupItem value="30" className="px-4">۳۰ روز</ToggleGroupItem>
            <ToggleGroupItem value="90" className="px-4">۹۰ روز</ToggleGroupItem>
          </ToggleGroup>
        </ControlSizeProvider>
      </header>

      {/* ردیفِ اول: چهار شاخص، هر کدام یک نوع نمایشِ سبک. */}
      <section aria-label="شاخص‌های کلیدی" className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
        <StatTile className="gap-3">
          <StatTileHeader>
            <StatTileLabel>درآمد</StatTileLabel>
            <StatTileAction aria-label="جزئیات درآمد" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue className="text-2xl">
              {formatNumber(data.revenue)}
              <StatTileUnit>میلیون تومان</StatTileUnit>
            </StatTileValue>
            <StatTileTrend value={12.5} formatValue={() => "+۱۲٫۵٪"} />
          </StatTileContent>
          <StatTileSparkline values={[...data.visits]} />
        </StatTile>

        <StatTile className="gap-3">
          <StatTileHeader>
            <StatTileLabel>سفارش‌ها</StatTileLabel>
            <StatTileAction aria-label="جزئیات سفارش‌ها" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue className="text-2xl">{formatNumber(data.orders)}</StatTileValue>
            <span className="ms-auto text-sm text-muted-foreground">
              <strong className="font-semibold text-foreground">٪۴۲</strong> تا هدف
            </span>
          </StatTileContent>
          <StatTileMeter value={42} />
        </StatTile>

        <StatTile className="gap-3">
          <StatTileHeader>
            <StatTileLabel>مشتریان تازه</StatTileLabel>
            <StatTileAction aria-label="جزئیات مشتریان" />
          </StatTileHeader>
          <div className="grid grid-cols-[62fr_38fr] gap-1.5">
            <div className="flex flex-col gap-1.5 border-s-2 border-info ps-3">
              <span className="text-2xl font-bold tabular-nums">{formatNumber(302)}</span>
              <span className="text-xs text-muted-foreground">خرید مستقیم</span>
            </div>
            <div className="flex flex-col gap-1.5 border-s-2 border-warning ps-3">
              <span className="text-2xl font-bold tabular-nums">{formatNumber(184)}</span>
              <span className="text-xs text-muted-foreground">معرفی</span>
            </div>
          </div>
          <StatTileSegments
            segments={[
              { value: 302, color: "var(--info)" },
              { value: 184, color: "var(--warning)" },
            ]}
          />
        </StatTile>

        <StatTile className="gap-3">
          <StatTileHeader>
            <StatTileLabel>نرخ تبدیل</StatTileLabel>
            <StatTileAction aria-label="جزئیات نرخ تبدیل" />
          </StatTileHeader>
          <div className="flex items-end justify-between gap-3">
            <div className="flex flex-col gap-1.5">
              <StatTileValue className="text-2xl">٪{formatNumber(data.conversion)}</StatTileValue>
              <StatTileTrend value={9.2} formatValue={() => "+۹٫۲٪"} />
            </div>
            <StatTileChart
              className="h-20 min-w-0 max-w-44 flex-1"
              color="var(--success)"
              data={[
                { label: "تیر", value: 40 },
                { label: "مرداد", value: 36 },
                { label: "شهریور", value: 33 },
                { label: "مهر", value: 45 },
              ]}
            />
          </div>
        </StatTile>
      </section>

      {/* ردیفِ دوم: نمودارهای بزرگ‌تر، کنارِ هم با ارتفاعِ برابر. */}
      <section aria-label="جزئیات" className="grid grid-cols-1 gap-4 lg:grid-cols-3">
        <StatTile>
          <StatTileHeader>
            <StatTileLabel className="text-base text-foreground">سهمِ کانال‌های فروش</StatTileLabel>
            <StatTileAction aria-label="جزئیات کانال‌ها" />
          </StatTileHeader>
          <StatTileRing segments={CHANNELS}>
            <span className="text-2xl font-bold tabular-nums">{formatNumber(1_560)}</span>
            <span className="text-xs text-muted-foreground">سفارش</span>
          </StatTileRing>
          <ul className="flex flex-col gap-2.5 text-sm">
            {CHANNELS.map((item) => (
              <li key={item.label} className="flex items-center gap-2">
                <span aria-hidden className="size-2.5 rounded-full" style={{ background: item.color }} />
                <span className="text-muted-foreground">{item.label}</span>
                <span className="ms-auto font-semibold tabular-nums">٪{formatNumber(item.value)}</span>
              </li>
            ))}
          </ul>
        </StatTile>

        <StatTile>
          <StatTileHeader>
            <StatTileLabel className="text-base text-foreground">قیفِ خرید</StatTileLabel>
            <StatTileAction aria-label="جزئیات قیف" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue className="text-3xl">٪۶۲</StatTileValue>
            <StatTileDescription>به سبد خرید رسیده‌اند</StatTileDescription>
          </StatTileContent>
          <StatTileList
            items={[
              { label: "بازدید", value: 100, display: "٪۱۰۰" },
              { label: "دیدنِ محصول", value: 74, display: "٪۷۴" },
              { label: "افزودن به سبد", value: 62, display: "٪۶۲" },
              { label: "شروعِ پرداخت", value: 38, display: "٪۳۸" },
              { label: "خریدِ موفق", value: 21, display: "٪۲۱" },
            ]}
          />
        </StatTile>

        <StatTile>
          <StatTileHeader>
            <StatTileLabel className="text-base text-foreground">اعتبارِ پیامک</StatTileLabel>
            <StatTileAction aria-label="خرید اعتبار پیامک" />
          </StatTileHeader>
          <StatTileGauge value={62} className="mt-2">
            <span className="text-3xl font-bold tabular-nums">{formatNumber(750)}</span>
            <span className="text-xs text-muted-foreground">پیامک باقی‌مانده</span>
          </StatTileGauge>
          <StatTileDescription className="text-center">
            با این روند، اعتبار تا <strong>۱۲ روز</strong> دیگر کافی است.
          </StatTileDescription>
        </StatTile>
      </section>

      {/* ردیفِ سوم: شاخص‌های عملیاتی با آیکون و نوارِ پیشرفت. */}
      <section aria-label="عملیات" className="grid grid-cols-1 gap-4 sm:grid-cols-2">
        <StatTile>
          <StatTileHeader>
            <StatTileIcon tone="success">
              <UsersIcon />
            </StatTileIcon>
            <StatTileLabel>تیکت‌های پاسخ‌داده‌شده</StatTileLabel>
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue>٪۹۲</StatTileValue>
            <StatTileTrend value={12} formatValue={() => "+۱۲٪"} />
          </StatTileContent>
          <StatTileBar value={92} />
          <StatTileDescription>تقریباً همهٔ تیکت‌ها زیرِ یک ساعت پاسخ گرفته‌اند.</StatTileDescription>
        </StatTile>
        <StatTile>
          <StatTileHeader>
            <StatTileIcon tone="accent">
              <WalletIcon />
            </StatTileIcon>
            <StatTileLabel>میانگینِ سبد خرید</StatTileLabel>
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue>
              {formatNumber(562_000)}
              <StatTileUnit>تومان</StatTileUnit>
            </StatTileValue>
            <StatTileTrend value={-3.1} formatValue={() => "−۳٫۱٪"} />
          </StatTileContent>
          <StatTileSparkline values={[6, 5.6, 5.9, 5.2, 5.4, 4.9, 5.1, 4.8]} color="var(--destructive)" />
        </StatTile>
      </section>
    </main>
    </ControlSizeProvider>
  )
}
analytics.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import ControlSize from "@/components/ui/ControlSize.vue"
import StatTile from "@/components/ui/StatTile.vue"
import StatTileAction from "@/components/ui/StatTileAction.vue"
import StatTileBar from "@/components/ui/StatTileBar.vue"
import StatTileChart from "@/components/ui/StatTileChart.vue"
import StatTileContent from "@/components/ui/StatTileContent.vue"
import StatTileDescription from "@/components/ui/StatTileDescription.vue"
import StatTileGauge from "@/components/ui/StatTileGauge.vue"
import StatTileHeader from "@/components/ui/StatTileHeader.vue"
import StatTileIcon from "@/components/ui/StatTileIcon.vue"
import StatTileLabel from "@/components/ui/StatTileLabel.vue"
import StatTileList from "@/components/ui/StatTileList.vue"
import StatTileMeter from "@/components/ui/StatTileMeter.vue"
import StatTileRing from "@/components/ui/StatTileRing.vue"
import StatTileSegments from "@/components/ui/StatTileSegments.vue"
import StatTileSparkline from "@/components/ui/StatTileSparkline.vue"
import StatTileTrend from "@/components/ui/StatTileTrend.vue"
import StatTileUnit from "@/components/ui/StatTileUnit.vue"
import StatTileValue from "@/components/ui/StatTileValue.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { formatNumber } from "@/lib/persian"

/** دادهٔ نمونه برای هر بازه؛ در پروژهٔ واقعی همین‌ها پاسخِ API هستند. */
const DATA = {
  "7": { visits: [42, 48, 45, 52, 61, 58, 66], revenue: 186, orders: 820, conversion: 3.4 },
  "30": { visits: [38, 41, 47, 44, 52, 49, 58, 55, 63, 60, 68, 72], revenue: 824, orders: 3_285, conversion: 3.9 },
  "90": { visits: [30, 34, 33, 41, 39, 45, 50, 47, 55, 58, 61, 66, 70], revenue: 2_410, orders: 9_870, conversion: 4.2 },
} as const

const CHANNELS = [
  { label: "فروشگاه آنلاین", value: 45, color: "var(--chart-1)" },
  { label: "اپلیکیشن", value: 35, color: "var(--chart-2)" },
  { label: "فروش حضوری", value: 20, color: "var(--chart-4)" },
]

const period = ref<keyof typeof DATA>("30")
const data = computed(() => DATA[period.value])

function setPeriod(value: string | string[] | undefined) {
  if (typeof value === "string" && value) period.value = value as keyof typeof DATA
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full min-w-0 max-w-6xl flex-col gap-6 bg-muted p-4 sm:p-6">
      <header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">گزارش‌ها</h1>
          <p class="text-sm text-muted-foreground">نمای کلی فروش، بازدید و مشتریان در بازهٔ انتخابی.</p>
        </div>
        <ControlSize size="lg" mobile-size="default" as-child>
          <ToggleGroup type="single" variant="segmented" :value="period" aria-label="بازهٔ زمانی" @update:value="setPeriod">
            <ToggleGroupItem value="7" class="px-4">۷ روز</ToggleGroupItem>
            <ToggleGroupItem value="30" class="px-4">۳۰ روز</ToggleGroupItem>
            <ToggleGroupItem value="90" class="px-4">۹۰ روز</ToggleGroupItem>
          </ToggleGroup>
        </ControlSize>
      </header>

      <!-- ردیفِ اول: چهار شاخص، هر کدام یک نوع نمایشِ سبک. -->
      <section aria-label="شاخص‌های کلیدی" class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
        <StatTile class="gap-3">
          <StatTileHeader>
            <StatTileLabel>درآمد</StatTileLabel>
            <StatTileAction aria-label="جزئیات درآمد" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue class="text-2xl">
              {{ formatNumber(data.revenue) }}
              <StatTileUnit>میلیون تومان</StatTileUnit>
            </StatTileValue>
            <StatTileTrend :value="12.5" :format-value="() => '+۱۲٫۵٪'" />
          </StatTileContent>
          <StatTileSparkline :values="[...data.visits]" />
        </StatTile>

        <StatTile class="gap-3">
          <StatTileHeader>
            <StatTileLabel>سفارش‌ها</StatTileLabel>
            <StatTileAction aria-label="جزئیات سفارش‌ها" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue class="text-2xl">{{ formatNumber(data.orders) }}</StatTileValue>
            <span class="ms-auto text-sm text-muted-foreground">
              <strong class="font-semibold text-foreground">٪۴۲</strong> تا هدف
            </span>
          </StatTileContent>
          <StatTileMeter :value="42" />
        </StatTile>

        <StatTile class="gap-3">
          <StatTileHeader>
            <StatTileLabel>مشتریان تازه</StatTileLabel>
            <StatTileAction aria-label="جزئیات مشتریان" />
          </StatTileHeader>
          <div class="grid grid-cols-[62fr_38fr] gap-1.5">
            <div class="flex flex-col gap-1.5 border-s-2 border-info ps-3">
              <span class="text-2xl font-bold tabular-nums">{{ formatNumber(302) }}</span>
              <span class="text-xs text-muted-foreground">خرید مستقیم</span>
            </div>
            <div class="flex flex-col gap-1.5 border-s-2 border-warning ps-3">
              <span class="text-2xl font-bold tabular-nums">{{ formatNumber(184) }}</span>
              <span class="text-xs text-muted-foreground">معرفی</span>
            </div>
          </div>
          <StatTileSegments
            :segments="[
              { value: 302, color: 'var(--info)' },
              { value: 184, color: 'var(--warning)' },
            ]"
          />
        </StatTile>

        <StatTile class="gap-3">
          <StatTileHeader>
            <StatTileLabel>نرخ تبدیل</StatTileLabel>
            <StatTileAction aria-label="جزئیات نرخ تبدیل" />
          </StatTileHeader>
          <div class="flex items-end justify-between gap-3">
            <div class="flex flex-col gap-1.5">
              <StatTileValue class="text-2xl">٪{{ formatNumber(data.conversion) }}</StatTileValue>
              <StatTileTrend :value="9.2" :format-value="() => '+۹٫۲٪'" />
            </div>
            <StatTileChart
              class="h-20 min-w-0 max-w-44 flex-1"
              color="var(--success)"
              :data="[
                { label: 'تیر', value: 40 },
                { label: 'مرداد', value: 36 },
                { label: 'شهریور', value: 33 },
                { label: 'مهر', value: 45 },
              ]"
            />
          </div>
        </StatTile>
      </section>

      <!-- ردیفِ دوم: نمودارهای بزرگ‌تر، کنارِ هم با ارتفاعِ برابر. -->
      <section aria-label="جزئیات" class="grid grid-cols-1 gap-4 lg:grid-cols-3">
        <StatTile>
          <StatTileHeader>
            <StatTileLabel class="text-base text-foreground">سهمِ کانال‌های فروش</StatTileLabel>
            <StatTileAction aria-label="جزئیات کانال‌ها" />
          </StatTileHeader>
          <StatTileRing :segments="CHANNELS">
            <span class="text-2xl font-bold tabular-nums">{{ formatNumber(1_560) }}</span>
            <span class="text-xs text-muted-foreground">سفارش</span>
          </StatTileRing>
          <ul class="flex flex-col gap-2.5 text-sm">
            <li v-for="item in CHANNELS" :key="item.label" class="flex items-center gap-2">
              <span aria-hidden="true" class="size-2.5 rounded-full" :style="{ background: item.color }" />
              <span class="text-muted-foreground">{{ item.label }}</span>
              <span class="ms-auto font-semibold tabular-nums">٪{{ formatNumber(item.value) }}</span>
            </li>
          </ul>
        </StatTile>

        <StatTile>
          <StatTileHeader>
            <StatTileLabel class="text-base text-foreground">قیفِ خرید</StatTileLabel>
            <StatTileAction aria-label="جزئیات قیف" />
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue class="text-3xl">٪۶۲</StatTileValue>
            <StatTileDescription>به سبد خرید رسیده‌اند</StatTileDescription>
          </StatTileContent>
          <StatTileList
            :items="[
              { label: 'بازدید', value: 100, display: '٪۱۰۰' },
              { label: 'دیدنِ محصول', value: 74, display: '٪۷۴' },
              { label: 'افزودن به سبد', value: 62, display: '٪۶۲' },
              { label: 'شروعِ پرداخت', value: 38, display: '٪۳۸' },
              { label: 'خریدِ موفق', value: 21, display: '٪۲۱' },
            ]"
          />
        </StatTile>

        <StatTile>
          <StatTileHeader>
            <StatTileLabel class="text-base text-foreground">اعتبارِ پیامک</StatTileLabel>
            <StatTileAction aria-label="خرید اعتبار پیامک" />
          </StatTileHeader>
          <StatTileGauge :value="62" class="mt-2">
            <span class="text-3xl font-bold tabular-nums">{{ formatNumber(750) }}</span>
            <span class="text-xs text-muted-foreground">پیامک باقی‌مانده</span>
          </StatTileGauge>
          <StatTileDescription class="text-center">
            با این روند، اعتبار تا <strong>۱۲ روز</strong> دیگر کافی است.
          </StatTileDescription>
        </StatTile>
      </section>

      <!-- ردیفِ سوم: شاخص‌های عملیاتی با آیکون و نوارِ پیشرفت. -->
      <section aria-label="عملیات" class="grid grid-cols-1 gap-4 sm:grid-cols-2">
        <StatTile>
          <StatTileHeader>
            <StatTileIcon tone="success">
              <DigIcon name="users" />
            </StatTileIcon>
            <StatTileLabel>تیکت‌های پاسخ‌داده‌شده</StatTileLabel>
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue>٪۹۲</StatTileValue>
            <StatTileTrend :value="12" :format-value="() => '+۱۲٪'" />
          </StatTileContent>
          <StatTileBar :value="92" />
          <StatTileDescription>تقریباً همهٔ تیکت‌ها زیرِ یک ساعت پاسخ گرفته‌اند.</StatTileDescription>
        </StatTile>
        <StatTile>
          <StatTileHeader>
            <StatTileIcon tone="accent">
              <DigIcon name="wallet" />
            </StatTileIcon>
            <StatTileLabel>میانگینِ سبد خرید</StatTileLabel>
          </StatTileHeader>
          <StatTileContent>
            <StatTileValue>
              {{ formatNumber(562_000) }}
              <StatTileUnit>تومان</StatTileUnit>
            </StatTileValue>
            <StatTileTrend :value="-3.1" :format-value="() => '−۳٫۱٪'" />
          </StatTileContent>
          <StatTileSparkline :values="[6, 5.6, 5.9, 5.2, 5.4, 4.9, 5.1, 4.8]" color="var(--destructive)" />
        </StatTile>
      </section>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: control-sizepersianstat-tiletoggle-groupآیکون usersآیکون wallet

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

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

import { DigControlSize } from "@/components/ui/control-size"
import {
  DigToggleGroup,
  DigToggleGroupItem,
} from "@/components/ui/toggle-group"
import {
  DigStatTile,
  DigStatTileHeader,
  DigStatTileLabel,
  DigStatTileAction,
  DigStatTileContent,
  DigStatTileValue,
  DigStatTileUnit,
  DigStatTileTrend,
  DigStatTileSparkline,
  DigStatTileMeter,
  DigStatTileSegments,
  DigStatTileChart,
  DigStatTileRing,
  DigStatTileDescription,
  DigStatTileList,
  DigStatTileGauge,
  DigStatTileIcon,
  DigStatTileBar,
} from "@/components/ui/stat-tile"
import { DigIcon } from "@/lib/icons"
import { formatNumber } from "@/lib/persian"

const DATA = {
  "7": {
    visits: [42, 48, 45, 52, 61, 58, 66],
    revenue: 186,
    orders: 820,
    conversion: 3.4,
  },
  "30": {
    visits: [38, 41, 47, 44, 52, 49, 58, 55, 63, 60, 68, 72],
    revenue: 824,
    orders: 3_285,
    conversion: 3.9,
  },
  "90": {
    visits: [30, 34, 33, 41, 39, 45, 50, 47, 55, 58, 61, 66, 70],
    revenue: 2_410,
    orders: 9_870,
    conversion: 4.2,
  },
} as const

const CHANNELS = [
  { label: "فروشگاه آنلاین", value: 45, color: "var(--chart-1)" },
  { label: "اپلیکیشن", value: 35, color: "var(--chart-2)" },
  { label: "فروش حضوری", value: 20, color: "var(--chart-4)" },
]

@Component({
  selector: "dig-block-analytics",
  imports: [
    DigControlSize,
    DigToggleGroup,
    DigToggleGroupItem,
    DigStatTile,
    DigStatTileHeader,
    DigStatTileLabel,
    DigStatTileAction,
    DigStatTileContent,
    DigStatTileValue,
    DigStatTileUnit,
    DigStatTileTrend,
    DigStatTileSparkline,
    DigStatTileMeter,
    DigStatTileSegments,
    DigStatTileChart,
    DigStatTileRing,
    DigStatTileDescription,
    DigStatTileList,
    DigStatTileGauge,
    DigStatTileIcon,
    DigStatTileBar,
    DigIcon,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main
      digControlSize="xl"
      class="mx-auto flex w-full min-w-0 max-w-6xl flex-col gap-6 bg-muted p-4 sm:p-6"
    >
      <header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">گزارش‌ها</h1>
          <p class="text-sm text-muted-foreground">
            نمای کلی فروش، بازدید و مشتریان در بازهٔ انتخابی.
          </p>
        </div>
        <div digControlSize="lg" mobileSize="default">
          <div
            digToggleGroup
            type="single"
            variant="segmented"
            [value]="period()"
            aria-label="بازهٔ زمانی"
            (valueChange)="setPeriod($event)"
          >
            <button digToggleGroupItem value="7" class="px-4">۷ روز</button>
            <button digToggleGroupItem value="30" class="px-4">۳۰ روز</button>
            <button digToggleGroupItem value="90" class="px-4">۹۰ روز</button>
          </div>
        </div>
      </header>

      <!-- ردیفِ اول: چهار شاخص، هر کدام یک نوع نمایشِ سبک. -->
      <section
        aria-label="شاخص‌های کلیدی"
        class="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4"
      >
        <div digStatTile class="gap-3">
          <div digStatTileHeader>
            <div digStatTileLabel>درآمد</div>
            <button digStatTileAction aria-label="جزئیات درآمد"></button>
          </div>
          <div digStatTileContent>
            <div digStatTileValue class="text-2xl">
              {{ formatNumber(data().revenue) }}
              <span digStatTileUnit>میلیون تومان</span>
            </div>
            <div
              digStatTileTrend
              [value]="12.5"
              [formatValue]="() => '+۱۲٫۵٪'"
            ></div>
          </div>
          <svg digStatTileSparkline [values]="[...data().visits]"></svg>
        </div>

        <div digStatTile class="gap-3">
          <div digStatTileHeader>
            <div digStatTileLabel>سفارش‌ها</div>
            <button digStatTileAction aria-label="جزئیات سفارش‌ها"></button>
          </div>
          <div digStatTileContent>
            <div digStatTileValue class="text-2xl">
              {{ formatNumber(data().orders) }}
            </div>
            <span class="ms-auto text-sm text-muted-foreground"
              ><strong class="font-semibold text-foreground">٪۴۲</strong> تا هدف
            </span>
          </div>
          <div digStatTileMeter [value]="42"></div>
        </div>

        <div digStatTile class="gap-3">
          <div digStatTileHeader>
            <div digStatTileLabel>مشتریان تازه</div>
            <button digStatTileAction aria-label="جزئیات مشتریان"></button>
          </div>
          <div class="grid grid-cols-[62fr_38fr] gap-1.5">
            <div class="flex flex-col gap-1.5 border-s-2 border-info ps-3">
              <span class="text-2xl font-bold tabular-nums">{{
                formatNumber(302)
              }}</span>
              <span class="text-xs text-muted-foreground">خرید مستقیم</span>
            </div>
            <div class="flex flex-col gap-1.5 border-s-2 border-warning ps-3">
              <span class="text-2xl font-bold tabular-nums">{{
                formatNumber(184)
              }}</span>
              <span class="text-xs text-muted-foreground">معرفی</span>
            </div>
          </div>
          <div
            digStatTileSegments
            [segments]="[
              { value: 302, color: 'var(--info)' },
              { value: 184, color: 'var(--warning)' },
            ]"
          ></div>
        </div>

        <div digStatTile class="gap-3">
          <div digStatTileHeader>
            <div digStatTileLabel>نرخ تبدیل</div>
            <button digStatTileAction aria-label="جزئیات نرخ تبدیل"></button>
          </div>
          <div class="flex items-end justify-between gap-3">
            <div class="flex flex-col gap-1.5">
              <div digStatTileValue class="text-2xl">
                ٪{{ formatNumber(data().conversion) }}
              </div>
              <div
                digStatTileTrend
                [value]="9.2"
                [formatValue]="() => '+۹٫۲٪'"
              ></div>
            </div>
            <div
              digStatTileChart
              class="h-20 min-w-0 max-w-44 flex-1"
              color="var(--success)"
              [data]="[
                { label: 'تیر', value: 40 },
                { label: 'مرداد', value: 36 },
                { label: 'شهریور', value: 33 },
                { label: 'مهر', value: 45 },
              ]"
            ></div>
          </div>
        </div>
      </section>

      <!-- ردیفِ دوم: نمودارهای بزرگ‌تر، کنارِ هم با ارتفاعِ برابر. -->
      <section
        aria-label="جزئیات"
        class="grid grid-cols-1 gap-4 lg:grid-cols-3"
      >
        <div digStatTile>
          <div digStatTileHeader>
            <div digStatTileLabel class="text-base text-foreground">
              سهمِ کانال‌های فروش
            </div>
            <button digStatTileAction aria-label="جزئیات کانال‌ها"></button>
          </div>
          <div digStatTileRing [segments]="CHANNELS">
            <span class="text-2xl font-bold tabular-nums">{{
              formatNumber(1_560)
            }}</span>
            <span class="text-xs text-muted-foreground">سفارش</span>
          </div>
          <ul class="flex flex-col gap-2.5 text-sm">
            @for (item of CHANNELS; track item.label) {
              <li class="flex items-center gap-2">
                <span
                  aria-hidden="true"
                  class="size-2.5 rounded-full"
                  [style]="{ background: item.color }"
                ></span>
                <span class="text-muted-foreground">{{ item.label }}</span>
                <span class="ms-auto font-semibold tabular-nums"
                  >٪{{ formatNumber(item.value) }}</span
                >
              </li>
            }
          </ul>
        </div>

        <div digStatTile>
          <div digStatTileHeader>
            <div digStatTileLabel class="text-base text-foreground">
              قیفِ خرید
            </div>
            <button digStatTileAction aria-label="جزئیات قیف"></button>
          </div>
          <div digStatTileContent>
            <div digStatTileValue class="text-3xl">٪۶۲</div>
            <p digStatTileDescription>به سبد خرید رسیده‌اند</p>
          </div>
          <ul
            digStatTileList
            [items]="[
              { label: 'بازدید', value: 100, display: '٪۱۰۰' },
              { label: 'دیدنِ محصول', value: 74, display: '٪۷۴' },
              { label: 'افزودن به سبد', value: 62, display: '٪۶۲' },
              { label: 'شروعِ پرداخت', value: 38, display: '٪۳۸' },
              { label: 'خریدِ موفق', value: 21, display: '٪۲۱' },
            ]"
          ></ul>
        </div>

        <div digStatTile>
          <div digStatTileHeader>
            <div digStatTileLabel class="text-base text-foreground">
              اعتبارِ پیامک
            </div>
            <button digStatTileAction aria-label="خرید اعتبار پیامک"></button>
          </div>
          <div digStatTileGauge [value]="62" class="mt-2">
            <span class="text-3xl font-bold tabular-nums">{{
              formatNumber(750)
            }}</span>
            <span class="text-xs text-muted-foreground">پیامک باقی‌مانده</span>
          </div>
          <p digStatTileDescription class="text-center">
            با این روند، اعتبار تا <strong>۱۲ روز</strong> دیگر کافی است.
          </p>
        </div>
      </section>

      <!-- ردیفِ سوم: شاخص‌های عملیاتی با آیکون و نوارِ پیشرفت. -->
      <section
        aria-label="عملیات"
        class="grid grid-cols-1 gap-4 sm:grid-cols-2"
      >
        <div digStatTile>
          <div digStatTileHeader>
            <span digStatTileIcon tone="success"
              ><svg digIcon="users"></svg
            ></span>
            <div digStatTileLabel>تیکت‌های پاسخ‌داده‌شده</div>
          </div>
          <div digStatTileContent>
            <div digStatTileValue>٪۹۲</div>
            <div
              digStatTileTrend
              [value]="12"
              [formatValue]="() => '+۱۲٪'"
            ></div>
          </div>
          <div digStatTileBar [value]="92"></div>
          <p digStatTileDescription>
            تقریباً همهٔ تیکت‌ها زیرِ یک ساعت پاسخ گرفته‌اند.
          </p>
        </div>
        <div digStatTile>
          <div digStatTileHeader>
            <span digStatTileIcon tone="accent"
              ><svg digIcon="wallet"></svg
            ></span>
            <div digStatTileLabel>میانگینِ سبد خرید</div>
          </div>
          <div digStatTileContent>
            <div digStatTileValue>
              {{ formatNumber(562_000) }} <span digStatTileUnit>تومان</span>
            </div>
            <div
              digStatTileTrend
              [value]="-3.1"
              [formatValue]="() => '−۳٫۱٪'"
            ></div>
          </div>
          <svg
            digStatTileSparkline
            [values]="[6, 5.6, 5.9, 5.2, 5.4, 4.9, 5.1, 4.8]"
            color="var(--destructive)"
          ></svg>
        </div>
      </section>
    </main>
  `,
})
export class AnalyticsBlock {
  readonly formatNumber = formatNumber

  readonly CHANNELS = CHANNELS

  readonly period = signal<keyof typeof DATA>("30")

  readonly data = computed(() => DATA[this.period()])

  setPeriod(value: string | string[] | undefined) {
    if (typeof value === "string" && value)
      this.period.set(value as keyof typeof DATA)
  }
}

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

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

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