ریاکت ۱۹ و Next.js با پیادهسازی دسترسپذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده
ثبتنام (ساده)
پیشنمایش تمامصفحهثبتنام، مدلِ ساده: همان فرم وسطِ صفحه، بدونِ پنلِ کناری. همان فرم، اعتبارسنجی و حالتهای صفحهٔ اصلی.
۱. نصب کامپوننتها
این بلاک از ۱۱ آیتم دیگ استفاده میکند: buttoncheckboxcontrol-sizeiconsinput-otplabellinkpassword-fieldpersiansocial-auth-buttonstext-field
پکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.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/label.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/social-auth-buttons.json https://docs.digdesign.ir/r/text-field.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.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/label.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/social-auth-buttons.json https://docs.digdesign.ir/r/text-field.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.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/label.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/social-auth-buttons.json https://docs.digdesign.ir/r/text-field.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.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/label.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/social-auth-buttons.json https://docs.digdesign.ir/r/text-field.jsonپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework vuepnpm dlx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework vueyarn dlx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework vuebunx --bun digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework vueپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx 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 svelteپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add button checkbox control-size icons input input-otp label link password-field persian social-auth-buttons text-field --framework angularpnpm dlx digdesign@latest add button checkbox control-size icons input input-otp label link password-field persian social-auth-buttons text-field --framework angularyarn dlx digdesign@latest add button checkbox control-size icons input input-otp label link password-field persian social-auth-buttons text-field --framework angularbunx --bun digdesign@latest add button checkbox control-size icons input input-otp label link password-field persian social-auth-buttons text-field --framework angularپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework androidpnpm dlx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework androidyarn dlx digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework androidbunx --bun digdesign@latest add button checkbox control-size input-otp label link password-field persian social-auth-buttons text-field --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
signup-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 { Checkbox } from "@/components/ui/checkbox"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp"
import { Label } from "@/components/ui/label"
import { Link } from "@/components/ui/link"
import { PasswordField } from "@/components/ui/password-field"
import { SocialAuthButtons } from "@/components/ui/social-auth-buttons"
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 SignupSimpleBlock() {
const [password, setPassword] = React.useState("")
const [confirm, setConfirm] = React.useState("")
const [accepted, setAccepted] = React.useState(false)
const [sending, setSending] = React.useState(false)
const [mobile, setMobile] = React.useState("")
// بعد از ثبتنام کاربر باید بداند قدمِ بعد چیست: تأییدِ شماره، بعد ورود.
const [step, setStep] = React.useState<"form" | "verify" | "done">("form")
const mismatch = confirm.length > 0 && confirm !== password
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
if (mismatch || !accepted || !isValidMobile(mobile)) return
setSending(true)
// جای درخواستِ واقعی ثبتنام و ارسالِ پیامک.
await new Promise((resolve) => setTimeout(resolve, 900))
setSending(false)
setStep("verify")
}
async function verify() {
setSending(true)
await new Promise((resolve) => setTimeout(resolve, 700))
setSending(false)
setStep("done")
}
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 === "form" && (
<>
<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">ساخت حساب</h1>
<p className="text-sm text-muted-foreground">۱۴ روز رایگان، بدونِ کارتِ بانکی.</p>
</div>
</header>
<form onSubmit={onSubmit} className="flex flex-col gap-4">
<TextField label="نام و نام خانوادگی" name="fullName" autoComplete="name" required />
<TextField
label="شماره موبایل"
name="mobile"
type="tel"
dir="ltr"
maxLength={11}
autoComplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
value={mobile}
onValueChange={setMobile}
description="کد تأیید به همین شماره پیامک میشود."
required
validate={(value) => (isValidMobile(value) ? undefined : "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد.")}
/>
<PasswordField label="رمز عبور" name="password" autoComplete="new-password" value={password} onValueChange={setPassword} strength requirements requirementsWhen="weak" required />
<PasswordField
label="تکرار رمز عبور"
name="confirm"
autoComplete="new-password"
value={confirm}
onValueChange={setConfirm}
invalid={mismatch}
errorMessage="با رمز بالا یکی نیست."
required
/>
<div className="flex items-start gap-2">
<Checkbox id="terms" name="terms" checked={accepted} onCheckedChange={(checked) => setAccepted(checked === true)} required />
<Label htmlFor="terms" className="leading-6 font-normal">
<span>
<Link href="#">قوانین و مقررات</Link> را خواندهام و میپذیرم.
</span>
</Label>
</div>
<Button type="submit" fullWidth loading={sending} disabled={!accepted || mismatch} className="mt-4">
ساخت حساب
</Button>
</form>
<SocialAuthButtons mode="signup" />
<p className="text-center text-sm text-muted-foreground">
حساب دارید؟ <Link href="/login">وارد شوید</Link>
</p>
</>
)}
{step === "verify" && (
<>
<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">تأیید شماره موبایل</h1>
<p className="text-sm leading-6 text-muted-foreground">
کدِ ۶ رقمی به <bdi dir="ltr" className="font-medium text-foreground">{toFaDigits(mobile)}</bdi> پیامک شد.
</p>
</div>
</header>
<InputOTP aria-label="کد تأیید" onComplete={verify} disabled={sending} className="mx-auto">
<InputOTPGroup>
{[0, 1, 2, 3, 4, 5].map((index) => (
<InputOTPSlot key={index} index={index} />
))}
</InputOTPGroup>
</InputOTP>
<p className="text-center text-sm text-muted-foreground">
شماره اشتباه است؟{" "}
<Button variant="link" className="h-auto p-0" onClick={() => setStep("form")}>
ویرایش شماره
</Button>
</p>
</>
)}
{step === "done" && (
<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="/">رفتن به داشبورد</NextLink>
</Button>
</div>
)}
</ControlSizeProvider>
<p className="pt-10 text-xs text-muted-foreground">
<Link href="#" size="sm">
قوانین
</Link>{" "}
و{" "}
<Link href="#" size="sm">
حریم خصوصی
</Link>
</p>
</div>
</main>
)
}
signup-simple.vue
<script setup lang="ts">
import { computed, ref } from "vue"
import Button from "@/components/ui/Button.vue"
import Checkbox from "@/components/ui/Checkbox.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 Label from "@/components/ui/Label.vue"
import Link from "@/components/ui/Link.vue"
import PasswordField from "@/components/ui/PasswordField.vue"
import SocialAuthButtons from "@/components/ui/SocialAuthButtons.vue"
import TextField from "@/components/ui/TextField.vue"
import { DigIcon } from "@/lib/icons"
import { isValidMobile, toFaDigits } from "@/lib/persian"
/**
* مدلِ ساده: همان فرم وسطِ صفحه، بدونِ پنلِ کناری؛ برای اپهایی که برند را در خودِ فرم نشان میدهند.
* بعد از فرم، تأییدِ شماره و پیامِ موفقیت در همان ستون میآیند.
*/
const password = ref("")
const confirm = ref("")
const accepted = ref(false)
const sending = ref(false)
const mobile = ref("")
// بعد از ثبتنام کاربر باید بداند قدمِ بعد چیست: تأییدِ شماره، بعد ورود.
const step = ref<"form" | "verify" | "done">("form")
const mismatch = computed(() => confirm.value.length > 0 && confirm.value !== password.value)
async function onSubmit() {
if (mismatch.value || !accepted.value || !isValidMobile(mobile.value)) return
sending.value = true
// جای درخواستِ واقعی ثبتنام و ارسالِ پیامک.
await new Promise((resolve) => setTimeout(resolve, 900))
sending.value = false
step.value = "verify"
}
async function verify() {
sending.value = true
await new Promise((resolve) => setTimeout(resolve, 700))
sending.value = false
step.value = "done"
}
function validateMobile(value: string) {
return isValidMobile(value) ? undefined : "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد."
}
</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 === 'form'">
<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">ساخت حساب</h1>
<p class="text-sm text-muted-foreground">۱۴ روز رایگان، بدونِ کارتِ بانکی.</p>
</div>
</header>
<form class="flex flex-col gap-4" @submit.prevent="onSubmit">
<TextField label="نام و نام خانوادگی" name="fullName" autocomplete="name" required />
<TextField
v-model="mobile"
label="شماره موبایل"
name="mobile"
type="tel"
dir="ltr"
maxlength="11"
autocomplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
description="کد تأیید به همین شماره پیامک میشود."
required
:validate="validateMobile"
/>
<PasswordField v-model="password" label="رمز عبور" name="password" autocomplete="new-password" strength requirements requirements-when="weak" required />
<PasswordField
v-model="confirm"
label="تکرار رمز عبور"
name="confirm"
autocomplete="new-password"
:invalid="mismatch"
error-message="با رمز بالا یکی نیست."
required
/>
<div class="flex items-start gap-2">
<Checkbox id="terms" name="terms" :checked="accepted" required @update:checked="(checked) => (accepted = checked === true)" />
<Label for="terms" class="leading-6 font-normal">
<span>
<Link href="#">قوانین و مقررات</Link> را خواندهام و میپذیرم.
</span>
</Label>
</div>
<Button type="submit" full-width :loading="sending" :disabled="!accepted || mismatch" class="mt-4">ساخت حساب</Button>
</form>
<SocialAuthButtons mode="signup" />
<p class="text-center text-sm text-muted-foreground">
حساب دارید؟ <Link href="/login">وارد شوید</Link>
</p>
</template>
<template v-if="step === 'verify'">
<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">تأیید شماره موبایل</h1>
<p class="text-sm leading-6 text-muted-foreground">
کدِ ۶ رقمی به <bdi dir="ltr" class="font-medium text-foreground">{{ toFaDigits(mobile) }}</bdi> پیامک شد.
</p>
</div>
</header>
<InputOTP aria-label="کد تأیید" :disabled="sending" class="mx-auto" @complete="verify">
<InputOTPGroup>
<InputOTPSlot v-for="index in [0, 1, 2, 3, 4, 5]" :key="index" :index="index" />
</InputOTPGroup>
</InputOTP>
<p class="text-center text-sm text-muted-foreground">
شماره اشتباه است؟
<Button variant="link" class="h-auto p-0" @click="step = 'form'">ویرایش شماره</Button>
</p>
</template>
<div v-if="step === 'done'" 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="/">رفتن به داشبورد</a>
</Button>
</div>
</ControlSize>
<p class="pt-10 text-xs text-muted-foreground">
<Link href="#" size="sm">قوانین</Link>
و
<Link href="#" size="sm">حریم خصوصی</Link>
</p>
</div>
</main>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: checkboxcontrol-sizeinput-otplabellinkpassword-fieldpersiansocial-auth-buttonstext-fieldآیکون checkآیکون sparkles
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
signup-simple.ts
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
inject,
} from "@angular/core"
import { DigButton } from "@/components/ui/button"
import { DigCheckbox } from "@/components/ui/checkbox"
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 { DigLabel } from "@/components/ui/label"
import { DigLink } from "@/components/ui/link"
import { DigPasswordField } from "@/components/ui/password-field"
import { DigSocialAuthButtons } from "@/components/ui/social-auth-buttons"
import { DigTextField } from "@/components/ui/text-field"
import { isValidMobile, toFaDigits } from "@/lib/persian"
let nextFieldId = 0
@Component({
selector: "dig-block-signup-simple",
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
DigButton,
DigCheckbox,
DigControlSize,
DigIcon,
DigInput,
DigInputField,
DigInputOtp,
DigInputOtpGroup,
DigInputOtpSlot,
DigLabel,
DigLink,
DigPasswordField,
DigSocialAuthButtons,
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 === "form") {
<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">ساخت حساب</h1>
<p class="text-sm text-muted-foreground">
۱۴ روز رایگان، بدونِ کارتِ بانکی.
</p>
</div>
</header>
<form
class="flex flex-col gap-4"
(submit)="$event.preventDefault(); onSubmit()"
>
<div digTextField label="نام و نام خانوادگی" required>
<dig-input>
<input digInput name="fullName" autocomplete="name" />
</dig-input>
</div>
<div
digTextField
label="شماره موبایل"
description="کد تأیید به همین شماره پیامک میشود."
required
[validate]="validateMobile"
>
<dig-input>
<input
digInput
[value]="mobile"
(valueChange)="mobile = $event"
name="mobile"
type="tel"
dir="ltr"
maxlength="11"
autocomplete="tel"
placeholder="۰۹۱۲۳۴۵۶۷۸۹"
/>
</dig-input>
</div>
<div
digPasswordField
[(value)]="password"
label="رمز عبور"
name="password"
autocomplete="new-password"
strength
requirements
requirementsWhen="weak"
required
></div>
<div
digPasswordField
[(value)]="confirm"
label="تکرار رمز عبور"
name="confirm"
autocomplete="new-password"
[invalid]="mismatch"
errorMessage="با رمز بالا یکی نیست."
required
></div>
<div class="flex items-start gap-2">
<button
digCheckbox
type="button"
[checked]="accepted"
required
(checkedChange)="accepted = $event === true"
[attr.id]="fieldId"
></button>
<label
digLabel
[attr.for]="fieldId"
class="leading-6 font-normal"
>
<span>
<a digLink href="#">قوانین و مقررات</a> را خواندهام و
میپذیرم.
</span>
</label>
</div>
<button
digButton
type="submit"
fullWidth
[loading]="sending"
[disabled]="!accepted || mismatch"
class="mt-4"
>
ساخت حساب
</button>
</form>
<dig-social-auth-buttons mode="signup"></dig-social-auth-buttons>
<p class="text-center text-sm text-muted-foreground">
حساب دارید؟ <a digLink href="/login">وارد شوید</a>
</p>
}
@if (step === "verify") {
<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">تأیید شماره موبایل</h1>
<p class="text-sm leading-6 text-muted-foreground">
کدِ ۶ رقمی به
<bdi dir="ltr" class="font-medium text-foreground">{{
toFaDigits(mobile)
}}</bdi>
پیامک شد.
</p>
</div>
</header>
<div
digInputOtp
aria-label="کد تأیید"
[disabled]="sending"
class="mx-auto"
(complete)="verify()"
>
<div digInputOtpGroup>
@for (index of [0, 1, 2, 3, 4, 5]; track index) {
<input digInputOtpSlot [index]="index" />
}
</div>
</div>
<p class="text-center text-sm text-muted-foreground">
شماره اشتباه است؟
<button
digButton
type="button"
variant="link"
class="h-auto p-0"
(click)="step = 'form'"
>
ویرایش شماره
</button>
</p>
}
@if (step === "done") {
<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="/">رفتن به داشبورد</a>
</div>
}
</div>
<p class="pt-10 text-xs text-muted-foreground">
<a digLink href="#" size="sm">قوانین</a>
و
<a digLink href="#" size="sm">حریم خصوصی</a>
</p>
</div>
</main>
`,
})
export class SignupSimpleBlock {
private readonly changeDetector = inject(ChangeDetectorRef)
readonly fieldId = `signup-simple-${++nextFieldId}`
readonly toFaDigits = toFaDigits
/**
* مدلِ ساده: همان فرم وسطِ صفحه، بدونِ پنلِ کناری؛ برای اپهایی که برند را در خودِ فرم نشان میدهند.
* بعد از فرم، تأییدِ شماره و پیامِ موفقیت در همان ستون میآیند.
*/
password = ""
confirm = ""
accepted = false
sending = false
mobile = ""
// بعد از ثبتنام کاربر باید بداند قدمِ بعد چیست: تأییدِ شماره، بعد ورود.
step: "form" | "verify" | "done" = "form"
get mismatch() {
return this.confirm.length > 0 && this.confirm !== this.password
}
async onSubmit() {
if (
this.sending ||
!this.password ||
this.password !== this.confirm ||
!this.accepted ||
!isValidMobile(this.mobile)
)
return
this.sending = true
// جای درخواستِ واقعی ثبتنام و ارسالِ پیامک.
await new Promise((resolve) => setTimeout(resolve, 900))
this.sending = false
this.step = "verify"
this.changeDetector.markForCheck()
}
async verify() {
if (this.sending) return
this.sending = true
await new Promise((resolve) => setTimeout(resolve, 700))
this.sending = false
this.step = "done"
this.changeDetector.markForCheck()
}
validateMobile(value: string) {
return isValidMobile(value)
? undefined
: "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد."
}
}
SignupSimpleScreen.kt
package ir.digdesign.compose.demo.blocks
// sync: src/blocks/signup-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.Checkbox
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.SocialAuthButtons
import ir.digdesign.compose.SocialAuthMode
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 enum class SignupStep { Form, Verify, Finished }
/** ثبتنام با نام، موبایل و رمز، بعد تأیید شماره با کدِ پیامکی و پیامِ موفقیت در همان صفحه. */
@Composable
fun SignupSimpleScreen(onNavigate: (String) -> Unit = {}) {
var step by remember { mutableStateOf(SignupStep.Form) }
var name by remember { mutableStateOf("") }
var mobile by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var confirm by remember { mutableStateOf("") }
var accepted by remember { mutableStateOf(false) }
var code by remember { mutableStateOf("") }
var sending by remember { mutableStateOf(false) }
val mismatch = confirm.isNotEmpty() && confirm != password
// جای درخواستِ واقعیِ ثبتنام و تأییدِ پیامک.
LaunchedEffect(sending) {
if (sending) {
delay(800)
sending = false
step = if (step == SignupStep.Form) SignupStep.Verify else SignupStep.Finished
}
}
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,
) {
when (step) {
SignupStep.Form -> {
BrandMark()
Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 2), horizontalAlignment = Alignment.CenterHorizontally) {
TypographyH3("ساخت حساب")
Txt("۱۴ روز رایگان، بدونِ کارتِ بانکی.")
}
Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(DigSpacing * 4)) {
TextField(value = name, onValueChange = { name = it }, label = "نام و نام خانوادگی", contentType = ContentType.PersonFullName, required = true)
TextField(
value = mobile,
onValueChange = { mobile = it },
label = "شماره موبایل",
mode = InputMode.Tel,
maxLength = 11,
placeholder = "۰۹۱۲۳۴۵۶۷۸۹",
description = "کد تأیید به همین شماره پیامک میشود.",
required = true,
validate = { if (isValidMobile(it)) null else "شماره موبایل باید با ۰۹ شروع شود و ۱۱ رقم باشد." },
)
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,
)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(DigSpacing)) {
Checkbox(checked = accepted, onCheckedChange = { accepted = it }, label = "را خواندهام و میپذیرم.", contentDescription = "پذیرشِ قوانین و مقررات")
Link("قوانین و مقررات", onClick = {})
}
Button(
"ساخت حساب",
onClick = { if (isValidMobile(mobile)) sending = true },
fullWidth = true,
loading = sending,
enabled = accepted && !mismatch,
modifier = Modifier.padding(top = DigSpacing * 2),
)
}
SocialAuthButtons(onProviderClick = {}, mode = SocialAuthMode.Signup)
Row(horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.CenterVertically) {
Txt("حساب دارید؟")
Link("وارد شوید", onClick = { onNavigate("login-simple") })
}
}
SignupStep.Verify -> {
BrandMark()
Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 2), horizontalAlignment = Alignment.CenterHorizontally) {
TypographyH3("تأیید شماره موبایل")
Txt("کدِ ۶ رقمی به ${toFaDigits(mobile)} پیامک شد.")
}
InputOTP(
value = code,
onValueChange = { code = it },
onComplete = { sending = true },
enabled = !sending,
contentDescription = "کد تأیید",
)
Row(horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.CenterVertically) {
Txt("شماره اشتباه است؟")
Link("ویرایش شماره", onClick = { step = SignupStep.Form; code = "" })
}
}
SignupStep.Finished -> {
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("dashboard") }, 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)
}
}