باشگاهِ مشتریان
پیشنمایش تمامصفحهامتیاز و سطح با فاصله تا سطحِ بعد، جوایز با دلیلِ صریح برای غیرفعالها («۲٬۵۸۰ امتیاز کم داری»)، کدِ جایزه با کپی و تاریخچهٔ امتیاز.
۱. نصب کامپوننتها
این بلاک از ۶ آیتم دیگ استفاده میکند: buttoncontrol-sizeiconspersianprogresstoast
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/toast.jsonpnpm 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/toast.jsonyarn 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/toast.jsonbunx --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/toast.jsonnpx digdesign@latest add button control-size persian progress toast --framework vuepnpm dlx digdesign@latest add button control-size persian progress toast --framework vueyarn dlx digdesign@latest add button control-size persian progress toast --framework vuebunx --bun digdesign@latest add button control-size persian progress toast --framework vuenpx digdesign@latest add button --framework sveltepnpm dlx digdesign@latest add button --framework svelteyarn dlx digdesign@latest add button --framework sveltebunx --bun digdesign@latest add button --framework sveltenpx digdesign@latest add button control-size icons persian progress toast --framework angularpnpm dlx digdesign@latest add button control-size icons persian progress toast --framework angularyarn dlx digdesign@latest add button control-size icons persian progress toast --framework angularbunx --bun digdesign@latest add button control-size icons persian progress toast --framework angularnpx digdesign@latest add button control-size persian progress toast --framework androidpnpm dlx digdesign@latest add button control-size persian progress toast --framework androidyarn dlx digdesign@latest add button control-size persian progress toast --framework androidbunx --bun digdesign@latest add button control-size persian progress toast --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { BadgeStarIcon, CheckIcon, CopyIcon, ShopIcon, SparklesIcon, 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 { toast } from "@/components/ui/toast"
import { formatCurrency, formatNumber, toFaDigits } from "@/lib/persian"
const LEVEL = { name: "نقرهای", next: "طلایی", points: 3_420, nextAt: 5_000 }
const REWARDS = [
{ title: "۵۰ هزار تومان اعتبار", cost: 1_000, code: "AVND50", label: "اعتبار خرید", tone: "violet", icon: <WalletIcon /> },
{ title: "ارسالِ رایگانِ یک ماهه", cost: 1_500, code: "SHIPFREE", label: "ارسال رایگان", tone: "blue", icon: <TruckIcon /> },
{ title: "٪۱۰ تخفیفِ خانهٔ سفال", cost: 2_500, code: "SOFAL10", label: "پیشنهاد شریک", tone: "amber", icon: <ShopIcon /> },
{ title: "اشتراکِ حرفهای، یک ماه", cost: 6_000, code: "PRO1M", label: "ارتقای حساب", tone: "green", icon: <SparklesIcon /> },
]
const HISTORY = [
{ title: "خریدِ کافه رست", points: 185, date: "امروز" },
{ title: "دعوتِ سارا محمدی", points: 500, date: "دیروز" },
{ title: "خرید از فروشگاهِ بوم", points: 740, date: "۱۲ مهر" },
]
/**
* باشگاهِ مشتریان: کارتِ تیرهٔ امتیاز با سطحِ فعلی و فاصله تا سطحِ بعد، جوایزِ قابلِ دریافت
* (جایزهٔ گرانتر از موجودی غیرفعال با دلیلِ «۲٬۵۸۰ امتیاز کم داری»)، و تاریخچهٔ کسبِ امتیاز.
*/
export default function WalletRewardsBlock() {
const [points, setPoints] = React.useState(LEVEL.points)
const [claimed, setClaimed] = React.useState<string[]>([])
return (
<ControlSizeProvider size="xl" asChild>
<main className="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 className="sr-only">باشگاهِ مشتریان</h1>
<section aria-label="امتیازِ من" className="flex flex-col gap-5 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)] sm:p-8">
<div className="flex items-center justify-between gap-3">
<span className="flex items-center gap-2 font-semibold">
<BadgeStarIcon aria-hidden className="size-5 text-[var(--dig-orange-400)]" />
باشگاهِ آوند · سطحِ {LEVEL.name}
</span>
</div>
<div className="flex flex-col gap-1">
<span className="text-sm text-muted-foreground">امتیازِ قابلِ خرج</span>
<span className="text-4xl font-black tabular-nums">{formatNumber(points)}</span>
</div>
<div className="flex flex-col gap-2">
<Progress value={(LEVEL.points / LEVEL.nextAt) * 100} aria-label={`پیشرفت تا سطحِ ${LEVEL.next}`} className="[--progress:var(--dig-orange-400)]" />
<span className="text-sm text-muted-foreground">
{formatNumber(LEVEL.nextAt - LEVEL.points)} امتیاز تا سطحِ {LEVEL.next} (ارسالِ رایگانِ همیشگی)
</span>
</div>
</section>
<section aria-labelledby="wr-rewards" className="flex flex-col gap-4">
<h2 id="wr-rewards" className="text-xl font-bold">
جوایز
</h2>
<ul className="grid grid-cols-1 gap-3 sm:grid-cols-2">
{REWARDS.map((reward) => {
const missing = reward.cost - points
const done = claimed.includes(reward.code)
return (
<li key={reward.code} className="overflow-hidden rounded-xl border border-border bg-card">
<div
className="relative flex h-24 items-center justify-between overflow-hidden px-5"
style={{
background: `linear-gradient(120deg, color-mix(in oklab, var(--dig-${reward.tone}-500) 16%, var(--card)), color-mix(in oklab, var(--dig-${reward.tone}-500) 5%, var(--card)))`,
color: `var(--dig-${reward.tone}-700)`,
}}
>
<span aria-hidden className="absolute -start-8 -bottom-12 size-28 rounded-full border-[18px] border-current opacity-[0.08]" />
<span aria-hidden className="absolute end-20 -top-10 size-20 rounded-full bg-current opacity-[0.06]" />
<span className="relative z-10 text-sm font-semibold">{reward.label}</span>
<span aria-hidden className="relative z-10 flex size-12 items-center justify-center rounded-2xl bg-card shadow-sm [&>svg]:size-6">
{reward.icon}
</span>
</div>
<div className="flex flex-col gap-4 p-4">
<div className="flex items-start justify-between gap-3">
<span className="font-semibold">{reward.title}</span>
<span className="shrink-0 text-sm text-muted-foreground tabular-nums">{formatNumber(reward.cost)} امتیاز</span>
</div>
{done ? (
<Button
variant="outline"
onClick={() => {
void navigator.clipboard?.writeText(reward.code)
toast.success("کد کپی شد.")
}}
>
<CopyIcon />
<bdi dir="ltr">{reward.code}</bdi>
</Button>
) : (
<Button
// در شبکهٔ گزینهها هیچکدام دکمهٔ اصلی نیست؛ چند دکمهٔ پررنگ کنارِ هم با هم رقابت میکنند.
variant="outline"
disabled={missing > 0}
onClick={() => {
setPoints((value) => value - reward.cost)
setClaimed((list) => [...list, reward.code])
toast.success("جایزه گرفتی؛ کدش آماده است.")
}}
>
{missing > 0 ? `${formatNumber(missing)} امتیاز کم داری` : "دریافت"}
</Button>
)}
</div>
</li>
)
})}
</ul>
</section>
<section aria-labelledby="wr-history" className="flex flex-col gap-3">
<h2 id="wr-history" className="text-xl font-bold">
امتیازهای اخیر
</h2>
<ul className="flex flex-col divide-y divide-border rounded-xl border border-border bg-card">
{HISTORY.map((item) => (
<li key={item.title} className="flex items-center gap-3 p-4">
<CheckIcon aria-hidden className="size-4 text-success-subtle-foreground" />
<span className="flex-1">{item.title}</span>
<span className="text-sm text-muted-foreground">{item.date}</span>
<span className="font-bold text-success-subtle-foreground tabular-nums">
<bdi dir="ltr">+{toFaDigits(item.points)}</bdi>
</span>
</li>
))}
</ul>
<p className="text-xs text-muted-foreground">هر {formatCurrency(1_000)} خرید یک امتیاز؛ امتیازها تا یک سال معتبرند.</p>
</section>
</main>
</ControlSizeProvider>
)
}
<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 { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, formatNumber, toFaDigits } from "@/lib/persian"
const LEVEL = { name: "نقرهای", next: "طلایی", points: 3_420, nextAt: 5_000 }
const REWARDS = [
{ title: "۵۰ هزار تومان اعتبار", cost: 1_000, code: "AVND50", label: "اعتبار خرید", tone: "violet", icon: "wallet" },
{ title: "ارسالِ رایگانِ یک ماهه", cost: 1_500, code: "SHIPFREE", label: "ارسال رایگان", tone: "blue", icon: "truck" },
{ title: "٪۱۰ تخفیفِ خانهٔ سفال", cost: 2_500, code: "SOFAL10", label: "پیشنهاد شریک", tone: "amber", icon: "shop" },
{ title: "اشتراکِ حرفهای، یک ماه", cost: 6_000, code: "PRO1M", label: "ارتقای حساب", tone: "green", icon: "sparkles" },
]
const HISTORY = [
{ title: "خریدِ کافه رست", points: 185, date: "امروز" },
{ title: "دعوتِ سارا محمدی", points: 500, date: "دیروز" },
{ title: "خرید از فروشگاهِ بوم", points: 740, date: "۱۲ مهر" },
]
/**
* باشگاهِ مشتریان: کارتِ تیرهٔ امتیاز با سطحِ فعلی و فاصله تا سطحِ بعد، جوایزِ قابلِ دریافت
* (جایزهٔ گرانتر از موجودی غیرفعال با دلیلِ «۲٬۵۸۰ امتیاز کم داری»)، و تاریخچهٔ کسبِ امتیاز.
*/
const points = ref(LEVEL.points)
const claimed = ref<string[]>([])
function copyCode(code: string) {
void navigator.clipboard?.writeText(code)
toast.success("کد کپی شد.")
}
function claim(reward: (typeof REWARDS)[number]) {
points.value -= reward.cost
claimed.value = [...claimed.value, reward.code]
toast.success("جایزه گرفتی؛ کدش آماده است.")
}
</script>
<template>
<ControlSize size="xl" as-child>
<main class="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 class="sr-only">باشگاهِ مشتریان</h1>
<section aria-label="امتیازِ من" class="flex flex-col gap-5 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)] sm:p-8">
<div class="flex items-center justify-between gap-3">
<span class="flex items-center gap-2 font-semibold">
<DigIcon name="badge-star" aria-hidden="true" class="size-5 text-[var(--dig-orange-400)]" />
باشگاهِ آوند · سطحِ {{ LEVEL.name }}
</span>
</div>
<div class="flex flex-col gap-1">
<span class="text-sm text-muted-foreground">امتیازِ قابلِ خرج</span>
<span class="text-4xl font-black tabular-nums">{{ formatNumber(points) }}</span>
</div>
<div class="flex flex-col gap-2">
<Progress :value="(LEVEL.points / LEVEL.nextAt) * 100" :aria-label="`پیشرفت تا سطحِ ${LEVEL.next}`" class="[--progress:var(--dig-orange-400)]" />
<span class="text-sm text-muted-foreground">{{ formatNumber(LEVEL.nextAt - LEVEL.points) }} امتیاز تا سطحِ {{ LEVEL.next }} (ارسالِ رایگانِ همیشگی)</span>
</div>
</section>
<section aria-labelledby="wr-rewards" class="flex flex-col gap-4">
<h2 id="wr-rewards" class="text-xl font-bold">جوایز</h2>
<ul class="grid grid-cols-1 gap-3 sm:grid-cols-2">
<li v-for="reward in REWARDS" :key="reward.code" class="overflow-hidden rounded-xl border border-border bg-card">
<div
class="relative flex h-24 items-center justify-between overflow-hidden px-5"
:style="{
background: `linear-gradient(120deg, color-mix(in oklab, var(--dig-${reward.tone}-500) 16%, var(--card)), color-mix(in oklab, var(--dig-${reward.tone}-500) 5%, var(--card)))`,
color: `var(--dig-${reward.tone}-700)`,
}"
>
<span aria-hidden="true" class="absolute -start-8 -bottom-12 size-28 rounded-full border-[18px] border-current opacity-[0.08]" />
<span aria-hidden="true" class="absolute end-20 -top-10 size-20 rounded-full bg-current opacity-[0.06]" />
<span class="relative z-10 text-sm font-semibold">{{ reward.label }}</span>
<span aria-hidden="true" class="relative z-10 flex size-12 items-center justify-center rounded-2xl bg-card shadow-sm [&>svg]:size-6">
<DigIcon :name="reward.icon" />
</span>
</div>
<div class="flex flex-col gap-4 p-4">
<div class="flex items-start justify-between gap-3">
<span class="font-semibold">{{ reward.title }}</span>
<span class="shrink-0 text-sm text-muted-foreground tabular-nums">{{ formatNumber(reward.cost) }} امتیاز</span>
</div>
<Button v-if="claimed.includes(reward.code)" variant="outline" @click="copyCode(reward.code)">
<DigIcon name="copy" />
<bdi dir="ltr">{{ reward.code }}</bdi>
</Button>
<!-- در شبکهٔ گزینهها هیچکدام دکمهٔ اصلی نیست؛ چند دکمهٔ پررنگ کنارِ هم با هم رقابت میکنند. -->
<Button v-else variant="outline" :disabled="reward.cost - points > 0" @click="claim(reward)">
{{ reward.cost - points > 0 ? `${formatNumber(reward.cost - points)} امتیاز کم داری` : "دریافت" }}
</Button>
</div>
</li>
</ul>
</section>
<section aria-labelledby="wr-history" class="flex flex-col gap-3">
<h2 id="wr-history" class="text-xl font-bold">امتیازهای اخیر</h2>
<ul class="flex flex-col divide-y divide-border rounded-xl border border-border bg-card">
<li v-for="item in HISTORY" :key="item.title" class="flex items-center gap-3 p-4">
<DigIcon name="check" aria-hidden="true" class="size-4 text-success-subtle-foreground" />
<span class="flex-1">{{ item.title }}</span>
<span class="text-sm text-muted-foreground">{{ item.date }}</span>
<span class="font-bold text-success-subtle-foreground tabular-nums">
<bdi dir="ltr">+{{ toFaDigits(item.points) }}</bdi>
</span>
</li>
</ul>
<p class="text-xs text-muted-foreground">هر {{ formatCurrency(1_000) }} خرید یک امتیاز؛ امتیازها تا یک سال معتبرند.</p>
</section>
</main>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: control-sizepersianprogresstoastآیکون badge-starآیکون checkآیکون copyآیکون shopآیکون sparklesآیکون truckآیکون wallet
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import { Component, ChangeDetectionStrategy, signal } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigIcon } from "@/lib/icons"
import { DigProgress } from "@/components/ui/progress"
import { DigButton } from "@/components/ui/button"
import { toast } from "@/components/ui/toast"
import { formatCurrency, formatNumber, toFaDigits } from "@/lib/persian"
const LEVEL = { name: "نقرهای", next: "طلایی", points: 3_420, nextAt: 5_000 }
const REWARDS = [
{
title: "۵۰ هزار تومان اعتبار",
cost: 1_000,
code: "AVND50",
label: "اعتبار خرید",
tone: "violet",
icon: "wallet" as const,
},
{
title: "ارسالِ رایگانِ یک ماهه",
cost: 1_500,
code: "SHIPFREE",
label: "ارسال رایگان",
tone: "blue",
icon: "truck" as const,
},
{
title: "٪۱۰ تخفیفِ خانهٔ سفال",
cost: 2_500,
code: "SOFAL10",
label: "پیشنهاد شریک",
tone: "amber",
icon: "shop" as const,
},
{
title: "اشتراکِ حرفهای، یک ماه",
cost: 6_000,
code: "PRO1M",
label: "ارتقای حساب",
tone: "green",
icon: "sparkles" as const,
},
] as const
const HISTORY = [
{ title: "خریدِ کافه رست", points: 185, date: "امروز" },
{ title: "دعوتِ سارا محمدی", points: 500, date: "دیروز" },
{ title: "خرید از فروشگاهِ بوم", points: 740, date: "۱۲ مهر" },
]
function copyCode(code: string) {
void navigator.clipboard?.writeText(code)
toast.success("کد کپی شد.")
}
@Component({
selector: "dig-block-wallet-rewards",
imports: [DigControlSize, DigIcon, DigProgress, DigButton],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<main digControlSize="xl" class="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 class="sr-only">باشگاهِ مشتریان</h1>
<section
aria-label="امتیازِ من"
class="flex flex-col gap-5 rounded-xl bg-inverse p-6 text-[var(--dig-white)] [--muted-foreground:var(--dig-neutral-400)] sm:p-8"
>
<div class="flex items-center justify-between gap-3">
<span class="flex items-center gap-2 font-semibold"
><svg digIcon="badge-star" aria-hidden="true" class="size-5 text-[var(--dig-orange-400)]"></svg> باشگاهِ آوند
· سطحِ {{ LEVEL.name }}</span
>
</div>
<div class="flex flex-col gap-1">
<span class="text-sm text-muted-foreground">امتیازِ قابلِ خرج</span>
<span class="text-4xl font-black tabular-nums">{{ formatNumber(points()) }}</span>
</div>
<div class="flex flex-col gap-2">
<div
digProgress
[value]="(LEVEL.points / LEVEL.nextAt) * 100"
[attr.aria-label]="\`پیشرفت تا سطحِ \${LEVEL.next}\`"
class="[--progress:var(--dig-orange-400)]"
></div>
<span class="text-sm text-muted-foreground"
>{{ formatNumber(LEVEL.nextAt - LEVEL.points) }} امتیاز تا سطحِ {{ LEVEL.next }} (ارسالِ رایگانِ همیشگی)</span
>
</div>
</section>
<section aria-labelledby="wr-rewards" class="flex flex-col gap-4">
<h2 id="wr-rewards" class="text-xl font-bold">جوایز</h2>
<ul class="grid grid-cols-1 gap-3 sm:grid-cols-2">
@for (reward of REWARDS; track reward.code) {
<li class="overflow-hidden rounded-xl border border-border bg-card">
<div
class="relative flex h-24 items-center justify-between overflow-hidden px-5"
[style]="{
background: \`linear-gradient(120deg, color-mix(in oklab, var(--dig-\${reward.tone}-500) 16%, var(--card)), color-mix(in oklab, var(--dig-\${reward.tone}-500) 5%, var(--card)))\`,
color: \`var(--dig-\${reward.tone}-700)\`,
}"
>
<span
aria-hidden="true"
class="absolute -start-8 -bottom-12 size-28 rounded-full border-[18px] border-current opacity-[0.08]"
></span>
<span
aria-hidden="true"
class="absolute end-20 -top-10 size-20 rounded-full bg-current opacity-[0.06]"
></span>
<span class="relative z-10 text-sm font-semibold">{{ reward.label }}</span>
<span
aria-hidden="true"
class="relative z-10 flex size-12 items-center justify-center rounded-2xl bg-card shadow-sm [&>svg]:size-6"
><svg [digIcon]="reward.icon"></svg
></span>
</div>
<div class="flex flex-col gap-4 p-4">
<div class="flex items-start justify-between gap-3">
<span class="font-semibold">{{ reward.title }}</span>
<span class="shrink-0 text-sm text-muted-foreground tabular-nums"
>{{ formatNumber(reward.cost) }} امتیاز</span
>
</div>
@if (claimed().includes(reward.code)) {
<button digButton type="button" variant="outline" (click)="copyCode(reward.code)">
<svg digIcon="copy"></svg> <bdi dir="ltr">{{ reward.code }}</bdi>
</button>
} @else {
<button
digButton
type="button"
variant="outline"
[disabled]="reward.cost - points() > 0"
(click)="claim(reward)"
>
{{
reward.cost - points() > 0
? \`\${formatNumber(reward.cost - points())} امتیاز کم داری\`
: "دریافت"
}}
</button>
}
</div>
</li>
}
</ul>
</section>
<section aria-labelledby="wr-history" class="flex flex-col gap-3">
<h2 id="wr-history" class="text-xl font-bold">امتیازهای اخیر</h2>
<ul class="flex flex-col divide-y divide-border rounded-xl border border-border bg-card">
@for (item of HISTORY; track item.title) {
<li class="flex items-center gap-3 p-4">
<svg digIcon="check" aria-hidden="true" class="size-4 text-success-subtle-foreground"></svg>
<span class="flex-1">{{ item.title }}</span>
<span class="text-sm text-muted-foreground">{{ item.date }}</span>
<span class="font-bold text-success-subtle-foreground tabular-nums"
><bdi dir="ltr">+{{ toFaDigits(item.points) }}</bdi></span
>
</li>
}
</ul>
<p class="text-xs text-muted-foreground">
هر {{ formatCurrency(1_000) }} خرید یک امتیاز؛ امتیازها تا یک سال معتبرند.
</p>
</section>
</main>
`,
})
export class WalletRewardsBlock {
readonly toFaDigits = toFaDigits
readonly formatNumber = formatNumber
readonly formatCurrency = formatCurrency
readonly copyCode = copyCode
readonly HISTORY = HISTORY
readonly REWARDS = REWARDS
readonly LEVEL = LEVEL
readonly points = signal(LEVEL.points)
readonly claimed = signal<string[]>([])
claim(reward: (typeof REWARDS)[number]) {
this.points.set(this.points() - reward.cost)
this.claimed.set([...this.claimed(), reward.code])
toast.success("جایزه گرفتی؛ کدش آماده است.")
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.