نتایجِ جستوجو
پیشنمایش تمامصفحهصفحهٔ نتایج: جستوجو با تعدادِ نتیجه، زبانههای نوع با شمار، نتایجِ ترکیبی (کالا، مقاله، راهنما) با برجستهشدنِ واژه، جستوجوهای مرتبط و حالتِ بینتیجه.
۱. نصب کامپوننتها
این بلاک از ۷ آیتم دیگ استفاده میکند: buttoncontrol-sizeempty-stateiconspersiansearch-fieldtoggle-group
npx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.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/search-field.json https://docs.digdesign.ir/r/toggle-group.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.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/search-field.json https://docs.digdesign.ir/r/toggle-group.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.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/search-field.json https://docs.digdesign.ir/r/toggle-group.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.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/search-field.json https://docs.digdesign.ir/r/toggle-group.jsonnpx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework vuepnpm dlx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework vueyarn dlx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework vuebunx --bun digdesign@latest add button control-size empty-state persian search-field toggle-group --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 button control-size empty-state icons persian search-field toggle-group --framework angularpnpm dlx digdesign@latest add button control-size empty-state icons persian search-field toggle-group --framework angularyarn dlx digdesign@latest add button control-size empty-state icons persian search-field toggle-group --framework angularbunx --bun digdesign@latest add button control-size empty-state icons persian search-field toggle-group --framework angularnpx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework androidpnpm dlx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework androidyarn dlx digdesign@latest add button control-size empty-state persian search-field toggle-group --framework androidbunx --bun digdesign@latest add button control-size empty-state persian search-field toggle-group --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { ChevronLeftIcon, FileTextIcon, GuideIcon, ShoppingCartIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateTitle } from "@/components/ui/empty-state"
import { SearchField } from "@/components/ui/search-field"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { formatCurrency, toFaDigits, toSearchKey } from "@/lib/persian"
import { stockImages, type StockImageName } from "@/lib/stock-images"
type Result =
| { type: "product"; title: string; text: string; price: number; image: StockImageName }
| { type: "article"; title: string; text: string; minutes: number; image: StockImageName }
| { type: "help"; title: string; text: string; path: string }
const RESULTS: Result[] = [
{ type: "product", title: "گلدانِ سرامیکی دوقلو", text: "دستسازِ لالجین، لعابِ مات، ارتفاعِ ۳۲ سانتیمتر.", price: 1_290_000, image: "productVase" },
{ type: "article", title: "نگهداری گلدانِ سرامیکی در زمستان", text: "سه اشتباهِ رایج که باعثِ ترکخوردنِ گلدان میشود.", minutes: 5, image: "coverMinimalRoom" },
{ type: "help", title: "مرجوعی گلدانِ آسیبدیده", text: "اگر گلدان شکسته رسید، تا ۷ روز با عکس درخواست بده.", path: "راهنما › سفارش و ارسال" },
{ type: "product", title: "گلدانِ سنگی کوچک", text: "مناسبِ گیاهِ آپارتمانی و میزِ کار.", price: 640_000, image: "coverNotebook" },
{ type: "help", title: "بستهبندی کالاهای شکستنی", text: "همهٔ سفالها با بستهبندی ضدضربه ارسال میشوند.", path: "راهنما › ارسال" },
]
const TABS = [
{ value: "all", label: "همه" },
{ value: "product", label: "کالا" },
{ value: "article", label: "مقاله" },
{ value: "help", label: "راهنما" },
] as const
const ICON = { product: <ShoppingCartIcon />, article: <FileTextIcon />, help: <GuideIcon /> }
/** واژهٔ جستوجو را در متن برجسته میکند (با یکسانسازی ی/ک عربی و فارسی). */
function Highlight({ text, query }: { text: string; query: string }) {
const key = toSearchKey(query.trim())
if (!key) return <>{text}</>
// کلیدِ جستوجو فاصله و نیمفاصله را حذف میکند؛ برای هر نویسهٔ کلید جایش در متنِ اصلی را
// نگه میداریم تا هایلایت روی همان حروف بنشیند، نه چند حرف جلوتر.
const positions: number[] = []
let normalized = ""
for (let i = 0; i < text.length; i++) {
const piece = toSearchKey(text[i])
for (const char of piece) {
normalized += char
positions.push(i)
}
}
const index = normalized.indexOf(key)
if (index < 0) return <>{text}</>
const start = positions[index]
const end = positions[index + key.length - 1] + 1
return (
<>
{text.slice(0, start)}
<mark className="rounded-sm bg-[var(--dig-amber-100)] text-foreground dark:bg-[color-mix(in_oklab,var(--dig-amber-400)_28%,var(--card))]">{text.slice(start, end)}</mark>
{text.slice(end)}
</>
)
}
/**
* نتایجِ جستوجو: نوارِ جستوجو با تعدادِ نتیجه، زبانههای نوع با شمار، نتایجِ ترکیبی
* (کالا با قیمت، مقاله با زمانِ خواندن، راهنما با مسیر) با برجستهکردنِ واژه، جستوجوهای
* مرتبط و حالتِ بینتیجه با پیشنهاد.
*/
export default function SearchResultsBlock() {
const [query, setQuery] = React.useState("گلدان")
const [tab, setTab] = React.useState<(typeof TABS)[number]["value"]>("all")
const matches = RESULTS.filter((result) => toSearchKey(result.title + result.text).includes(toSearchKey(query.trim())))
const visible = matches.filter((result) => tab === "all" || result.type === tab)
const count = (value: string) => (value === "all" ? matches.length : matches.filter((result) => result.type === value).length)
return (
<ControlSizeProvider size="xl" asChild>
<main className="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 className="sr-only">نتایجِ جستوجو</h1>
<div className="flex flex-col gap-3">
<SearchField aria-label="جستوجو" value={query} onValueChange={setQuery} placeholder="جستوجوی کالا، مقاله یا راهنما" />
<p className="text-sm text-muted-foreground">
{toFaDigits(matches.length)} نتیجه برای «<span className="font-medium text-foreground">{query}</span>»
</p>
</div>
<ControlSizeProvider size="lg" mobileSize="default" asChild>
<ToggleGroup type="single" variant="segmented" value={tab} onValueChange={(value) => value && setTab(value as typeof tab)} aria-label="نوعِ نتیجه" className="self-start">
{TABS.map((item) => (
<ToggleGroupItem key={item.value} value={item.value} className="gap-2">
{item.label}
<span className="text-xs text-muted-foreground tabular-nums">{toFaDigits(count(item.value))}</span>
</ToggleGroupItem>
))}
</ToggleGroup>
</ControlSizeProvider>
{visible.length === 0 ? (
<EmptyState variant="bordered" className="rounded-xl py-12">
<EmptyStateTitle>نتیجهای پیدا نشد</EmptyStateTitle>
<EmptyStateDescription>کلمهٔ کوتاهتر یا هممعنی امتحان کن؛ مثلاً «سفال» بهجای «سفالینه».</EmptyStateDescription>
<EmptyStateActions>
<Button variant="outline" onClick={() => setQuery("گلدان")}>
جستوجوی «گلدان»
</Button>
</EmptyStateActions>
</EmptyState>
) : (
<ul className="flex flex-col divide-y divide-border">
{visible.map((result) => (
<li key={result.title}>
<a href="#" className="group flex items-start gap-4 py-5 first:pt-0">
{"image" in result ? (
// eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ
<img src={stockImages[result.image].src} alt="" className="size-20 shrink-0 rounded-lg object-cover" />
) : (
<span aria-hidden className="flex size-20 shrink-0 items-center justify-center rounded-lg bg-subtle text-brand-secondary [&>svg]:size-6">
{ICON[result.type]}
</span>
)}
<span className="flex flex-1 flex-col gap-1.5">
<span className="flex items-center gap-2 text-xs text-muted-foreground [&>svg]:size-3.5">
{ICON[result.type]}
{result.type === "product" ? "کالا" : result.type === "article" ? `مقاله · ${toFaDigits(result.minutes)} دقیقه` : result.path}
</span>
<span className="text-lg font-bold group-hover:underline">
<Highlight text={result.title} query={query} />
</span>
<span className="leading-7 text-muted-foreground">
<Highlight text={result.text} query={query} />
</span>
{result.type === "product" && <span className="font-bold tabular-nums">{formatCurrency(result.price)}</span>}
</span>
<ChevronLeftIcon aria-hidden className="mt-2 size-5 shrink-0 text-muted-foreground ltr:rotate-180" />
</a>
</li>
))}
</ul>
)}
<section aria-labelledby="related-searches" className="flex flex-col gap-3 rounded-xl bg-subtle p-5">
<h2 id="related-searches" className="text-sm font-semibold">
جستوجوهای مرتبط
</h2>
<div className="flex flex-wrap gap-2">
{["گلدانِ بزرگ", "سفالِ لالجین", "گلدانِ آویز", "کودِ گیاه"].map((item) => (
<Button key={item} variant="outline" onClick={() => setQuery(item)} className="bg-card">
{item}
</Button>
))}
</div>
</section>
</main>
</ControlSizeProvider>
)
}
<script setup lang="ts">
import { computed, ref } from "vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.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 SearchField from "@/components/ui/SearchField.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits, toSearchKey } from "@/lib/persian"
const IMAGES = "https://docs.digdesign.ir/images"
type Result =
| { type: "product"; title: string; text: string; price: number; image: string }
| { type: "article"; title: string; text: string; minutes: number; image: string }
| { type: "help"; title: string; text: string; path: string }
const RESULTS: Result[] = [
{ type: "product", title: "گلدانِ سرامیکی دوقلو", text: "دستسازِ لالجین، لعابِ مات، ارتفاعِ ۳۲ سانتیمتر.", price: 1_290_000, image: `${IMAGES}/product-vase.webp` },
{ type: "article", title: "نگهداری گلدانِ سرامیکی در زمستان", text: "سه اشتباهِ رایج که باعثِ ترکخوردنِ گلدان میشود.", minutes: 5, image: `${IMAGES}/cover-minimal-room.webp` },
{ type: "help", title: "مرجوعی گلدانِ آسیبدیده", text: "اگر گلدان شکسته رسید، تا ۷ روز با عکس درخواست بده.", path: "راهنما › سفارش و ارسال" },
{ type: "product", title: "گلدانِ سنگی کوچک", text: "مناسبِ گیاهِ آپارتمانی و میزِ کار.", price: 640_000, image: `${IMAGES}/cover-notebook.webp` },
{ type: "help", title: "بستهبندی کالاهای شکستنی", text: "همهٔ سفالها با بستهبندی ضدضربه ارسال میشوند.", path: "راهنما › ارسال" },
]
const TABS = [
{ value: "all", label: "همه" },
{ value: "product", label: "کالا" },
{ value: "article", label: "مقاله" },
{ value: "help", label: "راهنما" },
]
const ICON = { product: "shopping-cart", article: "file-text", help: "guide" }
const RELATED = ["گلدانِ بزرگ", "سفالِ لالجین", "گلدانِ آویز", "کودِ گیاه"]
/** واژهٔ جستوجو را در متن برجسته میکند (با یکسانسازی ی/ک عربی و فارسی). */
function highlight(text: string, rawQuery: string): { text: string; mark: boolean }[] {
const key = toSearchKey(rawQuery.trim())
if (!key) return [{ text, mark: false }]
// کلیدِ جستوجو فاصله و نیمفاصله را حذف میکند؛ برای هر نویسهٔ کلید جایش در متنِ اصلی را
// نگه میداریم تا هایلایت روی همان حروف بنشیند، نه چند حرف جلوتر.
const positions: number[] = []
let normalized = ""
for (let i = 0; i < text.length; i++) {
const piece = toSearchKey(text[i])
for (const char of piece) {
normalized += char
positions.push(i)
}
}
const index = normalized.indexOf(key)
if (index < 0) return [{ text, mark: false }]
const start = positions[index]
const end = positions[index + key.length - 1] + 1
return [
{ text: text.slice(0, start), mark: false },
{ text: text.slice(start, end), mark: true },
{ text: text.slice(end), mark: false },
]
}
/**
* نتایجِ جستوجو: نوارِ جستوجو با تعدادِ نتیجه، زبانههای نوع با شمار، نتایجِ ترکیبی
* (کالا با قیمت، مقاله با زمانِ خواندن، راهنما با مسیر) با برجستهکردنِ واژه، جستوجوهای
* مرتبط و حالتِ بینتیجه با پیشنهاد.
*/
const query = ref("گلدان")
const tab = ref("all")
const matches = computed(() => RESULTS.filter((result) => toSearchKey(result.title + result.text).includes(toSearchKey(query.value.trim()))))
const visible = computed(() => matches.value.filter((result) => tab.value === "all" || result.type === tab.value))
const count = (value: string) => (value === "all" ? matches.value.length : matches.value.filter((result) => result.type === value).length)
function onTab(value: string | string[] | undefined) {
if (value) tab.value = value as string
}
</script>
<template>
<ControlSize size="xl" as-child>
<main class="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 class="sr-only">نتایجِ جستوجو</h1>
<div class="flex flex-col gap-3">
<SearchField v-model="query" aria-label="جستوجو" placeholder="جستوجوی کالا، مقاله یا راهنما" />
<p class="text-sm text-muted-foreground">
{{ toFaDigits(matches.length) }} نتیجه برای «<span class="font-medium text-foreground">{{ query }}</span>»
</p>
</div>
<ControlSize size="lg" mobile-size="default" as-child>
<ToggleGroup type="single" variant="segmented" :value="tab" aria-label="نوعِ نتیجه" class="self-start" @update:value="onTab">
<ToggleGroupItem v-for="item in TABS" :key="item.value" :value="item.value" class="gap-2">
{{ item.label }}
<span class="text-xs text-muted-foreground tabular-nums">{{ toFaDigits(count(item.value)) }}</span>
</ToggleGroupItem>
</ToggleGroup>
</ControlSize>
<EmptyState v-if="visible.length === 0" variant="bordered" class="rounded-xl py-12">
<EmptyStateTitle>نتیجهای پیدا نشد</EmptyStateTitle>
<EmptyStateDescription>کلمهٔ کوتاهتر یا هممعنی امتحان کن؛ مثلاً «سفال» بهجای «سفالینه».</EmptyStateDescription>
<EmptyStateActions>
<Button variant="outline" @click="query = 'گلدان'">جستوجوی «گلدان»</Button>
</EmptyStateActions>
</EmptyState>
<ul v-else class="flex flex-col divide-y divide-border">
<li v-for="result in visible" :key="result.title">
<a href="#" class="group flex items-start gap-4 py-5 first:pt-0">
<img v-if="result.type !== 'help'" :src="result.image" alt="" class="size-20 shrink-0 rounded-lg object-cover" />
<span v-else aria-hidden="true" class="flex size-20 shrink-0 items-center justify-center rounded-lg bg-subtle text-brand-secondary [&>svg]:size-6">
<DigIcon :name="ICON[result.type]" />
</span>
<span class="flex flex-1 flex-col gap-1.5">
<span class="flex items-center gap-2 text-xs text-muted-foreground [&>svg]:size-3.5">
<DigIcon :name="ICON[result.type]" />
{{ result.type === "product" ? "کالا" : result.type === "article" ? `مقاله · ${toFaDigits(result.minutes)} دقیقه` : result.path }}
</span>
<span class="text-lg font-bold group-hover:underline">
<template v-for="(part, index) in highlight(result.title, query)" :key="index">
<mark v-if="part.mark" class="rounded-sm bg-[var(--dig-amber-100)] text-foreground dark:bg-[color-mix(in_oklab,var(--dig-amber-400)_28%,var(--card))]">{{ part.text }}</mark>
<template v-else>{{ part.text }}</template>
</template>
</span>
<span class="leading-7 text-muted-foreground">
<template v-for="(part, index) in highlight(result.text, query)" :key="index">
<mark v-if="part.mark" class="rounded-sm bg-[var(--dig-amber-100)] text-foreground dark:bg-[color-mix(in_oklab,var(--dig-amber-400)_28%,var(--card))]">{{ part.text }}</mark>
<template v-else>{{ part.text }}</template>
</template>
</span>
<span v-if="result.type === 'product'" class="font-bold tabular-nums">{{ formatCurrency(result.price) }}</span>
</span>
<DigIcon name="chevron-left" aria-hidden="true" class="mt-2 size-5 shrink-0 text-muted-foreground ltr:rotate-180" />
</a>
</li>
</ul>
<section aria-labelledby="related-searches" class="flex flex-col gap-3 rounded-xl bg-subtle p-5">
<h2 id="related-searches" class="text-sm font-semibold">جستوجوهای مرتبط</h2>
<div class="flex flex-wrap gap-2">
<Button v-for="item in RELATED" :key="item" variant="outline" class="bg-card" @click="query = item">{{ item }}</Button>
</div>
</section>
</main>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: control-sizeempty-statepersiansearch-fieldtoggle-groupآیکون chevron-leftآیکون file-textآیکون guideآیکون shopping-cart
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigSearchField } from "@/components/ui/search-field"
import { DigToggleGroup, DigToggleGroupItem } from "@/components/ui/toggle-group"
import {
DigEmptyState,
DigEmptyStateTitle,
DigEmptyStateDescription,
DigEmptyStateActions,
} from "@/components/ui/empty-state"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits, toSearchKey } from "@/lib/persian"
const IMAGES = "https://docs.digdesign.ir/images"
type Result =
| {
type: "product"
title: string
text: string
price: number
image: string
}
| {
type: "article"
title: string
text: string
minutes: number
image: string
}
| { type: "help"; title: string; text: string; path: string }
const RESULTS: Result[] = [
{
type: "product",
title: "گلدانِ سرامیکی دوقلو",
text: "دستسازِ لالجین، لعابِ مات، ارتفاعِ ۳۲ سانتیمتر.",
price: 1_290_000,
image: `${IMAGES}/product-vase.webp`,
},
{
type: "article",
title: "نگهداری گلدانِ سرامیکی در زمستان",
text: "سه اشتباهِ رایج که باعثِ ترکخوردنِ گلدان میشود.",
minutes: 5,
image: `${IMAGES}/cover-minimal-room.webp`,
},
{
type: "help",
title: "مرجوعی گلدانِ آسیبدیده",
text: "اگر گلدان شکسته رسید، تا ۷ روز با عکس درخواست بده.",
path: "راهنما › سفارش و ارسال",
},
{
type: "product",
title: "گلدانِ سنگی کوچک",
text: "مناسبِ گیاهِ آپارتمانی و میزِ کار.",
price: 640_000,
image: `${IMAGES}/cover-notebook.webp`,
},
{
type: "help",
title: "بستهبندی کالاهای شکستنی",
text: "همهٔ سفالها با بستهبندی ضدضربه ارسال میشوند.",
path: "راهنما › ارسال",
},
]
const TABS = [
{ value: "all", label: "همه" },
{ value: "product", label: "کالا" },
{ value: "article", label: "مقاله" },
{ value: "help", label: "راهنما" },
]
const ICON = {
product: "shopping-cart",
article: "file-text",
help: "guide",
} as const
const RELATED = ["گلدانِ بزرگ", "سفالِ لالجین", "گلدانِ آویز", "کودِ گیاه"]
function highlight(text: string, rawQuery: string): { text: string; mark: boolean }[] {
const key = toSearchKey(rawQuery.trim())
if (!key) return [{ text, mark: false }]
// کلیدِ جستوجو فاصله و نیمفاصله را حذف میکند؛ برای هر نویسهٔ کلید جایش در متنِ اصلی را
// نگه میداریم تا هایلایت روی همان حروف بنشیند، نه چند حرف جلوتر.
const positions: number[] = []
let normalized = ""
for (let i = 0; i < text.length; i++) {
const piece = toSearchKey(text[i])
for (const char of piece) {
normalized += char
positions.push(i)
}
}
const index = normalized.indexOf(key)
if (index < 0) return [{ text, mark: false }]
const start = positions[index]
const end = positions[index + key.length - 1] + 1
return [
{ text: text.slice(0, start), mark: false },
{ text: text.slice(start, end), mark: true },
{ text: text.slice(end), mark: false },
]
}
@Component({
selector: "dig-block-search-results",
imports: [
DigControlSize,
DigSearchField,
DigToggleGroup,
DigToggleGroupItem,
DigEmptyState,
DigEmptyStateTitle,
DigEmptyStateDescription,
DigEmptyStateActions,
DigButton,
DigIcon,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<main digControlSize="xl" class="mx-auto flex w-full max-w-4xl flex-col gap-8 p-4 sm:p-6">
<h1 class="sr-only">نتایجِ جستوجو</h1>
<div class="flex flex-col gap-3">
<div
digSearchField
[value]="query()"
(valueChange)="query.set($event)"
aria-label="جستوجو"
placeholder="جستوجوی کالا، مقاله یا راهنما"
></div>
<p class="text-sm text-muted-foreground">
{{ toFaDigits(matches().length) }} نتیجه برای «<span class="font-medium text-foreground">{{ query() }}</span
>»
</p>
</div>
<div digControlSize="lg" mobileSize="default">
<div
digToggleGroup
type="single"
variant="segmented"
[value]="tab()"
aria-label="نوعِ نتیجه"
class="self-start"
(valueChange)="onTab($event)"
>
@for (item of TABS; track item.value) {
<button digToggleGroupItem [value]="item.value" class="gap-2">
{{ item.label }}
<span class="text-xs text-muted-foreground tabular-nums">{{ toFaDigits(count(item.value)) }}</span>
</button>
}
</div>
</div>
@if (visible().length === 0) {
<div digEmptyState variant="bordered" class="rounded-xl py-12">
<h3 digEmptyStateTitle>نتیجهای پیدا نشد</h3>
<p digEmptyStateDescription>کلمهٔ کوتاهتر یا هممعنی امتحان کن؛ مثلاً «سفال» بهجای «سفالینه».</p>
<div digEmptyStateActions>
<button digButton type="button" variant="outline" (click)="query.set('گلدان')">جستوجوی «گلدان»</button>
</div>
</div>
} @else {
<ul class="flex flex-col divide-y divide-border">
@for (result of visible(); track result.title) {
<li>
<a href="#" class="group flex items-start gap-4 py-5 first:pt-0">
@if (result.type !== "help") {
<img [src]="result.image" alt="" class="size-20 shrink-0 rounded-lg object-cover" />
} @else {
<span
aria-hidden="true"
class="flex size-20 shrink-0 items-center justify-center rounded-lg bg-subtle text-brand-secondary [&>svg]:size-6"
><svg [digIcon]="ICON[result.type]"></svg
></span>
}
<span class="flex flex-1 flex-col gap-1.5"
><span class="flex items-center gap-2 text-xs text-muted-foreground [&>svg]:size-3.5"
><svg [digIcon]="ICON[result.type]"></svg>
{{
result.type === "product"
? "کالا"
: result.type === "article"
? \`مقاله · \${toFaDigits(result.minutes)} دقیقه\`
: result.path
}}</span
>
<span class="text-lg font-bold group-hover:underline">
@for (part of highlight(result.title, query()); track $index; let index = $index) {
@if (part.mark) {
<mark
class="rounded-sm bg-[var(--dig-amber-100)] text-foreground dark:bg-[color-mix(in_oklab,var(--dig-amber-400)_28%,var(--card))]"
>{{ part.text }}</mark
>
} @else {
{{ part.text }}
}
}
</span>
<span class="leading-7 text-muted-foreground">
@for (part of highlight(result.text, query()); track $index; let index = $index) {
@if (part.mark) {
<mark
class="rounded-sm bg-[var(--dig-amber-100)] text-foreground dark:bg-[color-mix(in_oklab,var(--dig-amber-400)_28%,var(--card))]"
>{{ part.text }}</mark
>
} @else {
{{ part.text }}
}
}
</span>
@if (result.type === "product") {
<span class="font-bold tabular-nums">{{ formatCurrency(result.price) }}</span>
}
</span>
<svg
digIcon="chevron-left"
aria-hidden="true"
class="mt-2 size-5 shrink-0 text-muted-foreground ltr:rotate-180"
></svg
></a>
</li>
}
</ul>
}
<section aria-labelledby="related-searches" class="flex flex-col gap-3 rounded-xl bg-subtle p-5">
<h2 id="related-searches" class="text-sm font-semibold">جستوجوهای مرتبط</h2>
<div class="flex flex-wrap gap-2">
@for (item of RELATED; track item) {
<button digButton type="button" variant="outline" class="bg-card" (click)="query.set(item)">
{{ item }}
</button>
}
</div>
</section>
</main>
`,
})
export class SearchResultsBlock {
readonly toFaDigits = toFaDigits
readonly formatCurrency = formatCurrency
readonly highlight = highlight
readonly RELATED = RELATED
readonly ICON = ICON
readonly TABS = TABS
readonly query = signal("گلدان")
readonly tab = signal("all")
readonly matches = computed(() =>
RESULTS.filter((result) => toSearchKey(result.title + result.text).includes(toSearchKey(this.query().trim())))
)
readonly visible = computed(() =>
this.matches().filter((result) => this.tab() === "all" || result.type === this.tab())
)
readonly count = (value: string) =>
value === "all" ? this.matches().length : this.matches().filter((result) => result.type === value).length
onTab(value: string | string[] | undefined) {
if (value) this.tab.set(value as string)
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.