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

فراموشی رمز (ساده)

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

فراموشی رمز، مدلِ ساده: همان فرم وسطِ صفحه، بدونِ پنلِ کناری. همان فرم، اعتبارسنجی و حالت‌های صفحهٔ اصلی.

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

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

پکیج‌منیجر پیش‌فرض 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/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/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/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/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 button control-size input-otp link password-field persian stepper text-field --framework vue
pnpm dlx digdesign@latest add button control-size input-otp link password-field persian stepper text-field --framework vue
yarn dlx digdesign@latest add button control-size input-otp link password-field persian stepper text-field --framework vue
bunx --bun digdesign@latest add 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 button control-size icons input input-otp link password-field persian stepper text-field --framework angular
pnpm dlx digdesign@latest add button control-size icons input input-otp link password-field persian stepper text-field --framework angular
yarn dlx digdesign@latest add button control-size icons input input-otp link password-field persian stepper text-field --framework angular
bunx --bun digdesign@latest add 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 button control-size input-otp link password-field persian stepper text-field --framework android
pnpm dlx digdesign@latest add button control-size input-otp link password-field persian stepper text-field --framework android
yarn dlx digdesign@latest add button control-size input-otp link password-field persian stepper text-field --framework android
bunx --bun digdesign@latest add button control-size input-otp link password-field persian stepper text-field --framework android

۲. کد صفحه

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

forgot-password-simple.tsx
"use client"

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

import { CheckIcon, SparklesIcon } from "@/components/icons"
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 ForgotPasswordSimpleBlock() {
  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="flex min-h-svh flex-col items-center bg-background p-4">
      <div className="flex w-full flex-1 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>
    </main>
  )
}
forgot-password-simple.vue
<script setup lang="ts">
import { computed, ref } from "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="flex min-h-svh flex-col items-center bg-background p-4">
    <div class="flex w-full flex-1 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>
  </main>
</template>

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

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

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

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

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-simple",
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [
    DigButton,
    DigControlSize,
    DigIcon,
    DigInput,
    DigInputField,
    DigInputOtp,
    DigInputOtpGroup,
    DigInputOtpSlot,
    DigLink,
    DigPasswordField,
    DigStepper,
    DigStepperItem,
    DigStepperTitle,
    DigTextField,
  ],
  template: `
    <main class="flex min-h-svh flex-col items-center bg-background p-4">
      <div class="flex w-full flex-1 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>
    </main>
  `,
})
export class ForgotPasswordSimpleBlock {
  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()
  }
}
ForgotPasswordSimpleScreen.kt
package ir.digdesign.compose.demo.blocks

// sync: src/blocks/forgot-password-simple.tsx

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.autofill.ContentType
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import ir.digdesign.compose.Button
import ir.digdesign.compose.ControlSize
import ir.digdesign.compose.ControlSizeProvider
import ir.digdesign.compose.DigIcon
import ir.digdesign.compose.DigIcons
import ir.digdesign.compose.DigRadius
import ir.digdesign.compose.DigSpacing
import ir.digdesign.compose.DigText
import ir.digdesign.compose.DigTheme
import ir.digdesign.compose.InputMode
import ir.digdesign.compose.InputOTP
import ir.digdesign.compose.Link
import ir.digdesign.compose.LinkSize
import ir.digdesign.compose.PasswordField
import ir.digdesign.compose.PasswordRequirementsWhen
import ir.digdesign.compose.Stepper
import ir.digdesign.compose.StepperStep
import ir.digdesign.compose.TextField
import ir.digdesign.compose.TypographyH3
import ir.digdesign.compose.isValidMobile
import ir.digdesign.compose.toFaDigits
import kotlinx.coroutines.delay

private val StepTitles = listOf("فراموشی رمز", "کد تأیید", "رمز تازه")
private val StepTexts = listOf("شمارهٔ موبایلِ حساب را بنویسید تا کدِ بازیابی بفرستیم.", "", "رمزی بسازید که جای دیگری استفاده نکرده‌اید.")
private val Steps = listOf(StepperStep("شماره"), StepperStep("کد تأیید"), StepperStep("رمز تازه"))

/** بازیابی رمز عبور در سه قدم (شماره ← کد ← رمز تازه) با Stepper و صفحهٔ موفقیت. */
@Composable
fun ForgotPasswordSimpleScreen(onNavigate: (String) -> Unit = {}) {
    var step by remember { mutableStateOf(0) }
    var mobile by remember { mutableStateOf("") }
    var code by remember { mutableStateOf("") }
    var password by remember { mutableStateOf("") }
    var confirm by remember { mutableStateOf("") }
    var loading by remember { mutableStateOf(false) }
    val mismatch = confirm.isNotEmpty() && confirm != password

    // جای درخواستِ واقعیِ هر قدم.
    LaunchedEffect(loading) {
        if (loading) {
            delay(600)
            loading = false
            step += 1
        }
    }

    Box(
        Modifier.fillMaxSize().background(DigTheme.colors.background).safeDrawingPadding(),
        contentAlignment = Alignment.TopCenter,
    ) {
        ControlSizeProvider(ControlSize.Xl) {
            Column(
                Modifier
                    .widthIn(max = 480.dp)
                    .fillMaxWidth()
                    .verticalScroll(rememberScrollState())
                    .imePadding()
                    .padding(horizontal = DigSpacing * 6, vertical = DigSpacing * 10),
                verticalArrangement = Arrangement.spacedBy(DigSpacing * 8),
                horizontalAlignment = Alignment.CenterHorizontally,
            ) {
                if (step < 3) {
                    BrandMark()
                    Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 2), horizontalAlignment = Alignment.CenterHorizontally) {
                        TypographyH3(StepTitles[step])
                        Txt(if (step == 1) "کدِ ۶ رقمی به ${toFaDigits(mobile)} پیامک شد." else StepTexts[step])
                    }
                    Stepper(steps = Steps, value = step, modifier = Modifier.fillMaxWidth())

                    when (step) {
                        0 -> Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(DigSpacing * 4)) {
                            TextField(
                                value = mobile,
                                onValueChange = { mobile = it },
                                label = "شماره موبایل",
                                mode = InputMode.Tel,
                                maxLength = 11,
                                placeholder = "۰۹۱۲۳۴۵۶۷۸۹",
                                required = true,
                                validate = { if (isValidMobile(it)) null else "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد." },
                            )
                            Button(
                                "ارسال کد",
                                onClick = { if (isValidMobile(mobile)) loading = true },
                                fullWidth = true,
                                loading = loading,
                                modifier = Modifier.padding(top = DigSpacing * 2),
                            )
                        }
                        1 -> Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(DigSpacing * 6), horizontalAlignment = Alignment.CenterHorizontally) {
                            InputOTP(
                                value = code,
                                onValueChange = { code = it },
                                onComplete = { loading = true },
                                enabled = !loading,
                                contentDescription = "کد تأیید",
                            )
                            Row(horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.CenterVertically) {
                                Txt("شماره اشتباه است؟")
                                Link("تغییر شماره", onClick = { step = 0; code = "" })
                            }
                        }
                        else -> Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(DigSpacing * 4)) {
                            PasswordField(
                                value = password,
                                onValueChange = { password = it },
                                label = "رمز تازه",
                                contentType = ContentType.NewPassword,
                                strength = true,
                                requirements = true,
                                requirementsWhen = PasswordRequirementsWhen.Weak,
                                required = true,
                            )
                            PasswordField(
                                value = confirm,
                                onValueChange = { confirm = it },
                                label = "تکرار رمز تازه",
                                contentType = ContentType.NewPassword,
                                isError = mismatch,
                                errorMessage = if (mismatch) "با رمز بالا یکی نیست." else null,
                                required = true,
                            )
                            Button(
                                "ذخیرهٔ رمز",
                                onClick = { loading = true },
                                fullWidth = true,
                                loading = loading,
                                enabled = password.isNotEmpty() && !mismatch,
                                modifier = Modifier.padding(top = DigSpacing * 2),
                            )
                        }
                    }

                    Row(horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.CenterVertically) {
                        Txt("رمز یادتان آمد؟")
                        Link("وارد شوید", onClick = { onNavigate("login-simple") })
                    }
                } else {
                    Box(
                        Modifier.size(48.dp).clip(RoundedCornerShape(DigRadius.xl)).background(DigTheme.colors.successSubtle),
                        contentAlignment = Alignment.Center,
                    ) {
                        DigIcon(DigIcons.Tick, contentDescription = null, size = 24.dp, tint = DigTheme.colors.successSubtleForeground)
                    }
                    Column(
                        Modifier.semantics(mergeDescendants = true) {},
                        verticalArrangement = Arrangement.spacedBy(DigSpacing * 2),
                        horizontalAlignment = Alignment.CenterHorizontally,
                    ) {
                        TypographyH3("رمز عبور تغییر کرد")
                        Txt("از این به بعد با رمز تازه وارد شوید.")
                    }
                    Button("ورود به حساب", onClick = { onNavigate("login-simple") }, fullWidth = true)
                }
                LegalLinks()
            }
        }
    }
}

/** نشانِ برند بالای فرم. */
@Composable
private fun BrandMark() {
    Box(
        Modifier.size(48.dp).clip(RoundedCornerShape(DigRadius.xl)).background(DigTheme.colors.violet),
        contentAlignment = Alignment.Center,
    ) {
        DigIcon(DigIcons.BadgeStar, contentDescription = null, size = 24.dp, tint = DigTheme.colors.violetForeground)
    }
}

@Composable
private fun Txt(text: String, modifier: Modifier = Modifier, size: TextUnit = DigText.sm, color: Color = DigTheme.colors.mutedForeground, weight: FontWeight = FontWeight.Normal) {
    BasicText(
        text,
        modifier,
        style = TextStyle(
            color = color,
            fontFamily = DigTheme.fontFamily,
            fontSize = size,
            fontWeight = weight,
            lineHeight = size * DigText.lineHeightBase,
            textAlign = TextAlign.Center,
        ),
    )
}

@Composable
private fun LegalLinks() {
    Row(horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.CenterVertically) {
        Link("قوانین", onClick = {}, size = LinkSize.Sm)
        Txt("و", size = DigText.xs)
        Link("حریم خصوصی", onClick = {}, size = LinkSize.Sm)
    }
}