فراموشی رمز (کارت)
پیشنمایش تمامصفحهفراموشی رمز، مدلِ کارت: فرم در کارتی وسطچین روی پترنِ نقطهای، بدونِ پنلِ کناری. همان فرم، اعتبارسنجی و حالتهای صفحهٔ اصلی.
۱. نصب کامپوننتها
این بلاک از ۱۰ آیتم دیگ استفاده میکند: background-patternbuttoncontrol-sizeiconsinput-otplinkpassword-fieldpersiansteppertext-field
npx digdesign@latest add https://docs.digdesign.ir/r/background-pattern.json 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/input-otp.json https://docs.digdesign.ir/r/link.json https://docs.digdesign.ir/r/password-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/background-pattern.json 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/input-otp.json https://docs.digdesign.ir/r/link.json https://docs.digdesign.ir/r/password-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/background-pattern.json 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/input-otp.json https://docs.digdesign.ir/r/link.json https://docs.digdesign.ir/r/password-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/background-pattern.json 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/input-otp.json https://docs.digdesign.ir/r/link.json https://docs.digdesign.ir/r/password-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/stepper.json https://docs.digdesign.ir/r/text-field.jsonnpx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework vuepnpm dlx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework vueyarn dlx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework vuebunx --bun digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --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 background-pattern button control-size icons input input-otp link password-field persian stepper text-field --framework angularpnpm dlx digdesign@latest add background-pattern button control-size icons input input-otp link password-field persian stepper text-field --framework angularyarn dlx digdesign@latest add background-pattern button control-size icons input input-otp link password-field persian stepper text-field --framework angularbunx --bun digdesign@latest add background-pattern button control-size icons input input-otp link password-field persian stepper text-field --framework angularnpx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework androidpnpm dlx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework androidyarn dlx digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework androidbunx --bun digdesign@latest add background-pattern button control-size input-otp link password-field persian stepper text-field --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import NextLink from "next/link"
import { CheckIcon, SparklesIcon } from "@/components/icons"
import { DotPattern } from "@/components/ui/background-pattern"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp"
import { Link } from "@/components/ui/link"
import { PasswordField } from "@/components/ui/password-field"
import { Stepper, StepperItem, StepperTitle } from "@/components/ui/stepper"
import { TextField } from "@/components/ui/text-field"
import { isValidMobile, toFaDigits } from "@/lib/persian"
/** نشانِ برند بالای فرم. */
function BrandMark() {
return (
<span aria-hidden className="flex size-12 items-center justify-center rounded-xl bg-[var(--dig-violet-700)] text-[var(--dig-white)] [&>svg]:size-6">
<SparklesIcon />
</span>
)
}
/**
* بازیابی رمز با همان ساختارِ ورود و ثبتنام: فرم در ستونِ شروع، پنلِ برند در
* ستونِ پایان. سه قدم (شماره ← کد ← رمزِ تازه) در همان ستون عوض میشوند.
*/
/** مدلِ کارت: فرم در کارتی وسطچین روی پترنِ نقطهای، بدونِ پنلِ کناری. */
export default function ForgotPasswordCardBlock() {
const [step, setStep] = React.useState(0)
const [mobile, setMobile] = React.useState("")
const [password, setPassword] = React.useState("")
const [confirm, setConfirm] = React.useState("")
const [loading, setLoading] = React.useState(false)
const mismatch = confirm.length > 0 && confirm !== password
const next = async () => {
setLoading(true)
await new Promise((resolve) => setTimeout(resolve, 600))
setLoading(false)
setStep((value) => value + 1)
}
const titles = [
{ title: "فراموشی رمز", text: "شمارهٔ موبایلِ حساب را بنویسید تا کدِ بازیابی بفرستیم." },
{ title: "کد تأیید", text: "" },
{ title: "رمز تازه", text: "رمزی بسازید که جای دیگری استفاده نکردهاید." },
]
return (
<main className="relative flex min-h-svh flex-col items-center justify-center overflow-hidden bg-muted p-4">
<DotPattern size={22} />
<div className="relative flex w-full max-w-md flex-col items-center gap-8 rounded-xl border border-border bg-card px-6 py-10 shadow-card sm:px-10">
<ControlSizeProvider size="xl" className="flex w-full max-w-sm flex-1 flex-col justify-center gap-8">
{step < 3 ? (
<>
<header className="flex flex-col items-center gap-4 text-center">
<BrandMark />
<div className="flex flex-col gap-2">
<h1 className="text-2xl font-bold">{titles[step].title}</h1>
<p className="text-sm leading-6 text-muted-foreground">
{step === 1 ? (
<>
کدِ ۶ رقمی به <bdi dir="ltr" className="font-medium text-foreground">{toFaDigits(mobile)}</bdi> پیامک شد.
</>
) : (
titles[step].text
)}
</p>
</div>
</header>
<Stepper value={step} className="w-full">
<StepperItem>
<StepperTitle>شماره</StepperTitle>
</StepperItem>
<StepperItem>
<StepperTitle>کد تأیید</StepperTitle>
</StepperItem>
<StepperItem>
<StepperTitle>رمز تازه</StepperTitle>
</StepperItem>
</Stepper>
{step === 0 && (
<form
onSubmit={(event) => {
event.preventDefault()
if (isValidMobile(mobile)) void next()
}}
className="flex flex-col gap-4"
>
<TextField
label="شماره موبایل"
type="tel"
dir="ltr"
maxLength={11}
autoComplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
value={mobile}
onValueChange={setMobile}
required
validate={(value) => (isValidMobile(value) ? undefined : "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد.")}
/>
<Button type="submit" fullWidth loading={loading} className="mt-4">
ارسال کد
</Button>
</form>
)}
{step === 1 && (
<div className="flex flex-col items-center gap-6">
<InputOTP aria-label="کد تأیید" onComplete={next} disabled={loading}>
<InputOTPGroup>
{[0, 1, 2, 3, 4, 5].map((index) => (
<InputOTPSlot key={index} index={index} />
))}
</InputOTPGroup>
</InputOTP>
<p className="text-sm text-muted-foreground">
شماره اشتباه است؟{" "}
<Button variant="link" className="h-auto p-0" onClick={() => setStep(0)}>
تغییر شماره
</Button>
</p>
</div>
)}
{step === 2 && (
<form
onSubmit={(event) => {
event.preventDefault()
if (password && !mismatch) void next()
}}
className="flex flex-col gap-4"
>
<PasswordField label="رمز تازه" autoComplete="new-password" value={password} onValueChange={setPassword} strength requirements requirementsWhen="weak" required />
<PasswordField
label="تکرار رمز تازه"
autoComplete="new-password"
value={confirm}
onValueChange={setConfirm}
invalid={mismatch}
errorMessage="با رمز بالا یکی نیست."
required
/>
<Button type="submit" fullWidth loading={loading} disabled={!password || mismatch} className="mt-4">
ذخیرهٔ رمز
</Button>
</form>
)}
<p className="text-center text-sm text-muted-foreground">
رمز یادتان آمد؟ <Link href="/login">وارد شوید</Link>
</p>
</>
) : (
<div className="flex flex-col items-center gap-4 text-center" role="status">
<span aria-hidden className="flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6">
<CheckIcon />
</span>
<div className="flex flex-col gap-2">
<h1 className="text-2xl font-bold">رمز عبور تغییر کرد</h1>
<p className="text-sm text-muted-foreground">از این به بعد با رمز تازه وارد شوید.</p>
</div>
<Button asChild fullWidth className="mt-4">
<NextLink href="/login">ورود به حساب</NextLink>
</Button>
</div>
)}
</ControlSizeProvider>
<p className="text-xs text-muted-foreground">
<Link href="#" size="sm">
قوانین
</Link>{" "}
و{" "}
<Link href="#" size="sm">
حریم خصوصی
</Link>
</p>
</div>
</main>
)
}
<script setup lang="ts">
import { computed, ref } from "vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import DotPattern from "@/components/ui/DotPattern.vue"
import InputOTP from "@/components/ui/InputOTP.vue"
import InputOTPGroup from "@/components/ui/InputOTPGroup.vue"
import InputOTPSlot from "@/components/ui/InputOTPSlot.vue"
import Link from "@/components/ui/Link.vue"
import PasswordField from "@/components/ui/PasswordField.vue"
import Stepper from "@/components/ui/Stepper.vue"
import StepperItem from "@/components/ui/StepperItem.vue"
import StepperTitle from "@/components/ui/StepperTitle.vue"
import TextField from "@/components/ui/TextField.vue"
import { DigIcon } from "@/lib/icons"
import { isValidMobile, toFaDigits } from "@/lib/persian"
/**
* بازیابی رمز با همان ساختارِ ورود و ثبتنام: فرم در ستونِ شروع، پنلِ برند در
* ستونِ پایان. سه قدم (شماره ← کد ← رمزِ تازه) در همان ستون عوض میشوند.
* مدلِ کارت: فرم در کارتی وسطچین روی پترنِ نقطهای، بدونِ پنلِ کناری.
*/
const step = ref(0)
const mobile = ref("")
const password = ref("")
const confirm = ref("")
const loading = ref(false)
const mismatch = computed(() => confirm.value.length > 0 && confirm.value !== password.value)
async function next() {
loading.value = true
await new Promise((resolve) => setTimeout(resolve, 600))
loading.value = false
step.value += 1
}
const titles = [
{ title: "فراموشی رمز", text: "شمارهٔ موبایلِ حساب را بنویسید تا کدِ بازیابی بفرستیم." },
{ title: "کد تأیید", text: "" },
{ title: "رمز تازه", text: "رمزی بسازید که جای دیگری استفاده نکردهاید." },
]
function validateMobile(value: string) {
return isValidMobile(value) ? undefined : "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد."
}
function onMobileSubmit() {
if (isValidMobile(mobile.value)) void next()
}
function onPasswordSubmit() {
if (password.value && !mismatch.value) void next()
}
</script>
<template>
<main class="relative flex min-h-svh flex-col items-center justify-center overflow-hidden bg-muted p-4">
<DotPattern :size="22" />
<div class="relative flex w-full max-w-md flex-col items-center gap-8 rounded-xl border border-border bg-card px-6 py-10 shadow-card sm:px-10">
<ControlSize size="xl" class="flex w-full max-w-sm flex-1 flex-col justify-center gap-8">
<template v-if="step < 3">
<header class="flex flex-col items-center gap-4 text-center">
<span aria-hidden="true" class="flex size-12 items-center justify-center rounded-xl bg-[var(--dig-violet-700)] text-[var(--dig-white)] [&>svg]:size-6">
<DigIcon name="sparkles" />
</span>
<div class="flex flex-col gap-2">
<h1 class="text-2xl font-bold">{{ titles[step].title }}</h1>
<p class="text-sm leading-6 text-muted-foreground">
<template v-if="step === 1">
کدِ ۶ رقمی به <bdi dir="ltr" class="font-medium text-foreground">{{ toFaDigits(mobile) }}</bdi> پیامک شد.
</template>
<template v-else>{{ titles[step].text }}</template>
</p>
</div>
</header>
<Stepper :value="step" class="w-full">
<StepperItem>
<StepperTitle>شماره</StepperTitle>
</StepperItem>
<StepperItem>
<StepperTitle>کد تأیید</StepperTitle>
</StepperItem>
<StepperItem>
<StepperTitle>رمز تازه</StepperTitle>
</StepperItem>
</Stepper>
<form v-if="step === 0" class="flex flex-col gap-4" @submit.prevent="onMobileSubmit">
<TextField
v-model="mobile"
label="شماره موبایل"
type="tel"
dir="ltr"
maxlength="11"
autocomplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
required
:validate="validateMobile"
/>
<Button type="submit" full-width :loading="loading" class="mt-4">ارسال کد</Button>
</form>
<div v-if="step === 1" class="flex flex-col items-center gap-6">
<InputOTP aria-label="کد تأیید" :disabled="loading" @complete="next">
<InputOTPGroup>
<InputOTPSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
</InputOTPGroup>
</InputOTP>
<p class="text-sm text-muted-foreground">
شماره اشتباه است؟
<Button variant="link" class="h-auto p-0" @click="step = 0">تغییر شماره</Button>
</p>
</div>
<form v-if="step === 2" class="flex flex-col gap-4" @submit.prevent="onPasswordSubmit">
<PasswordField v-model="password" label="رمز تازه" autocomplete="new-password" strength requirements requirements-when="weak" required />
<PasswordField
v-model="confirm"
label="تکرار رمز تازه"
autocomplete="new-password"
:invalid="mismatch"
error-message="با رمز بالا یکی نیست."
required
/>
<Button type="submit" full-width :loading="loading" :disabled="!password || mismatch" class="mt-4">ذخیرهٔ رمز</Button>
</form>
<p class="text-center text-sm text-muted-foreground">
رمز یادتان آمد؟ <Link href="/login">وارد شوید</Link>
</p>
</template>
<div v-else class="flex flex-col items-center gap-4 text-center" role="status">
<span aria-hidden="true" class="flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6">
<DigIcon name="check" />
</span>
<div class="flex flex-col gap-2">
<h1 class="text-2xl font-bold">رمز عبور تغییر کرد</h1>
<p class="text-sm text-muted-foreground">از این به بعد با رمز تازه وارد شوید.</p>
</div>
<Button as-child full-width class="mt-4">
<a href="/login">ورود به حساب</a>
</Button>
</div>
</ControlSize>
<p class="text-xs text-muted-foreground">
<Link href="#" size="sm">قوانین</Link>
و
<Link href="#" size="sm">حریم خصوصی</Link>
</p>
</div>
</main>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: background-patterncontrol-sizeinput-otplinkpassword-fieldpersiansteppertext-fieldآیکون checkآیکون sparkles
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
inject,
} from "@angular/core"
import { DigButton } from "@/components/ui/button"
import { DigControlSize } from "@/components/ui/control-size"
import { DigDotPattern } from "@/components/ui/background-pattern"
import { DigIcon } from "@/lib/icons"
import { DigInput, DigInputField } from "@/components/ui/input"
import {
DigInputOtp,
DigInputOtpGroup,
DigInputOtpSlot,
} from "@/components/ui/input-otp"
import { DigLink } from "@/components/ui/link"
import { DigPasswordField } from "@/components/ui/password-field"
import {
DigStepper,
DigStepperItem,
DigStepperTitle,
} from "@/components/ui/stepper"
import { DigTextField } from "@/components/ui/text-field"
import { isValidMobile, toFaDigits } from "@/lib/persian"
@Component({
selector: "dig-block-forgot-password-card",
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
DigButton,
DigControlSize,
DigDotPattern,
DigIcon,
DigInput,
DigInputField,
DigInputOtp,
DigInputOtpGroup,
DigInputOtpSlot,
DigLink,
DigPasswordField,
DigStepper,
DigStepperItem,
DigStepperTitle,
DigTextField,
],
template: `
<main
class="relative flex min-h-svh flex-col items-center justify-center overflow-hidden bg-muted p-4"
>
<div digDotPattern [size]="22"></div>
<div
class="relative flex w-full max-w-md flex-col items-center gap-8 rounded-xl border border-border bg-card px-6 py-10 shadow-card sm:px-10"
>
<div
digControlSize="xl"
class="flex w-full max-w-sm flex-1 flex-col justify-center gap-8"
>
@if (step < 3) {
<header class="flex flex-col items-center gap-4 text-center">
<span
aria-hidden="true"
class="flex size-12 items-center justify-center rounded-xl bg-[var(--dig-violet-700)] text-[var(--dig-white)] [&>svg]:size-6"
>
<svg digIcon="sparkles"></svg>
</span>
<div class="flex flex-col gap-2">
<h1 class="text-2xl font-bold">{{ titles[step].title }}</h1>
<p class="text-sm leading-6 text-muted-foreground">
@if (step === 1) {
کدِ ۶ رقمی به
<bdi dir="ltr" class="font-medium text-foreground">{{
toFaDigits(mobile)
}}</bdi>
پیامک شد.
} @else {
{{ titles[step].text }}
}
</p>
</div>
</header>
<ol digStepper [value]="step" class="w-full">
<li digStepperItem>
<span digStepperTitle>شماره</span>
</li>
<li digStepperItem>
<span digStepperTitle>کد تأیید</span>
</li>
<li digStepperItem>
<span digStepperTitle>رمز تازه</span>
</li>
</ol>
@if (step === 0) {
<form
class="flex flex-col gap-4"
(submit)="$event.preventDefault(); onMobileSubmit()"
>
<div
digTextField
label="شماره موبایل"
required
[validate]="validateMobile"
>
<dig-input>
<input
digInput
[value]="mobile"
(valueChange)="mobile = $event"
type="tel"
dir="ltr"
maxlength="11"
autocomplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
/>
</dig-input>
</div>
<button
digButton
type="submit"
fullWidth
[loading]="loading"
class="mt-4"
>
ارسال کد
</button>
</form>
}
@if (step === 1) {
<div class="flex flex-col items-center gap-6">
<div
digInputOtp
aria-label="کد تأیید"
[disabled]="loading"
(complete)="next()"
>
<div digInputOtpGroup>
@for (index of [0, 1, 2, 3, 4, 5]; track index) {
<input digInputOtpSlot [index]="index" />
}
</div>
</div>
<p class="text-sm text-muted-foreground">
شماره اشتباه است؟
<button
digButton
type="button"
variant="link"
class="h-auto p-0"
[disabled]="loading"
(click)="step = 0"
>
تغییر شماره
</button>
</p>
</div>
}
@if (step === 2) {
<form
class="flex flex-col gap-4"
(submit)="$event.preventDefault(); onPasswordSubmit()"
>
<div
digPasswordField
[(value)]="password"
label="رمز تازه"
autocomplete="new-password"
strength
requirements
requirementsWhen="weak"
required
></div>
<div
digPasswordField
[(value)]="confirm"
label="تکرار رمز تازه"
autocomplete="new-password"
[invalid]="mismatch"
errorMessage="با رمز بالا یکی نیست."
required
></div>
<button
digButton
type="submit"
fullWidth
[loading]="loading"
[disabled]="!password || mismatch"
class="mt-4"
>
ذخیرهٔ رمز
</button>
</form>
}
<p class="text-center text-sm text-muted-foreground">
رمز یادتان آمد؟ <a digLink href="/login">وارد شوید</a>
</p>
} @else {
<div
class="flex flex-col items-center gap-4 text-center"
role="status"
>
<span
aria-hidden="true"
class="flex size-12 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-6"
>
<svg digIcon="check"></svg>
</span>
<div class="flex flex-col gap-2">
<h1 class="text-2xl font-bold">رمز عبور تغییر کرد</h1>
<p class="text-sm text-muted-foreground">
از این به بعد با رمز تازه وارد شوید.
</p>
</div>
<a digButton fullWidth class="mt-4" href="/login">ورود به حساب</a>
</div>
}
</div>
<p class="text-xs text-muted-foreground">
<a digLink href="#" size="sm">قوانین</a>
و
<a digLink href="#" size="sm">حریم خصوصی</a>
</p>
</div>
</main>
`,
})
export class ForgotPasswordCardBlock {
private readonly changeDetector = inject(ChangeDetectorRef)
readonly toFaDigits = toFaDigits
/**
* بازیابی رمز با همان ساختارِ ورود و ثبتنام: فرم در ستونِ شروع، پنلِ برند در
* ستونِ پایان. سه قدم (شماره ← کد ← رمزِ تازه) در همان ستون عوض میشوند.
* مدلِ کارت: فرم در کارتی وسطچین روی پترنِ نقطهای، بدونِ پنلِ کناری.
*/
step = 0
mobile = ""
password = ""
confirm = ""
loading = false
get mismatch() {
return this.confirm.length > 0 && this.confirm !== this.password
}
async next() {
if (this.loading) return
this.loading = true
await new Promise((resolve) => setTimeout(resolve, 600))
this.loading = false
this.step += 1
this.changeDetector.markForCheck()
}
readonly titles = [
{
title: "فراموشی رمز",
text: "شمارهٔ موبایلِ حساب را بنویسید تا کدِ بازیابی بفرستیم.",
},
{ title: "کد تأیید", text: "" },
{ title: "رمز تازه", text: "رمزی بسازید که جای دیگری استفاده نکردهاید." },
]
validateMobile(value: string) {
return isValidMobile(value)
? undefined
: "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد."
}
onMobileSubmit() {
if (isValidMobile(this.mobile)) void this.next()
}
onPasswordSubmit() {
if (this.password && this.password === this.confirm) void this.next()
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.