ریاکت ۱۹ و Next.js با پیادهسازی دسترسپذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده
پیامهای اپ
پیشنمایش تمامصفحهپیامرسانِ اپ: فهرستِ گفتوگوها با جستوجو، عکس، آنلاین، آخرین پیام و شمارِ خواندهنشده؛ صفحهٔ گفتوگو با بازگشت و ورودیِ پیامِ چسبان.
۱. نصب کامپوننتها
این بلاک از ۱۰ آیتم دیگ استفاده میکند: app-baravatarbadgebuttonchat-messagecontrol-sizeiconspersianprompt-inputsearch-field
پکیجمنیجر پیشفرض 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/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/chat-message.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/prompt-input.json https://docs.digdesign.ir/r/search-field.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/app-bar.json 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/chat-message.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/prompt-input.json https://docs.digdesign.ir/r/search-field.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/app-bar.json 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/chat-message.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/prompt-input.json https://docs.digdesign.ir/r/search-field.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/app-bar.json 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/chat-message.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/prompt-input.json https://docs.digdesign.ir/r/search-field.jsonپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework vuepnpm dlx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework vueyarn dlx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework vuebunx --bun digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input 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 app-bar avatar badge button chat-message control-size icons persian prompt-input search-field utils --framework angularpnpm dlx digdesign@latest add app-bar avatar badge button chat-message control-size icons persian prompt-input search-field utils --framework angularyarn dlx digdesign@latest add app-bar avatar badge button chat-message control-size icons persian prompt-input search-field utils --framework angularbunx --bun digdesign@latest add app-bar avatar badge button chat-message control-size icons persian prompt-input search-field utils --framework angularپکیجمنیجر پیشفرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیجمنیجر Bun
npx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework androidpnpm dlx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework androidyarn dlx digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework androidbunx --bun digdesign@latest add app-bar avatar badge button chat-message control-size persian prompt-input search-field --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
mobile-messages.tsx
"use client"
import * as React from "react"
import { ChevronRightIcon } from "@/components/icons"
import { AppBar, AppBarLeading, AppBarTitle } from "@/components/ui/app-bar"
import { Avatar } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ChatMessage, ChatMessageAvatar, ChatMessageBubble, ChatMessageContent } from "@/components/ui/chat-message"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { PromptInput, PromptInputSubmitButton, PromptInputTextarea, PromptInputToolbar, PromptInputTools, PromptInputAttachButton } from "@/components/ui/prompt-input"
import { SearchField } from "@/components/ui/search-field"
import { toFaDigits, toSearchKey } from "@/lib/persian"
import { stockImages, type StockImageName } from "@/lib/stock-images"
type Thread = { id: string; name: string; photo: StockImageName; last: string; time: string; unread: number; online?: boolean }
const THREADS: Thread[] = [
{ id: "1", name: "سارا محمدی", photo: "personWoman2", last: "فایلِ فاکتور را فرستادم 👌", time: "۱۰:۴۲", unread: 2, online: true },
{ id: "2", name: "امیر رضایی", photo: "personMan1", last: "جلسه را بگذاریم فردا؟", time: "۰۹:۱۵", unread: 0, online: true },
{ id: "3", name: "نگار احمدی", photo: "personWoman3", last: "ممنون، رسید.", time: "دیروز", unread: 0 },
{ id: "4", name: "علی کاظمی", photo: "personMan2", last: "قیمتها بهروز شد.", time: "دوشنبه", unread: 5 },
]
/**
* پیامها در اپ: فهرستِ گفتوگوها با جستوجو، عکس، وضعیتِ آنلاین، آخرین پیام و شمارِ
* خواندهنشده؛ لمسِ هر ردیف صفحهٔ گفتوگو را با نوارِ بازگشت و ورودی پیامِ چسبان باز میکند.
*/
export default function MobileMessagesBlock() {
const [query, setQuery] = React.useState("")
const [open, setOpen] = React.useState<Thread | null>(null)
const [messages, setMessages] = React.useState([
{ id: 1, role: "assistant" as const, text: "سلام! فاکتورِ مهر آماده شد؟" },
{ id: 2, role: "user" as const, text: "بله، الان میفرستم." },
{ id: 3, role: "assistant" as const, text: "فایلِ فاکتور را فرستادم 👌" },
])
if (open) {
return (
<ControlSizeProvider size="xl" asChild>
<div className="mx-auto flex h-svh w-full max-w-md flex-col bg-background">
<AppBar>
<AppBarLeading>
<Button variant="ghost" size="icon" aria-label="بازگشت به پیامها" onClick={() => setOpen(null)}>
<ChevronRightIcon className="ltr:rotate-180" />
</Button>
</AppBarLeading>
<AppBarTitle className="flex items-center gap-3">
<Avatar size="sm" alt="" src={stockImages[open.photo].src} />
<span className="flex flex-col items-start">
{open.name}
<span className="text-xs font-normal text-muted-foreground">{open.online ? "آنلاین" : "اخیراً"}</span>
</span>
</AppBarTitle>
</AppBar>
<main className="flex flex-1 flex-col gap-4 overflow-y-auto bg-subtle p-4" aria-live="polite">
{messages.map((message) => (
<ChatMessage key={message.id} role={message.role}>
{message.role === "assistant" && <ChatMessageAvatar alt={open.name} src={stockImages[open.photo].src} />}
<ChatMessageContent>
<ChatMessageBubble>{message.text}</ChatMessageBubble>
</ChatMessageContent>
</ChatMessage>
))}
</main>
<footer className="border-t border-border p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]">
<PromptInput onSubmit={(text) => text.trim() && setMessages((list) => [...list, { id: list.length + 1, role: "user", text }])}>
<PromptInputTextarea placeholder="پیام…" aria-label="پیام" />
<PromptInputToolbar>
<PromptInputTools>
<PromptInputAttachButton />
</PromptInputTools>
<PromptInputSubmitButton />
</PromptInputToolbar>
</PromptInput>
</footer>
</div>
</ControlSizeProvider>
)
}
const visible = THREADS.filter((thread) => toSearchKey(thread.name + thread.last).includes(toSearchKey(query)))
return (
<ControlSizeProvider size="xl" asChild>
<div className="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
<AppBar sticky>
<AppBarTitle>پیامها</AppBarTitle>
</AppBar>
<main className="flex flex-1 flex-col gap-4 p-4">
<SearchField aria-label="جستوجو در گفتوگوها" placeholder="جستوجو" value={query} onValueChange={setQuery} />
<ul className="flex flex-col">
{visible.map((thread) => (
<li key={thread.id}>
<Button variant="ghost" onClick={() => setOpen(thread)} className="h-auto min-h-18 w-full justify-start gap-3 px-2 py-3 text-start font-normal">
<span className="relative shrink-0">
<Avatar size="lg" alt="" src={stockImages[thread.photo].src} />
{thread.online && <span aria-label="آنلاین" className="absolute -end-0.5 -bottom-0.5 size-3.5 rounded-full bg-success ring-2 ring-background" />}
</span>
<span className="flex min-w-0 flex-1 flex-col gap-1">
<span className="flex items-center justify-between gap-2">
<span className={thread.unread ? "font-bold" : "font-medium"}>{thread.name}</span>
<span className="text-xs text-muted-foreground">{thread.time}</span>
</span>
<span className="flex items-center justify-between gap-2">
<span className={`truncate text-sm ${thread.unread ? "text-foreground" : "text-muted-foreground"}`}>{thread.last}</span>
{thread.unread > 0 && <Badge color="primary">{toFaDigits(thread.unread)}</Badge>}
</span>
</span>
</Button>
</li>
))}
</ul>
</main>
</div>
</ControlSizeProvider>
)
}
mobile-messages.vue
<script setup lang="ts">
import { computed, ref } from "vue"
import AppBar from "@/components/ui/AppBar.vue"
import AppBarLeading from "@/components/ui/AppBarLeading.vue"
import AppBarTitle from "@/components/ui/AppBarTitle.vue"
import Avatar from "@/components/ui/Avatar.vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import ChatMessage from "@/components/ui/ChatMessage.vue"
import ChatMessageAvatar from "@/components/ui/ChatMessageAvatar.vue"
import ChatMessageBubble from "@/components/ui/ChatMessageBubble.vue"
import ChatMessageContent from "@/components/ui/ChatMessageContent.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import PromptInput from "@/components/ui/PromptInput.vue"
import PromptInputAttachButton from "@/components/ui/PromptInputAttachButton.vue"
import PromptInputSubmitButton from "@/components/ui/PromptInputSubmitButton.vue"
import PromptInputTextarea from "@/components/ui/PromptInputTextarea.vue"
import PromptInputToolbar from "@/components/ui/PromptInputToolbar.vue"
import PromptInputTools from "@/components/ui/PromptInputTools.vue"
import SearchField from "@/components/ui/SearchField.vue"
import { DigIcon } from "@/lib/icons"
import { toFaDigits, toSearchKey } from "@/lib/persian"
const IMAGE_BASE = "https://docs.digdesign.ir/images"
type Thread = { id: string; name: string; photo: string; last: string; time: string; unread: number; online?: boolean }
const THREADS: Thread[] = [
{ id: "1", name: "سارا محمدی", photo: `${IMAGE_BASE}/person-woman-2.webp`, last: "فایلِ فاکتور را فرستادم 👌", time: "۱۰:۴۲", unread: 2, online: true },
{ id: "2", name: "امیر رضایی", photo: `${IMAGE_BASE}/person-man-1.webp`, last: "جلسه را بگذاریم فردا؟", time: "۰۹:۱۵", unread: 0, online: true },
{ id: "3", name: "نگار احمدی", photo: `${IMAGE_BASE}/person-woman-3.webp`, last: "ممنون، رسید.", time: "دیروز", unread: 0 },
{ id: "4", name: "علی کاظمی", photo: `${IMAGE_BASE}/person-man-2.webp`, last: "قیمتها بهروز شد.", time: "دوشنبه", unread: 5 },
]
/**
* پیامها در اپ: فهرستِ گفتوگوها با جستوجو، عکس، وضعیتِ آنلاین، آخرین پیام و شمارِ
* خواندهنشده؛ لمسِ هر ردیف صفحهٔ گفتوگو را با نوارِ بازگشت و ورودی پیامِ چسبان باز میکند.
*/
const query = ref("")
const open = ref<Thread | null>(null)
const messages = ref<{ id: number; role: "assistant" | "user"; text: string }[]>([
{ id: 1, role: "assistant", text: "سلام! فاکتورِ مهر آماده شد؟" },
{ id: 2, role: "user", text: "بله، الان میفرستم." },
{ id: 3, role: "assistant", text: "فایلِ فاکتور را فرستادم 👌" },
])
const visible = computed(() => THREADS.filter((thread) => toSearchKey(thread.name + thread.last).includes(toSearchKey(query.value))))
function send(text: string) {
if (text.trim()) messages.value = [...messages.value, { id: messages.value.length + 1, role: "user", text }]
}
</script>
<template>
<ControlSize v-if="open" size="xl" as-child>
<div class="mx-auto flex h-svh w-full max-w-md flex-col bg-background">
<AppBar>
<AppBarLeading>
<Button variant="ghost" size="icon" aria-label="بازگشت به پیامها" @click="open = null">
<DigIcon name="chevron-right" class="ltr:rotate-180" />
</Button>
</AppBarLeading>
<AppBarTitle class="flex items-center gap-3">
<Avatar size="sm" alt="" :src="open.photo" />
<span class="flex flex-col items-start">
{{ open.name }}
<span class="text-xs font-normal text-muted-foreground">{{ open.online ? "آنلاین" : "اخیراً" }}</span>
</span>
</AppBarTitle>
</AppBar>
<main class="flex flex-1 flex-col gap-4 overflow-y-auto bg-subtle p-4" aria-live="polite">
<ChatMessage v-for="message in messages" :key="message.id" :role="message.role">
<ChatMessageAvatar v-if="message.role === 'assistant'" :alt="open.name" :src="open.photo" />
<ChatMessageContent>
<ChatMessageBubble>{{ message.text }}</ChatMessageBubble>
</ChatMessageContent>
</ChatMessage>
</main>
<footer class="border-t border-border p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]">
<PromptInput @submit="send">
<PromptInputTextarea placeholder="پیام…" aria-label="پیام" />
<PromptInputToolbar>
<PromptInputTools>
<PromptInputAttachButton />
</PromptInputTools>
<PromptInputSubmitButton />
</PromptInputToolbar>
</PromptInput>
</footer>
</div>
</ControlSize>
<ControlSize v-else size="xl" as-child>
<div class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
<AppBar sticky>
<AppBarTitle>پیامها</AppBarTitle>
</AppBar>
<main class="flex flex-1 flex-col gap-4 p-4">
<SearchField v-model="query" aria-label="جستوجو در گفتوگوها" placeholder="جستوجو" />
<ul class="flex flex-col">
<li v-for="thread in visible" :key="thread.id">
<Button variant="ghost" class="h-auto min-h-18 w-full justify-start gap-3 px-2 py-3 text-start font-normal" @click="open = thread">
<span class="relative shrink-0">
<Avatar size="lg" alt="" :src="thread.photo" />
<span v-if="thread.online" aria-label="آنلاین" class="absolute -end-0.5 -bottom-0.5 size-3.5 rounded-full bg-success ring-2 ring-background" />
</span>
<span class="flex min-w-0 flex-1 flex-col gap-1">
<span class="flex items-center justify-between gap-2">
<span :class="thread.unread ? 'font-bold' : 'font-medium'">{{ thread.name }}</span>
<span class="text-xs text-muted-foreground">{{ thread.time }}</span>
</span>
<span class="flex items-center justify-between gap-2">
<span :class="['truncate text-sm', thread.unread ? 'text-foreground' : 'text-muted-foreground']">{{ thread.last }}</span>
<Badge v-if="thread.unread > 0" color="primary">{{ toFaDigits(thread.unread) }}</Badge>
</span>
</span>
</Button>
</li>
</ul>
</main>
</div>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: app-baravatarbadgechat-messagecontrol-sizepersianprompt-inputsearch-fieldآیکون chevron-right
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
mobile-messages.ts
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import { DigAppBar, DigAppBarLeading, DigAppBarTitle } from "@/components/ui/app-bar"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { DigAvatar } from "@/components/ui/avatar"
import {
DigChatMessage,
DigChatMessageAvatar,
DigChatMessageContent,
DigChatMessageBubble,
} from "@/components/ui/chat-message"
import {
DigPromptInput,
DigPromptInputTextarea,
DigPromptInputToolbar,
DigPromptInputTools,
DigPromptInputAttachButton,
DigPromptInputSubmitButton,
} from "@/components/ui/prompt-input"
import { DigSearchField } from "@/components/ui/search-field"
import { cn } from "@/lib/utils"
import { DigBadge } from "@/components/ui/badge"
import { toFaDigits, toSearchKey } from "@/lib/persian"
const IMAGE_BASE = "https://docs.digdesign.ir/images"
type Thread = { id: string; name: string; photo: string; last: string; time: string; unread: number; online?: boolean }
const THREADS: Thread[] = [
{
id: "1",
name: "سارا محمدی",
photo: `${IMAGE_BASE}/person-woman-2.webp`,
last: "فایلِ فاکتور را فرستادم 👌",
time: "۱۰:۴۲",
unread: 2,
online: true,
},
{
id: "2",
name: "امیر رضایی",
photo: `${IMAGE_BASE}/person-man-1.webp`,
last: "جلسه را بگذاریم فردا؟",
time: "۰۹:۱۵",
unread: 0,
online: true,
},
{
id: "3",
name: "نگار احمدی",
photo: `${IMAGE_BASE}/person-woman-3.webp`,
last: "ممنون، رسید.",
time: "دیروز",
unread: 0,
},
{
id: "4",
name: "علی کاظمی",
photo: `${IMAGE_BASE}/person-man-2.webp`,
last: "قیمتها بهروز شد.",
time: "دوشنبه",
unread: 5,
},
]
@Component({
selector: "dig-block-mobile-messages",
imports: [
DigControlSize,
DigAppBar,
DigAppBarLeading,
DigAppBarTitle,
DigButton,
DigIcon,
DigAvatar,
DigChatMessage,
DigChatMessageAvatar,
DigChatMessageContent,
DigChatMessageBubble,
DigPromptInput,
DigPromptInputTextarea,
DigPromptInputToolbar,
DigPromptInputTools,
DigPromptInputAttachButton,
DigPromptInputSubmitButton,
DigSearchField,
DigBadge,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (open(); as open) {
<div digControlSize="xl" class="mx-auto flex h-svh w-full max-w-md flex-col bg-background">
<header digAppBar>
<div digAppBarLeading>
<button
digButton
type="button"
variant="ghost"
size="icon"
aria-label="بازگشت به پیامها"
(click)="closeThread()"
>
<svg digIcon="chevron-right" class="ltr:rotate-180"></svg>
</button>
</div>
<h1 digAppBarTitle class="flex items-center gap-3">
<span digAvatar size="sm" alt="" [src]="open.photo"></span>
<span class="flex flex-col items-start"
>{{ open.name }}
<span class="text-xs font-normal text-muted-foreground">{{
open.online ? "آنلاین" : "اخیراً"
}}</span></span
>
</h1>
</header>
<main class="flex flex-1 flex-col gap-4 overflow-y-auto bg-subtle p-4" aria-live="polite">
@for (message of messages(); track message.id) {
<div digChatMessage [role]="message.role">
@if (message.role === "assistant") {
<span digChatMessageAvatar [alt]="open.name" [src]="open.photo"></span>
}
<div digChatMessageContent>
<div digChatMessageBubble>{{ message.text }}</div>
</div>
</div>
}
</main>
<footer class="border-t border-border p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]">
<form digPromptInput (send)="send($event)">
<textarea digPromptInputTextarea placeholder="پیام…" aria-label="پیام"></textarea>
<div digPromptInputToolbar>
<div digPromptInputTools><button digPromptInputAttachButton></button></div>
<button digPromptInputSubmitButton></button>
</div>
</form>
</footer>
</div>
} @else {
<div digControlSize="xl" class="mx-auto flex min-h-svh w-full max-w-md flex-col bg-background">
<header digAppBar sticky><h1 digAppBarTitle>پیامها</h1></header>
<main class="flex flex-1 flex-col gap-4 p-4">
<div
digSearchField
[value]="query()"
(valueChange)="query.set($event)"
aria-label="جستوجو در گفتوگوها"
placeholder="جستوجو"
></div>
<ul class="flex flex-col">
@for (thread of visible(); track thread.id) {
<li>
<button
digButton
type="button"
variant="ghost"
class="h-auto min-h-18 w-full justify-start gap-3 px-2 py-3 text-start font-normal"
(click)="open.set(thread)"
>
<span class="relative shrink-0"
><span digAvatar size="lg" alt="" [src]="thread.photo"></span>
@if (thread.online) {
<span
aria-label="آنلاین"
class="absolute -end-0.5 -bottom-0.5 size-3.5 rounded-full bg-success ring-2 ring-background"
></span>
}
</span>
<span class="flex min-w-0 flex-1 flex-col gap-1"
><span class="flex items-center justify-between gap-2"
><span [class]="thread.unread ? 'font-bold' : 'font-medium'">{{ thread.name }}</span>
<span class="text-xs text-muted-foreground">{{ thread.time }}</span></span
>
<span class="flex items-center justify-between gap-2"
><span
[class]="cn('truncate text-sm', thread.unread ? 'text-foreground' : 'text-muted-foreground')"
>{{ thread.last }}</span
>
@if (thread.unread > 0) {
<span digBadge color="primary">{{ toFaDigits(thread.unread) }}</span>
}
</span></span
>
</button>
</li>
}
</ul>
</main>
</div>
}
`,
})
export class MobileMessagesBlock {
readonly cn = cn
readonly toFaDigits = toFaDigits
readonly query = signal("")
readonly open = signal<Thread | null>(null)
readonly messages = signal<{ id: number; role: "assistant" | "user"; text: string }[]>([
{ id: 1, role: "assistant", text: "سلام! فاکتورِ مهر آماده شد؟" },
{ id: 2, role: "user", text: "بله، الان میفرستم." },
{ id: 3, role: "assistant", text: "فایلِ فاکتور را فرستادم 👌" },
])
readonly visible = computed(() =>
THREADS.filter((thread) => toSearchKey(thread.name + thread.last).includes(toSearchKey(this.query())))
)
send(text: string) {
if (text.trim()) this.messages.set([...this.messages(), { id: this.messages().length + 1, role: "user", text }])
}
closeThread() {
this.open.set(null)
}
}
MobileMessagesScreen.kt
package ir.digdesign.compose.demo.blocks
// sync: src/blocks/mobile-messages.tsx
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
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.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.foundation.layout.size
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.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
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.Badge
import ir.digdesign.compose.BadgeColor
import ir.digdesign.compose.Button
import ir.digdesign.compose.ButtonSize
import ir.digdesign.compose.ButtonVariant
import ir.digdesign.compose.ChatMessage
import ir.digdesign.compose.ChatMessageAvatar
import ir.digdesign.compose.ChatMessageBubble
import ir.digdesign.compose.ChatMessageContent
import ir.digdesign.compose.ChatMessageRole
import ir.digdesign.compose.ControlSize
import ir.digdesign.compose.ControlSizeProvider
import ir.digdesign.compose.DigIcon
import ir.digdesign.compose.DigIcons
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.EmptyState
import ir.digdesign.compose.EmptyStateTitle
import ir.digdesign.compose.PromptInput
import ir.digdesign.compose.PromptInputAttachButton
import ir.digdesign.compose.SearchField
import ir.digdesign.compose.Separator
import ir.digdesign.compose.toFaDigits
import ir.digdesign.compose.toSearchKey
private class MessageThread(val id: String, val name: String, val last: String, val time: String, val unread: Int, val online: Boolean = false)
private class ChatLine(val id: Int, val mine: Boolean, val text: String)
private val Threads = listOf(
MessageThread("1", "سارا محمدی", "فایلِ فاکتور را فرستادم 👌", "۱۰:۴۲", 2, online = true),
MessageThread("2", "امیر رضایی", "جلسه را بگذاریم فردا؟", "۰۹:۱۵", 0, online = true),
MessageThread("3", "نگار احمدی", "ممنون، رسید.", "دیروز", 0),
MessageThread("4", "علی کاظمی", "قیمتها بهروز شد.", "دوشنبه", 5),
)
/** پیامها در اپ: فهرستِ گفتوگوها با جستوجو و شمارِ خواندهنشده، و صفحهٔ گفتوگو با حبابها و ورودیِ پیامِ چسبان. */
@Composable
fun MobileMessagesScreen() {
var query by remember { mutableStateOf("") }
var open by remember { mutableStateOf<MessageThread?>(null) }
var draft by remember { mutableStateOf("") }
var lines by remember {
mutableStateOf(
listOf(
ChatLine(1, false, "سلام! فاکتورِ مهر آماده شد؟"),
ChatLine(2, true, "بله، الان میفرستم."),
ChatLine(3, false, "فایلِ فاکتور را فرستادم 👌"),
),
)
}
val colors = DigTheme.colors
val thread = open
Box(
Modifier.fillMaxSize().background(colors.background).safeDrawingPadding(),
contentAlignment = Alignment.TopCenter,
) {
ControlSizeProvider(ControlSize.Xl) {
Column(Modifier.widthIn(max = 480.dp).fillMaxWidth().fillMaxHeight().imePadding()) {
if (thread != null) {
DigTopAppBar(
title = thread.name,
subtitle = if (thread.online) "آنلاین" else "اخیراً",
windowInsets = WindowInsets(),
navigationIcon = {
Button(onClick = { open = null }, variant = ButtonVariant.Ghost, size = ButtonSize.Icon, contentDescription = "بازگشت به پیامها") {
DigIcon(DigIcons.ArrowLeft, contentDescription = null)
}
},
)
Column(
Modifier.weight(1f).fillMaxWidth().background(colors.subtle).verticalScroll(rememberScrollState()).padding(DigSpacing * 4),
verticalArrangement = Arrangement.spacedBy(DigSpacing * 4),
) {
lines.forEach { line ->
ChatMessage(role = if (line.mine) ChatMessageRole.User else ChatMessageRole.Assistant) {
if (!line.mine) ChatMessageAvatar(name = thread.name)
ChatMessageContent { ChatMessageBubble(line.text) }
}
}
}
Separator()
PromptInput(
value = draft,
onValueChange = { draft = it },
onSubmit = { text ->
if (text.isNotBlank()) {
lines = lines + ChatLine(lines.size + 1, true, text)
draft = ""
}
},
placeholder = "پیام…",
modifier = Modifier.padding(DigSpacing * 3),
tools = { PromptInputAttachButton(onClick = {}) },
)
} else {
DigTopAppBar(title = "پیامها", windowInsets = WindowInsets())
val visible = Threads.filter { toSearchKey(it.name + it.last).contains(toSearchKey(query)) }
Column(
Modifier.weight(1f).verticalScroll(rememberScrollState()).padding(DigSpacing * 4),
verticalArrangement = Arrangement.spacedBy(DigSpacing * 4),
) {
SearchField(value = query, onValueChange = { query = it }, placeholder = "جستوجو", label = null)
if (visible.isEmpty()) EmptyState { EmptyStateTitle("گفتوگویی پیدا نشد") }
visible.forEach { item ->
Row(
Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(DigRadius.xl))
.clickable(role = Role.Button) { open = item }
.semantics(mergeDescendants = true) {
if (item.unread > 0) stateDescription = "${toFaDigits(item.unread)} پیامِ خواندهنشده"
}
.padding(horizontal = DigSpacing * 2, vertical = DigSpacing * 3),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(DigSpacing * 3),
) {
Box {
Avatar(name = item.name, size = AvatarSize.Lg)
if (item.online) {
Box(
Modifier
.align(Alignment.BottomEnd)
.size(14.dp)
.clip(CircleShape)
.background(colors.success)
.border(2.dp, colors.background, CircleShape)
.semantics { contentDescription = "آنلاین" },
)
}
}
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(DigSpacing)) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Txt(item.name, color = colors.foreground, weight = if (item.unread > 0) FontWeight.Bold else FontWeight.Medium)
Txt(item.time, size = DigText.xs)
}
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
Txt(item.last, Modifier.weight(1f), color = if (item.unread > 0) colors.foreground else colors.mutedForeground, maxLines = 1)
if (item.unread > 0) Badge(toFaDigits(item.unread), color = BadgeColor.Primary)
}
}
}
}
}
}
}
}
}
}
@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,
)
}