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

خانهٔ اپ سلامت

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

کارت‌های رنگی با حلقهٔ پیشرفت، میله‌های خواب و نمودار وزن، برنامهٔ روز و نوار ناوبری پایین.

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

این بلاک از ۸ آیتم دیگ استفاده می‌کند: app-baravatarbottom-navigationbuttoncontrol-sizeiconspersianstat-tile

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

۲. کد صفحه

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

mobile-health.tsx
"use client"

import * as React from "react"

import {
  ActivityIcon,
  BarChartIcon,
  BellIcon,
  CalendarIcon,
  CheckIcon,
  DropletIcon,
  FlameIcon,
  HeartIcon,
  MoonIcon,
} from "@/components/icons"
import { AppBar, AppBarActions, AppBarTitle } from "@/components/ui/app-bar"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Avatar } from "@/components/ui/avatar"
import { StatTileRing, StatTileSparkline } from "@/components/ui/stat-tile"
import { BottomNavigation, BottomNavigationItem } from "@/components/ui/bottom-navigation"
import { Button } from "@/components/ui/button"
import { formatNumber, toFaDigits } from "@/lib/persian"

/**
 * شیار و میله‌های غیرفعال با رنگِ میانی همان خانواده (ترکیبِ رنگِ اصلی با
 * زمینهٔ کمرنگ)، نه سفید: سفید روی زمینهٔ رنگی روشن دیده نمی‌شود.
 */
const TRACK: Record<string, string> = {
  orange: "[--track:color-mix(in_oklab,var(--color-orange)_28%,var(--color-orange-subtle))]",
  cyan: "[--track:color-mix(in_oklab,var(--color-cyan)_28%,var(--color-cyan-subtle))]",
  warning: "[--track:color-mix(in_oklab,var(--color-warning)_28%,var(--color-warning-subtle))]",
  success: "[--track:color-mix(in_oklab,var(--color-success)_28%,var(--color-success-subtle))]",
}

/** حلقهٔ پیشرفت: همان StatTileRing با دو بخش (پیشرفت و باقی‌مانده). */
function Ring({ value, color, track }: { value: number; color: string; track: string }) {
  return (
    <StatTileRing
      role="img"
      aria-label={`${toFaDigits(value)} درصد از هدف`}
      className="size-14 shrink-0"
      segments={[
        { value, color },
        { value: 100 - value, color: track },
      ]}
    />
  )
}

function Bars({ values, className }: { values: number[]; className: string }) {
  const max = Math.max(...values)
  return (
    <div className={`flex h-14 items-end gap-1 ${className}`} aria-hidden>
      {values.map((value, index) => (
        <span
          key={index}
          // امروز (آخرین میله) پررنگ؛ بقیه رنگِ میانی.
          className={index === values.length - 1 ? "w-1.5 rounded-full bg-current" : "w-1.5 rounded-full bg-(--track)"}
          style={{ height: `${(value / max) * 100}%` }}
        />
      ))}
    </div>
  )
}

const TILES = [
  {
    title: "کالری",
    value: formatNumber(1_839),
    unit: "کیلوکالری",
    icon: <FlameIcon />,
    tone: `bg-orange-subtle text-orange ${TRACK.orange}`,
    chart: <Ring value={72} color="var(--orange)" track="color-mix(in oklab, var(--orange) 26%, var(--orange-subtle))" />,
  },
  {
    title: "آب",
    value: formatNumber(1_200),
    unit: "میلی‌لیتر",
    icon: <DropletIcon />,
    tone: `bg-cyan-subtle text-cyan ${TRACK.cyan}`,
    chart: <Ring value={60} color="var(--cyan)" track="color-mix(in oklab, var(--cyan) 26%, var(--cyan-subtle))" />,
  },
  {
    title: "خواب",
    value: toFaDigits("7:30"),
    unit: "ساعت",
    icon: <MoonIcon />,
    tone: `bg-warning-subtle text-warning-subtle-foreground ${TRACK.warning}`,
    chart: <Bars values={[5, 6.5, 6, 8, 5.5, 7, 7.5]} className="text-warning-subtle-foreground" />,
  },
  {
    title: "وزن",
    value: formatNumber(68),
    unit: "کیلوگرم",
    icon: <ActivityIcon />,
    tone: `bg-success-subtle text-success-subtle-foreground ${TRACK.success}`,
    chart: <StatTileSparkline values={[70, 69.6, 69.8, 69.1, 68.7, 68.9, 68.2, 68]} className="h-14 w-24" />,
  },
]

const PLAN = [
  { time: "۰۷:۳۰", title: "پیاده‌روی صبح", detail: "۳۰ دقیقه · ۲٫۵ کیلومتر", done: true },
  { time: "۱۳:۰۰", title: "ناهار سبک", detail: "۶۵۰ کیلوکالری", done: true },
  { time: "۱۸:۳۰", title: "یوگا", detail: "۴۵ دقیقه", done: false },
]

export default function MobileHealthBlock() {
  const [tab, setTab] = React.useState("activity")

  return (
    // قابِ اپ: در موبایل تمام‌صفحه، در دسکتاپ ستونی به عرضِ گوشی.
    <ControlSizeProvider size="xl" asChild>
    <div className="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <AppBar sticky>
        <Avatar alt="آرمیتا رستگار" size="sm" />
        <AppBarTitle>سلام آرمیتا</AppBarTitle>
        <AppBarActions>
          <Button variant="ghost" size="icon" aria-label="اعلان‌ها">
            <BellIcon />
          </Button>
        </AppBarActions>
      </AppBar>

      <main className="flex flex-1 flex-col gap-5 p-4">
        <section aria-labelledby="today" className="flex flex-col gap-3">
          <div className="flex items-baseline justify-between">
            <h1 id="today" className="text-lg font-bold">
              امروز
            </h1>
            <span className="text-sm text-muted-foreground">۷۲٪ هدف روزانه</span>
          </div>
          <div className="grid grid-cols-2 gap-3">
            {TILES.map((tile) => (
              <article key={tile.title} className={`flex flex-col gap-3 rounded-xl p-4 ${tile.tone}`}>
                <div className="flex items-center gap-2 text-foreground">
                  <span aria-hidden className={`[&_svg]:size-5 ${tile.tone.split(" ")[1]}`}>
                    {tile.icon}
                  </span>
                  <h2 className="font-semibold">{tile.title}</h2>
                </div>
                <div className="flex items-end justify-between gap-2">
                  <div className="flex flex-col text-foreground">
                    <span className="text-2xl font-bold">{tile.value}</span>
                    <span className="text-xs text-muted-foreground">{tile.unit}</span>
                  </div>
                  {tile.chart}
                </div>
              </article>
            ))}
          </div>
        </section>

        <section aria-labelledby="plan" className="flex flex-col gap-3">
          <h2 id="plan" className="font-bold">
            برنامهٔ امروز
          </h2>
          <ol className="flex flex-col gap-2">
            {PLAN.map((item) => (
              <li key={item.title} className="flex items-center gap-3 rounded-xl border border-border p-3">
                {/* تیک برای انجام‌شده؛ متن خط نمی‌خورد تا خوانا بماند. */}
                <span
                  className={
                    item.done
                      ? "flex size-8 shrink-0 items-center justify-center rounded-full bg-success-subtle text-success-subtle-foreground [&_svg]:size-4"
                      : "size-8 shrink-0 rounded-full border-2 border-dashed border-border"
                  }
                  role="img"
                  aria-label={item.done ? "انجام شد" : "انجام نشده"}
                >
                  {item.done && <CheckIcon />}
                </span>
                <div className="flex min-w-0 flex-1 flex-col">
                  <span className="font-medium">{item.title}</span>
                  <span className="text-xs text-muted-foreground">{item.detail}</span>
                </div>
                <span className="shrink-0 text-sm text-muted-foreground">{item.time}</span>
              </li>
            ))}
          </ol>
        </section>
      </main>

      <BottomNavigation value={tab} onValueChange={setTab} indicator="pill" fixed={false} className="sticky bottom-0">
        <BottomNavigationItem value="activity" icon={<ActivityIcon />} label="فعالیت" />
        <BottomNavigationItem value="fitness" icon={<HeartIcon />} label="تمرین" />
        <BottomNavigationItem value="plans" icon={<CalendarIcon />} label="برنامه" />
        <BottomNavigationItem value="progress" icon={<BarChartIcon />} label="پیشرفت" />
      </BottomNavigation>
    </div>
    </ControlSizeProvider>
  )
}
mobile-health.vue
<script setup lang="ts">
import { ref } from "vue"

import AppBar from "@/components/ui/AppBar.vue"
import AppBarActions from "@/components/ui/AppBarActions.vue"
import AppBarTitle from "@/components/ui/AppBarTitle.vue"
import Avatar from "@/components/ui/Avatar.vue"
import BottomNavigation from "@/components/ui/BottomNavigation.vue"
import BottomNavigationItem from "@/components/ui/BottomNavigationItem.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import StatTileRing from "@/components/ui/StatTileRing.vue"
import StatTileSparkline from "@/components/ui/StatTileSparkline.vue"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { formatNumber, toFaDigits } from "@/lib/persian"

/**
 * شیار و میله‌های غیرفعال با رنگِ میانی همان خانواده (ترکیبِ رنگِ اصلی با
 * زمینهٔ کمرنگ)، نه سفید: سفید روی زمینهٔ رنگی روشن دیده نمی‌شود.
 */
const TRACK: Record<string, string> = {
  orange: "[--track:color-mix(in_oklab,var(--color-orange)_28%,var(--color-orange-subtle))]",
  cyan: "[--track:color-mix(in_oklab,var(--color-cyan)_28%,var(--color-cyan-subtle))]",
  warning: "[--track:color-mix(in_oklab,var(--color-warning)_28%,var(--color-warning-subtle))]",
  success: "[--track:color-mix(in_oklab,var(--color-success)_28%,var(--color-success-subtle))]",
}

type Tile = {
  title: string
  value: string
  unit: string
  icon: DigIconName
  tone: string
  // حلقه (ring)، میله‌ها (bars) یا نمودارِ خطی (sparkline)؛ در نسخهٔ React اینها زیرکامپوننت‌های همان فایل‌اند.
  chart: { kind: "ring"; value: number; color: string; track: string } | { kind: "bars"; values: number[]; className: string } | { kind: "sparkline"; values: number[] }
}

const TILES: Tile[] = [
  {
    title: "کالری",
    value: formatNumber(1_839),
    unit: "کیلوکالری",
    icon: "flame",
    tone: `bg-orange-subtle text-orange ${TRACK.orange}`,
    chart: { kind: "ring", value: 72, color: "var(--orange)", track: "color-mix(in oklab, var(--orange) 26%, var(--orange-subtle))" },
  },
  {
    title: "آب",
    value: formatNumber(1_200),
    unit: "میلی‌لیتر",
    icon: "droplet",
    tone: `bg-cyan-subtle text-cyan ${TRACK.cyan}`,
    chart: { kind: "ring", value: 60, color: "var(--cyan)", track: "color-mix(in oklab, var(--cyan) 26%, var(--cyan-subtle))" },
  },
  {
    title: "خواب",
    value: toFaDigits("7:30"),
    unit: "ساعت",
    icon: "moon",
    tone: `bg-warning-subtle text-warning-subtle-foreground ${TRACK.warning}`,
    chart: { kind: "bars", values: [5, 6.5, 6, 8, 5.5, 7, 7.5], className: "text-warning-subtle-foreground" },
  },
  {
    title: "وزن",
    value: formatNumber(68),
    unit: "کیلوگرم",
    icon: "activity",
    tone: `bg-success-subtle text-success-subtle-foreground ${TRACK.success}`,
    chart: { kind: "sparkline", values: [70, 69.6, 69.8, 69.1, 68.7, 68.9, 68.2, 68] },
  },
]

const PLAN = [
  { time: "۰۷:۳۰", title: "پیاده‌روی صبح", detail: "۳۰ دقیقه · ۲٫۵ کیلومتر", done: true },
  { time: "۱۳:۰۰", title: "ناهار سبک", detail: "۶۵۰ کیلوکالری", done: true },
  { time: "۱۸:۳۰", title: "یوگا", detail: "۴۵ دقیقه", done: false },
]

const tab = ref("activity")
</script>

<template>
  <!-- قابِ اپ: در موبایل تمام‌صفحه، در دسکتاپ ستونی به عرضِ گوشی. -->
  <ControlSize size="xl" as-child>
    <div class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <AppBar sticky>
        <Avatar alt="آرمیتا رستگار" size="sm" />
        <AppBarTitle>سلام آرمیتا</AppBarTitle>
        <AppBarActions>
          <Button variant="ghost" size="icon" aria-label="اعلان‌ها">
            <DigIcon name="bell" />
          </Button>
        </AppBarActions>
      </AppBar>

      <main class="flex flex-1 flex-col gap-5 p-4">
        <section aria-labelledby="today" class="flex flex-col gap-3">
          <div class="flex items-baseline justify-between">
            <h1 id="today" class="text-lg font-bold">امروز</h1>
            <span class="text-sm text-muted-foreground">۷۲٪ هدف روزانه</span>
          </div>
          <div class="grid grid-cols-2 gap-3">
            <article v-for="tile in TILES" :key="tile.title" :class="`flex flex-col gap-3 rounded-xl p-4 ${tile.tone}`">
              <div class="flex items-center gap-2 text-foreground">
                <span aria-hidden="true" :class="`[&_svg]:size-5 ${tile.tone.split(' ')[1]}`">
                  <DigIcon :name="tile.icon" />
                </span>
                <h2 class="font-semibold">{{ tile.title }}</h2>
              </div>
              <div class="flex items-end justify-between gap-2">
                <div class="flex flex-col text-foreground">
                  <span class="text-2xl font-bold">{{ tile.value }}</span>
                  <span class="text-xs text-muted-foreground">{{ tile.unit }}</span>
                </div>
                <!-- حلقهٔ پیشرفت: همان StatTileRing با دو بخش (پیشرفت و باقی‌مانده). -->
                <StatTileRing
                  v-if="tile.chart.kind === 'ring'"
                  role="img"
                  :aria-label="`${toFaDigits(tile.chart.value)} درصد از هدف`"
                  class="size-14 shrink-0"
                  :segments="[
                    { value: tile.chart.value, color: tile.chart.color },
                    { value: 100 - tile.chart.value, color: tile.chart.track },
                  ]"
                />
                <div v-else-if="tile.chart.kind === 'bars'" :class="`flex h-14 items-end gap-1 ${tile.chart.className}`" aria-hidden="true">
                  <!-- امروز (آخرین میله) پررنگ؛ بقیه رنگِ میانی. -->
                  <span
                    v-for="(value, index) in tile.chart.values"
                    :key="index"
                    :class="index === tile.chart.values.length - 1 ? 'w-1.5 rounded-full bg-current' : 'w-1.5 rounded-full bg-(--track)'"
                    :style="{ height: `${(value / Math.max(...tile.chart.values)) * 100}%` }"
                  />
                </div>
                <StatTileSparkline v-else :values="tile.chart.values" class="h-14 w-24" />
              </div>
            </article>
          </div>
        </section>

        <section aria-labelledby="plan" class="flex flex-col gap-3">
          <h2 id="plan" class="font-bold">برنامهٔ امروز</h2>
          <ol class="flex flex-col gap-2">
            <li v-for="item in PLAN" :key="item.title" class="flex items-center gap-3 rounded-xl border border-border p-3">
              <!-- تیک برای انجام‌شده؛ متن خط نمی‌خورد تا خوانا بماند. -->
              <span
                :class="
                  item.done
                    ? 'flex size-8 shrink-0 items-center justify-center rounded-full bg-success-subtle text-success-subtle-foreground [&_svg]:size-4'
                    : 'size-8 shrink-0 rounded-full border-2 border-dashed border-border'
                "
                role="img"
                :aria-label="item.done ? 'انجام شد' : 'انجام نشده'"
              >
                <DigIcon v-if="item.done" name="check" />
              </span>
              <div class="flex min-w-0 flex-1 flex-col">
                <span class="font-medium">{{ item.title }}</span>
                <span class="text-xs text-muted-foreground">{{ item.detail }}</span>
              </div>
              <span class="shrink-0 text-sm text-muted-foreground">{{ item.time }}</span>
            </li>
          </ol>
        </section>
      </main>

      <BottomNavigation v-model:value="tab" indicator="pill" :fixed="false" class="sticky bottom-0">
        <BottomNavigationItem value="activity" label="فعالیت">
          <template #icon><DigIcon name="activity" /></template>
        </BottomNavigationItem>
        <BottomNavigationItem value="fitness" label="تمرین">
          <template #icon><DigIcon name="heart" /></template>
        </BottomNavigationItem>
        <BottomNavigationItem value="plans" label="برنامه">
          <template #icon><DigIcon name="calendar" /></template>
        </BottomNavigationItem>
        <BottomNavigationItem value="progress" label="پیشرفت">
          <template #icon><DigIcon name="bar-chart" /></template>
        </BottomNavigationItem>
      </BottomNavigation>
    </div>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: app-baravatarbottom-navigationcontrol-sizepersianstat-tileآیکون activityآیکون bar-chartآیکون bellآیکون calendarآیکون checkآیکون dropletآیکون flameآیکون heartآیکون moon

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

mobile-health.ts
import { Component, ChangeDetectionStrategy, signal } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigAppBar, DigAppBarTitle, DigAppBarActions } from "@/components/ui/app-bar"
import { DigAvatar } from "@/components/ui/avatar"
import { DigButton } from "@/components/ui/button"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { DigStatTileRing, DigStatTileSparkline } from "@/components/ui/stat-tile"
import {
  DigBottomNavigation,
  DigBottomNavigationItem,
  DigBottomNavigationActiveIcon,
  DigBottomNavigationBadge,
} from "@/components/ui/bottom-navigation"
import { formatNumber, toFaDigits } from "@/lib/persian"

const TRACK: Record<string, string> = {
  orange: "[--track:color-mix(in_oklab,var(--color-orange)_28%,var(--color-orange-subtle))]",
  cyan: "[--track:color-mix(in_oklab,var(--color-cyan)_28%,var(--color-cyan-subtle))]",
  warning: "[--track:color-mix(in_oklab,var(--color-warning)_28%,var(--color-warning-subtle))]",
  success: "[--track:color-mix(in_oklab,var(--color-success)_28%,var(--color-success-subtle))]",
}

type Tile = {
  title: string
  value: string
  unit: string
  icon: DigIconName
  tone: string
  // حلقه (ring)، میله‌ها (bars) یا نمودارِ خطی (sparkline)؛ در نسخهٔ React اینها زیرکامپوننت‌های همان فایل‌اند.
  chart:
    | { kind: "ring"; value: number; color: string; track: string }
    | { kind: "bars"; values: number[]; className: string }
    | { kind: "sparkline"; values: number[] }
}

const TILES: Tile[] = [
  {
    title: "کالری",
    value: formatNumber(1_839),
    unit: "کیلوکالری",
    icon: "flame" as const,
    tone: `bg-orange-subtle text-orange ${TRACK.orange}`,
    chart: {
      kind: "ring",
      value: 72,
      color: "var(--orange)",
      track: "color-mix(in oklab, var(--orange) 26%, var(--orange-subtle))",
    },
  },
  {
    title: "آب",
    value: formatNumber(1_200),
    unit: "میلی‌لیتر",
    icon: "droplet" as const,
    tone: `bg-cyan-subtle text-cyan ${TRACK.cyan}`,
    chart: {
      kind: "ring",
      value: 60,
      color: "var(--cyan)",
      track: "color-mix(in oklab, var(--cyan) 26%, var(--cyan-subtle))",
    },
  },
  {
    title: "خواب",
    value: toFaDigits("7:30"),
    unit: "ساعت",
    icon: "moon" as const,
    tone: `bg-warning-subtle text-warning-subtle-foreground ${TRACK.warning}`,
    chart: { kind: "bars", values: [5, 6.5, 6, 8, 5.5, 7, 7.5], className: "text-warning-subtle-foreground" },
  },
  {
    title: "وزن",
    value: formatNumber(68),
    unit: "کیلوگرم",
    icon: "activity" as const,
    tone: `bg-success-subtle text-success-subtle-foreground ${TRACK.success}`,
    chart: { kind: "sparkline", values: [70, 69.6, 69.8, 69.1, 68.7, 68.9, 68.2, 68] },
  },
]

const PLAN = [
  { time: "۰۷:۳۰", title: "پیاده‌روی صبح", detail: "۳۰ دقیقه · ۲٫۵ کیلومتر", done: true },
  { time: "۱۳:۰۰", title: "ناهار سبک", detail: "۶۵۰ کیلوکالری", done: true },
  { time: "۱۸:۳۰", title: "یوگا", detail: "۴۵ دقیقه", done: false },
]

@Component({
  selector: "dig-block-mobile-health",
  imports: [
    DigControlSize,
    DigAppBar,
    DigAppBarTitle,
    DigAppBarActions,
    DigAvatar,
    DigButton,
    DigIcon,
    DigStatTileRing,
    DigStatTileSparkline,
    DigBottomNavigation,
    DigBottomNavigationItem,
    DigBottomNavigationActiveIcon,
    DigBottomNavigationBadge,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <!-- قابِ اپ: در موبایل تمام‌صفحه، در دسکتاپ ستونی به عرضِ گوشی. -->
    <div digControlSize="xl" class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
      <header digAppBar sticky>
        <span digAvatar alt="آرمیتا رستگار" size="sm"></span>
        <h1 digAppBarTitle>سلام آرمیتا</h1>
        <div digAppBarActions>
          <button digButton type="button" variant="ghost" size="icon" aria-label="اعلان‌ها">
            <svg digIcon="bell"></svg>
          </button>
        </div>
      </header>

      <main class="flex flex-1 flex-col gap-5 p-4">
        <section aria-labelledby="today" class="flex flex-col gap-3">
          <div class="flex items-baseline justify-between">
            <h1 id="today" class="text-lg font-bold">امروز</h1>
            <span class="text-sm text-muted-foreground">۷۲٪ هدف روزانه</span>
          </div>
          <div class="grid grid-cols-2 gap-3">
            @for (tile of TILES; track tile.title) {
              <article [class]="\`flex flex-col gap-3 rounded-xl p-4 \${tile.tone}\`">
                <div class="flex items-center gap-2 text-foreground">
                  <span aria-hidden="true" [class]="\`[&_svg]:size-5 \${tile.tone.split(' ')[1]}\`"
                    ><svg [digIcon]="tile.icon"></svg
                  ></span>
                  <h2 class="font-semibold">{{ tile.title }}</h2>
                </div>
                <div class="flex items-end justify-between gap-2">
                  <div class="flex flex-col text-foreground">
                    <span class="text-2xl font-bold">{{ tile.value }}</span>
                    <span class="text-xs text-muted-foreground">{{ tile.unit }}</span>
                  </div>
                  <!-- حلقهٔ پیشرفت: همان StatTileRing با دو بخش (پیشرفت و باقی‌مانده). -->
                  @if (tile.chart.kind === "ring") {
                    <div
                      digStatTileRing
                      role="img"
                      [attr.aria-label]="\`\${toFaDigits(tile.chart.value)} درصد از هدف\`"
                      class="size-14 shrink-0"
                      [segments]="[
                        { value: tile.chart.value, color: tile.chart.color },
                        { value: 100 - tile.chart.value, color: tile.chart.track },
                      ]"
                    ></div>
                  } @else if (tile.chart.kind === "bars") {
                    <div [class]="\`flex h-14 items-end gap-1 \${tile.chart.className}\`" aria-hidden="true">
                      <!-- امروز (آخرین میله) پررنگ؛ بقیه رنگِ میانی. -->
                      @for (value of tile.chart.values; track $index; let index = $index) {
                        <span
                          [class]="
                            index === tile.chart.values.length - 1
                              ? 'w-1.5 rounded-full bg-current'
                              : 'w-1.5 rounded-full bg-(--track)'
                          "
                          [style]="{ height: \`\${(value / math.max(...tile.chart.values)) * 100}%\` }"
                        ></span>
                      }
                    </div>
                  } @else {
                    <svg digStatTileSparkline [values]="tile.chart.values" class="h-14 w-24"></svg>
                  }
                </div>
              </article>
            }
          </div>
        </section>

        <section aria-labelledby="plan" class="flex flex-col gap-3">
          <h2 id="plan" class="font-bold">برنامهٔ امروز</h2>
          <ol class="flex flex-col gap-2">
            @for (item of PLAN; track item.title) {
              <li class="flex items-center gap-3 rounded-xl border border-border p-3">
                <!-- تیک برای انجام‌شده؛ متن خط نمی‌خورد تا خوانا بماند. -->
                <span
                  [class]="
                    item.done
                      ? 'flex size-8 shrink-0 items-center justify-center rounded-full bg-success-subtle text-success-subtle-foreground [&_svg]:size-4'
                      : 'size-8 shrink-0 rounded-full border-2 border-dashed border-border'
                  "
                  role="img"
                  [attr.aria-label]="item.done ? 'انجام شد' : 'انجام نشده'"
                >
                  @if (item.done) {
                    <svg digIcon="check"></svg>
                  }
                </span>
                <div class="flex min-w-0 flex-1 flex-col">
                  <span class="font-medium">{{ item.title }}</span>
                  <span class="text-xs text-muted-foreground">{{ item.detail }}</span>
                </div>
                <span class="shrink-0 text-sm text-muted-foreground">{{ item.time }}</span>
              </li>
            }
          </ol>
        </section>
      </main>

      <nav
        digBottomNavigation
        [value]="tab()"
        (valueChange)="typeof $event === 'string' && tab.set($event)"
        indicator="pill"
        [fixed]="false"
        class="sticky bottom-0"
      >
        <button digBottomNavigationItem value="activity" label="فعالیت"><svg digIcon="activity"></svg></button>
        <button digBottomNavigationItem value="fitness" label="تمرین"><svg digIcon="heart"></svg></button>
        <button digBottomNavigationItem value="plans" label="برنامه"><svg digIcon="calendar"></svg></button>
        <button digBottomNavigationItem value="progress" label="پیشرفت"><svg digIcon="bar-chart"></svg></button>
      </nav>
    </div>
  `,
})
export class MobileHealthBlock {
  readonly math = Math

  readonly toFaDigits = toFaDigits

  readonly PLAN = PLAN

  readonly TILES = TILES

  readonly tab = signal("activity")
}
MobileHealthScreen.kt
package ir.digdesign.compose.demo.blocks

// sync: src/blocks/mobile-health.tsx

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import ir.digdesign.compose.Avatar
import ir.digdesign.compose.AvatarSize
import ir.digdesign.compose.Button
import ir.digdesign.compose.ButtonSize
import ir.digdesign.compose.ButtonVariant
import ir.digdesign.compose.ControlSize
import ir.digdesign.compose.ControlSizeProvider
import ir.digdesign.compose.DigIcon
import ir.digdesign.compose.DigIcons
import ir.digdesign.compose.DigNavigationBar
import ir.digdesign.compose.DigNavigationIndicator
import ir.digdesign.compose.DigNavigationItem
import ir.digdesign.compose.DigRadius
import ir.digdesign.compose.DigSpacing
import ir.digdesign.compose.DigText
import ir.digdesign.compose.DigTheme
import ir.digdesign.compose.DigTopAppBar
import ir.digdesign.compose.StatTileRing
import ir.digdesign.compose.StatTileSegment
import ir.digdesign.compose.StatTileSparkline
import ir.digdesign.compose.TypographyLarge
import ir.digdesign.compose.formatNumber
import ir.digdesign.compose.toFaDigits

private class HealthTile(
    val title: String,
    val value: String,
    val unit: String,
    val icon: ImageVector,
    val tone: HealthTone,
    val chart: @Composable (HealthTone) -> Unit,
)

private enum class HealthTone { Orange, Cyan, Amber, Green }

private class PlanItem(val time: String, val title: String, val detail: String, val done: Boolean)

private val TodayPlan = listOf(
    PlanItem("۰۷:۳۰", "پیاده‌روی صبح", "۳۰ دقیقه · ۲٫۵ کیلومتر", true),
    PlanItem("۱۳:۰۰", "ناهار سبک", "۶۵۰ کیلوکالری", true),
    PlanItem("۱۸:۳۰", "یوگا", "۴۵ دقیقه", false),
)

private val SleepHours = listOf(5f, 6.5f, 6f, 8f, 5.5f, 7f, 7.5f)

private val Tiles = listOf(
    HealthTile("کالری", formatNumber(1_839L), "کیلوکالری", DigIcons.Danger, HealthTone.Orange) { Ring(72f, it) },
    HealthTile("آب", formatNumber(1_200L), "میلی‌لیتر", DigIcons.Info, HealthTone.Cyan) { Ring(60f, it) },
    HealthTile("خواب", "۷:۳۰", "ساعت", DigIcons.ClockCircle, HealthTone.Amber) { Bars(SleepHours, it) },
    HealthTile("وزن", formatNumber(68L), "کیلوگرم", DigIcons.User, HealthTone.Green) {
        StatTileSparkline(listOf(70f, 69.6f, 69.8f, 69.1f, 68.7f, 68.9f, 68.2f, 68f), Modifier.height(56.dp).width(96.dp), color = it.main())
    },
)

/** داشبوردِ سلامت: چهار کاشیِ امروز (کالری، آب، خواب، وزن)، برنامهٔ امروز با وضعیتِ انجام و ناوبریِ پایین. */
@Composable
fun MobileHealthScreen() {
    var tab by remember { mutableStateOf("activity") }
    val colors = DigTheme.colors

    Box(
        Modifier.fillMaxSize().background(colors.background).safeDrawingPadding(),
        contentAlignment = Alignment.TopCenter,
    ) {
        ControlSizeProvider(ControlSize.Xl) {
            Column(Modifier.widthIn(max = 480.dp).fillMaxWidth().fillMaxHeight()) {
                DigTopAppBar(
                    title = "سلام آرمیتا",
                    windowInsets = WindowInsets(),
                    navigationIcon = { Avatar(name = "آرمیتا رستگار", size = AvatarSize.Sm) },
                    actions = {
                        Button(onClick = {}, variant = ButtonVariant.Ghost, size = ButtonSize.Icon, contentDescription = "اعلان‌ها") {
                            DigIcon(DigIcons.NotificationBell, contentDescription = null)
                        }
                    },
                )
                Column(
                    Modifier.weight(1f).verticalScroll(rememberScrollState()).padding(DigSpacing * 4),
                    verticalArrangement = Arrangement.spacedBy(DigSpacing * 5),
                ) {
                    Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
                        Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom) {
                            TypographyLarge("امروز", Modifier.semantics { heading() })
                            Txt("۷۲٪ هدف روزانه")
                        }
                        Tiles.chunked(2).forEach { pair ->
                            Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
                                pair.forEach { tile -> TileCard(tile, Modifier.weight(1f)) }
                            }
                        }
                    }
                    Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
                        TypographyLarge("برنامهٔ امروز", Modifier.semantics { heading() })
                        TodayPlan.forEach { item -> PlanRow(item) }
                    }
                }
                DigNavigationBar(indicator = DigNavigationIndicator.Pill, windowInsets = WindowInsets()) {
                    DigNavigationItem(tab == "activity", { tab = "activity" }, { DigIcon(DigIcons.ClockCircle, contentDescription = null) }, "فعالیت")
                    DigNavigationItem(tab == "fitness", { tab = "fitness" }, { DigIcon(DigIcons.BadgeStar, contentDescription = null) }, "تمرین")
                    DigNavigationItem(tab == "plans", { tab = "plans" }, { DigIcon(DigIcons.Calendar, contentDescription = null) }, "برنامه")
                    DigNavigationItem(tab == "progress", { tab = "progress" }, { DigIcon(DigIcons.VerifiedUser, contentDescription = null) }, "پیشرفت")
                }
            }
        }
    }
}

@Composable
private fun HealthTone.main(): Color = when (this) {
    HealthTone.Orange -> DigTheme.colors.orange
    HealthTone.Cyan -> DigTheme.colors.cyan
    HealthTone.Amber -> DigTheme.colors.warning
    HealthTone.Green -> DigTheme.colors.success
}

@Composable
private fun HealthTone.subtle(): Color = when (this) {
    HealthTone.Orange -> DigTheme.colors.orangeSubtle
    HealthTone.Cyan -> DigTheme.colors.cyanSubtle
    HealthTone.Amber -> DigTheme.colors.warningSubtle
    HealthTone.Green -> DigTheme.colors.successSubtle
}

@Composable
private fun TileCard(tile: HealthTile, modifier: Modifier = Modifier) {
    val colors = DigTheme.colors
    Column(
        modifier.clip(RoundedCornerShape(DigRadius.xl)).background(tile.tone.subtle()).padding(DigSpacing * 4),
        verticalArrangement = Arrangement.spacedBy(DigSpacing * 3),
    ) {
        Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(DigSpacing * 2)) {
            DigIcon(tile.icon, contentDescription = null, size = 20.dp, tint = tile.tone.main())
            Txt(tile.title, size = DigText.sm, color = colors.foreground, weight = FontWeight.SemiBold)
        }
        Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.Bottom) {
            Column {
                TypographyLarge(tile.value)
                Txt(tile.unit, size = DigText.xs)
            }
            tile.chart(tile.tone)
        }
    }
}

/** حلقهٔ پیشرفت: دو بخش (پیشرفت و باقی‌مانده)؛ مقدارش برای TalkBack خوانده می‌شود. */
@Composable
private fun Ring(value: Float, tone: HealthTone) {
    StatTileRing(
        segments = listOf(StatTileSegment(value, tone.main()), StatTileSegment(100f - value, DigTheme.colors.background)),
        modifier = Modifier.size(56.dp).semantics { contentDescription = "${toFaDigits(value.toInt())} درصد از هدف" },
    )
}

/** میله‌های هفتگی؛ امروز (آخرین میله) پررنگ و بقیه رنگ زمینه. */
@Composable
private fun Bars(values: List<Float>, tone: HealthTone) {
    val top = values.max()
    Row(Modifier.height(56.dp).clearAndSetSemantics { }, horizontalArrangement = Arrangement.spacedBy(DigSpacing), verticalAlignment = Alignment.Bottom) {
        values.forEachIndexed { index, value ->
            Box(
                Modifier
                    .width(DigSpacing + DigSpacing / 2)
                    .height(56.dp * (value / top))
                    .clip(RoundedCornerShape(DigRadius.xl))
                    .background(if (index == values.lastIndex) tone.main() else DigTheme.colors.background),
            )
        }
    }
}

@Composable
private fun PlanRow(item: PlanItem) {
    val colors = DigTheme.colors
    Row(
        Modifier.fillMaxWidth().clip(RoundedCornerShape(DigRadius.xl)).border(1.dp, colors.border, RoundedCornerShape(DigRadius.xl)).padding(DigSpacing * 3),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3),
    ) {
        // تیک برای انجام‌شده، دایرهٔ خالی برای نشده؛ وضعیت با شکل و متنِ TalkBack هم گفته می‌شود نه فقط رنگ.
        Box(
            Modifier
                .size(32.dp)
                .clip(CircleShape)
                .background(if (item.done) colors.successSubtle else colors.background)
                .then(if (item.done) Modifier else Modifier.border(2.dp, colors.border, CircleShape))
                .semantics { contentDescription = if (item.done) "انجام شد" else "انجام نشده" },
            contentAlignment = Alignment.Center,
        ) {
            if (item.done) DigIcon(DigIcons.Tick, contentDescription = null, tint = colors.successSubtleForeground)
        }
        Column(Modifier.weight(1f)) {
            Txt(item.title, size = DigText.sm, color = colors.foreground, weight = FontWeight.Medium)
            Txt(item.detail, size = DigText.xs)
        }
        Txt(item.time)
    }
}

@Composable
private fun Txt(
    text: String,
    modifier: Modifier = Modifier,
    size: TextUnit = DigText.sm,
    color: Color = DigTheme.colors.mutedForeground,
    weight: FontWeight = FontWeight.Normal,
    align: TextAlign = TextAlign.Start,
    maxLines: Int = Int.MAX_VALUE,
) {
    BasicText(
        text,
        modifier,
        style = TextStyle(
            color = color,
            fontFamily = DigTheme.fontFamily,
            fontSize = size,
            fontWeight = weight,
            lineHeight = size * DigText.lineHeightBase,
            textAlign = align,
        ),
        maxLines = maxLines,
        overflow = TextOverflow.Ellipsis,
    )
}