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

اینترنت قطع است، هم‌سبکِ صفحه‌های خطا: تصویرِ خطیِ ابرِ قطع‌شده، وضعیتِ زندهٔ اتصال که با برگشتِ اینترنت پیام و دکمه را عوض می‌کند و نکته‌های بررسی.

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

این بلاک از ۳ آیتم دیگ استفاده می‌کند: buttoncontrol-sizeicons

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

۲. کد صفحه

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

offline.tsx
"use client"

import * as React from "react"

import { RefreshIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"

/** تصویرِ خطی ابر با سیمِ قطع‌شده؛ هم‌سبکِ تابلوهای ۴۰۴ و ۵۰۲، با رنگِ تم. */
function DisconnectedCloud({ className }: { className?: string }) {
  return (
    <svg viewBox="0 0 320 220" role="img" aria-label="ابری با سیمِ قطع‌شده" className={className}>
      <path
        d="M92 150h138a42 42 0 0 0 4-84 62 62 0 0 0-118-12 46 46 0 0 0-24 96z"
        fill="var(--background)"
        stroke="currentColor"
        strokeWidth="2.5"
        strokeLinejoin="round"
      />
      <path d="M100 158h138a42 42 0 0 0 10-82" transform="translate(6 6)" fill="none" stroke="currentColor" strokeWidth="2" strokeLinejoin="round" />
      <path d="M150 150v22m0 0-10 10m10-10 10 10" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
      <path d="M170 198v-10m0 0 10-10m-10 10-10-10" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" transform="translate(-20 14)" />
      <path d="M118 188l-8 6M196 188l8 6M158 206v8" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
      <path d="M128 100h0M192 100h0" stroke="currentColor" strokeWidth="6" strokeLinecap="round" />
      <path d="M140 124c12-8 28-8 40 0" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
    </svg>
  )
}

/**
 * صفحهٔ آفلاین: هم‌سبکِ صفحه‌های خطا، با وضعیتِ زندهٔ اتصال؛ وقتی اینترنت برگشت،
 * پیام و دکمه خودشان عوض می‌شوند. کارهای ذخیره‌شده دست نمی‌خورند.
 */
export default function OfflineBlock() {
  const [online, setOnline] = React.useState(false)
  const [checking, setChecking] = React.useState(false)

  React.useEffect(() => {
    const on = () => setOnline(true)
    const off = () => setOnline(false)
    window.addEventListener("online", on)
    window.addEventListener("offline", off)
    return () => {
      window.removeEventListener("online", on)
      window.removeEventListener("offline", off)
    }
  }, [])

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="flex min-h-svh flex-col items-center justify-center gap-8 p-6 text-center">
        <DisconnectedCloud className="w-64 max-w-full text-foreground sm:w-80" />
        <div className="flex max-w-md flex-col items-center gap-3" aria-live="polite">
          <h1 className="text-3xl leading-snug font-bold">{online ? "برگشتیم!" : "اینترنت قطعه"}</h1>
          <p className="leading-7 text-muted-foreground">
            {online ? "اتصال برقرار شد؛ صفحه را تازه کن و ادامه بده." : "نگران نباش، چیزی پاک نشده. وقتی وصل شدی همه‌چیز همان‌جاست که گذاشته بودی."}
          </p>
        </div>
        <Button
          loading={checking}
          onClick={() => {
            setChecking(true)
            window.setTimeout(() => {
              setChecking(false)
              setOnline(navigator.onLine)
            }, 900)
          }}
        >
          <RefreshIcon />
          {online ? "تازه کردنِ صفحه" : "دوباره امتحان کن"}
        </Button>
        <ul className="flex flex-col gap-1 text-sm text-muted-foreground">
          <li>وای‌فای یا دادهٔ همراه روشن است؟</li>
          <li>حالتِ هواپیما خاموش است؟</li>
        </ul>
      </main>
    </ControlSizeProvider>
  )
}
offline.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue"

import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import { DigIcon } from "@/lib/icons"

/**
 * صفحهٔ آفلاین: هم‌سبکِ صفحه‌های خطا، با وضعیتِ زندهٔ اتصال؛ وقتی اینترنت برگشت،
 * پیام و دکمه خودشان عوض می‌شوند. کارهای ذخیره‌شده دست نمی‌خورند.
 */
const online = ref(false)
const checking = ref(false)

const on = () => (online.value = true)
const off = () => (online.value = false)

onMounted(() => {
  window.addEventListener("online", on)
  window.addEventListener("offline", off)
})
onBeforeUnmount(() => {
  window.removeEventListener("online", on)
  window.removeEventListener("offline", off)
})

function check() {
  checking.value = true
  window.setTimeout(() => {
    checking.value = false
    online.value = navigator.onLine
  }, 900)
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="flex min-h-svh flex-col items-center justify-center gap-8 p-6 text-center">
      <svg viewBox="0 0 320 220" role="img" aria-label="ابری با سیمِ قطع‌شده" class="w-64 max-w-full text-foreground sm:w-80">
        <path
          d="M92 150h138a42 42 0 0 0 4-84 62 62 0 0 0-118-12 46 46 0 0 0-24 96z"
          fill="var(--background)"
          stroke="currentColor"
          stroke-width="2.5"
          stroke-linejoin="round"
        />
        <path d="M100 158h138a42 42 0 0 0 10-82" transform="translate(6 6)" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" />
        <path d="M150 150v22m0 0-10 10m10-10 10 10" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" />
        <path d="M170 198v-10m0 0 10-10m-10 10-10-10" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" transform="translate(-20 14)" />
        <path d="M118 188l-8 6M196 188l8 6M158 206v8" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
        <path d="M128 100h0M192 100h0" stroke="currentColor" stroke-width="6" stroke-linecap="round" />
        <path d="M140 124c12-8 28-8 40 0" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" />
      </svg>
      <div class="flex max-w-md flex-col items-center gap-3" aria-live="polite">
        <h1 class="text-3xl leading-snug font-bold">{{ online ? "برگشتیم!" : "اینترنت قطعه" }}</h1>
        <p class="leading-7 text-muted-foreground">
          {{ online ? "اتصال برقرار شد؛ صفحه را تازه کن و ادامه بده." : "نگران نباش، چیزی پاک نشده. وقتی وصل شدی همه‌چیز همان‌جاست که گذاشته بودی." }}
        </p>
      </div>
      <Button :loading="checking" @click="check">
        <DigIcon name="refresh" />
        {{ online ? "تازه کردنِ صفحه" : "دوباره امتحان کن" }}
      </Button>
      <ul class="flex flex-col gap-1 text-sm text-muted-foreground">
        <li>وای‌فای یا دادهٔ همراه روشن است؟</li>
        <li>حالتِ هواپیما خاموش است؟</li>
      </ul>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: control-sizeآیکون refresh

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

offline.ts
import {
  ChangeDetectionStrategy,
  Component,
  DestroyRef,
  inject,
  signal,
} from "@angular/core"

import { DigButton } from "@/components/ui/button"
import { DigControlSize } from "@/components/ui/control-size"
import { DigIcon } from "@/lib/icons"

@Component({
  selector: "dig-block-offline",
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [DigButton, DigControlSize, DigIcon],
  host: {
    "(window:online)": "online.set(true)",
    "(window:offline)": "online.set(false)",
  },
  template: `
    <main
      digControlSize="xl"
      class="flex min-h-svh flex-col items-center justify-center gap-8 p-6 text-center"
    >
      <svg
        viewBox="0 0 320 220"
        role="img"
        aria-label="ابری با سیمِ قطع‌شده"
        class="w-64 max-w-full text-foreground sm:w-80"
      >
        <path
          d="M92 150h138a42 42 0 0 0 4-84 62 62 0 0 0-118-12 46 46 0 0 0-24 96z"
          fill="var(--background)"
          stroke="currentColor"
          strokeWidth="2.5"
          strokeLinejoin="round"
        ></path>
        <path
          d="M100 158h138a42 42 0 0 0 10-82"
          transform="translate(6 6)"
          fill="none"
          stroke="currentColor"
          strokeWidth="2"
          strokeLinejoin="round"
        ></path>
        <path
          d="M150 150v22m0 0-10 10m10-10 10 10"
          fill="none"
          stroke="currentColor"
          strokeWidth="2.5"
          strokeLinecap="round"
        ></path>
        <path
          d="M170 198v-10m0 0 10-10m-10 10-10-10"
          fill="none"
          stroke="currentColor"
          strokeWidth="2.5"
          strokeLinecap="round"
          transform="translate(-20 14)"
        ></path>
        <path
          d="M118 188l-8 6M196 188l8 6M158 206v8"
          stroke="currentColor"
          strokeWidth="2"
          strokeLinecap="round"
        ></path>
        <path
          d="M128 100h0M192 100h0"
          stroke="currentColor"
          strokeWidth="6"
          strokeLinecap="round"
        ></path>
        <path
          d="M140 124c12-8 28-8 40 0"
          fill="none"
          stroke="currentColor"
          strokeWidth="2.5"
          strokeLinecap="round"
        ></path>
      </svg>
      <div class="flex max-w-md flex-col items-center gap-3" aria-live="polite">
        <h1 class="text-3xl leading-snug font-bold">
          {{ online() ? "برگشتیم!" : "اینترنت قطعه" }}
        </h1>
        <p class="leading-7 text-muted-foreground">
          {{
            online()
              ? "اتصال برقرار شد؛ صفحه را تازه کن و ادامه بده."
              : "نگران نباش، چیزی پاک نشده. وقتی وصل شدی همه‌چیز همان‌جاست که گذاشته بودی."
          }}
        </p>
      </div>
      <button digButton type="button" [loading]="checking()" (click)="check()">
        <svg digIcon="refresh"></svg>
        {{ online() ? "تازه کردنِ صفحه" : "دوباره امتحان کن" }}
      </button>
      <ul class="flex flex-col gap-1 text-sm text-muted-foreground">
        <li>وای‌فای یا دادهٔ همراه روشن است؟</li>
        <li>حالتِ هواپیما خاموش است؟</li>
      </ul>
    </main>
  `,
})
export class OfflineBlock {
  readonly online = signal(false)
  readonly checking = signal(false)
  private timer?: ReturnType<typeof setTimeout>

  constructor() {
    inject(DestroyRef).onDestroy(() => clearTimeout(this.timer))
  }

  check() {
    if (this.checking()) return
    if (this.online()) {
      window.location.reload()
      return
    }
    this.checking.set(true)
    this.timer = setTimeout(() => {
      this.online.set(navigator.onLine)
      this.checking.set(false)
    }, 900)
  }
}

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

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

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