تماس با ما
پیشنمایش تمامصفحهمعرفی، راههای ارتباطی با آیکون و نقشه، فرمِ کارتی با موضوعِ چیپی، نام و ایمیل با آیکون، اندازهٔ کسبوکار، موافقت با حریم خصوصی و پیامِ موفقیت.
۱. نصب کامپوننتها
این بلاک از ۱۲ آیتم دیگ استفاده میکند: badgebuttoncheckboxchoice-chipscontrol-sizeiconslabelmap-viewpersianselecttext-fieldtextarea
npx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/map-view.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/textarea.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/map-view.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/textarea.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/map-view.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/textarea.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/map-view.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/textarea.jsonnpx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework vuepnpm dlx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework vueyarn dlx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework vuebunx --bun digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework vuenpx 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 sveltenpx digdesign@latest add badge button checkbox choice-chips control-size icons input label map-view persian select text-field textarea --framework angularpnpm dlx digdesign@latest add badge button checkbox choice-chips control-size icons input label map-view persian select text-field textarea --framework angularyarn dlx digdesign@latest add badge button checkbox choice-chips control-size icons input label map-view persian select text-field textarea --framework angularbunx --bun digdesign@latest add badge button checkbox choice-chips control-size icons input label map-view persian select text-field textarea --framework angularnpx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework androidpnpm dlx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework androidyarn dlx digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework androidbunx --bun digdesign@latest add badge button checkbox choice-chips control-size label map-view persian select text-field textarea --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { CheckIcon, ClockIcon, EnvelopeIcon, GlobeIcon, PhoneIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ChoiceChip, ChoiceChips } from "@/components/ui/choice-chips"
import { Checkbox } from "@/components/ui/checkbox"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Label } from "@/components/ui/label"
import { MapMarker, MapView } from "@/components/ui/map-view"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { TextField } from "@/components/ui/text-field"
import { Textarea } from "@/components/ui/textarea"
import { isValidEmail, isValidMobile, toFaDigits } from "@/lib/persian"
/** مرکزِ نقشه (حوالیِ میدانِ ونک، تهران) و تبدیلِ جای نمونهها به مختصات؛ در محصول lat و lng را از داده بگیرید. */
const MAP_CENTER = { lat: 35.7575, lng: 51.4135 }
const at = (x: number, y: number) => ({ lat: MAP_CENTER.lat + (50 - y) * 0.00012, lng: MAP_CENTER.lng + (x - 50) * 0.00024 })
const CHANNELS = [
{ icon: <PhoneIcon />, title: "تلفن", value: toFaDigits("021-91001234"), href: "tel:02191001234", dir: "ltr" as const },
{ icon: <EnvelopeIcon />, title: "ایمیل", value: "hello@hesabyar.example", href: "mailto:hello@hesabyar.example", dir: "ltr" as const },
{ icon: <GlobeIcon />, title: "دفتر", value: "تهران، خیابان ولیعصر، بالاتر از پارک ساعی، پلاک ۱۲", dir: "rtl" as const },
{ icon: <ClockIcon />, title: "ساعات پاسخگویی", value: "شنبه تا چهارشنبه، ۹ تا ۱۸", dir: "rtl" as const },
]
const TOPICS = ["پشتیبانی فنی", "فروش و پلنها", "همکاری", "رسانه", "سایر"]
/**
* صفحهٔ تماس: معرفی و راههای ارتباطی با نقشه در یک ستون، فرمِ کامل در کارتِ
* کنارش. موضوع با چیپهای تکانتخابی، نام و ایمیل با آیکون، موافقت با قوانین
* پیش از ارسال، و پیامِ موفقیت در همان جای فرم.
*/
export default function ContactBlock() {
const [topic, setTopic] = React.useState(TOPICS[0])
const [agreed, setAgreed] = React.useState(false)
const [sending, setSending] = React.useState(false)
const [sent, setSent] = React.useState(false)
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
const form = event.currentTarget
setSending(true)
await new Promise((resolve) => setTimeout(resolve, 800))
setSending(false)
form.reset()
setAgreed(false)
setSent(true)
}
return (
<ControlSizeProvider size="xl" asChild>
<main className="mx-auto grid w-full grid-cols-1 max-w-6xl gap-12 px-4 py-16 sm:px-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] lg:gap-16">
{/* ستونِ معرفی: تیتر، راههای ارتباطی و نقشه. */}
<section aria-labelledby="contact-title" className="flex flex-col gap-10">
<div className="flex flex-col gap-4">
<Badge variant="soft" className="self-start">
تماس با ما
</Badge>
<h1 id="contact-title" className="text-3xl leading-snug font-bold sm:text-4xl sm:leading-snug">
بیایید گفتوگو کنیم
</h1>
<p className="leading-7 text-muted-foreground sm:text-lg sm:leading-8">سؤال، پیشنهاد یا همکاری؛ فرم را پر کنید و تا یک روزِ کاری جواب میدهیم.</p>
</div>
<ul className="grid grid-cols-1 gap-5 sm:grid-cols-2">
{CHANNELS.map((channel) => (
<li key={channel.title} className="flex items-start gap-3">
<span aria-hidden className="flex size-11 shrink-0 items-center justify-center rounded-xl bg-muted text-foreground [&>svg]:size-5">
{channel.icon}
</span>
<span className="flex min-w-0 flex-col gap-0.5">
<span className="text-sm text-muted-foreground">{channel.title}</span>
{channel.href ? (
<a href={channel.href} className="font-semibold underline-offset-4 hover:underline">
<bdi dir={channel.dir}>{channel.value}</bdi>
</a>
) : (
<span className="text-sm leading-6 font-medium">{channel.value}</span>
)}
</span>
</li>
))}
</ul>
<figure className="overflow-hidden rounded-xl border border-border">
{/* نقشهٔ دیگ با نشانگرِ هماندازهٔ بقیهٔ بلاکها؛ در محصول src کاشیِ نقشهٔ واقعی میشود. نشانگرِ تکی
تزئینی است و برچسبِ نقشه موقعیت را میگوید. */}
<MapView center={MAP_CENTER} zoom={15} label="موقعیت دفتر روی نقشه، خیابان ولیعصر" className="aspect-[16/10] rounded-none border-0">
<MapMarker {...at(50, 55)} label="دفتر" tabIndex={-1} aria-hidden />
</MapView>
<figcaption className="flex items-center justify-between gap-3 bg-card px-5 py-4 text-sm">
<span className="text-muted-foreground">خیابان ولیعصر، پلاک ۱۲</span>
<a href="#" className="font-semibold text-brand-secondary underline-offset-4 hover:underline">
مسیریابی
</a>
</figcaption>
</figure>
</section>
{/* فرم در کارت؛ نتیجه همانجا که کاربر نگاه میکند. */}
<section aria-label="فرم تماس" className="rounded-xl border border-border bg-card p-6 shadow-card sm:p-10">
{sent ? (
<div className="flex h-full flex-col items-center justify-center gap-4 py-16 text-center" role="status">
<span aria-hidden className="flex size-14 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-7">
<CheckIcon />
</span>
<h2 className="text-xl font-bold">پیامتان رسید</h2>
<p className="max-w-sm text-sm leading-7 text-muted-foreground">تا یک روزِ کاری از همان راهی که گذاشتید جواب میدهیم. ممنون که وقت گذاشتید.</p>
<Button variant="outline" className="mt-4" onClick={() => setSent(false)}>
ارسالِ پیامی دیگر
</Button>
</div>
) : (
<form onSubmit={onSubmit} className="flex flex-col gap-8">
<div className="flex flex-col gap-2">
<h2 className="text-2xl font-bold">پیام بفرستید</h2>
<p className="text-sm text-muted-foreground">فیلدهای ستارهدار لازماند.</p>
</div>
<ControlSizeProvider size="xl" className="flex flex-col gap-5">
<div className="flex flex-col gap-2">
<span id="contact-topic" className="text-sm font-medium">
موضوع
</span>
{/* پنج موضوع در عرضِ فرم جا نمیشد و آخری در لبه بریده میشد؛ چیپها به خطِ بعد میروند. */}
<ChoiceChips type="single" value={topic} onValueChange={(value) => value && setTopic(value)} aria-labelledby="contact-topic">
{TOPICS.map((item) => (
<ChoiceChip key={item} value={item}>
{item}
</ChoiceChip>
))}
</ChoiceChips>
</div>
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2">
<TextField label="نام" name="firstName" autoComplete="given-name" required />
<TextField label="نام خانوادگی" name="lastName" autoComplete="family-name" required />
</div>
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2">
<TextField
label="ایمیل"
name="email"
type="email"
dir="ltr"
autoComplete="email"
required
validate={(value) => (isValidEmail(value) ? undefined : "یک ایمیلِ درست وارد کنید.")}
/>
<TextField
label="موبایل"
name="mobile"
type="tel"
dir="ltr"
autoComplete="tel"
optional
validate={(value) => (!value || isValidMobile(value) ? undefined : "شمارهٔ موبایل درست نیست.")}
/>
</div>
<div className="flex flex-col gap-2">
<Label id="contact-size-label">اندازهٔ کسبوکار</Label>
<Select name="size" defaultValue="small">
<SelectTrigger aria-labelledby="contact-size-label" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="solo">تکنفره</SelectItem>
<SelectItem value="small">۲ تا ۱۰ نفر</SelectItem>
<SelectItem value="medium">۱۱ تا ۵۰ نفر</SelectItem>
<SelectItem value="large">بیش از ۵۰ نفر</SelectItem>
</SelectContent>
</Select>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="contact-message">پیام</Label>
<Textarea id="contact-message" name="message" rows={5} required placeholder="دربارهٔ نیاز، زمانبندی یا سؤالتان بنویسید…" />
</div>
</ControlSizeProvider>
<div className="flex items-start gap-2">
<Checkbox id="contact-agree" name="agree" checked={agreed} onCheckedChange={(checked) => setAgreed(checked === true)} />
<Label htmlFor="contact-agree" className="text-sm leading-6 font-normal text-muted-foreground">
با{" "}
<a href="#" className="font-medium text-foreground underline underline-offset-4">
حریم خصوصی
</a>{" "}
موافقم.
</Label>
</div>
<ControlSizeProvider size="xl">
<Button type="submit" loading={sending} disabled={!agreed} fullWidth>
ارسالِ پیام
</Button>
</ControlSizeProvider>
</form>
)}
</section>
</main>
</ControlSizeProvider>
)
}
<script setup lang="ts">
import { ref } from "vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import Checkbox from "@/components/ui/Checkbox.vue"
import ChoiceChip from "@/components/ui/ChoiceChip.vue"
import ChoiceChips from "@/components/ui/ChoiceChips.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Label from "@/components/ui/Label.vue"
import MapMarker from "@/components/ui/MapMarker.vue"
import MapView from "@/components/ui/MapView.vue"
import Select from "@/components/ui/Select.vue"
import SelectContent from "@/components/ui/SelectContent.vue"
import SelectItem from "@/components/ui/SelectItem.vue"
import SelectTrigger from "@/components/ui/SelectTrigger.vue"
import SelectValue from "@/components/ui/SelectValue.vue"
import TextField from "@/components/ui/TextField.vue"
import Textarea from "@/components/ui/Textarea.vue"
import { DigIcon } from "@/lib/icons"
import { isValidEmail, isValidMobile, toFaDigits } from "@/lib/persian"
/** مرکزِ نقشه (حوالیِ میدانِ ونک، تهران) و تبدیلِ جای نمونهها به مختصات؛ در محصول lat و lng را از داده بگیرید. */
const MAP_CENTER = { lat: 35.7575, lng: 51.4135 }
const at = (x: number, y: number) => ({ lat: MAP_CENTER.lat + (50 - y) * 0.00012, lng: MAP_CENTER.lng + (x - 50) * 0.00024 })
const CHANNELS: { icon: string; title: string; value: string; href?: string; dir: "ltr" | "rtl" }[] = [
{ icon: "phone", title: "تلفن", value: toFaDigits("021-91001234"), href: "tel:02191001234", dir: "ltr" },
{ icon: "envelope", title: "ایمیل", value: "hello@hesabyar.example", href: "mailto:hello@hesabyar.example", dir: "ltr" },
{ icon: "globe", title: "دفتر", value: "تهران، خیابان ولیعصر، بالاتر از پارک ساعی، پلاک ۱۲", dir: "rtl" },
{ icon: "clock", title: "ساعات پاسخگویی", value: "شنبه تا چهارشنبه، ۹ تا ۱۸", dir: "rtl" },
]
const TOPICS = ["پشتیبانی فنی", "فروش و پلنها", "همکاری", "رسانه", "سایر"]
/**
* صفحهٔ تماس: معرفی و راههای ارتباطی با نقشه در یک ستون، فرمِ کامل در کارتِ
* کنارش. موضوع با چیپهای تکانتخابی، نام و ایمیل با آیکون، موافقت با قوانین
* پیش از ارسال، و پیامِ موفقیت در همان جای فرم.
*/
const topic = ref(TOPICS[0])
const agreed = ref(false)
const sending = ref(false)
const sent = ref(false)
async function onSubmit(event: Event) {
const form = event.currentTarget as HTMLFormElement
sending.value = true
await new Promise((resolve) => setTimeout(resolve, 800))
sending.value = false
form.reset()
agreed.value = false
sent.value = true
}
</script>
<template>
<ControlSize size="xl" as-child>
<main class="mx-auto grid w-full grid-cols-1 max-w-6xl gap-12 px-4 py-16 sm:px-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] lg:gap-16">
<!-- ستونِ معرفی: تیتر، راههای ارتباطی و نقشه. -->
<section aria-labelledby="contact-title" class="flex flex-col gap-10">
<div class="flex flex-col gap-4">
<Badge variant="soft" class="self-start">تماس با ما</Badge>
<h1 id="contact-title" class="text-3xl leading-snug font-bold sm:text-4xl sm:leading-snug">بیایید گفتوگو کنیم</h1>
<p class="leading-7 text-muted-foreground sm:text-lg sm:leading-8">سؤال، پیشنهاد یا همکاری؛ فرم را پر کنید و تا یک روزِ کاری جواب میدهیم.</p>
</div>
<ul class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<li v-for="channel in CHANNELS" :key="channel.title" class="flex items-start gap-3">
<span aria-hidden="true" class="flex size-11 shrink-0 items-center justify-center rounded-xl bg-muted text-foreground [&>svg]:size-5">
<DigIcon :name="channel.icon" />
</span>
<span class="flex min-w-0 flex-col gap-0.5">
<span class="text-sm text-muted-foreground">{{ channel.title }}</span>
<a v-if="channel.href" :href="channel.href" class="font-semibold underline-offset-4 hover:underline">
<bdi :dir="channel.dir">{{ channel.value }}</bdi>
</a>
<span v-else class="text-sm leading-6 font-medium">{{ channel.value }}</span>
</span>
</li>
</ul>
<figure class="overflow-hidden rounded-xl border border-border">
<!-- نقشهٔ دیگ با نشانگرِ هماندازهٔ بقیهٔ بلاکها؛ در محصول src کاشیِ نقشهٔ واقعی میشود. نشانگرِ تکی
تزئینی است و برچسبِ نقشه موقعیت را میگوید. -->
<MapView :center="MAP_CENTER" :zoom="15" label="موقعیت دفتر روی نقشه، خیابان ولیعصر" class="aspect-[16/10] rounded-none border-0">
<MapMarker v-bind="at(50, 55)" label="دفتر" :tabindex="-1" aria-hidden="true" />
</MapView>
<figcaption class="flex items-center justify-between gap-3 bg-card px-5 py-4 text-sm">
<span class="text-muted-foreground">خیابان ولیعصر، پلاک ۱۲</span>
<a href="#" class="font-semibold text-brand-secondary underline-offset-4 hover:underline">مسیریابی</a>
</figcaption>
</figure>
</section>
<!-- فرم در کارت؛ نتیجه همانجا که کاربر نگاه میکند. -->
<section aria-label="فرم تماس" class="rounded-xl border border-border bg-card p-6 shadow-card sm:p-10">
<div v-if="sent" class="flex h-full flex-col items-center justify-center gap-4 py-16 text-center" role="status">
<span aria-hidden="true" class="flex size-14 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-7">
<DigIcon name="check" />
</span>
<h2 class="text-xl font-bold">پیامتان رسید</h2>
<p class="max-w-sm text-sm leading-7 text-muted-foreground">تا یک روزِ کاری از همان راهی که گذاشتید جواب میدهیم. ممنون که وقت گذاشتید.</p>
<Button variant="outline" class="mt-4" @click="sent = false">ارسالِ پیامی دیگر</Button>
</div>
<form v-else class="flex flex-col gap-8" @submit.prevent="onSubmit">
<div class="flex flex-col gap-2">
<h2 class="text-2xl font-bold">پیام بفرستید</h2>
<p class="text-sm text-muted-foreground">فیلدهای ستارهدار لازماند.</p>
</div>
<ControlSize size="xl" class="flex flex-col gap-5">
<div class="flex flex-col gap-2">
<span id="contact-topic" class="text-sm font-medium">موضوع</span>
<!-- پنج موضوع در عرضِ فرم جا نمیشد و آخری در لبه بریده میشد؛ چیپها به خطِ بعد میروند. -->
<ChoiceChips type="single" :value="topic" aria-labelledby="contact-topic" @update:value="(value) => value && (topic = value as string)">
<ChoiceChip v-for="item in TOPICS" :key="item" :value="item">{{ item }}</ChoiceChip>
</ChoiceChips>
</div>
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<TextField label="نام" name="firstName" autocomplete="given-name" required />
<TextField label="نام خانوادگی" name="lastName" autocomplete="family-name" required />
</div>
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<TextField label="ایمیل" name="email" type="email" dir="ltr" autocomplete="email" required :validate="(value) => (isValidEmail(value) ? undefined : 'یک ایمیلِ درست وارد کنید.')" />
<TextField label="موبایل" name="mobile" type="tel" dir="ltr" autocomplete="tel" optional :validate="(value) => (!value || isValidMobile(value) ? undefined : 'شمارهٔ موبایل درست نیست.')" />
</div>
<div class="flex flex-col gap-2">
<Label id="contact-size-label">اندازهٔ کسبوکار</Label>
<Select name="size" default-value="small">
<SelectTrigger aria-labelledby="contact-size-label" class="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="solo">تکنفره</SelectItem>
<SelectItem value="small">۲ تا ۱۰ نفر</SelectItem>
<SelectItem value="medium">۱۱ تا ۵۰ نفر</SelectItem>
<SelectItem value="large">بیش از ۵۰ نفر</SelectItem>
</SelectContent>
</Select>
</div>
<div class="flex flex-col gap-2">
<Label for="contact-message">پیام</Label>
<Textarea id="contact-message" name="message" :rows="5" required placeholder="دربارهٔ نیاز، زمانبندی یا سؤالتان بنویسید…" />
</div>
</ControlSize>
<div class="flex items-start gap-2">
<Checkbox id="contact-agree" name="agree" :checked="agreed" @update:checked="(checked) => (agreed = checked === true)" />
<Label for="contact-agree" class="text-sm leading-6 font-normal text-muted-foreground">
با
<a href="#" class="font-medium text-foreground underline underline-offset-4">حریم خصوصی</a>
موافقم.
</Label>
</div>
<ControlSize size="xl">
<Button type="submit" :loading="sending" :disabled="!agreed" full-width>ارسالِ پیام</Button>
</ControlSize>
</form>
</section>
</main>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: badgecheckboxchoice-chipscontrol-sizelabelmap-viewpersianselecttext-fieldtextareaآیکون checkآیکون clockآیکون envelopeآیکون globeآیکون phone
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
inject,
signal,
} from "@angular/core"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { isValidEmail, isValidMobile, toFaDigits } from "@/lib/persian"
import { DigBadge } from "@/components/ui/badge"
import { DigButton } from "@/components/ui/button"
import { DigCheckbox } from "@/components/ui/checkbox"
import { DigChoiceChip, DigChoiceChips } from "@/components/ui/choice-chips"
import { DigControlSize } from "@/components/ui/control-size"
import { DigInput, DigInputField } from "@/components/ui/input"
import { DigLabel } from "@/components/ui/label"
import { DigMapMarker, DigMapView } from "@/components/ui/map-view"
import {
DigSelect,
DigSelectContent,
DigSelectItem,
DigSelectTrigger,
DigSelectValue,
} from "@/components/ui/select"
import { DigTextField } from "@/components/ui/text-field"
import { DigTextarea } from "@/components/ui/textarea"
const MAP_CENTER = { lat: 35.7575, lng: 51.4135 }
const OFFICE = {
lat: MAP_CENTER.lat + (50 - 55) * 0.00012,
lng: MAP_CENTER.lng,
}
const CHANNELS: {
icon: DigIconName
title: string
value: string
href?: string
dir: "ltr" | "rtl"
}[] = [
{
icon: "phone",
title: "تلفن",
value: toFaDigits("021-91001234"),
href: "tel:02191001234",
dir: "ltr",
},
{
icon: "envelope",
title: "ایمیل",
value: "hello@hesabyar.example",
href: "mailto:hello@hesabyar.example",
dir: "ltr",
},
{
icon: "globe",
title: "دفتر",
value: "تهران، خیابان ولیعصر، بالاتر از پارک ساعی، پلاک ۱۲",
dir: "rtl",
},
{
icon: "clock",
title: "ساعات پاسخگویی",
value: "شنبه تا چهارشنبه، ۹ تا ۱۸",
dir: "rtl",
},
]
const TOPICS = ["پشتیبانی فنی", "فروش و پلنها", "همکاری", "رسانه", "سایر"]
@Component({
selector: "dig-block-contact",
imports: [
DigBadge,
DigButton,
DigCheckbox,
DigChoiceChip,
DigChoiceChips,
DigControlSize,
DigIcon,
DigInput,
DigInputField,
DigLabel,
DigMapMarker,
DigMapView,
DigSelect,
DigSelectContent,
DigSelectItem,
DigSelectTrigger,
DigSelectValue,
DigTextField,
DigTextarea,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<main
digControlSize="xl"
class="mx-auto grid w-full grid-cols-1 max-w-6xl gap-12 px-4 py-16 sm:px-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.15fr)] lg:gap-16"
>
<!-- ستونِ معرفی: تیتر، راههای ارتباطی و نقشه. -->
<section aria-labelledby="contact-title" class="flex flex-col gap-10">
<div class="flex flex-col gap-4">
<span digBadge variant="soft" class="self-start">تماس با ما</span>
<h1
id="contact-title"
class="text-3xl leading-snug font-bold sm:text-4xl sm:leading-snug"
>
بیایید گفتوگو کنیم
</h1>
<p class="leading-7 text-muted-foreground sm:text-lg sm:leading-8">
سؤال، پیشنهاد یا همکاری؛ فرم را پر کنید و تا یک روزِ کاری جواب
میدهیم.
</p>
</div>
<ul class="grid grid-cols-1 gap-5 sm:grid-cols-2">
@for (channel of CHANNELS; track channel.title) {
<li class="flex items-start gap-3">
<span
aria-hidden="true"
class="flex size-11 shrink-0 items-center justify-center rounded-xl bg-muted text-foreground [&>svg]:size-5"
>
<svg [digIcon]="channel.icon"></svg>
</span>
<span class="flex min-w-0 flex-col gap-0.5">
<span class="text-sm text-muted-foreground">{{
channel.title
}}</span>
@if (channel.href) {
<a
[href]="channel.href"
class="font-semibold underline-offset-4 hover:underline"
>
<bdi [dir]="channel.dir">{{ channel.value }}</bdi>
</a>
} @else {
<span class="text-sm leading-6 font-medium">{{
channel.value
}}</span>
}
</span>
</li>
}
</ul>
<figure class="overflow-hidden rounded-xl border border-border">
<!-- نقشهٔ دیگ با نشانگرِ هماندازهٔ بقیهٔ بلاکها؛ در محصول src کاشیِ نقشهٔ واقعی میشود. نشانگرِ تکی
تزئینی است و برچسبِ نقشه موقعیت را میگوید. -->
<div
digMapView
[center]="MAP_CENTER"
[zoom]="15"
label="موقعیت دفتر روی نقشه، خیابان ولیعصر"
class="aspect-[16/10] rounded-none border-0"
>
<button
digMapMarker
type="button"
[lat]="OFFICE.lat"
[lng]="OFFICE.lng"
label="دفتر"
[tabindex]="-1"
aria-hidden="true"
></button>
</div>
<figcaption
class="flex items-center justify-between gap-3 bg-card px-5 py-4 text-sm"
>
<span class="text-muted-foreground">خیابان ولیعصر، پلاک ۱۲</span>
<a
href="#"
class="font-semibold text-brand-secondary underline-offset-4 hover:underline"
>مسیریابی</a
>
</figcaption>
</figure>
</section>
<!-- فرم در کارت؛ نتیجه همانجا که کاربر نگاه میکند. -->
<section
aria-label="فرم تماس"
class="rounded-xl border border-border bg-card p-6 shadow-card sm:p-10"
>
@if (sent()) {
<div
class="flex h-full flex-col items-center justify-center gap-4 py-16 text-center"
role="status"
>
<span
aria-hidden="true"
class="flex size-14 items-center justify-center rounded-xl bg-success-subtle text-success-subtle-foreground [&_svg]:size-7"
>
<svg digIcon="check"></svg>
</span>
<h2 class="text-xl font-bold">پیامتان رسید</h2>
<p class="max-w-sm text-sm leading-7 text-muted-foreground">
تا یک روزِ کاری از همان راهی که گذاشتید جواب میدهیم. ممنون که وقت
گذاشتید.
</p>
<button
digButton
type="button"
variant="outline"
class="mt-4"
(click)="sent.set(false)"
>
ارسالِ پیامی دیگر
</button>
</div>
} @else {
<form
class="flex flex-col gap-8"
(submit)="$event.preventDefault(); submit($event)"
>
<div class="flex flex-col gap-2">
<h2 class="text-2xl font-bold">پیام بفرستید</h2>
<p class="text-sm text-muted-foreground">
فیلدهای ستارهدار لازماند.
</p>
</div>
<div digControlSize="xl" class="flex flex-col gap-5">
<div class="flex flex-col gap-2">
<span id="contact-topic" class="text-sm font-medium"
>موضوع</span
>
<!-- پنج موضوع در عرضِ فرم جا نمیشد و آخری در لبه بریده میشد؛ چیپها به خطِ بعد میروند. -->
<div
digChoiceChips
type="single"
[value]="topic()"
aria-labelledby="contact-topic"
(valueChange)="onTopic($event)"
>
@for (item of TOPICS; track item) {
<button digChoiceChip type="button" [value]="item">
{{ item }}
</button>
}
</div>
</div>
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<div digTextField label="نام" required>
<dig-input
><input digInput name="firstName" autocomplete="given-name"
/></dig-input>
</div>
<div digTextField label="نام خانوادگی" required>
<dig-input
><input digInput name="lastName" autocomplete="family-name"
/></dig-input>
</div>
</div>
<div class="grid grid-cols-1 gap-5 sm:grid-cols-2">
<div
digTextField
label="ایمیل"
required
[validate]="validateEmail"
[invalid]="!!emailError()"
[errorMessage]="emailError()"
>
<dig-input
><input
digInput
name="email"
type="email"
dir="ltr"
autocomplete="email"
/></dig-input>
</div>
<div
digTextField
label="موبایل"
optional
[validate]="validateMobile"
[invalid]="!!mobileError()"
[errorMessage]="mobileError()"
>
<dig-input
><input
digInput
name="mobile"
type="tel"
dir="ltr"
autocomplete="tel"
/></dig-input>
</div>
</div>
<div class="flex flex-col gap-2">
<label digLabel id="contact-size-label">اندازهٔ کسبوکار</label>
<ng-container digSelect name="size" value="small">
<button
digSelectTrigger
type="button"
aria-labelledby="contact-size-label"
class="w-full"
>
<span digSelectValue></span>
</button>
<div digSelectContent>
<div digSelectItem value="solo">تکنفره</div>
<div digSelectItem value="small">۲ تا ۱۰ نفر</div>
<div digSelectItem value="medium">۱۱ تا ۵۰ نفر</div>
<div digSelectItem value="large">بیش از ۵۰ نفر</div>
</div>
</ng-container>
</div>
<div class="flex flex-col gap-2">
<label digLabel for="contact-message">پیام</label>
<textarea
digTextarea
id="contact-message"
name="message"
[rows]="5"
required
placeholder="دربارهٔ نیاز، زمانبندی یا سؤالتان بنویسید…"
></textarea>
</div>
</div>
<div class="flex items-start gap-2">
<button
digCheckbox
type="button"
id="contact-agree"
name="agree"
[checked]="agreed()"
(checkedChange)="agreed.set($event === true)"
></button>
<label
digLabel
for="contact-agree"
class="text-sm leading-6 font-normal text-muted-foreground"
>
با
<a
href="#"
class="font-medium text-foreground underline underline-offset-4"
>حریم خصوصی</a
>
موافقم.
</label>
</div>
<div digControlSize="xl">
<button
digButton
type="submit"
[loading]="sending()"
[disabled]="!agreed()"
fullWidth
>
ارسالِ پیام
</button>
</div>
</form>
}
</section>
</main>
`,
})
export class ContactBlock {
readonly MAP_CENTER = MAP_CENTER
readonly OFFICE = OFFICE
readonly CHANNELS = CHANNELS
readonly TOPICS = TOPICS
readonly topic = signal(TOPICS[0])
readonly agreed = signal(false)
readonly sending = signal(false)
readonly sent = signal(false)
readonly emailError = signal<string | undefined>(undefined)
readonly mobileError = signal<string | undefined>(undefined)
private sendTimer?: ReturnType<typeof setTimeout>
constructor() {
inject(DestroyRef).onDestroy(() => clearTimeout(this.sendTimer))
}
onTopic(value: string | string[] | undefined) {
if (typeof value === "string" && value) this.topic.set(value)
}
readonly validateEmail = (value: string) =>
isValidEmail(value) ? undefined : "یک ایمیلِ درست وارد کنید."
readonly validateMobile = (value: string) =>
!value || isValidMobile(value) ? undefined : "شمارهٔ موبایل درست نیست."
submit(event: Event) {
const form = event.currentTarget as HTMLFormElement
if (!this.agreed() || this.sending() || !form.reportValidity()) return
const data = new FormData(form)
const emailError = this.validateEmail(String(data.get("email") ?? ""))
const mobileError = this.validateMobile(String(data.get("mobile") ?? ""))
this.emailError.set(emailError)
this.mobileError.set(mobileError)
if (emailError || mobileError) return
this.sending.set(true)
this.sendTimer = setTimeout(() => {
this.sending.set(false)
this.agreed.set(false)
this.sent.set(true)
}, 800)
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.