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

سفارشِ داروی نسخه‌ای با عکسِ نسخه یا کدِ رهگیریِ نسخهٔ الکترونیک و کدِ ملی، برای چه کسی، نشانیِ تحویل و راهنمای مراحلِ بعد از ثبت.

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

این بلاک از ۱۰ آیتم دیگ استفاده می‌کند: buttoncontrol-sizefile-uploadiconspersianradio-cardradio-grouptext-fieldtoasttoggle-group

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

۲. کد صفحه

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

pharmacy-prescription.tsx
"use client"

import * as React from "react"

import { ClockIcon, FileTextIcon, LocationIcon, TruckIcon, WalletIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { FileUpload } from "@/components/ui/file-upload"
import { RadioCard } from "@/components/ui/radio-card"
import { RadioGroup } from "@/components/ui/radio-group"
import { TextField } from "@/components/ui/text-field"
import { toast } from "@/components/ui/toast"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { isValidNationalId, toEnDigits, toFaDigits } from "@/lib/persian"

const HOW = [
  { icon: <FileTextIcon />, title: "نسخه را ثبت کن", text: "عکسِ نسخهٔ کاغذی یا کدِ رهگیریِ نسخهٔ الکترونیک." },
  { icon: <ClockIcon />, title: "داروخانه قیمت می‌دهد", text: "معمولاً تا ۱۵ دقیقه، با سهمِ بیمه و داروهای جایگزین." },
  { icon: <WalletIcon />, title: "پرداخت می‌کنی", text: "بعد از تأییدِ تو و فقط مبلغِ نهایی." },
  { icon: <TruckIcon />, title: "پیک می‌آورد", text: "داروی یخچالی با کیفِ سرد." },
]

/**
 * سفارشِ داروی نسخه‌ای: یک انتخابِ تکی بینِ «عکسِ نسخه» و «نسخهٔ الکترونیک» (سگمنت، نه دو فرم کنارِ هم)،
 * بارگذاریِ تا ۳ عکس یا کدِ ملی و کدِ رهگیری با خطای کنارِ فیلد، برای چه کسی، و نشانیِ تحویل. ستونِ
 * کنار مراحل را می‌گوید تا کاربر بداند بعد از ثبت چه می‌شود و الان پولی پرداخت نمی‌کند.
 */
export default function PharmacyPrescriptionBlock() {
  const [method, setMethod] = React.useState("photo")
  const [patient, setPatient] = React.useState("me")
  const [nationalId, setNationalId] = React.useState("")
  const [code, setCode] = React.useState("")
  const [blurred, setBlurred] = React.useState({ id: false, code: false })

  const idDigits = toEnDigits(nationalId).replace(/\D/g, "")
  const idError = !blurred.id || isValidNationalId(idDigits)
    ? undefined
    : !idDigits
      ? "کدِ ملی را بنویس؛ ۱۰ رقم است."
      : idDigits.length !== 10
        ? `کدِ ملی ۱۰ رقم است، ${toFaDigits(idDigits.length)} رقم وارد شده.`
        : "این کدِ ملی معتبر نیست؛ یک بار دیگر از روی کارت نگاه کن."
  const codeError = blurred.code && toEnDigits(code).replace(/\D/g, "").length < 6 ? "کدِ رهگیری در پیامکِ پزشک آمده؛ دست‌کم ۶ رقم." : undefined

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto grid w-full max-w-5xl grid-cols-1 items-start gap-6 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem] lg:gap-8">
        <form
          className="flex min-w-0 flex-col gap-6"
          noValidate
          onSubmit={(event) => {
            event.preventDefault()
            if (method === "code") {
              setBlurred({ id: true, code: true })
              if (!isValidNationalId(toEnDigits(nationalId).replace(/\D/g, "")) || toEnDigits(code).replace(/\D/g, "").length < 6) return
            }
            toast.success("نسخه ثبت شد؛ قیمت را تا ۱۵ دقیقهٔ دیگر پیامک می‌کنیم.")
          }}
        >
          <header className="flex flex-col gap-1">
            <h1 className="text-2xl leading-snug font-bold">سفارش با نسخه</h1>
            <p className="text-sm text-muted-foreground">الان پولی پرداخت نمی‌کنی؛ اول قیمت را می‌بینی.</p>
          </header>

          <section aria-labelledby="method-title" className="flex flex-col gap-4">
            <h2 id="method-title" className="sr-only">
              روشِ ثبتِ نسخه
            </h2>
            <ControlSizeProvider size="lg" mobileSize="default" asChild>
              <ToggleGroup type="single" variant="segmented" fullWidth value={method} onValueChange={(value) => value && setMethod(value)} aria-label="روشِ ثبتِ نسخه" className="sm:w-max">
                <ToggleGroupItem value="photo">عکسِ نسخه</ToggleGroupItem>
                <ToggleGroupItem value="code">نسخهٔ الکترونیک</ToggleGroupItem>
              </ToggleGroup>
            </ControlSizeProvider>

            {method === "photo" ? (
              <FileUpload name="prescription" multiple maxFiles={3} accept="image/*" title="عکسِ نسخه را بکش یا انتخاب کن" hint="تا ۳ عکس، هر کدام تا ۵ مگابایت؛ نامِ پزشک و مهر خوانا باشد." />
            ) : (
              <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
                <TextField
                  label="کدِ ملیِ بیمار"
                  inputMode="numeric"
                  dir="ltr"
                  maxLength={10}
                  value={nationalId}
                  onValueChange={setNationalId}
                  onBlur={() => setBlurred((value) => ({ ...value, id: true }))}
                  invalid={Boolean(idError)}
                  errorMessage={idError}
                  autoComplete="off"
                />
                <TextField
                  label="کدِ رهگیریِ نسخه"
                  inputMode="numeric"
                  dir="ltr"
                  value={code}
                  onValueChange={setCode}
                  onBlur={() => setBlurred((value) => ({ ...value, code: true }))}
                  invalid={Boolean(codeError)}
                  errorMessage={codeError}
                  description="در پیامکی که بعد از ویزیت گرفتی."
                  autoComplete="one-time-code"
                />
              </div>
            )}
          </section>

          <section aria-labelledby="patient-title" className="flex flex-col gap-3">
            <h2 id="patient-title" className="text-lg leading-snug font-bold">
              برای چه کسی؟
            </h2>
            <RadioGroup value={patient} onValueChange={setPatient} aria-labelledby="patient-title" className="grid grid-cols-2 gap-3">
              <RadioCard layout="tile" value="me" title="خودم" description="آرمیتا رستگار" />
              <RadioCard layout="tile" value="other" title="شخصِ دیگر" description="کدِ ملیِ او را بنویس" />
            </RadioGroup>
          </section>

          <section aria-labelledby="address-title" className="flex flex-col gap-3">
            <h2 id="address-title" className="text-lg leading-snug font-bold">
              تحویل به
            </h2>
            <div className="flex items-start gap-3 rounded-xl border border-border bg-card p-4">
              <LocationIcon aria-hidden className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
              <span className="flex min-w-0 flex-1 flex-col gap-0.5">
                <span className="font-semibold">خانه</span>
                <span className="text-sm text-muted-foreground">تهران، خیابانِ آزادی، کوچهٔ نسترن، پلاکِ ۱۲، واحدِ ۴</span>
              </span>
              <ControlSizeProvider size="sm" asChild>
                <Button type="button" variant="ghost" className="-me-2 text-brand-secondary">
                  تغییر
                </Button>
              </ControlSizeProvider>
            </div>
          </section>

          <Button type="submit" fullWidth className="mt-2">
            ثبتِ نسخه و دریافتِ قیمت
          </Button>
        </form>

        <aside aria-labelledby="how-title" className="flex flex-col gap-4 rounded-xl border border-border bg-card p-5 lg:sticky lg:top-6">
          <h2 id="how-title" className="font-bold">
            بعد از ثبت چه می‌شود؟
          </h2>
          <ol className="flex flex-col gap-4">
            {HOW.map((item) => (
              <li key={item.title} className="flex gap-3">
                <span aria-hidden className="relative flex size-9 shrink-0 items-center justify-center rounded-full bg-primary-subtle text-primary-subtle-foreground [&>svg]:size-4">
                  {item.icon}
                </span>
                <span className="flex flex-col gap-0.5">
                  <span className="text-sm font-semibold">{item.title}</span>
                  <span className="text-xs leading-5 text-muted-foreground">{item.text}</span>
                </span>
              </li>
            ))}
          </ol>
        </aside>
      </main>
    </ControlSizeProvider>
  )
}
pharmacy-prescription.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 FileUpload from "@/components/ui/FileUpload.vue"
import RadioCard from "@/components/ui/RadioCard.vue"
import RadioGroup from "@/components/ui/RadioGroup.vue"
import TextField from "@/components/ui/TextField.vue"
import { toast } from "@/components/ui/Toast.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { isValidNationalId, toEnDigits, toFaDigits } from "@/lib/persian"

const HOW = [
  { icon: "file-text", title: "نسخه را ثبت کن", text: "عکسِ نسخهٔ کاغذی یا کدِ رهگیریِ نسخهٔ الکترونیک." },
  { icon: "clock", title: "داروخانه قیمت می‌دهد", text: "معمولاً تا ۱۵ دقیقه، با سهمِ بیمه و داروهای جایگزین." },
  { icon: "wallet", title: "پرداخت می‌کنی", text: "بعد از تأییدِ تو و فقط مبلغِ نهایی." },
  { icon: "truck", title: "پیک می‌آورد", text: "داروی یخچالی با کیفِ سرد." },
]

/**
 * سفارشِ داروی نسخه‌ای: یک انتخابِ تکی بینِ «عکسِ نسخه» و «نسخهٔ الکترونیک» (سگمنت، نه دو فرم کنارِ هم)،
 * بارگذاریِ تا ۳ عکس یا کدِ ملی و کدِ رهگیری با خطای کنارِ فیلد، برای چه کسی، و نشانیِ تحویل. ستونِ
 * کنار مراحل را می‌گوید تا کاربر بداند بعد از ثبت چه می‌شود و الان پولی پرداخت نمی‌کند.
 */
const method = ref("photo")
const patient = ref("me")
const nationalId = ref("")
const code = ref("")
const blurred = ref({ id: false, code: false })

const idDigits = computed(() => toEnDigits(nationalId.value).replace(/\D/g, ""))
const idError = computed(() =>
  !blurred.value.id || isValidNationalId(idDigits.value)
    ? undefined
    : !idDigits.value
      ? "کدِ ملی را بنویس؛ ۱۰ رقم است."
      : idDigits.value.length !== 10
        ? `کدِ ملی ۱۰ رقم است، ${toFaDigits(idDigits.value.length)} رقم وارد شده.`
        : "این کدِ ملی معتبر نیست؛ یک بار دیگر از روی کارت نگاه کن."
)
const codeError = computed(() => (blurred.value.code && toEnDigits(code.value).replace(/\D/g, "").length < 6 ? "کدِ رهگیری در پیامکِ پزشک آمده؛ دست‌کم ۶ رقم." : undefined))

function onMethod(value: string | string[] | undefined) {
  if (value) method.value = value as string
}

function onSubmit() {
  if (method.value === "code") {
    blurred.value = { id: true, code: true }
    if (!isValidNationalId(toEnDigits(nationalId.value).replace(/\D/g, "")) || toEnDigits(code.value).replace(/\D/g, "").length < 6) return
  }
  toast.success("نسخه ثبت شد؛ قیمت را تا ۱۵ دقیقهٔ دیگر پیامک می‌کنیم.")
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto grid w-full max-w-5xl grid-cols-1 items-start gap-6 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem] lg:gap-8">
      <form class="flex min-w-0 flex-col gap-6" novalidate @submit.prevent="onSubmit">
        <header class="flex flex-col gap-1">
          <h1 class="text-2xl leading-snug font-bold">سفارش با نسخه</h1>
          <p class="text-sm text-muted-foreground">الان پولی پرداخت نمی‌کنی؛ اول قیمت را می‌بینی.</p>
        </header>

        <section aria-labelledby="method-title" class="flex flex-col gap-4">
          <h2 id="method-title" class="sr-only">روشِ ثبتِ نسخه</h2>
          <ControlSize size="lg" mobile-size="default" as-child>
            <ToggleGroup type="single" variant="segmented" full-width :value="method" aria-label="روشِ ثبتِ نسخه" class="sm:w-max" @update:value="onMethod">
              <ToggleGroupItem value="photo">عکسِ نسخه</ToggleGroupItem>
              <ToggleGroupItem value="code">نسخهٔ الکترونیک</ToggleGroupItem>
            </ToggleGroup>
          </ControlSize>

          <FileUpload v-if="method === 'photo'" name="prescription" multiple :max-files="3" accept="image/*">
            <template #title>عکسِ نسخه را بکش یا انتخاب کن</template>
            <template #hint>تا ۳ عکس، هر کدام تا ۵ مگابایت؛ نامِ پزشک و مهر خوانا باشد.</template>
          </FileUpload>
          <div v-else class="grid grid-cols-1 gap-4 sm:grid-cols-2">
            <TextField
              v-model="nationalId"
              label="کدِ ملیِ بیمار"
              inputmode="numeric"
              dir="ltr"
              :maxlength="10"
              :invalid="Boolean(idError)"
              :error-message="idError"
              autocomplete="off"
              @blur="blurred = { ...blurred, id: true }"
            />
            <TextField
              v-model="code"
              label="کدِ رهگیریِ نسخه"
              inputmode="numeric"
              dir="ltr"
              :invalid="Boolean(codeError)"
              :error-message="codeError"
              description="در پیامکی که بعد از ویزیت گرفتی."
              autocomplete="one-time-code"
              @blur="blurred = { ...blurred, code: true }"
            />
          </div>
        </section>

        <section aria-labelledby="patient-title" class="flex flex-col gap-3">
          <h2 id="patient-title" class="text-lg leading-snug font-bold">برای چه کسی؟</h2>
          <RadioGroup v-model:value="patient" aria-labelledby="patient-title" class="grid grid-cols-2 gap-3">
            <RadioCard layout="tile" value="me" title="خودم" description="آرمیتا رستگار" />
            <RadioCard layout="tile" value="other" title="شخصِ دیگر" description="کدِ ملیِ او را بنویس" />
          </RadioGroup>
        </section>

        <section aria-labelledby="address-title" class="flex flex-col gap-3">
          <h2 id="address-title" class="text-lg leading-snug font-bold">تحویل به</h2>
          <div class="flex items-start gap-3 rounded-xl border border-border bg-card p-4">
            <DigIcon name="location" aria-hidden="true" class="mt-0.5 size-5 shrink-0 text-muted-foreground" />
            <span class="flex min-w-0 flex-1 flex-col gap-0.5">
              <span class="font-semibold">خانه</span>
              <span class="text-sm text-muted-foreground">تهران، خیابانِ آزادی، کوچهٔ نسترن، پلاکِ ۱۲، واحدِ ۴</span>
            </span>
            <ControlSize size="sm" as-child>
              <Button type="button" variant="ghost" class="-me-2 text-brand-secondary">تغییر</Button>
            </ControlSize>
          </div>
        </section>

        <Button type="submit" full-width class="mt-2">ثبتِ نسخه و دریافتِ قیمت</Button>
      </form>

      <aside aria-labelledby="how-title" class="flex flex-col gap-4 rounded-xl border border-border bg-card p-5 lg:sticky lg:top-6">
        <h2 id="how-title" class="font-bold">بعد از ثبت چه می‌شود؟</h2>
        <ol class="flex flex-col gap-4">
          <li v-for="item in HOW" :key="item.title" class="flex gap-3">
            <span aria-hidden="true" class="relative flex size-9 shrink-0 items-center justify-center rounded-full bg-primary-subtle text-primary-subtle-foreground [&>svg]:size-4">
              <DigIcon :name="item.icon" />
            </span>
            <span class="flex flex-col gap-0.5">
              <span class="text-sm font-semibold">{{ item.title }}</span>
              <span class="text-xs leading-5 text-muted-foreground">{{ item.text }}</span>
            </span>
          </li>
        </ol>
      </aside>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: control-sizefile-uploadpersianradio-cardradio-grouptext-fieldtoasttoggle-groupآیکون clockآیکون file-textآیکون locationآیکون truckآیکون wallet

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

pharmacy-prescription.ts
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigToggleGroup, DigToggleGroupItem } from "@/components/ui/toggle-group"
import { DigFileUpload } from "@/components/ui/file-upload"
import { DigTextField } from "@/components/ui/text-field"
import { DigInput, DigInputField } from "@/components/ui/input"
import { DigRadioGroup } from "@/components/ui/radio-group"
import { DigRadioCard, DigRadioCardMedia } from "@/components/ui/radio-card"
import { DigIcon } from "@/lib/icons"
import { DigButton } from "@/components/ui/button"
import { FormsModule } from "@angular/forms"
import { toast } from "@/components/ui/toast"
import { isValidNationalId, toEnDigits, toFaDigits } from "@/lib/persian"

const HOW = [
  { icon: "file-text" as const, title: "نسخه را ثبت کن", text: "عکسِ نسخهٔ کاغذی یا کدِ رهگیریِ نسخهٔ الکترونیک." },
  { icon: "clock" as const, title: "داروخانه قیمت می‌دهد", text: "معمولاً تا ۱۵ دقیقه، با سهمِ بیمه و داروهای جایگزین." },
  { icon: "wallet" as const, title: "پرداخت می‌کنی", text: "بعد از تأییدِ تو و فقط مبلغِ نهایی." },
  { icon: "truck" as const, title: "پیک می‌آورد", text: "داروی یخچالی با کیفِ سرد." },
] as const

@Component({
  selector: "dig-block-pharmacy-prescription",
  imports: [
    DigControlSize,
    DigToggleGroup,
    DigToggleGroupItem,
    DigFileUpload,
    DigTextField,
    DigInput,
    DigInputField,
    DigRadioGroup,
    DigRadioCard,
    DigRadioCardMedia,
    DigIcon,
    DigButton,
    FormsModule,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main
      digControlSize="xl"
      class="mx-auto grid w-full max-w-5xl grid-cols-1 items-start gap-6 p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_20rem] lg:gap-8"
    >
      <form class="flex min-w-0 flex-col gap-6" novalidate (submit)="$event.preventDefault(); onSubmit()">
        <header class="flex flex-col gap-1">
          <h1 class="text-2xl leading-snug font-bold">سفارش با نسخه</h1>
          <p class="text-sm text-muted-foreground">الان پولی پرداخت نمی‌کنی؛ اول قیمت را می‌بینی.</p>
        </header>

        <section aria-labelledby="method-title" class="flex flex-col gap-4">
          <h2 id="method-title" class="sr-only">روشِ ثبتِ نسخه</h2>
          <div digControlSize="lg" mobileSize="default">
            <div
              digToggleGroup
              type="single"
              variant="segmented"
              fullWidth
              [value]="method()"
              aria-label="روشِ ثبتِ نسخه"
              class="sm:w-max"
              (valueChange)="onMethod($event)"
            >
              <button digToggleGroupItem value="photo">عکسِ نسخه</button>
              <button digToggleGroupItem value="code">نسخهٔ الکترونیک</button>
            </div>
          </div>

          @if (method() === "photo") {
            <div
              digFileUpload
              name="prescription"
              multiple
              [maxFiles]="3"
              accept="image/*"
              title="عکسِ نسخه را بکش یا انتخاب کن"
              hint="تا ۳ عکس، هر کدام تا ۵ مگابایت؛ نامِ پزشک و مهر خوانا باشد."
            ></div>
          } @else {
            <div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
              <div digTextField label="کدِ ملیِ بیمار" [invalid]="boolean(idError())" [errorMessage]="idError()">
                <dig-input
                  ><input
                    digInput
                    [ngModel]="nationalId()"
                    [ngModelOptions]="{ standalone: true }"
                    (ngModelChange)="nationalId.set($event)"
                    inputmode="numeric"
                    dir="ltr"
                    [maxlength]="10"
                    autocomplete="off"
                    (blur)="blurred.set({ ...blurred(), id: true })"
                /></dig-input>
              </div>
              <div
                digTextField
                label="کدِ رهگیریِ نسخه"
                [invalid]="boolean(codeError())"
                [errorMessage]="codeError()"
                description="در پیامکی که بعد از ویزیت گرفتی."
              >
                <dig-input
                  ><input
                    digInput
                    [ngModel]="code()"
                    [ngModelOptions]="{ standalone: true }"
                    (ngModelChange)="code.set($event)"
                    inputmode="numeric"
                    dir="ltr"
                    autocomplete="one-time-code"
                    (blur)="blurred.set({ ...blurred(), code: true })"
                /></dig-input>
              </div>
            </div>
          }
        </section>

        <section aria-labelledby="patient-title" class="flex flex-col gap-3">
          <h2 id="patient-title" class="text-lg leading-snug font-bold">برای چه کسی؟</h2>
          <div
            digRadioGroup
            [value]="patient()"
            (valueChange)="setPatient($event)"
            aria-labelledby="patient-title"
            class="grid grid-cols-2 gap-3"
          >
            <label digRadioCard layout="tile" value="me" title="خودم" description="آرمیتا رستگار"></label>
            <label digRadioCard layout="tile" value="other" title="شخصِ دیگر" description="کدِ ملیِ او را بنویس"></label>
          </div>
        </section>

        <section aria-labelledby="address-title" class="flex flex-col gap-3">
          <h2 id="address-title" class="text-lg leading-snug font-bold">تحویل به</h2>
          <div class="flex items-start gap-3 rounded-xl border border-border bg-card p-4">
            <svg digIcon="location" aria-hidden="true" class="mt-0.5 size-5 shrink-0 text-muted-foreground"></svg>
            <span class="flex min-w-0 flex-1 flex-col gap-0.5"
              ><span class="font-semibold">خانه</span>
              <span class="text-sm text-muted-foreground">تهران، خیابانِ آزادی، کوچهٔ نسترن، پلاکِ ۱۲، واحدِ ۴</span></span
            >
            <button digControlSize="sm" digButton type="button" variant="ghost" class="-me-2 text-brand-secondary">
              تغییر
            </button>
          </div>
        </section>

        <button digButton type="submit" fullWidth class="mt-2">ثبتِ نسخه و دریافتِ قیمت</button>
      </form>

      <aside
        aria-labelledby="how-title"
        class="flex flex-col gap-4 rounded-xl border border-border bg-card p-5 lg:sticky lg:top-6"
      >
        <h2 id="how-title" class="font-bold">بعد از ثبت چه می‌شود؟</h2>
        <ol class="flex flex-col gap-4">
          @for (item of HOW; track item.title) {
            <li class="flex gap-3">
              <span
                aria-hidden="true"
                class="relative flex size-9 shrink-0 items-center justify-center rounded-full bg-primary-subtle text-primary-subtle-foreground [&>svg]:size-4"
                ><svg [digIcon]="item.icon"></svg
              ></span>
              <span class="flex flex-col gap-0.5"
                ><span class="text-sm font-semibold">{{ item.title }}</span>
                <span class="text-xs leading-5 text-muted-foreground">{{ item.text }}</span></span
              >
            </li>
          }
        </ol>
      </aside>
    </main>
  `,
})
export class PharmacyPrescriptionBlock {
  readonly boolean = Boolean

  readonly HOW = HOW

  readonly method = signal("photo")

  readonly patient = signal("me")

  readonly nationalId = signal("")

  readonly code = signal("")

  readonly blurred = signal({ id: false, code: false })

  readonly idDigits = computed(() => toEnDigits(this.nationalId()).replace(/\D/g, ""))

  readonly idError = computed(() =>
    !this.blurred().id || isValidNationalId(this.idDigits())
      ? undefined
      : !this.idDigits()
        ? "کدِ ملی را بنویس؛ ۱۰ رقم است."
        : this.idDigits().length !== 10
          ? `کدِ ملی ۱۰ رقم است، ${toFaDigits(this.idDigits().length)} رقم وارد شده.`
          : "این کدِ ملی معتبر نیست؛ یک بار دیگر از روی کارت نگاه کن."
  )

  readonly codeError = computed(() =>
    this.blurred().code && toEnDigits(this.code()).replace(/\D/g, "").length < 6
      ? "کدِ رهگیری در پیامکِ پزشک آمده؛ دست‌کم ۶ رقم."
      : undefined
  )

  onMethod(value: string | string[] | undefined) {
    if (value) this.method.set(value as string)
  }

  onSubmit() {
    if (this.method() === "code") {
      this.blurred.set({ id: true, code: true })
      if (
        !isValidNationalId(toEnDigits(this.nationalId()).replace(/\D/g, "")) ||
        toEnDigits(this.code()).replace(/\D/g, "").length < 6
      )
        return
    }
    toast.success("نسخه ثبت شد؛ قیمت را تا ۱۵ دقیقهٔ دیگر پیامک می‌کنیم.")
  }

  setPatient(value: string | string[] | undefined) {
    if (typeof value === "string") this.patient.set(value)
  }
}

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

همهٔ کامپوننت‌های لازم برای Android آماده‌اند؛ با MCP می‌توانید همین صفحه را از روی نسخهٔ React بسازید.

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