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

تحلیلِ هزینه‌ها

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

هزینهٔ ماه با مقایسه، نوارِ سهمِ دسته‌ها و فهرستِ دسته‌ها با بودجه؛ عبور از بودجه با متنِ صریح و رنگ، نه فقط رنگ.

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

این بلاک از ۶ آیتم دیگ استفاده می‌کند: buttoncontrol-sizeiconspersianprogresstoggle-group

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

۲. کد صفحه

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

transactions-insights.tsx
"use client"

import * as React from "react"

import { ReceiptIcon, ShopIcon, TruckIcon, WalletIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Progress } from "@/components/ui/progress"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = [
  { key: "food", label: "خوراک و کافه", icon: <ShopIcon />, spent: 4_850_000, budget: 5_000_000, count: 23 },
  { key: "transport", label: "رفت‌وآمد", icon: <TruckIcon />, spent: 1_920_000, budget: 1_500_000, count: 31 },
  { key: "bills", label: "قبض و اشتراک", icon: <ReceiptIcon />, spent: 1_240_000, budget: 2_000_000, count: 6 },
  { key: "other", label: "سایر", icon: <WalletIcon />, spent: 2_310_000, budget: 3_000_000, count: 12 },
]

/**
 * تحلیلِ هزینه‌ها: جمعِ ماه با مقایسه با ماهِ قبل، نوارِ سهمِ هر دسته در یک خط، و فهرستِ
 * دسته‌ها با بودجه؛ دسته‌ای که از بودجه رد شده با رنگ و متنِ صریح («۴۲۰ هزار بیشتر») نشان
 * داده می‌شود، نه فقط رنگ. لمسِ هر دسته فهرستِ تراکنش‌هایش را باز می‌کند.
 */
export default function TransactionsInsightsBlock() {
  const [month, setMonth] = React.useState("this")
  const total = CATEGORIES.reduce((sum, item) => sum + item.spent, 0)
  const colors = [1, 2, 3, 4].map((tone) => `color-mix(in oklab, var(--chart-${tone}) 56%, var(--muted-foreground))`)
  const softWarning = "color-mix(in oklab, var(--warning) 58%, var(--muted-foreground))"
  const softDestructive = "color-mix(in oklab, var(--destructive) 54%, var(--muted-foreground))"

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-3xl flex-col gap-8 p-4 sm:p-6">
        <header className="flex flex-wrap items-end justify-between gap-x-4 gap-y-6">
          <div className="flex flex-col gap-1">
            <h1 className="text-2xl font-bold">هزینه‌های من</h1>
            <p className="text-muted-foreground">کجا خرج کردی و چقدر تا سقفِ هر دسته مانده.</p>
          </div>
          <ControlSizeProvider size="lg" mobileSize="default" asChild>
            <ToggleGroup type="single" variant="segmented" value={month} onValueChange={(value) => value && setMonth(value as string)} aria-label="ماه">
              <ToggleGroupItem value="last">شهریور</ToggleGroupItem>
              <ToggleGroupItem value="this">مهر</ToggleGroupItem>
            </ToggleGroup>
          </ControlSizeProvider>
        </header>

        <section aria-label="جمعِ هزینه" className="flex flex-col gap-5 rounded-xl bg-subtle p-6">
          <div className="flex flex-wrap items-end justify-between gap-3">
            <div className="flex flex-col gap-1">
              <span className="text-sm text-muted-foreground">جمعِ هزینهٔ {month === "this" ? "مهر" : "شهریور"}</span>
              <span className="text-3xl font-black tabular-nums">{formatCurrency(total)}</span>
            </div>
            <span className="text-sm text-muted-foreground">٪{toFaDigits(8)} کمتر از ماهِ قبل</span>
          </div>
          <div className="flex h-3 gap-0.5 overflow-hidden rounded-full" role="img" aria-label={CATEGORIES.map((item) => `${item.label} ٪${toFaDigits(Math.round((item.spent / total) * 100))}`).join("، ")}>
            {CATEGORIES.map((item, index) => (
              <span key={item.key} style={{ width: `${(item.spent / total) * 100}%`, background: colors[index] }} />
            ))}
          </div>
        </section>

        <ul className="flex flex-col gap-3">
          {CATEGORIES.map((item, index) => {
            const over = item.spent - item.budget
            // نزدیکِ سقف (۹۰٪ به بالا) پیش از عبور هشدار می‌گیرد تا کاربر فرصتِ ترمز داشته باشد.
            const near = over <= 0 && item.spent / item.budget >= 0.9
            return (
              <li key={item.key}>
                <Button variant="outline" className="h-auto w-full flex-col items-stretch gap-3 p-4 text-start font-normal">
                  <span className="flex items-center gap-3">
                    <span aria-hidden className="flex size-10 items-center justify-center rounded-lg [&>svg]:size-5" style={{ background: `color-mix(in oklab, ${colors[index]} 10%, var(--card))`, color: colors[index] }}>
                      {item.icon}
                    </span>
                    <span className="flex flex-1 flex-col">
                      <span className="font-semibold">{item.label}</span>
                      <span className="text-xs text-muted-foreground">{toFaDigits(item.count)} تراکنش</span>
                    </span>
                    <span className="flex flex-col items-end">
                      <span className="font-bold tabular-nums">{formatCurrency(item.spent)}</span>
                      <span
                        className={`text-xs ${over > 0 || near ? "font-medium" : "text-muted-foreground"}`}
                        style={over > 0 ? { color: softDestructive } : near ? { color: softWarning } : undefined}
                      >
                        {over > 0 ? `${formatCurrency(over)} بیشتر از بودجه` : near ? `نزدیکِ سقف؛ ${formatCurrency(-over)} مانده` : `${formatCurrency(-over)} مانده`}
                      </span>
                    </span>
                  </span>
                  <Progress value={Math.min(100, (item.spent / item.budget) * 100)} aria-label={`مصرفِ بودجهٔ ${item.label}`}
                    // رنگِ وضعیت هم کم‌اشباع است؛ متن همچنان معنای هشدار را مستقل از رنگ بیان می‌کند.
                    style={{ "--progress": over > 0 ? softDestructive : near ? softWarning : colors[index] } as React.CSSProperties}
                  />
                </Button>
              </li>
            )
          })}
        </ul>
      </main>
    </ControlSizeProvider>
  )
}
transactions-insights.vue
<script setup lang="ts">
import { ref } from "vue"

import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Progress from "@/components/ui/Progress.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = [
  { key: "food", label: "خوراک و کافه", icon: "shop", spent: 4_850_000, budget: 5_000_000, count: 23 },
  { key: "transport", label: "رفت‌وآمد", icon: "truck", spent: 1_920_000, budget: 1_500_000, count: 31 },
  { key: "bills", label: "قبض و اشتراک", icon: "receipt", spent: 1_240_000, budget: 2_000_000, count: 6 },
  { key: "other", label: "سایر", icon: "wallet", spent: 2_310_000, budget: 3_000_000, count: 12 },
]

/**
 * تحلیلِ هزینه‌ها: جمعِ ماه با مقایسه با ماهِ قبل، نوارِ سهمِ هر دسته در یک خط، و فهرستِ
 * دسته‌ها با بودجه؛ دسته‌ای که از بودجه رد شده با رنگ و متنِ صریح («۴۲۰ هزار بیشتر») نشان
 * داده می‌شود، نه فقط رنگ. لمسِ هر دسته فهرستِ تراکنش‌هایش را باز می‌کند.
 */
const month = ref("this")
const total = CATEGORIES.reduce((sum, item) => sum + item.spent, 0)
const colors = [1, 2, 3, 4].map((tone) => `color-mix(in oklab, var(--chart-${tone}) 56%, var(--muted-foreground))`)
const softWarning = "color-mix(in oklab, var(--warning) 58%, var(--muted-foreground))"
const softDestructive = "color-mix(in oklab, var(--destructive) 54%, var(--muted-foreground))"

const shareLabel = CATEGORIES.map((item) => `${item.label} ٪${toFaDigits(Math.round((item.spent / total) * 100))}`).join("، ")

function onMonthChange(value: string | string[] | undefined) {
  if (value) month.value = value as string
}

function overOf(item: (typeof CATEGORIES)[number]) {
  return item.spent - item.budget
}

// نزدیکِ سقف (۹۰٪ به بالا) پیش از عبور هشدار می‌گیرد تا کاربر فرصتِ ترمز داشته باشد.
function isNear(item: (typeof CATEGORIES)[number]) {
  return overOf(item) <= 0 && item.spent / item.budget >= 0.9
}

function statusColor(item: (typeof CATEGORIES)[number], index: number) {
  return overOf(item) > 0 ? softDestructive : isNear(item) ? softWarning : colors[index]
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full max-w-3xl flex-col gap-8 p-4 sm:p-6">
      <header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-6">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">هزینه‌های من</h1>
          <p class="text-muted-foreground">کجا خرج کردی و چقدر تا سقفِ هر دسته مانده.</p>
        </div>
        <ControlSize size="lg" mobile-size="default" as-child>
          <ToggleGroup type="single" variant="segmented" :value="month" aria-label="ماه" @update:value="onMonthChange">
            <ToggleGroupItem value="last">شهریور</ToggleGroupItem>
            <ToggleGroupItem value="this">مهر</ToggleGroupItem>
          </ToggleGroup>
        </ControlSize>
      </header>

      <section aria-label="جمعِ هزینه" class="flex flex-col gap-5 rounded-xl bg-subtle p-6">
        <div class="flex flex-wrap items-end justify-between gap-3">
          <div class="flex flex-col gap-1">
            <span class="text-sm text-muted-foreground">جمعِ هزینهٔ {{ month === "this" ? "مهر" : "شهریور" }}</span>
            <span class="text-3xl font-black tabular-nums">{{ formatCurrency(total) }}</span>
          </div>
          <span class="text-sm text-muted-foreground">٪{{ toFaDigits(8) }} کمتر از ماهِ قبل</span>
        </div>
        <div class="flex h-3 gap-0.5 overflow-hidden rounded-full" role="img" :aria-label="shareLabel">
          <span v-for="(item, index) in CATEGORIES" :key="item.key" :style="{ width: `${(item.spent / total) * 100}%`, background: colors[index] }" />
        </div>
      </section>

      <ul class="flex flex-col gap-3">
        <li v-for="(item, index) in CATEGORIES" :key="item.key">
          <Button variant="outline" class="h-auto w-full flex-col items-stretch gap-3 p-4 text-start font-normal">
            <span class="flex items-center gap-3">
              <span aria-hidden="true" class="flex size-10 items-center justify-center rounded-lg [&>svg]:size-5" :style="{ background: `color-mix(in oklab, ${colors[index]} 10%, var(--card))`, color: colors[index] }">
                <DigIcon :name="item.icon" />
              </span>
              <span class="flex flex-1 flex-col">
                <span class="font-semibold">{{ item.label }}</span>
                <span class="text-xs text-muted-foreground">{{ toFaDigits(item.count) }} تراکنش</span>
              </span>
              <span class="flex flex-col items-end">
                <span class="font-bold tabular-nums">{{ formatCurrency(item.spent) }}</span>
                <span
                  :class="['text-xs', overOf(item) > 0 || isNear(item) ? 'font-medium' : 'text-muted-foreground']"
                  :style="overOf(item) > 0 ? { color: softDestructive } : isNear(item) ? { color: softWarning } : undefined"
                >
                  {{ overOf(item) > 0 ? `${formatCurrency(overOf(item))} بیشتر از بودجه` : isNear(item) ? `نزدیکِ سقف؛ ${formatCurrency(-overOf(item))} مانده` : `${formatCurrency(-overOf(item))} مانده` }}
                </span>
              </span>
            </span>
            <!-- رنگِ وضعیت هم کم‌اشباع است؛ متن همچنان معنای هشدار را مستقل از رنگ بیان می‌کند. -->
            <Progress :value="Math.min(100, (item.spent / item.budget) * 100)" :aria-label="`مصرفِ بودجهٔ ${item.label}`" :style="{ '--progress': statusColor(item, index) }" />
          </Button>
        </li>
      </ul>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: control-sizepersianprogresstoggle-groupآیکون receiptآیکون shopآیکون truckآیکون wallet

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

transactions-insights.ts
import { Component, ChangeDetectionStrategy, signal } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigToggleGroup, DigToggleGroupItem } from "@/components/ui/toggle-group"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { cn } from "@/lib/utils"
import { DigProgress } from "@/components/ui/progress"
import { formatCurrency, toFaDigits } from "@/lib/persian"

const CATEGORIES = [
  { key: "food", label: "خوراک و کافه", icon: "shop" as const, spent: 4_850_000, budget: 5_000_000, count: 23 },
  { key: "transport", label: "رفت‌وآمد", icon: "truck" as const, spent: 1_920_000, budget: 1_500_000, count: 31 },
  { key: "bills", label: "قبض و اشتراک", icon: "receipt" as const, spent: 1_240_000, budget: 2_000_000, count: 6 },
  { key: "other", label: "سایر", icon: "wallet" as const, spent: 2_310_000, budget: 3_000_000, count: 12 },
] as const

const total = CATEGORIES.reduce((sum, item) => sum + item.spent, 0)

const colors = [1, 2, 3, 4].map((tone) => `color-mix(in oklab, var(--chart-${tone}) 56%, var(--muted-foreground))`)

const softWarning = "color-mix(in oklab, var(--warning) 58%, var(--muted-foreground))"

const softDestructive = "color-mix(in oklab, var(--destructive) 54%, var(--muted-foreground))"

const shareLabel = CATEGORIES.map(
  (item) => `${item.label} ٪${toFaDigits(Math.round((item.spent / total) * 100))}`
).join("، ")

function overOf(item: (typeof CATEGORIES)[number]) {
  return item.spent - item.budget
}

function isNear(item: (typeof CATEGORIES)[number]) {
  return overOf(item) <= 0 && item.spent / item.budget >= 0.9
}

function statusColor(item: (typeof CATEGORIES)[number], index: number) {
  return overOf(item) > 0 ? softDestructive : isNear(item) ? softWarning : colors[index]
}

@Component({
  selector: "dig-block-transactions-insights",
  imports: [DigControlSize, DigToggleGroup, DigToggleGroupItem, DigButton, DigIcon, DigProgress],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main digControlSize="xl" class="mx-auto flex w-full max-w-3xl flex-col gap-8 p-4 sm:p-6">
      <header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-6">
        <div class="flex flex-col gap-1">
          <h1 class="text-2xl font-bold">هزینه‌های من</h1>
          <p class="text-muted-foreground">کجا خرج کردی و چقدر تا سقفِ هر دسته مانده.</p>
        </div>
        <div digControlSize="lg" mobileSize="default">
          <div
            digToggleGroup
            type="single"
            variant="segmented"
            [value]="month()"
            aria-label="ماه"
            (valueChange)="onMonthChange($event)"
          >
            <button digToggleGroupItem value="last">شهریور</button> <button digToggleGroupItem value="this">مهر</button>
          </div>
        </div>
      </header>

      <section aria-label="جمعِ هزینه" class="flex flex-col gap-5 rounded-xl bg-subtle p-6">
        <div class="flex flex-wrap items-end justify-between gap-3">
          <div class="flex flex-col gap-1">
            <span class="text-sm text-muted-foreground">جمعِ هزینهٔ {{ month() === "this" ? "مهر" : "شهریور" }}</span>
            <span class="text-3xl font-black tabular-nums">{{ formatCurrency(total) }}</span>
          </div>
          <span class="text-sm text-muted-foreground">٪{{ toFaDigits(8) }} کمتر از ماهِ قبل</span>
        </div>
        <div class="flex h-3 gap-0.5 overflow-hidden rounded-full" role="img" [attr.aria-label]="shareLabel">
          @for (item of CATEGORIES; track item.key; let index = $index) {
            <span [style]="{ width: \`\${(item.spent / total) * 100}%\`, background: colors[index] }"></span>
          }
        </div>
      </section>

      <ul class="flex flex-col gap-3">
        @for (item of CATEGORIES; track item.key; let index = $index) {
          <li>
            <button
              digButton
              type="button"
              variant="outline"
              class="h-auto w-full flex-col items-stretch gap-3 p-4 text-start font-normal"
            >
              <span class="flex items-center gap-3"
                ><span
                  aria-hidden="true"
                  class="flex size-10 items-center justify-center rounded-lg [&>svg]:size-5"
                  [style]="{
                    background: \`color-mix(in oklab, \${colors[index]} 10%, var(--card))\`,
                    color: colors[index],
                  }"
                  ><svg [digIcon]="item.icon"></svg
                ></span>
                <span class="flex flex-1 flex-col"
                  ><span class="font-semibold">{{ item.label }}</span>
                  <span class="text-xs text-muted-foreground">{{ toFaDigits(item.count) }} تراکنش</span></span
                >
                <span class="flex flex-col items-end"
                  ><span class="font-bold tabular-nums">{{ formatCurrency(item.spent) }}</span>
                  <span
                    [class]="cn('text-xs', overOf(item) > 0 || isNear(item) ? 'font-medium' : 'text-muted-foreground')"
                    [style]="
                      overOf(item) > 0 ? { color: softDestructive } : isNear(item) ? { color: softWarning } : undefined
                    "
                    >{{
                      overOf(item) > 0
                        ? \`\${formatCurrency(overOf(item))} بیشتر از بودجه\`
                        : isNear(item)
                          ? \`نزدیکِ سقف؛ \${formatCurrency(-overOf(item))} مانده\`
                          : \`\${formatCurrency(-overOf(item))} مانده\`
                    }}</span
                  ></span
                ></span
              >
              <!-- رنگِ وضعیت هم کم‌اشباع است؛ متن همچنان معنای هشدار را مستقل از رنگ بیان می‌کند. -->
              <div
                digProgress
                [value]="math.min(100, (item.spent / item.budget) * 100)"
                [attr.aria-label]="\`مصرفِ بودجهٔ \${item.label}\`"
                [style]="{ '--progress': statusColor(item, index) }"
              ></div>
            </button>
          </li>
        }
      </ul>
    </main>
  `,
})
export class TransactionsInsightsBlock {
  readonly math = Math

  readonly cn = cn

  readonly toFaDigits = toFaDigits

  readonly formatCurrency = formatCurrency

  readonly statusColor = statusColor

  readonly isNear = isNear

  readonly overOf = overOf

  readonly shareLabel = shareLabel

  readonly softDestructive = softDestructive

  readonly softWarning = softWarning

  readonly colors = colors

  readonly total = total

  readonly CATEGORIES = CATEGORIES

  readonly month = signal("this")

  onMonthChange(value: string | string[] | undefined) {
    if (value) this.month.set(value as string)
  }
}

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

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

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