انتخابِ زمانِ نوبت
پیشنمایش تمامصفحهنوارِ هفت روزِ پیشِ رو با شمارِ نوبتِ خالی، ساعتهای صبح و عصر با RadioCard و ساعتِ پر، راهنمای نزدیکترین روزِ خالی برای روزِ پر یا تعطیل، و نوارِ پایین با خلاصهٔ انتخاب و ادامه.
۱. نصب کامپوننتها
این بلاک از ۱۱ آیتم دیگ استفاده میکند: avatarbottom-action-barbuttoncontrol-sizeday-stripempty-stateiconspersianradio-cardradio-grouptoast
npx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bottom-action-bar.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/day-strip.json https://docs.digdesign.ir/r/empty-state.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/toast.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bottom-action-bar.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/day-strip.json https://docs.digdesign.ir/r/empty-state.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/toast.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bottom-action-bar.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/day-strip.json https://docs.digdesign.ir/r/empty-state.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/toast.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/bottom-action-bar.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/day-strip.json https://docs.digdesign.ir/r/empty-state.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/toast.jsonnpx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework vuepnpm dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework vueyarn dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework vuebunx --bun digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework vuenpx digdesign@latest add bottom-action-bar button day-strip --framework sveltepnpm dlx digdesign@latest add bottom-action-bar button day-strip --framework svelteyarn dlx digdesign@latest add bottom-action-bar button day-strip --framework sveltebunx --bun digdesign@latest add bottom-action-bar button day-strip --framework sveltenpx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state icons persian radio-card radio-group toast --framework angularpnpm dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state icons persian radio-card radio-group toast --framework angularyarn dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state icons persian radio-card radio-group toast --framework angularbunx --bun digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state icons persian radio-card radio-group toast --framework angularnpx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework androidpnpm dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework androidyarn dlx digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework androidbunx --bun digdesign@latest add avatar bottom-action-bar button control-size day-strip empty-state persian radio-card radio-group toast --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { CalendarIcon, ChevronRightIcon, LocationIcon, MoonIcon, SunIcon } from "@/components/icons"
import { Avatar } from "@/components/ui/avatar"
import { BottomActionBar, BottomActionBarSummary } from "@/components/ui/bottom-action-bar"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { DayStrip } from "@/components/ui/day-strip"
import { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateTitle } from "@/components/ui/empty-state"
import { RadioCard } from "@/components/ui/radio-card"
import { RadioGroup } from "@/components/ui/radio-group"
import { toast } from "@/components/ui/toast"
import { formatCurrency, toFaDigits } from "@/lib/persian"
import { stockImages } from "@/lib/stock-images"
type Slot = { time: string; full?: boolean }
/** offset: چند روز بعد از امروز (جمعه تعطیل است و در نوار نمیآید). */
type Day = { id: string; offset: number; morning: Slot[]; evening: Slot[] }
/** هفت روزِ پیشِ رو؛ ساعتهای پر نمایش داده میشوند ولی انتخابشدنی نیستند تا کاربر تصویرِ درستی از ظرفیت داشته باشد. */
const DAYS: Day[] = [
{ id: "d0", offset: 0, morning: [], evening: [{ time: "۱۶:۳۰" }, { time: "۱۷:۰۰", full: true }, { time: "۱۸:۱۵" }] },
{ id: "d1", offset: 1, morning: [], evening: [{ time: "۱۶:۰۰" }, { time: "۱۶:۴۵" }, { time: "۱۷:۳۰", full: true }, { time: "۱۸:۰۰" }, { time: "۱۹:۱۵" }] },
{ id: "d2", offset: 2, morning: [], evening: [{ time: "۱۶:۰۰", full: true }, { time: "۱۷:۱۵", full: true }, { time: "۱۹:۰۰" }] },
{ id: "d3", offset: 3, morning: [], evening: [] },
{ id: "d4", offset: 4, morning: [{ time: "۰۹:۰۰" }, { time: "۰۹:۳۰" }, { time: "۱۰:۱۵" }, { time: "۱۱:۰۰", full: true }, { time: "۱۲:۰۰" }], evening: [] },
{ id: "d5", offset: 5, morning: [], evening: [] },
{ id: "d6", offset: 7, morning: [], evening: [{ time: "۱۶:۰۰" }, { time: "۱۶:۳۰" }, { time: "۱۸:۴۵" }] },
]
const dateOf = (day: Day) => {
const date = new Date()
date.setHours(0, 0, 0, 0)
date.setDate(date.getDate() + day.offset)
return date
}
const nameOf = (day: Day) => (day.offset === 0 ? "امروز" : day.offset === 1 ? "فردا" : new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long" }).format(dateOf(day)))
const dateText = (day: Day) => new Intl.DateTimeFormat("fa-IR-u-ca-persian", { day: "numeric", month: "long" }).format(dateOf(day))
const free = (day: Day) => [...day.morning, ...day.evening].filter((slot) => !slot.full).length
/**
* انتخابِ زمانِ نوبت: سرِ صفحه پزشک و مطب، نوارِ هفت روزِ پیشِ رو با شمارِ نوبتِ خالیِ هر روز (روزِ بینوبت
* «تعطیل» یا «پر» نوشته میشود و انتخابشدنی است تا پیامش دیده شود)، و ساعتها در دو گروهِ صبح و عصر با
* RadioCard؛ ساعتِ پر خطخورده نیست، «پر» مینویسد و غیرفعال است. انتخاب در نوارِ پایین خلاصه میشود و
* «ادامه» تا ساعت انتخاب نشده پیامِ راهنما میدهد، نه دکمهٔ مرده.
*/
export default function DoctorSlotsBlock() {
const [dayId, setDayId] = React.useState("d0")
const [time, setTime] = React.useState("")
const day = DAYS.find((item) => item.id === dayId) ?? DAYS[0]
const nextOpen = DAYS.find((item) => DAYS.indexOf(item) > DAYS.indexOf(day) && free(item) > 0)
const groups = [
{ id: "morning", label: "صبح", icon: <SunIcon />, slots: day.morning },
{ id: "evening", label: "عصر", icon: <MoonIcon />, slots: day.evening },
].filter((group) => group.slots.length > 0)
return (
<ControlSizeProvider size="xl" asChild>
<div className="mx-auto flex w-full max-w-3xl flex-col">
<main className="flex flex-col gap-8 p-4 sm:p-6">
<header className="flex items-center gap-3">
<Button variant="ghost" size="icon" aria-label="بازگشت به پروفایلِ پزشک" className="-ms-2 shrink-0">
<ChevronRightIcon className="ltr:rotate-180" />
</Button>
<Avatar src={stockImages.doctorWomanCurly.src} alt="" name="سارا محمدی" className="size-12 shrink-0" />
<div className="flex min-w-0 flex-col">
<h1 className="truncate leading-snug font-bold">دکتر سارا محمدی</h1>
<span className="flex items-center gap-1 truncate text-sm text-muted-foreground">
<LocationIcon aria-hidden className="size-4 shrink-0" />
ویزیتِ حضوری · مطبِ ونک
</span>
</div>
</header>
<section aria-labelledby="day-title" className="flex flex-col gap-3">
<h2 id="day-title" className="text-lg leading-snug font-bold">
روزِ نوبت
</h2>
<DayStrip
aria-label="روزِ نوبت"
className="-mx-4 px-4 sm:mx-0 sm:px-1"
value={dateOf(day)}
onValueChange={(date) => {
const next = DAYS.find((item) => dateOf(item).toDateString() === date.toDateString())
if (!next) return
setDayId(next.id)
setTime("")
}}
days={DAYS.map((item) => {
const count = free(item)
const closed = item.morning.length + item.evening.length === 0
return {
date: dateOf(item),
label: nameOf(item),
meta: closed ? "تعطیل" : count ? `${toFaDigits(count)} خالی` : "پر",
tone: closed || !count ? "muted" : "success",
description: `${nameOf(item)} ${dateText(item)}، ${closed ? "تعطیل" : count ? `${toFaDigits(count)} نوبتِ خالی` : "پر"}`,
}
})}
/>
</section>
<section aria-labelledby="time-title" className="flex flex-col gap-5">
<h2 id="time-title" className="text-lg leading-snug font-bold">
ساعتِ نوبت
</h2>
{free(day) === 0 ? (
<EmptyState variant="bordered">
<EmptyStateTitle>{groups.length ? "نوبتهای این روز پر شده" : "مطب این روز تعطیل است"}</EmptyStateTitle>
<EmptyStateDescription>{nextOpen ? `نزدیکترین روزِ خالی ${nameOf(nextOpen)}، ${dateText(nextOpen)} است.` : "این هفته نوبتِ خالی نمانده؛ میتوانی مشاورهٔ تلفنی بگیری."}</EmptyStateDescription>
{nextOpen && (
<EmptyStateActions>
<Button variant="outline" onClick={() => setDayId(nextOpen.id)}>
رفتن به {nameOf(nextOpen)}
</Button>
</EmptyStateActions>
)}
</EmptyState>
) : (
<RadioGroup value={time} onValueChange={setTime} aria-labelledby="time-title" className="flex flex-col gap-5">
{groups.map((group) => (
<div key={group.id} className="flex flex-col gap-3">
<span className="flex items-center gap-2 text-sm font-medium text-muted-foreground [&>svg]:size-4">
{group.icon}
{group.label}
</span>
<div className="grid grid-cols-3 gap-2 sm:grid-cols-5">
{group.slots.map((slot) => (
<RadioCard
key={slot.time}
value={slot.time}
layout="tile"
disabled={slot.full}
title={<span className="tabular-nums">{slot.time}</span>}
description={slot.full ? "پر" : undefined}
/>
))}
</div>
</div>
))}
</RadioGroup>
)}
</section>
</main>
{/* خلاصه و ادامه در دسترسِ شست؛ در دسکتاپ هم پایینِ ستون میچسبد. */}
<BottomActionBar hideFrom="none" className="sm:px-6">
<BottomActionBarSummary
label={
<>
<CalendarIcon aria-hidden />
ویزیت {formatCurrency(850_000)}
</>
}
value={time ? `${nameOf(day)} ${dateText(day)}، ساعت ${time}` : "ساعت را انتخاب کن"}
className="flex-1 shrink"
/>
<Button
className="min-w-32"
onClick={() => {
if (!time) {
toast("اول یکی از ساعتهای خالی را انتخاب کن.")
document.getElementById("time-title")?.scrollIntoView({ behavior: "smooth", block: "center" })
return
}
toast.success(`نوبتِ ${nameOf(day)} ساعت ${time} نگه داشته شد؛ ۱۰ دقیقه برای تکمیل وقت داری.`)
}}
>
ادامه
</Button>
</BottomActionBar>
</div>
</ControlSizeProvider>
)
}
<script setup lang="ts">
import { computed, ref } from "vue"
import Avatar from "@/components/ui/Avatar.vue"
import BottomActionBar from "@/components/ui/BottomActionBar.vue"
import BottomActionBarSummary from "@/components/ui/BottomActionBarSummary.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import DayStrip from "@/components/ui/DayStrip.vue"
import EmptyState from "@/components/ui/EmptyState.vue"
import EmptyStateActions from "@/components/ui/EmptyStateActions.vue"
import EmptyStateDescription from "@/components/ui/EmptyStateDescription.vue"
import EmptyStateTitle from "@/components/ui/EmptyStateTitle.vue"
import RadioCard from "@/components/ui/RadioCard.vue"
import RadioGroup from "@/components/ui/RadioGroup.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"
const doctorPhoto = "https://docs.digdesign.ir/images/doctor-woman-curly.webp"
type Slot = { time: string; full?: boolean }
/** offset: چند روز بعد از امروز (جمعه تعطیل است و در نوار نمیآید). */
type Day = { id: string; offset: number; morning: Slot[]; evening: Slot[] }
/** هفت روزِ پیشِ رو؛ ساعتهای پر نمایش داده میشوند ولی انتخابشدنی نیستند تا کاربر تصویرِ درستی از ظرفیت داشته باشد. */
const DAYS: Day[] = [
{ id: "d0", offset: 0, morning: [], evening: [{ time: "۱۶:۳۰" }, { time: "۱۷:۰۰", full: true }, { time: "۱۸:۱۵" }] },
{ id: "d1", offset: 1, morning: [], evening: [{ time: "۱۶:۰۰" }, { time: "۱۶:۴۵" }, { time: "۱۷:۳۰", full: true }, { time: "۱۸:۰۰" }, { time: "۱۹:۱۵" }] },
{ id: "d2", offset: 2, morning: [], evening: [{ time: "۱۶:۰۰", full: true }, { time: "۱۷:۱۵", full: true }, { time: "۱۹:۰۰" }] },
{ id: "d3", offset: 3, morning: [], evening: [] },
{ id: "d4", offset: 4, morning: [{ time: "۰۹:۰۰" }, { time: "۰۹:۳۰" }, { time: "۱۰:۱۵" }, { time: "۱۱:۰۰", full: true }, { time: "۱۲:۰۰" }], evening: [] },
{ id: "d5", offset: 5, morning: [], evening: [] },
{ id: "d6", offset: 7, morning: [], evening: [{ time: "۱۶:۰۰" }, { time: "۱۶:۳۰" }, { time: "۱۸:۴۵" }] },
]
const dateOf = (day: Day) => {
const date = new Date()
date.setHours(0, 0, 0, 0)
date.setDate(date.getDate() + day.offset)
return date
}
const nameOf = (day: Day) => (day.offset === 0 ? "امروز" : day.offset === 1 ? "فردا" : new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long" }).format(dateOf(day)))
const dateText = (day: Day) => new Intl.DateTimeFormat("fa-IR-u-ca-persian", { day: "numeric", month: "long" }).format(dateOf(day))
const free = (day: Day) => [...day.morning, ...day.evening].filter((slot) => !slot.full).length
/**
* انتخابِ زمانِ نوبت: سرِ صفحه پزشک و مطب، نوارِ هفت روزِ پیشِ رو با شمارِ نوبتِ خالیِ هر روز (روزِ بینوبت
* «تعطیل» یا «پر» نوشته میشود و انتخابشدنی است تا پیامش دیده شود)، و ساعتها در دو گروهِ صبح و عصر با
* RadioCard؛ ساعتِ پر خطخورده نیست، «پر» مینویسد و غیرفعال است. انتخاب در نوارِ پایین خلاصه میشود و
* «ادامه» تا ساعت انتخاب نشده پیامِ راهنما میدهد، نه دکمهٔ مرده.
*/
const dayId = ref("d0")
const time = ref("")
const day = computed(() => DAYS.find((item) => item.id === dayId.value) ?? DAYS[0])
const nextOpen = computed(() => DAYS.find((item) => DAYS.indexOf(item) > DAYS.indexOf(day.value) && free(item) > 0))
const groups = computed(
() =>
[
{ id: "morning", label: "صبح", icon: "sun", slots: day.value.morning },
{ id: "evening", label: "عصر", icon: "moon", slots: day.value.evening },
].filter((group) => group.slots.length > 0)
)
const stripDays = DAYS.map((item) => {
const count = free(item)
const closed = item.morning.length + item.evening.length === 0
return {
date: dateOf(item),
label: nameOf(item),
meta: closed ? "تعطیل" : count ? `${toFaDigits(count)} خالی` : "پر",
tone: (closed || !count ? "muted" : "success") as "muted" | "success",
description: `${nameOf(item)} ${dateText(item)}، ${closed ? "تعطیل" : count ? `${toFaDigits(count)} نوبتِ خالی` : "پر"}`,
}
})
function onDate(date: Date | undefined) {
if (!date) return
const next = DAYS.find((item) => dateOf(item).toDateString() === date.toDateString())
if (!next) return
dayId.value = next.id
time.value = ""
}
function onContinue() {
if (!time.value) {
toast("اول یکی از ساعتهای خالی را انتخاب کن.")
document.getElementById("time-title")?.scrollIntoView({ behavior: "smooth", block: "center" })
return
}
toast.success(`نوبتِ ${nameOf(day.value)} ساعت ${time.value} نگه داشته شد؛ ۱۰ دقیقه برای تکمیل وقت داری.`)
}
</script>
<template>
<ControlSize size="xl" as-child>
<div class="mx-auto flex w-full max-w-3xl flex-col">
<main class="flex flex-col gap-8 p-4 sm:p-6">
<header class="flex items-center gap-3">
<Button variant="ghost" size="icon" aria-label="بازگشت به پروفایلِ پزشک" class="-ms-2 shrink-0">
<DigIcon name="chevron-right" class="ltr:rotate-180" />
</Button>
<Avatar :src="doctorPhoto" alt="" name="سارا محمدی" class="size-12 shrink-0" />
<div class="flex min-w-0 flex-col">
<h1 class="truncate leading-snug font-bold">دکتر سارا محمدی</h1>
<span class="flex items-center gap-1 truncate text-sm text-muted-foreground">
<DigIcon name="location" aria-hidden="true" class="size-4 shrink-0" />
ویزیتِ حضوری · مطبِ ونک
</span>
</div>
</header>
<section aria-labelledby="day-title" class="flex flex-col gap-3">
<h2 id="day-title" class="text-lg leading-snug font-bold">روزِ نوبت</h2>
<DayStrip aria-label="روزِ نوبت" class="-mx-4 px-4 sm:mx-0 sm:px-1" :model-value="dateOf(day)" :days="stripDays" @update:model-value="onDate" />
</section>
<section aria-labelledby="time-title" class="flex flex-col gap-5">
<h2 id="time-title" class="text-lg leading-snug font-bold">ساعتِ نوبت</h2>
<EmptyState v-if="free(day) === 0" variant="bordered">
<EmptyStateTitle>{{ groups.length ? "نوبتهای این روز پر شده" : "مطب این روز تعطیل است" }}</EmptyStateTitle>
<EmptyStateDescription>{{ nextOpen ? `نزدیکترین روزِ خالی ${nameOf(nextOpen)}، ${dateText(nextOpen)} است.` : "این هفته نوبتِ خالی نمانده؛ میتوانی مشاورهٔ تلفنی بگیری." }}</EmptyStateDescription>
<EmptyStateActions v-if="nextOpen">
<Button variant="outline" @click="dayId = nextOpen.id">رفتن به {{ nameOf(nextOpen) }}</Button>
</EmptyStateActions>
</EmptyState>
<RadioGroup v-else :value="time" aria-labelledby="time-title" class="flex flex-col gap-5" @update:value="(value) => (time = value)">
<div v-for="group in groups" :key="group.id" class="flex flex-col gap-3">
<span class="flex items-center gap-2 text-sm font-medium text-muted-foreground [&>svg]:size-4">
<DigIcon :name="group.icon" />
{{ group.label }}
</span>
<div class="grid grid-cols-3 gap-2 sm:grid-cols-5">
<RadioCard v-for="slot in group.slots" :key="slot.time" :value="slot.time" layout="tile" :disabled="slot.full" :description="slot.full ? 'پر' : undefined">
<template #title><span class="tabular-nums">{{ slot.time }}</span></template>
</RadioCard>
</div>
</div>
</RadioGroup>
</section>
</main>
<!-- خلاصه و ادامه در دسترسِ شست؛ در دسکتاپ هم پایینِ ستون میچسبد. -->
<BottomActionBar hide-from="none" class="sm:px-6">
<BottomActionBarSummary :value="time ? `${nameOf(day)} ${dateText(day)}، ساعت ${time}` : 'ساعت را انتخاب کن'" class="flex-1 shrink">
<template #label>
<DigIcon name="calendar" aria-hidden="true" />
ویزیت {{ formatCurrency(850_000) }}
</template>
</BottomActionBarSummary>
<Button class="min-w-32" @click="onContinue">ادامه</Button>
</BottomActionBar>
</div>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: avatarcontrol-sizeempty-statepersianradio-cardradio-grouptoastآیکون calendarآیکون chevron-rightآیکون locationآیکون moonآیکون sun
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { DigAvatar } from "@/components/ui/avatar"
import { DigDayStrip } from "@/components/ui/day-strip"
import {
DigEmptyState,
DigEmptyStateTitle,
DigEmptyStateDescription,
DigEmptyStateActions,
} from "@/components/ui/empty-state"
import { DigRadioGroup } from "@/components/ui/radio-group"
import { DigRadioCard, DigRadioCardMedia } from "@/components/ui/radio-card"
import { DigBottomActionBar } from "@/components/ui/bottom-action-bar"
import { toast } from "@/components/ui/toast"
import { formatCurrency, toFaDigits } from "@/lib/persian"
const doctorPhoto = "https://docs.digdesign.ir/images/doctor-woman-curly.webp"
type Slot = { time: string; full?: boolean }
type Day = { id: string; offset: number; morning: Slot[]; evening: Slot[] }
const DAYS: Day[] = [
{ id: "d0", offset: 0, morning: [], evening: [{ time: "۱۶:۳۰" }, { time: "۱۷:۰۰", full: true }, { time: "۱۸:۱۵" }] },
{
id: "d1",
offset: 1,
morning: [],
evening: [
{ time: "۱۶:۰۰" },
{ time: "۱۶:۴۵" },
{ time: "۱۷:۳۰", full: true },
{ time: "۱۸:۰۰" },
{ time: "۱۹:۱۵" },
],
},
{
id: "d2",
offset: 2,
morning: [],
evening: [{ time: "۱۶:۰۰", full: true }, { time: "۱۷:۱۵", full: true }, { time: "۱۹:۰۰" }],
},
{ id: "d3", offset: 3, morning: [], evening: [] },
{
id: "d4",
offset: 4,
morning: [
{ time: "۰۹:۰۰" },
{ time: "۰۹:۳۰" },
{ time: "۱۰:۱۵" },
{ time: "۱۱:۰۰", full: true },
{ time: "۱۲:۰۰" },
],
evening: [],
},
{ id: "d5", offset: 5, morning: [], evening: [] },
{ id: "d6", offset: 7, morning: [], evening: [{ time: "۱۶:۰۰" }, { time: "۱۶:۳۰" }, { time: "۱۸:۴۵" }] },
]
@Component({
selector: "dig-block-doctor-slots",
imports: [
DigControlSize,
DigButton,
DigIcon,
DigAvatar,
DigDayStrip,
DigEmptyState,
DigEmptyStateTitle,
DigEmptyStateDescription,
DigEmptyStateActions,
DigRadioGroup,
DigRadioCard,
DigRadioCardMedia,
DigBottomActionBar,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<div digControlSize="xl" class="mx-auto flex w-full max-w-3xl flex-col">
<main class="flex flex-col gap-8 p-4 sm:p-6">
<header class="flex items-center gap-3">
<button
digButton
type="button"
variant="ghost"
size="icon"
aria-label="بازگشت به پروفایلِ پزشک"
class="-ms-2 shrink-0"
>
<svg digIcon="chevron-right" class="ltr:rotate-180"></svg>
</button>
<span digAvatar [src]="doctorPhoto" alt="" name="سارا محمدی" class="size-12 shrink-0"></span>
<div class="flex min-w-0 flex-col">
<h1 class="truncate leading-snug font-bold">دکتر سارا محمدی</h1>
<span class="flex items-center gap-1 truncate text-sm text-muted-foreground"
><svg digIcon="location" aria-hidden="true" class="size-4 shrink-0"></svg>
ویزیتِ حضوری · مطبِ ونک
</span>
</div>
</header>
<section aria-labelledby="day-title" class="flex flex-col gap-3">
<h2 id="day-title" class="text-lg leading-snug font-bold">روزِ نوبت</h2>
<dig-day-strip
aria-label="روزِ نوبت"
class="-mx-4 px-4 sm:mx-0 sm:px-1"
[value]="dateOf(day())"
[days]="stripDays"
(valueChange)="onDate($event)"
></dig-day-strip>
</section>
<section aria-labelledby="time-title" class="flex flex-col gap-5">
<h2 id="time-title" class="text-lg leading-snug font-bold">ساعتِ نوبت</h2>
@if (free(day()) === 0) {
<div digEmptyState variant="bordered">
<h3 digEmptyStateTitle>{{ groups().length ? "نوبتهای این روز پر شده" : "مطب این روز تعطیل است" }}</h3>
<p digEmptyStateDescription>{{ nextOpenSummary() }}</p>
@if (nextOpen(); as nextOpen) {
<div digEmptyStateActions>
<button digButton type="button" variant="outline" (click)="dayId.set(nextOpen.id)">
رفتن به {{ nameOf(nextOpen) }}
</button>
</div>
}
</div>
} @else {
<div
digRadioGroup
[value]="time()"
aria-labelledby="time-title"
class="flex flex-col gap-5"
(valueChange)="typeof $event === 'string' && time.set($event)"
>
@for (group of groups(); track group.id) {
<div class="flex flex-col gap-3">
<span class="flex items-center gap-2 text-sm font-medium text-muted-foreground [&>svg]:size-4"
><svg [digIcon]="group.icon"></svg> {{ group.label }}</span
>
<div class="grid grid-cols-3 gap-2 sm:grid-cols-5">
@for (slot of group.slots; track slot.time) {
<label
digRadioCard
[value]="slot.time"
layout="tile"
[disabled]="slot.full"
[description]="slot.full ? 'پر' : undefined"
class="tabular-nums"
[title]="slot.time"
></label>
}
</div>
</div>
}
</div>
}
</section>
</main>
<!-- خلاصه و ادامه در دسترسِ شست؛ در دسکتاپ هم پایینِ ستون میچسبد. -->
<dig-bottom-action-bar
hideFrom="none"
class="sm:px-6"
[value]="time() ? \`\${nameOf(day())} \${dateText(day())}، ساعت \${time()}\` : 'ساعت را انتخاب کن'"
[label]="'ویزیت ' + formatCurrency(850_000)"
><button digButton type="button" class="min-w-32" (click)="onContinue()">ادامه</button></dig-bottom-action-bar
>
</div>
`,
})
export class DoctorSlotsBlock {
readonly formatCurrency = formatCurrency
readonly doctorPhoto = doctorPhoto
readonly dateOf = (day: Day) => {
const date = new Date()
date.setHours(0, 0, 0, 0)
date.setDate(date.getDate() + day.offset)
return date
}
readonly nameOf = (day: Day) =>
day.offset === 0
? "امروز"
: day.offset === 1
? "فردا"
: new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long" }).format(this.dateOf(day))
readonly dateText = (day: Day) =>
new Intl.DateTimeFormat("fa-IR-u-ca-persian", { day: "numeric", month: "long" }).format(this.dateOf(day))
readonly free = (day: Day) => [...day.morning, ...day.evening].filter((slot) => !slot.full).length
readonly dayId = signal("d0")
readonly time = signal("")
readonly day = computed(() => DAYS.find((item) => item.id === this.dayId()) ?? DAYS[0])
readonly nextOpen = computed(() =>
DAYS.find((item) => DAYS.indexOf(item) > DAYS.indexOf(this.day()) && this.free(item) > 0)
)
readonly groups = computed(() =>
[
{ id: "morning", label: "صبح", icon: "sun" as const, slots: this.day().morning },
{ id: "evening", label: "عصر", icon: "moon" as const, slots: this.day().evening },
].filter((group) => group.slots.length > 0)
)
readonly stripDays = DAYS.map((item) => {
const count = this.free(item)
const closed = item.morning.length + item.evening.length === 0
return {
date: this.dateOf(item),
label: this.nameOf(item),
meta: closed ? "تعطیل" : count ? `${toFaDigits(count)} خالی` : "پر",
tone: (closed || !count ? "muted" : "success") as "muted" | "success",
description: `${this.nameOf(item)} ${this.dateText(item)}، ${closed ? "تعطیل" : count ? `${toFaDigits(count)} نوبتِ خالی` : "پر"}`,
}
})
onDate(date: Date | undefined) {
if (!date) return
const next = DAYS.find((item) => this.dateOf(item).toDateString() === date.toDateString())
if (!next) return
this.dayId.set(next.id)
this.time.set("")
}
onContinue() {
if (!this.time()) {
toast("اول یکی از ساعتهای خالی را انتخاب کن.")
document.getElementById("time-title")?.scrollIntoView({ behavior: "smooth", block: "center" })
return
}
toast.success(`نوبتِ ${this.nameOf(this.day())} ساعت ${this.time()} نگه داشته شد؛ ۱۰ دقیقه برای تکمیل وقت داری.`)
}
readonly nextOpenSummary = computed(() => {
const day = this.nextOpen()
return day
? `نزدیکترین روزِ خالی ${this.nameOf(day)}، ${this.dateText(day)} است.`
: "این هفته نوبتِ خالی نمانده؛ میتوانی مشاورهٔ تلفنی بگیری."
})
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.