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

همان ساختارِ ورود و ثبت‌نام: سه قدمِ شماره، کدِ پیامکی و رمزِ تازه با مراحل، در ستونِ فرم؛ پنلِ برند کنارش و پیامِ موفقیت.

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

این بلاک از ۱۰ آیتم دیگ استفاده می‌کند: avatarbuttoncontrol-sizeiconsinput-otplinkpassword-fieldpersiansteppertext-field

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

۲. کد صفحه

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

forgot-password.tsx
"use client"

import * as React from "react"
import NextLink from "next/link"

import { AvatarGenderIcon, CheckIcon, SparklesIcon } from "@/components/icons"
import { Avatar } from "@/components/ui/avatar"
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"
import { stockImages } from "@/lib/stock-images"

/**
 * پنلِ برند کنارِ فرم (در موبایل پنهان تا فرم بالای صفحه بماند): پیش‌نمایشِ تزئینی محصول و نظرِ یک
 * مشتری. رنگ‌ها با بازتعریفِ متغیرهای پایه روی خودِ پنل برعکس می‌شوند.
 */
function BrandPanel() {
  return (
    <aside
      aria-label="دربارهٔ حساب‌یار"
      className="relative hidden flex-col justify-end overflow-hidden rounded-xl bg-[var(--dig-violet-800)] p-10 text-[var(--dig-white)] lg:flex [--muted-foreground:var(--dig-violet-200)]"
    >
      {/* پیش‌نمایشِ محصول: سه پنجرهٔ پشتِ هم با خط‌های اسکلتی. */}
      <div aria-hidden className="absolute -end-16 top-12 hidden h-80 w-[115%] lg:block">
        {[2, 1, 0].map((layer) => (
          <div
            key={layer}
            className="absolute inset-y-0 rounded-xl border border-[var(--dig-violet-600)] bg-[var(--dig-violet-700)] p-5"
            style={{ insetInlineStart: `${layer * 2.5}rem`, top: `${layer * 1.5}rem`, transform: "rotate(-6deg)" }}
          >
            {layer === 0 && (
              <div className="flex h-full gap-4">
                <div className="flex w-40 flex-col gap-3">
                  <span className="flex size-9 items-center justify-center rounded-lg bg-[var(--dig-violet-500)] [&>svg]:size-4">
                    <SparklesIcon />
                  </span>
                  <span className="flex h-9 items-center gap-2 rounded-lg bg-[var(--dig-violet-600)] px-3 text-sm">داشبورد</span>
                  {[70, 55, 80, 60].map((width) => (
                    <span key={width} className="h-2.5 rounded-full bg-[var(--dig-violet-600)]" style={{ width: `${width}%` }} />
                  ))}
                </div>
                <div className="flex flex-1 flex-col gap-3">
                  <span className="h-16 rounded-lg bg-[var(--dig-violet-600)]" />
                  <span className="h-2.5 w-2/3 rounded-full bg-[var(--dig-violet-600)]" />
                  <span className="h-2.5 w-1/2 rounded-full bg-[var(--dig-violet-600)]" />
                </div>
              </div>
            )}
          </div>
        ))}
      </div>
      <span aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 h-2/3 bg-linear-to-t from-[var(--dig-violet-800)] from-40% to-transparent" />

      <figure className="relative flex max-w-md flex-col gap-4 lg:gap-6">
        <Avatar size="lg" alt="سارا محمدی" src={stockImages.personWoman2.src} icon={<AvatarGenderIcon gender="female" />} className="hidden ring-2 ring-[var(--dig-violet-500)] lg:flex" />
        <blockquote className="text-lg leading-relaxed font-bold lg:text-2xl">
          «حساب‌وکتابِ ماهانه‌مان از سه روز به یک ساعت رسید.{" "}
          <span className="text-muted-foreground">حالا وقتمان صرفِ فروش می‌شود، نه اکسل.»</span>
        </blockquote>
        <figcaption className="flex flex-col gap-0.5">
          <span className="font-semibold">سارا محمدی</span>
          <span className="text-sm text-muted-foreground">مدیرِ فروشگاهِ آنلاین</span>
        </figcaption>
      </figure>
    </aside>
  )
}

/** نشانِ برند بالای فرم. */
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 ForgotPasswordBlock() {
  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="grid grid-cols-1 min-h-svh gap-4 bg-background p-4 lg:grid-cols-2">
      <div className="flex flex-col items-center px-4 py-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>
      <BrandPanel />
    </main>
  )
}
forgot-password.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import Avatar from "@/components/ui/Avatar.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.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="grid grid-cols-1 min-h-svh gap-4 bg-background p-4 lg:grid-cols-2">
    <div class="flex flex-col items-center px-4 py-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>
    <aside
      aria-label="دربارهٔ حساب‌یار"
      class="relative hidden flex-col justify-end overflow-hidden rounded-xl bg-[var(--dig-violet-800)] p-10 text-[var(--dig-white)] lg:flex [--muted-foreground:var(--dig-violet-200)]"
    >
      <!-- پیش‌نمایشِ محصول: سه پنجرهٔ پشتِ هم با خط‌های اسکلتی. -->
      <div aria-hidden="true" class="absolute -end-16 top-12 hidden h-80 w-[115%] lg:block">
        <div
          v-for="layer in [2, 1, 0]"
          :key="layer"
          class="absolute inset-y-0 rounded-xl border border-[var(--dig-violet-600)] bg-[var(--dig-violet-700)] p-5"
          :style="{ insetInlineStart: `${layer * 2.5}rem`, top: `${layer * 1.5}rem`, transform: 'rotate(-6deg)' }"
        >
          <div v-if="layer === 0" class="flex h-full gap-4">
            <div class="flex w-40 flex-col gap-3">
              <span class="flex size-9 items-center justify-center rounded-lg bg-[var(--dig-violet-500)] [&>svg]:size-4">
                <DigIcon name="sparkles" />
              </span>
              <span class="flex h-9 items-center gap-2 rounded-lg bg-[var(--dig-violet-600)] px-3 text-sm">داشبورد</span>
              <span v-for="width in [70, 55, 80, 60]" :key="width" class="h-2.5 rounded-full bg-[var(--dig-violet-600)]" :style="{ width: `${width}%` }" />
            </div>
            <div class="flex flex-1 flex-col gap-3">
              <span class="h-16 rounded-lg bg-[var(--dig-violet-600)]" />
              <span class="h-2.5 w-2/3 rounded-full bg-[var(--dig-violet-600)]" />
              <span class="h-2.5 w-1/2 rounded-full bg-[var(--dig-violet-600)]" />
            </div>
          </div>
        </div>
      </div>
      <span aria-hidden="true" class="pointer-events-none absolute inset-x-0 bottom-0 h-2/3 bg-linear-to-t from-[var(--dig-violet-800)] from-40% to-transparent" />

      <figure class="relative flex max-w-md flex-col gap-4 lg:gap-6">
        <Avatar size="lg" alt="سارا محمدی" src="https://docs.digdesign.ir/images/person-woman-2.webp" class="hidden ring-2 ring-[var(--dig-violet-500)] lg:flex">
          <template #icon>
            <DigIcon name="avatar-female" class="size-[95%] translate-y-1 text-[color-mix(in_oklab,var(--muted-foreground)_55%,var(--muted))]" />
          </template>
        </Avatar>
        <blockquote class="text-lg leading-relaxed font-bold lg:text-2xl">
          «حساب‌وکتابِ ماهانه‌مان از سه روز به یک ساعت رسید.
          <span class="text-muted-foreground">حالا وقتمان صرفِ فروش می‌شود، نه اکسل.»</span>
        </blockquote>
        <figcaption class="flex flex-col gap-0.5">
          <span class="font-semibold">سارا محمدی</span>
          <span class="text-sm text-muted-foreground">مدیرِ فروشگاهِ آنلاین</span>
        </figcaption>
      </figure>
    </aside>
  </main>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: avatarcontrol-sizeinput-otplinkpassword-fieldpersiansteppertext-fieldآیکون avatar-genderآیکون checkآیکون sparkles

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

forgot-password.ts
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  inject,
} from "@angular/core"

import { DigAvatar } from "@/components/ui/avatar"
import { DigButton } from "@/components/ui/button"
import { DigControlSize } from "@/components/ui/control-size"
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",
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [
    DigAvatar,
    DigButton,
    DigControlSize,
    DigIcon,
    DigInput,
    DigInputField,
    DigInputOtp,
    DigInputOtpGroup,
    DigInputOtpSlot,
    DigLink,
    DigPasswordField,
    DigStepper,
    DigStepperItem,
    DigStepperTitle,
    DigTextField,
  ],
  template: `
    <main
      class="grid grid-cols-1 min-h-svh gap-4 bg-background p-4 lg:grid-cols-2"
    >
      <div class="flex flex-col items-center px-4 py-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>
      <aside
        aria-label="دربارهٔ حساب‌یار"
        class="relative hidden flex-col justify-end overflow-hidden rounded-xl bg-[var(--dig-violet-800)] p-10 text-[var(--dig-white)] lg:flex [--muted-foreground:var(--dig-violet-200)]"
      >
        <!-- پیش‌نمایشِ محصول: سه پنجرهٔ پشتِ هم با خط‌های اسکلتی. -->
        <div
          aria-hidden="true"
          class="absolute -end-16 top-12 hidden h-80 w-[115%] lg:block"
        >
          @for (layer of [2, 1, 0]; track layer) {
            <div
              class="absolute inset-y-0 rounded-xl border border-[var(--dig-violet-600)] bg-[var(--dig-violet-700)] p-5"
              [style.inset-inline-start.rem]="layer * 2.5"
              [style.top.rem]="layer * 1.5"
              style="transform: rotate(-6deg)"
            >
              @if (layer === 0) {
                <div class="flex h-full gap-4">
                  <div class="flex w-40 flex-col gap-3">
                    <span
                      class="flex size-9 items-center justify-center rounded-lg bg-[var(--dig-violet-500)] [&>svg]:size-4"
                    >
                      <svg digIcon="sparkles"></svg>
                    </span>
                    <span
                      class="flex h-9 items-center gap-2 rounded-lg bg-[var(--dig-violet-600)] px-3 text-sm"
                      >داشبورد</span
                    >
                    @for (width of [70, 55, 80, 60]; track width) {
                      <span
                        class="h-2.5 rounded-full bg-[var(--dig-violet-600)]"
                        [style.width.%]="width"
                      ></span>
                    }
                  </div>
                  <div class="flex flex-1 flex-col gap-3">
                    <span
                      class="h-16 rounded-lg bg-[var(--dig-violet-600)]"
                    ></span>
                    <span
                      class="h-2.5 w-2/3 rounded-full bg-[var(--dig-violet-600)]"
                    ></span>
                    <span
                      class="h-2.5 w-1/2 rounded-full bg-[var(--dig-violet-600)]"
                    ></span>
                  </div>
                </div>
              }
            </div>
          }
        </div>
        <span
          aria-hidden="true"
          class="pointer-events-none absolute inset-x-0 bottom-0 h-2/3 bg-linear-to-t from-[var(--dig-violet-800)] from-40% to-transparent"
        ></span>

        <figure class="relative flex max-w-md flex-col gap-4 lg:gap-6">
          <span
            digAvatar
            size="lg"
            alt="سارا محمدی"
            src="https://docs.digdesign.ir/images/person-woman-2.webp"
            class="hidden ring-2 ring-[var(--dig-violet-500)] lg:flex"
            iconName="avatar-female"
          ></span>
          <blockquote class="text-lg leading-relaxed font-bold lg:text-2xl">
            «حساب‌وکتابِ ماهانه‌مان از سه روز به یک ساعت رسید.
            <span class="text-muted-foreground"
              >حالا وقتمان صرفِ فروش می‌شود، نه اکسل.»</span
            >
          </blockquote>
          <figcaption class="flex flex-col gap-0.5">
            <span class="font-semibold">سارا محمدی</span>
            <span class="text-sm text-muted-foreground"
              >مدیرِ فروشگاهِ آنلاین</span
            >
          </figcaption>
        </figure>
      </aside>
    </main>
  `,
})
export class ForgotPasswordBlock {
  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 می‌سازد.