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

اعلان‌های زنگوله

پیش‌نمایش تمام‌صفحه

پنلِ کشوییِ زنگوله: شمارِ تازه روی زنگوله، سگمنتِ همه/خوانده‌نشده، ردیف‌ها با عکس یا آیکون و اقدامِ مستقیم، «همه خوانده شد» و راهِ تنظیمات.

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

این بلاک از ۸ آیتم دیگ استفاده می‌کند: avatarbadgebuttoncontrol-sizeiconspersianpopovertoggle-group

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

۲. کد صفحه

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

notifications-popover.tsx
"use client"

import * as React from "react"

import { BellIcon, ReceiptIcon, SettingsIcon, TruckIcon } from "@/components/icons"
import { Avatar } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { toFaDigits } from "@/lib/persian"
import { stockImages } from "@/lib/stock-images"

type Item = { id: string; title: string; text: string; time: string; read: boolean; icon?: React.ReactNode; photo?: string; action?: string }
const ITEMS: Item[] = [
  { id: "1", title: "سارا محمدی", text: "از تو در «داشبوردِ فروش» نام برد.", time: "۵ دقیقه پیش", read: false, photo: stockImages.personWoman2.src, action: "پاسخ" },
  { id: "2", title: "سفارشِ ۸۸۲۱۰۴۲ ارسال شد", text: "پیک تا ساعتِ ۱۸ می‌رسد.", time: "۱ ساعت پیش", read: false, icon: <TruckIcon /> },
  { id: "3", title: "فاکتورِ مهر آماده است", text: "مبلغ ۷٬۳۱۵٬۰۰۰ تومان.", time: "دیروز", read: true, icon: <ReceiptIcon />, action: "دیدنِ فاکتور" },
]

/**
 * اعلان‌ها در پنلِ کشویی زنگوله: نشانِ شمارِ تازه روی زنگوله، سگمنتِ همه/خوانده‌نشده، ردیف‌ها
 * با عکس یا آیکون و نقطهٔ تازه، اقدامِ مستقیم روی ردیف (پاسخ، دیدنِ فاکتور)، «همه خوانده شد»
 * و راهِ تنظیمات؛ بدونِ ترکِ صفحه.
 */
export default function NotificationsPopoverBlock() {
  const [items, setItems] = React.useState(ITEMS)
  const [filter, setFilter] = React.useState("all")
  const unread = items.filter((item) => !item.read).length
  const visible = items.filter((item) => filter === "all" || !item.read)

  return (
    <ControlSizeProvider size="xl" asChild>
      <div className="flex min-h-[36rem] w-full justify-end bg-subtle p-4 sm:p-6">
        <h1 className="sr-only">اعلان‌ها</h1>
        <Popover defaultOpen>
          <PopoverTrigger asChild>
            <Button variant="outline" size="icon" aria-label={unread ? `اعلان‌ها، ${toFaDigits(unread)} تازه` : "اعلان‌ها"} className="relative bg-card">
              <BellIcon />
              {unread > 0 && <Badge color="destructive" className="absolute -end-1.5 -top-1.5 min-w-5 justify-center px-1">{toFaDigits(unread)}</Badge>}
            </Button>
          </PopoverTrigger>
          <ControlSizeProvider size="xl" asChild>
            <PopoverContent align="end" className="flex w-[min(24rem,calc(100vw-2rem))] flex-col gap-0 p-0">
              <div className="flex items-center justify-between gap-3 border-b border-border p-4">
                <span className="font-bold">اعلان‌ها</span>
                <Button variant="ghost" disabled={unread === 0} onClick={() => setItems((list) => list.map((item) => ({ ...item, read: true })))}>
                  همه خوانده شد
                </Button>
              </div>
              <div className="p-3">
                <ControlSizeProvider size="lg" mobileSize="default" asChild>
                  <ToggleGroup type="single" variant="segmented" value={filter} onValueChange={(value) => value && setFilter(value as string)} aria-label="فیلتر" className="w-full">
                    <ToggleGroupItem value="all" className="flex-1">
                      همه
                    </ToggleGroupItem>
                    <ToggleGroupItem value="unread" className="flex-1">
                      خوانده‌نشده {unread > 0 && `(${toFaDigits(unread)})`}
                    </ToggleGroupItem>
                  </ToggleGroup>
                </ControlSizeProvider>
              </div>
              {visible.length === 0 ? (
                <p className="px-4 pt-4 pb-8 text-center text-sm text-muted-foreground">همه را خوانده‌ای. اعلانِ تازه که بیاید این‌جاست.</p>
              ) : (
                <ul className="flex max-h-80 flex-col overflow-y-auto">
                  {visible.map((item) => (
                    <li key={item.id} className={`flex gap-3 border-t border-border p-4 ${item.read ? "" : "bg-primary-subtle"}`}>
                      {item.photo ? (
                        <Avatar alt="" src={item.photo} />
                      ) : (
                        <span aria-hidden className="flex size-10 shrink-0 items-center justify-center rounded-full bg-card text-brand-secondary [&>svg]:size-5">
                          {item.icon}
                        </span>
                      )}
                      <div className="flex flex-1 flex-col gap-1">
                        <span className={item.read ? "text-sm font-medium" : "text-sm font-bold"}>{item.title}</span>
                        <span className="text-sm leading-6 text-muted-foreground">{item.text}</span>
                        <div className="mt-1 flex items-center justify-between gap-2">
                          <span className="text-xs text-muted-foreground">{item.time}</span>
                          {item.action && (
                            <Button variant="outline" className="bg-card" onClick={() => setItems((list) => list.map((entry) => (entry.id === item.id ? { ...entry, read: true } : entry)))}>
                              {item.action}
                            </Button>
                          )}
                        </div>
                      </div>
                      {!item.read && <span aria-label="تازه" className="mt-2 size-2.5 shrink-0 rounded-full bg-[var(--dig-blue-500)]" />}
                    </li>
                  ))}
                </ul>
              )}
              <Button variant="ghost" className="rounded-none border-t border-border">
                <SettingsIcon />
                تنظیمِ اعلان‌ها
              </Button>
            </PopoverContent>
          </ControlSizeProvider>
        </Popover>
      </div>
    </ControlSizeProvider>
  )
}
notifications-popover.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import Avatar from "@/components/ui/Avatar.vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Popover from "@/components/ui/Popover.vue"
import PopoverContent from "@/components/ui/PopoverContent.vue"
import PopoverTrigger from "@/components/ui/PopoverTrigger.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { toFaDigits } from "@/lib/persian"

// تصویرهای کتابخانهٔ تصویرِ دیگ (همان فایل‌های stock-images نسخهٔ React).
const stockImages = {
  personWoman2: { src: "https://docs.digdesign.ir/images/person-woman-2.webp", alt: "پرترهٔ زنی با کتِ طوسی" },
}
type StockImageName = keyof typeof stockImages

type Item = { id: string; title: string; text: string; time: string; read: boolean; icon?: string; photo?: string; action?: string }
const ITEMS: Item[] = [
  { id: "1", title: "سارا محمدی", text: "از تو در «داشبوردِ فروش» نام برد.", time: "۵ دقیقه پیش", read: false, photo: stockImages.personWoman2.src, action: "پاسخ" },
  { id: "2", title: "سفارشِ ۸۸۲۱۰۴۲ ارسال شد", text: "پیک تا ساعتِ ۱۸ می‌رسد.", time: "۱ ساعت پیش", read: false, icon: "truck" },
  { id: "3", title: "فاکتورِ مهر آماده است", text: "مبلغ ۷٬۳۱۵٬۰۰۰ تومان.", time: "دیروز", read: true, icon: "receipt", action: "دیدنِ فاکتور" },
]

/**
 * اعلان‌ها در پنلِ کشویی زنگوله: نشانِ شمارِ تازه روی زنگوله، سگمنتِ همه/خوانده‌نشده، ردیف‌ها
 * با عکس یا آیکون و نقطهٔ تازه، اقدامِ مستقیم روی ردیف (پاسخ، دیدنِ فاکتور)، «همه خوانده شد»
 * و راهِ تنظیمات؛ بدونِ ترکِ صفحه.
 */
const items = ref<Item[]>(ITEMS)
const filter = ref("all")
const unread = computed(() => items.value.filter((item) => !item.read).length)
const visible = computed(() => items.value.filter((item) => filter.value === "all" || !item.read))

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

function markRead(id: string) {
  items.value = items.value.map((entry) => (entry.id === id ? { ...entry, read: true } : entry))
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <div class="flex min-h-[36rem] w-full justify-end bg-subtle p-4 sm:p-6">
      <h1 class="sr-only">اعلان‌ها</h1>
      <Popover default-open>
        <PopoverTrigger as-child>
          <Button variant="outline" size="icon" :aria-label="unread ? `اعلان‌ها، ${toFaDigits(unread)} تازه` : 'اعلان‌ها'" class="relative bg-card">
            <DigIcon name="bell" />
            <Badge v-if="unread > 0" color="destructive" class="absolute -end-1.5 -top-1.5 min-w-5 justify-center px-1">{{ toFaDigits(unread) }}</Badge>
          </Button>
        </PopoverTrigger>
        <ControlSize size="xl" as-child>
          <PopoverContent align="end" class="flex w-[min(24rem,calc(100vw-2rem))] flex-col gap-0 p-0">
            <div class="flex items-center justify-between gap-3 border-b border-border p-4">
              <span class="font-bold">اعلان‌ها</span>
              <Button variant="ghost" :disabled="unread === 0" @click="items = items.map((item) => ({ ...item, read: true }))">همه خوانده شد</Button>
            </div>
            <div class="p-3">
              <ControlSize size="lg" mobile-size="default" as-child>
                <ToggleGroup type="single" variant="segmented" :value="filter" aria-label="فیلتر" class="w-full" @update:value="onFilter">
                  <ToggleGroupItem value="all" class="flex-1">همه</ToggleGroupItem>
                  <ToggleGroupItem value="unread" class="flex-1">خوانده‌نشده {{ unread > 0 ? `(${toFaDigits(unread)})` : "" }}</ToggleGroupItem>
                </ToggleGroup>
              </ControlSize>
            </div>
            <p v-if="visible.length === 0" class="px-4 pt-4 pb-8 text-center text-sm text-muted-foreground">همه را خوانده‌ای. اعلانِ تازه که بیاید این‌جاست.</p>
            <ul v-else class="flex max-h-80 flex-col overflow-y-auto">
              <li v-for="item in visible" :key="item.id" :class="`flex gap-3 border-t border-border p-4 ${item.read ? '' : 'bg-primary-subtle'}`">
                <Avatar v-if="item.photo" alt="" :src="item.photo" />
                <span v-else aria-hidden="true" class="flex size-10 shrink-0 items-center justify-center rounded-full bg-card text-brand-secondary [&>svg]:size-5">
                  <DigIcon v-if="item.icon" :name="item.icon" />
                </span>
                <div class="flex flex-1 flex-col gap-1">
                  <span :class="item.read ? 'text-sm font-medium' : 'text-sm font-bold'">{{ item.title }}</span>
                  <span class="text-sm leading-6 text-muted-foreground">{{ item.text }}</span>
                  <div class="mt-1 flex items-center justify-between gap-2">
                    <span class="text-xs text-muted-foreground">{{ item.time }}</span>
                    <Button v-if="item.action" variant="outline" class="bg-card" @click="markRead(item.id)">{{ item.action }}</Button>
                  </div>
                </div>
                <span v-if="!item.read" aria-label="تازه" class="mt-2 size-2.5 shrink-0 rounded-full bg-[var(--dig-blue-500)]" />
              </li>
            </ul>
            <Button variant="ghost" class="rounded-none border-t border-border">
              <DigIcon name="settings" />
              تنظیمِ اعلان‌ها
            </Button>
          </PopoverContent>
        </ControlSize>
      </Popover>
    </div>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: avatarbadgecontrol-sizepersianpopovertoggle-groupآیکون bellآیکون receiptآیکون settingsآیکون truck

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

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

import { DigControlSize } from "@/components/ui/control-size"
import { DigPopover, DigPopoverTrigger, DigPopoverContent } from "@/components/ui/popover"
import { DigButton } from "@/components/ui/button"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { DigBadge } from "@/components/ui/badge"
import { DigToggleGroup, DigToggleGroupItem } from "@/components/ui/toggle-group"
import { DigAvatar } from "@/components/ui/avatar"
import { toFaDigits } from "@/lib/persian"

const stockImages = {
  personWoman2: { src: "https://docs.digdesign.ir/images/person-woman-2.webp", alt: "پرترهٔ زنی با کتِ طوسی" },
}

type StockImageName = keyof typeof stockImages

type Item = {
  id: string
  title: string
  text: string
  time: string
  read: boolean
  icon?: DigIconName
  photo?: string
  action?: string
}

const ITEMS: Item[] = [
  {
    id: "1",
    title: "سارا محمدی",
    text: "از تو در «داشبوردِ فروش» نام برد.",
    time: "۵ دقیقه پیش",
    read: false,
    photo: stockImages.personWoman2.src,
    action: "پاسخ",
  },
  {
    id: "2",
    title: "سفارشِ ۸۸۲۱۰۴۲ ارسال شد",
    text: "پیک تا ساعتِ ۱۸ می‌رسد.",
    time: "۱ ساعت پیش",
    read: false,
    icon: "truck" as const,
  },
  {
    id: "3",
    title: "فاکتورِ مهر آماده است",
    text: "مبلغ ۷٬۳۱۵٬۰۰۰ تومان.",
    time: "دیروز",
    read: true,
    icon: "receipt" as const,
    action: "دیدنِ فاکتور",
  },
]

@Component({
  selector: "dig-block-notifications-popover",
  imports: [
    DigControlSize,
    DigPopover,
    DigPopoverTrigger,
    DigPopoverContent,
    DigButton,
    DigIcon,
    DigBadge,
    DigToggleGroup,
    DigToggleGroupItem,
    DigAvatar,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div digControlSize="xl" class="flex min-h-[36rem] w-full justify-end bg-subtle p-4 sm:p-6">
      <h1 class="sr-only">اعلان‌ها</h1>
      <ng-container digPopover [open]="true"
        ><button
          digPopoverTrigger
          digButton
          type="button"
          variant="outline"
          size="icon"
          [attr.aria-label]="unread() ? \`اعلان‌ها، \${toFaDigits(unread())} تازه\` : 'اعلان‌ها'"
          class="relative bg-card"
        >
          <svg digIcon="bell"></svg>
          @if (unread() > 0) {
            <span digBadge color="destructive" class="absolute -end-1.5 -top-1.5 min-w-5 justify-center px-1">{{
              toFaDigits(unread())
            }}</span>
          }
        </button>
        <div
          digControlSize="xl"
          digPopoverContent
          align="end"
          class="flex w-[min(24rem,calc(100vw-2rem))] flex-col gap-0 p-0"
        >
          <div class="flex items-center justify-between gap-3 border-b border-border p-4">
            <span class="font-bold">اعلان‌ها</span>
            <button
              digButton
              type="button"
              variant="ghost"
              [disabled]="unread() === 0"
              (click)="items.set(items().map((item) => ({ ...item, read: true })))"
            >
              همه خوانده شد
            </button>
          </div>
          <div class="p-3">
            <div digControlSize="lg" mobileSize="default">
              <div
                digToggleGroup
                type="single"
                variant="segmented"
                [value]="filter()"
                aria-label="فیلتر"
                class="w-full"
                (valueChange)="onFilter($event)"
              >
                <button digToggleGroupItem value="all" class="flex-1">همه</button>
                <button digToggleGroupItem value="unread" class="flex-1">
                  خوانده‌نشده {{ unread() > 0 ? \`(\${toFaDigits(unread())})\` : "" }}
                </button>
              </div>
            </div>
          </div>
          @if (visible().length === 0) {
            <p class="px-4 pt-4 pb-8 text-center text-sm text-muted-foreground">
              همه را خوانده‌ای. اعلانِ تازه که بیاید این‌جاست.
            </p>
          } @else {
            <ul class="flex max-h-80 flex-col overflow-y-auto">
              @for (item of visible(); track item.id) {
                <li [class]="\`flex gap-3 border-t border-border p-4 \${item.read ? '' : 'bg-primary-subtle'}\`">
                  @if (item.photo) {
                    <span digAvatar alt="" [src]="item.photo"></span>
                  } @else {
                    <span
                      aria-hidden="true"
                      class="flex size-10 shrink-0 items-center justify-center rounded-full bg-card text-brand-secondary [&>svg]:size-5"
                    >
                      @if (item.icon) {
                        <svg [digIcon]="item.icon"></svg>
                      }
                    </span>
                  }
                  <div class="flex flex-1 flex-col gap-1">
                    <span [class]="item.read ? 'text-sm font-medium' : 'text-sm font-bold'">{{ item.title }}</span>
                    <span class="text-sm leading-6 text-muted-foreground">{{ item.text }}</span>
                    <div class="mt-1 flex items-center justify-between gap-2">
                      <span class="text-xs text-muted-foreground">{{ item.time }}</span>
                      @if (item.action) {
                        <button digButton type="button" variant="outline" class="bg-card" (click)="markRead(item.id)">
                          {{ item.action }}
                        </button>
                      }
                    </div>
                  </div>
                  @if (!item.read) {
                    <span aria-label="تازه" class="mt-2 size-2.5 shrink-0 rounded-full bg-[var(--dig-blue-500)]"></span>
                  }
                </li>
              }
            </ul>
          }
          <button digButton type="button" variant="ghost" class="rounded-none border-t border-border">
            <svg digIcon="settings"></svg>
            تنظیمِ اعلان‌ها
          </button>
        </div></ng-container
      >
    </div>
  `,
})
export class NotificationsPopoverBlock {
  readonly toFaDigits = toFaDigits

  readonly items = signal<Item[]>(ITEMS)

  readonly filter = signal("all")

  readonly unread = computed(() => this.items().filter((item) => !item.read).length)

  readonly visible = computed(() => this.items().filter((item) => this.filter() === "all" || !item.read))

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

  markRead(id: string) {
    this.items.set(this.items().map((entry) => (entry.id === id ? { ...entry, read: true } : entry)))
  }
}

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

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

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