ریاکت ۱۹ و Next.js با پیادهسازی دسترسپذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده
کاوشِ اپ خبری
پیشنمایش تمامصفحهتیترِ بزرگ و جستوجو، «داغِ امروز» با کارتهای شمارهدارِ اسکرولخور، موضوعها با # و بازارها با نماد، درصدِ تغییرِ رنگی و عکس.
۱. نصب کامپوننتها
این بلاک از ۶ آیتم دیگ استفاده میکند: bottom-navigationbuttoncontrol-sizeiconspersiansearch-field
پکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add 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/search-field.jsonpnpm dlx digdesign@latest add 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/search-field.jsonyarn dlx digdesign@latest add 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/search-field.jsonbunx --bun digdesign@latest add 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/search-field.jsonپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add bottom-navigation button control-size persian search-field --framework vuepnpm dlx digdesign@latest add bottom-navigation button control-size persian search-field --framework vueyarn dlx digdesign@latest add bottom-navigation button control-size persian search-field --framework vuebunx --bun digdesign@latest add bottom-navigation button control-size persian search-field --framework vueپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx 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 svelteپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add bottom-navigation button control-size icons persian search-field --framework angularpnpm dlx digdesign@latest add bottom-navigation button control-size icons persian search-field --framework angularyarn dlx digdesign@latest add bottom-navigation button control-size icons persian search-field --framework angularbunx --bun digdesign@latest add bottom-navigation button control-size icons persian search-field --framework angularپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add bottom-navigation button control-size persian search-field --framework androidpnpm dlx digdesign@latest add bottom-navigation button control-size persian search-field --framework androidyarn dlx digdesign@latest add bottom-navigation button control-size persian search-field --framework androidbunx --bun digdesign@latest add bottom-navigation button control-size persian search-field --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
mobile-news-explore.tsx
"use client"
import * as React from "react"
import { DashboardIcon, HeartIcon, SearchIcon, TrendingDownIcon, TrendingUpIcon, UserIcon } from "@/components/icons"
import { BottomNavigation, BottomNavigationItem } from "@/components/ui/bottom-navigation"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { SearchField } from "@/components/ui/search-field"
import { toFaDigits } from "@/lib/persian"
import { stockImages, type StockImageName } from "@/lib/stock-images"
const TRENDING = [
{ id: "t1", title: "قیمتِ مسکن در پاییز؛ خریدارها منتظر میمانند", hours: 2, minutes: 4 },
{ id: "t2", title: "سه اپِ تازه که پسانداز را بازی کردهاند", hours: 3, minutes: 3 },
{ id: "t3", title: "مالیاتِ کسبوکارهای خانگی، به زبانِ ساده", hours: 5, minutes: 6 },
]
const TOPICS = ["طلا", "بورس", "مسکن", "رمزارز", "استارتاپ", "خودرو", "بیمه"]
const MARKETS: { id: string; symbol: string; change: number; title: string; image: StockImageName }[] = [
{ id: "m1", symbol: "طلای ۱۸", change: 1.2, title: "طلا سه روزِ پشتِسرِهم بالا رفت؛ تحلیلگرها محتاطاند", image: "coverFinanceDesk" },
{ id: "m2", symbol: "شاخص کل", change: -0.8, title: "بورس بعد از رشدِ هفتهٔ پیش کمی عقب نشست", image: "projectDashboard" },
{ id: "m3", symbol: "دلار", change: 0.3, title: "بازارِ ارز آرام؛ معاملهها کمحجم ماند", image: "coverCalculator" },
]
/**
* کاوشِ اپِ خبری: تیترِ بزرگ و جستوجوی تمامعرض، «داغِ امروز» با کارتهای شمارهدارِ اسکرولخور
* (عددِ درشت، تیتر، زمان)، موضوعها با برچسبِ # و «بازارها» با نمادِ هر بازار، درصدِ تغییر به
* کلمه و رنگ (بالا/پایین)، تیتر و عکسِ کوچک.
*/
export default function MobileNewsExploreBlock() {
const [query, setQuery] = React.useState("")
const [tab, setTab] = React.useState("explore")
return (
<ControlSizeProvider size="xl" asChild>
<div className="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
<main className="flex flex-1 flex-col gap-8 pt-6 pb-6">
<header className="flex flex-col gap-4 px-4">
<h1 className="text-3xl leading-snug font-black">کاوش</h1>
<SearchField aria-label="جستوجوی خبر" placeholder="خبر، نویسنده یا موضوع" value={query} onValueChange={setQuery} />
</header>
<section aria-labelledby="hot-title" className="flex flex-col gap-3">
<h2 id="hot-title" className="px-4 text-sm font-bold text-muted-foreground">
# داغِ امروز
</h2>
<ol className="flex snap-x snap-mandatory gap-3 overflow-x-auto scroll-px-4 px-4 [scrollbar-width:none]">
{TRENDING.map((item, index) => (
<li key={item.id} className="relative flex w-64 shrink-0 snap-start flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-card">
<span aria-hidden className="text-3xl leading-none font-black text-[var(--dig-orange-600)] dark:text-[var(--dig-orange-400)]">
#{toFaDigits(index + 1)}
</span>
<h3 className="line-clamp-3 min-h-18 leading-6 font-bold">
<a href="#" className="after:absolute after:inset-0">
{item.title}
</a>
</h3>
<span className="text-xs text-muted-foreground">
{toFaDigits(item.hours)} ساعت پیش · {toFaDigits(item.minutes)} دقیقه مطالعه
</span>
</li>
))}
</ol>
</section>
<section aria-labelledby="topics-title" className="flex flex-col gap-3 px-4">
<h2 id="topics-title" className="text-sm font-bold text-muted-foreground">
# موضوعها
</h2>
<ControlSizeProvider size="lg" className="flex flex-wrap gap-2">
{TOPICS.map((topic) => (
<Button key={topic} variant="secondary" className="rounded-full px-4">
#{topic}
</Button>
))}
</ControlSizeProvider>
</section>
<section aria-labelledby="markets-title" className="flex flex-col gap-1 px-4">
<h2 id="markets-title" className="text-sm font-bold text-muted-foreground">
# بازارها
</h2>
<ul className="flex flex-col divide-y divide-border">
{MARKETS.map((item) => {
const up = item.change >= 0
return (
<li key={item.id} className="relative flex items-center gap-3 py-4">
<div className="flex min-w-0 flex-1 flex-col gap-2">
<span className="flex w-fit items-center gap-2 rounded-full border border-border px-2.5 py-1 text-xs">
<span className="font-semibold">{item.symbol}</span>
<span className={`flex items-center gap-0.5 font-bold tabular-nums [&>svg]:size-3.5 ${up ? "text-success-subtle-foreground" : "text-destructive"}`}>
{up ? <TrendingUpIcon aria-hidden /> : <TrendingDownIcon aria-hidden />}
<span className="sr-only">{up ? "رشد" : "افت"}</span>
{toFaDigits(String(Math.abs(item.change)).replace(".", "٫"))}٪
</span>
</span>
<h3 className="line-clamp-2 leading-6 font-semibold">
<a href="#" className="after:absolute after:inset-0">
{item.title}
</a>
</h3>
</div>
{/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
<img src={stockImages[item.image].src} alt="" loading="lazy" className="size-16 shrink-0 rounded-lg object-cover" />
</li>
)
})}
</ul>
</section>
</main>
<BottomNavigation value={tab} onValueChange={setTab} indicator="pill" fixed={false} className="sticky bottom-0">
<BottomNavigationItem value="home" icon={<DashboardIcon />} label="خانه" />
<BottomNavigationItem value="explore" icon={<SearchIcon />} label="کاوش" />
<BottomNavigationItem value="saved" icon={<HeartIcon />} label="ذخیرهها" />
<BottomNavigationItem value="profile" icon={<UserIcon />} label="پروفایل" />
</BottomNavigation>
</div>
</ControlSizeProvider>
)
}
mobile-news-explore.vue
<script setup lang="ts">
import { ref } from "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 SearchField from "@/components/ui/SearchField.vue"
import { DigIcon } from "@/lib/icons"
import { toFaDigits } from "@/lib/persian"
// stock-images:begin
/** تصویرهای کتابخانهٔ دیگ (همان آدرسهای `stockImages` نسخهٔ React). */
const stockImages: Record<string, { src: string; alt: string }> = {
coverFinanceDesk: { src: "https://docs.digdesign.ir/images/cover-finance-desk.webp", alt: "میزِ کار با موبایل، ماشینحساب و نمودارهای مالی" },
projectDashboard: { src: "https://docs.digdesign.ir/images/project-dashboard.webp", alt: "لپتاپ با نمودارهای تحلیلی" },
coverCalculator: { src: "https://docs.digdesign.ir/images/cover-calculator.webp", alt: "ماشینحساب، عینک و جامدادی روی میزِ سفید" },
}
// stock-images:end
const TRENDING = [
{ id: "t1", title: "قیمتِ مسکن در پاییز؛ خریدارها منتظر میمانند", hours: 2, minutes: 4 },
{ id: "t2", title: "سه اپِ تازه که پسانداز را بازی کردهاند", hours: 3, minutes: 3 },
{ id: "t3", title: "مالیاتِ کسبوکارهای خانگی، به زبانِ ساده", hours: 5, minutes: 6 },
]
const TOPICS = ["طلا", "بورس", "مسکن", "رمزارز", "استارتاپ", "خودرو", "بیمه"]
const MARKETS: { id: string; symbol: string; change: number; title: string; image: string }[] = [
{ id: "m1", symbol: "طلای ۱۸", change: 1.2, title: "طلا سه روزِ پشتِسرِهم بالا رفت؛ تحلیلگرها محتاطاند", image: "coverFinanceDesk" },
{ id: "m2", symbol: "شاخص کل", change: -0.8, title: "بورس بعد از رشدِ هفتهٔ پیش کمی عقب نشست", image: "projectDashboard" },
{ id: "m3", symbol: "دلار", change: 0.3, title: "بازارِ ارز آرام؛ معاملهها کمحجم ماند", image: "coverCalculator" },
]
/**
* کاوشِ اپِ خبری: تیترِ بزرگ و جستوجوی تمامعرض، «داغِ امروز» با کارتهای شمارهدارِ اسکرولخور
* (عددِ درشت، تیتر، زمان)، موضوعها با برچسبِ # و «بازارها» با نمادِ هر بازار، درصدِ تغییر به
* کلمه و رنگ (بالا/پایین)، تیتر و عکسِ کوچک. همان صفحهٔ `mobile-news-explore` نسخهٔ React.
*/
const query = ref("")
const tab = ref("explore")
</script>
<template>
<ControlSize size="xl" as-child>
<div class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
<main class="flex flex-1 flex-col gap-8 pt-6 pb-6">
<header class="flex flex-col gap-4 px-4">
<h1 class="text-3xl leading-snug font-black">کاوش</h1>
<SearchField v-model="query" aria-label="جستوجوی خبر" placeholder="خبر، نویسنده یا موضوع" />
</header>
<section aria-labelledby="hot-title" class="flex flex-col gap-3">
<h2 id="hot-title" class="px-4 text-sm font-bold text-muted-foreground"># داغِ امروز</h2>
<ol class="flex snap-x snap-mandatory gap-3 overflow-x-auto scroll-px-4 px-4 [scrollbar-width:none]">
<li v-for="(item, index) in TRENDING" :key="item.id" class="relative flex w-64 shrink-0 snap-start flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-card">
<span aria-hidden="true" class="text-3xl leading-none font-black text-[var(--dig-orange-600)] dark:text-[var(--dig-orange-400)]">#{{ toFaDigits(index + 1) }}</span>
<h3 class="line-clamp-3 min-h-18 leading-6 font-bold">
<a href="#" class="after:absolute after:inset-0">{{ item.title }}</a>
</h3>
<span class="text-xs text-muted-foreground">{{ toFaDigits(item.hours) }} ساعت پیش · {{ toFaDigits(item.minutes) }} دقیقه مطالعه</span>
</li>
</ol>
</section>
<section aria-labelledby="topics-title" class="flex flex-col gap-3 px-4">
<h2 id="topics-title" class="text-sm font-bold text-muted-foreground"># موضوعها</h2>
<ControlSize size="lg" class="flex flex-wrap gap-2">
<Button v-for="topic in TOPICS" :key="topic" variant="secondary" class="rounded-full px-4">#{{ topic }}</Button>
</ControlSize>
</section>
<section aria-labelledby="markets-title" class="flex flex-col gap-1 px-4">
<h2 id="markets-title" class="text-sm font-bold text-muted-foreground"># بازارها</h2>
<ul class="flex flex-col divide-y divide-border">
<li v-for="item in MARKETS" :key="item.id" class="relative flex items-center gap-3 py-4">
<div class="flex min-w-0 flex-1 flex-col gap-2">
<span class="flex w-fit items-center gap-2 rounded-full border border-border px-2.5 py-1 text-xs">
<span class="font-semibold">{{ item.symbol }}</span>
<span :class="`flex items-center gap-0.5 font-bold tabular-nums [&>svg]:size-3.5 ${item.change >= 0 ? 'text-success-subtle-foreground' : 'text-destructive'}`">
<DigIcon :name="item.change >= 0 ? 'trending-up' : 'trending-down'" aria-hidden="true" />
<span class="sr-only">{{ item.change >= 0 ? "رشد" : "افت" }}</span>
{{ toFaDigits(String(Math.abs(item.change)).replace(".", "٫")) }}٪
</span>
</span>
<h3 class="line-clamp-2 leading-6 font-semibold">
<a href="#" class="after:absolute after:inset-0">{{ item.title }}</a>
</h3>
</div>
<img :src="stockImages[item.image].src" alt="" loading="lazy" class="size-16 shrink-0 rounded-lg object-cover" />
</li>
</ul>
</section>
</main>
<BottomNavigation v-model:value="tab" indicator="pill" :fixed="false" class="sticky bottom-0">
<BottomNavigationItem value="home" label="خانه">
<template #icon><DigIcon name="dashboard" /></template>
</BottomNavigationItem>
<BottomNavigationItem value="explore" label="کاوش">
<template #icon><DigIcon name="search" /></template>
</BottomNavigationItem>
<BottomNavigationItem value="saved" label="ذخیرهها">
<template #icon><DigIcon name="heart" /></template>
</BottomNavigationItem>
<BottomNavigationItem value="profile" label="پروفایل">
<template #icon><DigIcon name="user" /></template>
</BottomNavigationItem>
</BottomNavigation>
</div>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: bottom-navigationcontrol-sizepersiansearch-fieldآیکون dashboardآیکون heartآیکون searchآیکون trending-downآیکون trending-upآیکون user
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
mobile-news-explore.ts
import { Component, ChangeDetectionStrategy, signal } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigSearchField } from "@/components/ui/search-field"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import {
DigBottomNavigation,
DigBottomNavigationItem,
DigBottomNavigationActiveIcon,
DigBottomNavigationBadge,
} from "@/components/ui/bottom-navigation"
import { toFaDigits } from "@/lib/persian"
const stockImages: Record<string, { src: string; alt: string }> = {
coverFinanceDesk: {
src: "https://docs.digdesign.ir/images/cover-finance-desk.webp",
alt: "میزِ کار با موبایل، ماشینحساب و نمودارهای مالی",
},
projectDashboard: {
src: "https://docs.digdesign.ir/images/project-dashboard.webp",
alt: "لپتاپ با نمودارهای تحلیلی",
},
coverCalculator: {
src: "https://docs.digdesign.ir/images/cover-calculator.webp",
alt: "ماشینحساب، عینک و جامدادی روی میزِ سفید",
},
}
const TRENDING = [
{ id: "t1", title: "قیمتِ مسکن در پاییز؛ خریدارها منتظر میمانند", hours: 2, minutes: 4 },
{ id: "t2", title: "سه اپِ تازه که پسانداز را بازی کردهاند", hours: 3, minutes: 3 },
{ id: "t3", title: "مالیاتِ کسبوکارهای خانگی، به زبانِ ساده", hours: 5, minutes: 6 },
]
const TOPICS = ["طلا", "بورس", "مسکن", "رمزارز", "استارتاپ", "خودرو", "بیمه"]
const MARKETS: { id: string; symbol: string; change: number; title: string; image: string }[] = [
{
id: "m1",
symbol: "طلای ۱۸",
change: 1.2,
title: "طلا سه روزِ پشتِسرِهم بالا رفت؛ تحلیلگرها محتاطاند",
image: "coverFinanceDesk",
},
{
id: "m2",
symbol: "شاخص کل",
change: -0.8,
title: "بورس بعد از رشدِ هفتهٔ پیش کمی عقب نشست",
image: "projectDashboard",
},
{ id: "m3", symbol: "دلار", change: 0.3, title: "بازارِ ارز آرام؛ معاملهها کمحجم ماند", image: "coverCalculator" },
]
@Component({
selector: "dig-block-mobile-news-explore",
imports: [
DigControlSize,
DigSearchField,
DigButton,
DigIcon,
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">
<main class="flex flex-1 flex-col gap-8 pt-6 pb-6">
<header class="flex flex-col gap-4 px-4">
<h1 class="text-3xl leading-snug font-black">کاوش</h1>
<div
digSearchField
[value]="query()"
(valueChange)="query.set($event)"
aria-label="جستوجوی خبر"
placeholder="خبر، نویسنده یا موضوع"
></div>
</header>
<section aria-labelledby="hot-title" class="flex flex-col gap-3">
<h2 id="hot-title" class="px-4 text-sm font-bold text-muted-foreground"># داغِ امروز</h2>
<ol class="flex snap-x snap-mandatory gap-3 overflow-x-auto scroll-px-4 px-4 [scrollbar-width:none]">
@for (item of TRENDING; track item.id; let index = $index) {
<li
class="relative flex w-64 shrink-0 snap-start flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-card"
>
<span
aria-hidden="true"
class="text-3xl leading-none font-black text-[var(--dig-orange-600)] dark:text-[var(--dig-orange-400)]"
>#{{ toFaDigits(index + 1) }}</span
>
<h3 class="line-clamp-3 min-h-18 leading-6 font-bold">
<a href="#" class="after:absolute after:inset-0">{{ item.title }}</a>
</h3>
<span class="text-xs text-muted-foreground"
>{{ toFaDigits(item.hours) }} ساعت پیش · {{ toFaDigits(item.minutes) }} دقیقه مطالعه</span
>
</li>
}
</ol>
</section>
<section aria-labelledby="topics-title" class="flex flex-col gap-3 px-4">
<h2 id="topics-title" class="text-sm font-bold text-muted-foreground"># موضوعها</h2>
<div digControlSize="lg" class="flex flex-wrap gap-2">
@for (topic of TOPICS; track topic) {
<button digButton type="button" variant="secondary" class="rounded-full px-4">#{{ topic }}</button>
}
</div>
</section>
<section aria-labelledby="markets-title" class="flex flex-col gap-1 px-4">
<h2 id="markets-title" class="text-sm font-bold text-muted-foreground"># بازارها</h2>
<ul class="flex flex-col divide-y divide-border">
@for (item of MARKETS; track item.id) {
<li class="relative flex items-center gap-3 py-4">
<div class="flex min-w-0 flex-1 flex-col gap-2">
<span class="flex w-fit items-center gap-2 rounded-full border border-border px-2.5 py-1 text-xs"
><span class="font-semibold">{{ item.symbol }}</span>
<span
[class]="\`flex items-center gap-0.5 font-bold tabular-nums [&>svg]:size-3.5 \${item.change >= 0 ? 'text-success-subtle-foreground' : 'text-destructive'}\`"
><svg [digIcon]="item.change >= 0 ? 'trending-up' : 'trending-down'" aria-hidden="true"></svg>
<span class="sr-only">{{ item.change >= 0 ? "رشد" : "افت" }}</span>
{{ toFaDigits(string(math.abs(item.change)).replace(".", "٫")) }}٪
</span></span
>
<h3 class="line-clamp-2 leading-6 font-semibold">
<a href="#" class="after:absolute after:inset-0">{{ item.title }}</a>
</h3>
</div>
<img
[src]="stockImages[item.image].src"
alt=""
loading="lazy"
class="size-16 shrink-0 rounded-lg object-cover"
/>
</li>
}
</ul>
</section>
</main>
<nav
digBottomNavigation
[value]="tab()"
(valueChange)="typeof $event === 'string' && tab.set($event)"
indicator="pill"
[fixed]="false"
class="sticky bottom-0"
>
<button digBottomNavigationItem value="home" label="خانه"><svg digIcon="dashboard"></svg></button>
<button digBottomNavigationItem value="explore" label="کاوش"><svg digIcon="search"></svg></button>
<button digBottomNavigationItem value="saved" label="ذخیرهها"><svg digIcon="heart"></svg></button>
<button digBottomNavigationItem value="profile" label="پروفایل"><svg digIcon="user"></svg></button>
</nav>
</div>
`,
})
export class MobileNewsExploreBlock {
readonly math = Math
readonly string = String
readonly toFaDigits = toFaDigits
readonly MARKETS = MARKETS
readonly TOPICS = TOPICS
readonly TRENDING = TRENDING
readonly stockImages = stockImages
readonly query = signal("")
readonly tab = signal("explore")
}
MobileNewsExploreScreen.kt
package ir.digdesign.compose.demo.blocks
// sync: src/blocks/mobile-news-explore.tsx
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.FlowRow
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.heightIn
import androidx.compose.foundation.layout.imePadding
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.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.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.Button
import ir.digdesign.compose.ButtonRadius
import ir.digdesign.compose.ButtonVariant
import ir.digdesign.compose.Card
import ir.digdesign.compose.CardContent
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.SearchField
import ir.digdesign.compose.Separator
import ir.digdesign.compose.TypographyH3
import ir.digdesign.compose.TypographyLarge
import ir.digdesign.compose.formatNumber
import ir.digdesign.compose.toFaDigits
import kotlin.math.abs
private class TrendingNews(val id: String, val title: String, val hours: Int, val minutes: Int)
private class MarketNews(val id: String, val symbol: String, val change: Double, val title: String)
private val Trending = listOf(
TrendingNews("t1", "قیمتِ مسکن در پاییز؛ خریدارها منتظر میمانند", 2, 4),
TrendingNews("t2", "سه اپِ تازه که پسانداز را بازی کردهاند", 3, 3),
TrendingNews("t3", "مالیاتِ کسبوکارهای خانگی، به زبانِ ساده", 5, 6),
)
private val NewsTopics = listOf("طلا", "بورس", "مسکن", "رمزارز", "استارتاپ", "خودرو", "بیمه")
private val Markets = listOf(
MarketNews("m1", "طلای ۱۸", 1.2, "طلا سه روزِ پشتِسرِهم بالا رفت؛ تحلیلگرها محتاطاند"),
MarketNews("m2", "شاخص کل", -0.8, "بورس بعد از رشدِ هفتهٔ پیش کمی عقب نشست"),
MarketNews("m3", "دلار", 0.3, "بازارِ ارز آرام؛ معاملهها کمحجم ماند"),
)
/** کاوشِ اپِ خبری: جستوجو، «داغِ امروز» با کارتهای شمارهدار، موضوعها با # و «بازارها» با درصدِ تغییر به کلمه و رنگ. */
@Composable
fun MobileNewsExploreScreen() {
var query by remember { mutableStateOf("") }
var tab by remember { mutableStateOf("explore") }
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()) {
Column(
Modifier.weight(1f).verticalScroll(rememberScrollState()).imePadding().padding(top = DigSpacing * 6),
verticalArrangement = Arrangement.spacedBy(DigSpacing * 8),
) {
Column(Modifier.padding(horizontal = DigSpacing * 4), verticalArrangement = Arrangement.spacedBy(DigSpacing * 4)) {
TypographyH3("کاوش")
SearchField(value = query, onValueChange = { query = it }, placeholder = "خبر، نویسنده یا موضوع", label = null)
}
Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
Txt("# داغِ امروز", Modifier.padding(horizontal = DigSpacing * 4).semantics { heading() }, weight = FontWeight.Bold)
Row(Modifier.horizontalScroll(rememberScrollState()).padding(horizontal = DigSpacing * 4), horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
Trending.forEachIndexed { index, item ->
Card(Modifier.width(256.dp)) {
CardContent(Modifier.padding(top = DigSpacing * 4)) {
Column(verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
Txt("#${toFaDigits(index + 1)}", color = colors.orange, weight = FontWeight.Black)
TypographyLarge(item.title, Modifier.heightIn(min = DigSpacing * 18))
Txt("${toFaDigits(item.hours)} ساعت پیش · ${toFaDigits(item.minutes)} دقیقه مطالعه", size = DigText.xs)
}
}
}
}
}
}
Column(Modifier.padding(horizontal = DigSpacing * 4), verticalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
Txt("# موضوعها", Modifier.semantics { heading() }, weight = FontWeight.Bold)
FlowRow(horizontalArrangement = Arrangement.spacedBy(DigSpacing * 2), verticalArrangement = Arrangement.spacedBy(DigSpacing * 2)) {
NewsTopics.forEach { topic ->
Button("#$topic", onClick = {}, variant = ButtonVariant.Secondary, radius = ButtonRadius.Full)
}
}
}
Column(Modifier.padding(horizontal = DigSpacing * 4), verticalArrangement = Arrangement.spacedBy(DigSpacing)) {
Txt("# بازارها", Modifier.semantics { heading() }, weight = FontWeight.Bold)
Markets.forEach { item ->
val up = item.change >= 0
Row(Modifier.fillMaxWidth().padding(vertical = DigSpacing * 4), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3)) {
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(DigSpacing * 2)) {
Row(
Modifier.clip(RoundedCornerShape(DigRadius.xl)).border(1.dp, colors.border, RoundedCornerShape(DigRadius.xl)).padding(horizontal = DigSpacing * 3, vertical = DigSpacing),
horizontalArrangement = Arrangement.spacedBy(DigSpacing * 2),
) {
Txt(item.symbol, size = DigText.xs, color = colors.foreground, weight = FontWeight.SemiBold)
// جهتِ تغییر با کلمه گفته میشود، رنگ فقط تأکید است.
Txt(
"${if (up) "رشد" else "افت"} ${formatNumber(abs(item.change), 1)}٪",
size = DigText.xs,
color = if (up) colors.successSubtleForeground else colors.destructive,
weight = FontWeight.Bold,
)
}
Txt(item.title, size = DigText.sm * 1.15f, color = colors.foreground, weight = FontWeight.SemiBold, maxLines = 2)
}
Box(Modifier.size(64.dp).clip(RoundedCornerShape(DigRadius.lg)).background(colors.muted))
}
Separator()
}
}
}
DigNavigationBar(indicator = DigNavigationIndicator.Pill, windowInsets = WindowInsets()) {
DigNavigationItem(tab == "home", { tab = "home" }, { DigIcon(DigIcons.AccountSettings, contentDescription = null) }, "خانه")
DigNavigationItem(tab == "explore", { tab = "explore" }, { DigIcon(DigIcons.Search, contentDescription = null) }, "کاوش")
DigNavigationItem(tab == "saved", { tab = "saved" }, { DigIcon(DigIcons.BadgeStar, contentDescription = null) }, "ذخیرهها")
DigNavigationItem(tab == "profile", { tab = "profile" }, { DigIcon(DigIcons.User, contentDescription = null) }, "پروفایل")
}
}
}
}
}
@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,
)
}