مدیریت کاربران
پیشنمایش تمامصفحهجستوجو و فیلتر نقش، جدول کاربران با وضعیت، دعوت عضو و منوی عملیات.
۱. نصب کامپوننتها
این بلاک از ۱۷ آیتم دیگ استفاده میکند: action-baravatarbadgebuttoncontrol-sizedialogdropdown-menuempty-stateiconslabelpaginationpersiansearch-fieldselecttabletext-fieldtoast
npx digdesign@latest add https://docs.digdesign.ir/r/action-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/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/action-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/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/action-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/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/action-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/control-size.json https://docs.digdesign.ir/r/dialog.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/text-field.json https://docs.digdesign.ir/r/toast.jsonnpx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework vuepnpm dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework vueyarn dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework vuebunx --bun digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework vuenpx 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 sveltenpx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state icons input label pagination persian search-field select table text-field toast --framework angularpnpm dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state icons input label pagination persian search-field select table text-field toast --framework angularyarn dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state icons input label pagination persian search-field select table text-field toast --framework angularbunx --bun digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state icons input label pagination persian search-field select table text-field toast --framework angularnpx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework androidpnpm dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework androidyarn dlx digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework androidbunx --bun digdesign@latest add action-bar avatar badge button control-size dialog dropdown-menu empty-state label pagination persian search-field select table text-field toast --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client";
import * as React from "react";
import {
AvatarGenderIcon,
EditIcon,
MoreHorizontalIcon,
PlusIcon,
TrashIcon,
UsersIcon,
} from "@/components/icons";
import {
ActionBar,
ActionBarAction,
ActionBarClose,
ActionBarCount,
ActionBarSeparator,
} from "@/components/ui/action-bar";
import { Avatar } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { ControlSizeProvider } from "@/components/ui/control-size";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
EmptyState,
EmptyStateDescription,
EmptyStateTitle,
} from "@/components/ui/empty-state";
import { Label } from "@/components/ui/label";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
import { SearchField } from "@/components/ui/search-field";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Table,
TableBody,
TableCell,
TableCellStack,
TableCheckboxCell,
TableHead,
TableHeader,
TableRow,
TableSelectAllCheckbox,
} from "@/components/ui/table";
import { TextField } from "@/components/ui/text-field";
import { toast } from "@/components/ui/toast";
import {
formatJalaliDateTime,
formatRelativeTime,
isValidEmail,
toFaDigits,
toSearchKey,
} from "@/lib/persian";
import { avatarPhoto } from "@/lib/stock-images";
type Role = "admin" | "editor" | "viewer";
type Status = "active" | "away" | "inactive";
const ROLES: Record<Role, string> = {
admin: "مدیر",
editor: "ویرایشگر",
viewer: "بیننده",
};
const STATUS: Record<
Status,
{ label: string; color: "success" | "warning" | "default" }
> = {
active: { label: "فعال", color: "success" },
away: { label: "مرخصی", color: "warning" },
inactive: { label: "غیرفعال", color: "default" },
};
const USERS: {
id: string;
name: string;
email: string;
gender: "male" | "female";
role: Role;
lastSeen: string;
status: Status;
}[] = [
{
id: "1",
name: "آرمیتا رستگار",
email: "armita@dig.ir",
gender: "female" as const,
role: "admin",
lastSeen: "2026-10-05T09:40:00",
status: "active",
},
{
id: "2",
name: "کیان مرادی",
email: "kian@dig.ir",
gender: "male" as const,
role: "editor",
lastSeen: "2026-10-05T08:15:00",
status: "active",
},
{
id: "3",
name: "نیلوفر احمدی",
email: "niloofar@dig.ir",
gender: "female" as const,
role: "viewer",
lastSeen: "2026-09-20T10:00:00",
status: "inactive",
},
{
id: "4",
name: "سامان کریمی",
email: "saman@dig.ir",
gender: "male" as const,
role: "editor",
lastSeen: "2026-10-04T16:20:00",
status: "away",
},
{
id: "5",
name: "مهسا توکلی",
email: "mahsa@dig.ir",
gender: "female" as const,
role: "viewer",
lastSeen: "2026-10-03T11:45:00",
status: "active",
},
{
id: "6",
name: "پرهام نوری",
email: "parham@dig.ir",
gender: "male" as const,
role: "editor",
lastSeen: "2026-10-01T13:10:00",
status: "active",
},
{
id: "7",
name: "ترانه شریفی",
email: "taraneh@dig.ir",
gender: "female" as const,
role: "admin",
lastSeen: "2026-09-28T09:30:00",
status: "away",
},
{
id: "8",
name: "بهراد صالحی",
email: "behrad@dig.ir",
gender: "male" as const,
role: "viewer",
lastSeen: "2026-09-25T18:05:00",
status: "active",
},
];
const PAGE_SIZE = 5;
type SortDescriptor = { column: string; direction: "ascending" | "descending" };
export default function UserManagementBlock() {
const [users, setUsers] = React.useState(USERS);
const [query, setQuery] = React.useState("");
const [role, setRole] = React.useState<"all" | Role>("all");
const [open, setOpen] = React.useState(false);
const [selected, setSelected] = React.useState<Set<string>>(new Set());
const [sort, setSort] = React.useState<SortDescriptor>({
column: "lastSeen",
direction: "descending",
});
const [page, setPage] = React.useState(1);
const key = toSearchKey(query);
const filtered = users
.filter(
(user) =>
(role === "all" || user.role === role) &&
toSearchKey(user.name + user.email).includes(key),
)
.sort((a, b) => {
const order =
sort.column === "name"
? a.name.localeCompare(b.name, "fa")
: a.lastSeen.localeCompare(b.lastSeen);
return sort.direction === "ascending" ? order : -order;
});
const pageCount = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE));
const currentPage = Math.min(page, pageCount);
const rows = filtered.slice(
(currentPage - 1) * PAGE_SIZE,
currentPage * PAGE_SIZE,
);
const from = filtered.length === 0 ? 0 : (currentPage - 1) * PAGE_SIZE + 1;
const to = Math.min(currentPage * PAGE_SIZE, filtered.length);
// حذف برگشتپذیر است (دعوتِ دوباره)؛ پس اسنکبارِ «برگردان» بهجای دیالوگِ تأیید.
function remove(ids: string[]) {
const before = users;
setUsers((list) => list.filter((user) => !ids.includes(user.id)));
setSelected(new Set());
toast(
ids.length === 1
? "عضو از تیم حذف شد."
: `${toFaDigits(ids.length)} عضو از تیم حذف شدند.`,
{ action: { label: "برگردان", onClick: () => setUsers(before) } },
);
}
function bulk(message: string) {
toast.success(message, { description: `${toFaDigits(selected.size)} عضو` });
setSelected(new Set());
}
return (
<ControlSizeProvider size="xl" asChild>
<main className="mx-auto flex w-full min-w-0 max-w-5xl flex-col gap-6 p-4 pb-28 sm:p-6 sm:pb-28">
<ControlSizeProvider size="xl">
{/* سلسلهمراتب: عنوان و توضیح نزدیک، اکشنِ اصلی همردیفِ عنوان. */}
<header className="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
<div className="flex flex-col gap-1">
<h1 className="text-2xl font-bold">اعضای تیم</h1>
<p className="text-sm text-muted-foreground">
{toFaDigits(users.length)} عضو؛ نقش هر نفر مشخص میکند به چه
بخشهایی دسترسی دارد.
</p>
</div>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button>
<PlusIcon />
دعوت عضو
</Button>
</DialogTrigger>
<ControlSizeProvider size="xl" asChild>
<DialogContent>
<DialogHeader>
<DialogTitle>دعوت عضو تازه</DialogTitle>
<DialogDescription>
لینک دعوت به ایمیل او فرستاده میشود.
</DialogDescription>
</DialogHeader>
<form
id="invite"
className="flex flex-col gap-4"
onSubmit={(event) => {
event.preventDefault();
setOpen(false);
toast.success("دعوتنامه ارسال شد.");
}}
>
<TextField
label="ایمیل"
name="email"
type="email"
dir="ltr"
required
validate={(value) =>
isValidEmail(value)
? undefined
: "ایمیل معتبر نیست؛ مثل name@example.com"
}
/>
<div className="flex flex-col gap-2">
<Label id="invite-role">نقش</Label>
<Select name="role" defaultValue="viewer">
<SelectTrigger
aria-labelledby="invite-role"
className="w-full"
>
<SelectValue />
</SelectTrigger>
<SelectContent>
{(Object.keys(ROLES) as Role[]).map((item) => (
<SelectItem key={item} value={item}>
{ROLES[item]}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</form>
<DialogFooter>
<Button type="submit" form="invite">
ارسال دعوت
</Button>
</DialogFooter>
</DialogContent>
</ControlSizeProvider>
</Dialog>
</header>
{/* جدول، نوارِ ابزار و صفحهبندی یک سطحاند: هر سه داخلِ همان کارت. */}
{/* ابزارها بیرونِ قاب و ۳۲ پیکسل بالای جدول؛ فقط خودِ جدول قاب دارد، صفحهبندی زیرش. */}
<section aria-label="فهرست اعضا" className="flex flex-col gap-8">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
<SearchField
aria-label="جستوجوی عضو"
placeholder="جستوجوی نام یا ایمیل"
value={query}
onValueChange={(value) => {
setQuery(value);
setPage(1);
}}
className="min-w-0 flex-1 sm:max-w-xs"
/>
<Select
value={role}
onValueChange={(value) => {
setRole(value as "all" | Role);
setPage(1);
}}
>
<SelectTrigger
aria-label="فیلتر نقش"
className="w-full sm:ms-auto sm:w-40"
>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">همهٔ نقشها</SelectItem>
{(Object.keys(ROLES) as Role[]).map((item) => (
<SelectItem key={item} value={item}>
{ROLES[item]}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{rows.length === 0 ? (
<EmptyState variant="bordered" className="py-14">
<UsersIcon aria-hidden className="size-8 text-placeholder" />
<EmptyStateTitle>عضوی با این مشخصات نیست</EmptyStateTitle>
<EmptyStateDescription>
نام دیگری جستوجو کنید یا فیلتر نقش را بردارید.
</EmptyStateDescription>
</EmptyState>
) : (
<div className="flex flex-col gap-4">
<div className="overflow-x-auto rounded-xl border border-border bg-card">
{/* table-fixed با عرضِ ستونهای ثابت: مرتبسازی و فیلتر ستونها را جابهجا نمیکند. */}
<Table stackOnMobile
layout="fixed"
className="min-w-[44rem]"
selectionMode="multiple"
selectedKeys={selected}
onSelectionChange={setSelected}
sortDescriptor={sort}
onSortChange={(descriptor) =>
setSort(descriptor as SortDescriptor)
}
>
<TableHeader className="bg-muted">
<TableRow>
<TableSelectAllCheckbox />
<TableHead sortKey="name" className="w-[34%]">
عضو
</TableHead>
<TableHead className="w-[14%]">نقش</TableHead>
<TableHead sortKey="lastSeen" className="w-[24%]">
آخرین فعالیت
</TableHead>
<TableHead className="w-[16%]">وضعیت</TableHead>
<TableHead align="end" className="w-16 pe-4">
<span className="sr-only">عملیات</span>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{rows.map((user) => (
<TableRow key={user.id} value={user.id}>
<TableCheckboxCell />
<TableCell>
{/* آواتار همیشه آیکون است، نه حروفِ اول؛ alt نام را برای صفحهخوان نگه میدارد. */}
<TableCellStack
media={
<Avatar
size="sm"
alt={user.name}
src={avatarPhoto(user.name, user.gender)}
icon={
<AvatarGenderIcon gender={user.gender} />
}
className="ring-1 ring-border"
/>
}
title={user.name}
description={user.email}
descriptionDir="ltr"
/>
</TableCell>
<TableCell>{ROLES[user.role]}</TableCell>
<TableCell>
<TableCellStack
title={formatRelativeTime(user.lastSeen)}
description={formatJalaliDateTime(user.lastSeen)}
className="[&_span:first-child]:font-normal"
/>
</TableCell>
<TableCell>
<Badge
variant="soft"
color={STATUS[user.status].color}
className="gap-1.5"
>
<span
aria-hidden
className="size-1.5 rounded-full bg-current"
/>
{STATUS[user.status].label}
</Badge>
</TableCell>
<TableCell align="end" className="pe-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
aria-label={`عملیات ${user.name}`}
>
<MoreHorizontalIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<EditIcon />
تغییر نقش
</DropdownMenuItem>
<DropdownMenuItem>
<UsersIcon />
{user.status === "inactive"
? "فعالکردن"
: "غیرفعالکردن"}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
variant="destructive"
onSelect={() => remove([user.id])}
>
<TrashIcon />
حذف از تیم
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
<footer className="flex flex-wrap items-center justify-between gap-3">
<span className="text-sm text-muted-foreground">
نمایش {toFaDigits(from)} تا {toFaDigits(to)} از{" "}
{toFaDigits(filtered.length)} عضو
</span>
<Pagination className="mx-0 w-auto">
<PaginationContent>
<PaginationItem>
<PaginationPrevious
href="#"
aria-disabled={currentPage === 1}
onClick={(event) => {
event.preventDefault();
setPage(Math.max(1, currentPage - 1));
}}
/>
</PaginationItem>
{Array.from(
{ length: pageCount },
(_, index) => index + 1,
).map((number) => (
<PaginationItem key={number}>
<PaginationLink
href="#"
isActive={number === currentPage}
onClick={(event) => {
event.preventDefault();
setPage(number);
}}
>
{toFaDigits(number)}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationNext
href="#"
aria-disabled={currentPage === pageCount}
onClick={(event) => {
event.preventDefault();
setPage(Math.min(pageCount, currentPage + 1));
}}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</footer>
</div>
)}
</section>
</ControlSizeProvider>
{/* اقدامهای گروهی نزدیکِ دست، فقط وقتی چیزی انتخاب شده. */}
<ActionBar open={selected.size > 0} aria-label="اقدامهای گروهی">
<ActionBarCount>
<strong>{toFaDigits(selected.size)}</strong> از{" "}
{toFaDigits(users.length)} انتخاب شد
</ActionBarCount>
<ActionBarAction onClick={() => bulk("نقش اعضا تغییر کرد.")}>
<EditIcon />
تغییر نقش
</ActionBarAction>
<ActionBarAction onClick={() => bulk("اعضا غیرفعال شدند.")}>
<UsersIcon />
غیرفعالکردن
</ActionBarAction>
<ActionBarSeparator />
<ActionBarAction
variant="destructive"
onClick={() => remove([...selected])}
>
<TrashIcon />
حذف
</ActionBarAction>
<ActionBarClose onClick={() => setSelected(new Set())} />
</ActionBar>
</main>
</ControlSizeProvider>
);
}
<script setup lang="ts">
import { computed, ref } from "vue"
import ActionBar from "@/components/ui/ActionBar.vue"
import ActionBarAction from "@/components/ui/ActionBarAction.vue"
import ActionBarClose from "@/components/ui/ActionBarClose.vue"
import ActionBarCount from "@/components/ui/ActionBarCount.vue"
import ActionBarSeparator from "@/components/ui/ActionBarSeparator.vue"
import Avatar from "@/components/ui/Avatar.vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Dialog from "@/components/ui/Dialog.vue"
import DialogContent from "@/components/ui/DialogContent.vue"
import DialogDescription from "@/components/ui/DialogDescription.vue"
import DialogFooter from "@/components/ui/DialogFooter.vue"
import DialogHeader from "@/components/ui/DialogHeader.vue"
import DialogTitle from "@/components/ui/DialogTitle.vue"
import DialogTrigger from "@/components/ui/DialogTrigger.vue"
import DropdownMenu from "@/components/ui/DropdownMenu.vue"
import DropdownMenuContent from "@/components/ui/DropdownMenuContent.vue"
import DropdownMenuItem from "@/components/ui/DropdownMenuItem.vue"
import DropdownMenuSeparator from "@/components/ui/DropdownMenuSeparator.vue"
import DropdownMenuTrigger from "@/components/ui/DropdownMenuTrigger.vue"
import EmptyState from "@/components/ui/EmptyState.vue"
import EmptyStateDescription from "@/components/ui/EmptyStateDescription.vue"
import EmptyStateTitle from "@/components/ui/EmptyStateTitle.vue"
import Label from "@/components/ui/Label.vue"
import Pagination from "@/components/ui/Pagination.vue"
import PaginationContent from "@/components/ui/PaginationContent.vue"
import PaginationItem from "@/components/ui/PaginationItem.vue"
import PaginationLink from "@/components/ui/PaginationLink.vue"
import PaginationNext from "@/components/ui/PaginationNext.vue"
import PaginationPrevious from "@/components/ui/PaginationPrevious.vue"
import SearchField from "@/components/ui/SearchField.vue"
import Select from "@/components/ui/Select.vue"
import SelectContent from "@/components/ui/SelectContent.vue"
import SelectItem from "@/components/ui/SelectItem.vue"
import SelectTrigger from "@/components/ui/SelectTrigger.vue"
import SelectValue from "@/components/ui/SelectValue.vue"
import Table from "@/components/ui/Table.vue"
import TableBody from "@/components/ui/TableBody.vue"
import TableCell from "@/components/ui/TableCell.vue"
import TableCellStack from "@/components/ui/TableCellStack.vue"
import TableCheckboxCell from "@/components/ui/TableCheckboxCell.vue"
import TableHead from "@/components/ui/TableHead.vue"
import TableHeader from "@/components/ui/TableHeader.vue"
import TableRow from "@/components/ui/TableRow.vue"
import TableSelectAllCheckbox from "@/components/ui/TableSelectAllCheckbox.vue"
import TextField from "@/components/ui/TextField.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatJalaliDateTime, formatRelativeTime, isValidEmail, toFaDigits, toSearchKey } from "@/lib/persian"
// stock-images:begin
/** تصویرهای کتابخانهٔ دیگ (همان آدرسهای `stockImages` نسخهٔ React). */
const stockImages: Record<string, { src: string; alt: string }> = {
personWoman1: { src: "https://docs.digdesign.ir/images/person-woman-1.webp", alt: "پرترهٔ زنی با روسری" },
personWoman2: { src: "https://docs.digdesign.ir/images/person-woman-2.webp", alt: "پرترهٔ زنی با کتِ طوسی" },
personWoman3: { src: "https://docs.digdesign.ir/images/person-woman-3.webp", alt: "پرترهٔ زنی خندان" },
personMan1: { src: "https://docs.digdesign.ir/images/person-man-1.webp", alt: "پرترهٔ مردی با لبخند" },
personMan2: { src: "https://docs.digdesign.ir/images/person-man-2.webp", alt: "پرترهٔ مردی با تیشرتِ سفید" },
}
// stock-images:end
const AVATAR_ICON = "size-[95%] translate-y-1 text-[color-mix(in_oklab,var(--muted-foreground)_55%,var(--muted))]"
/** همان `avatarPhoto` نسخهٔ React: از روی نام، یکی از عکسهای آماده را انتخاب میکند (گاهی هیچ، تا حروفِ اولِ نام بنشیند). */
function avatarPhoto(name: string, gender: "male" | "female"): string | undefined {
let hash = 0
for (const char of name) hash = (hash * 31 + char.charCodeAt(0)) >>> 0
if (hash % 4 === 3) return undefined
const pool = gender === "female" ? ["personWoman1", "personWoman2", "personWoman3"] : ["personMan1", "personMan2"]
return stockImages[pool[hash % pool.length]].src
}
type Role = "admin" | "editor" | "viewer"
type Status = "active" | "away" | "inactive"
const ROLES: Record<Role, string> = {
admin: "مدیر",
editor: "ویرایشگر",
viewer: "بیننده",
}
const ROLE_KEYS = Object.keys(ROLES) as Role[]
const STATUS: Record<Status, { label: string; color: "success" | "warning" | "default" }> = {
active: { label: "فعال", color: "success" },
away: { label: "مرخصی", color: "warning" },
inactive: { label: "غیرفعال", color: "default" },
}
type User = { id: string; name: string; email: string; gender: "male" | "female"; role: Role; lastSeen: string; status: Status }
const USERS: User[] = [
{ id: "1", name: "آرمیتا رستگار", email: "armita@dig.ir", gender: "female", role: "admin", lastSeen: "2026-10-05T09:40:00", status: "active" },
{ id: "2", name: "کیان مرادی", email: "kian@dig.ir", gender: "male", role: "editor", lastSeen: "2026-10-05T08:15:00", status: "active" },
{ id: "3", name: "نیلوفر احمدی", email: "niloofar@dig.ir", gender: "female", role: "viewer", lastSeen: "2026-09-20T10:00:00", status: "inactive" },
{ id: "4", name: "سامان کریمی", email: "saman@dig.ir", gender: "male", role: "editor", lastSeen: "2026-10-04T16:20:00", status: "away" },
{ id: "5", name: "مهسا توکلی", email: "mahsa@dig.ir", gender: "female", role: "viewer", lastSeen: "2026-10-03T11:45:00", status: "active" },
{ id: "6", name: "پرهام نوری", email: "parham@dig.ir", gender: "male", role: "editor", lastSeen: "2026-10-01T13:10:00", status: "active" },
{ id: "7", name: "ترانه شریفی", email: "taraneh@dig.ir", gender: "female", role: "admin", lastSeen: "2026-09-28T09:30:00", status: "away" },
{ id: "8", name: "بهراد صالحی", email: "behrad@dig.ir", gender: "male", role: "viewer", lastSeen: "2026-09-25T18:05:00", status: "active" },
]
const PAGE_SIZE = 5
type SortDescriptor = { column: string; direction: "ascending" | "descending" }
/**
* اعضای تیم: جدولِ انتخابپذیر و مرتبشونده با جستوجو، فیلترِ نقش، صفحهبندی، دیالوگِ دعوت و نوارِ اقدامِ گروهی.
* همان صفحهٔ `user-management` نسخهٔ React.
*/
const users = ref<User[]>([...USERS])
const query = ref("")
const role = ref<"all" | Role>("all")
const open = ref(false)
const selected = ref<Set<string>>(new Set())
const sort = ref<SortDescriptor>({ column: "lastSeen", direction: "descending" })
const page = ref(1)
const filtered = computed(() => {
const key = toSearchKey(query.value)
return users.value
.filter((user) => (role.value === "all" || user.role === role.value) && toSearchKey(user.name + user.email).includes(key))
.sort((a, b) => {
const order = sort.value.column === "name" ? a.name.localeCompare(b.name, "fa") : a.lastSeen.localeCompare(b.lastSeen)
return sort.value.direction === "ascending" ? order : -order
})
})
const pageCount = computed(() => Math.max(1, Math.ceil(filtered.value.length / PAGE_SIZE)))
const currentPage = computed(() => Math.min(page.value, pageCount.value))
const rows = computed(() => filtered.value.slice((currentPage.value - 1) * PAGE_SIZE, currentPage.value * PAGE_SIZE))
const from = computed(() => (filtered.value.length === 0 ? 0 : (currentPage.value - 1) * PAGE_SIZE + 1))
const to = computed(() => Math.min(currentPage.value * PAGE_SIZE, filtered.value.length))
// حذف برگشتپذیر است (دعوتِ دوباره)؛ پس اسنکبارِ «برگردان» بهجای دیالوگِ تأیید.
function remove(ids: string[]) {
const before = users.value
users.value = users.value.filter((user) => !ids.includes(user.id))
selected.value = new Set()
toast(ids.length === 1 ? "عضو از تیم حذف شد." : `${toFaDigits(ids.length)} عضو از تیم حذف شدند.`, {
action: { label: "برگردان", onClick: () => (users.value = before) },
})
}
function bulk(message: string) {
toast.success(message, { description: `${toFaDigits(selected.value.size)} عضو` })
selected.value = new Set()
}
function onSearch(value: string) {
query.value = value
page.value = 1
}
function onRole(value: string | string[] | undefined) {
role.value = value as "all" | Role
page.value = 1
}
function validateEmail(value: string) {
return isValidEmail(value) ? undefined : "ایمیل معتبر نیست؛ مثل name@example.com"
}
function submitInvite() {
open.value = false
toast.success("دعوتنامه ارسال شد.")
}
</script>
<template>
<ControlSize size="xl" as-child>
<main class="mx-auto flex w-full min-w-0 max-w-5xl flex-col gap-6 p-4 pb-28 sm:p-6 sm:pb-28">
<ControlSize size="xl">
<!-- سلسلهمراتب: عنوان و توضیح نزدیک، اکشنِ اصلی همردیفِ عنوان. -->
<header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
<div class="flex flex-col gap-1">
<h1 class="text-2xl font-bold">اعضای تیم</h1>
<p class="text-sm text-muted-foreground">{{ toFaDigits(users.length) }} عضو؛ نقش هر نفر مشخص میکند به چه بخشهایی دسترسی دارد.</p>
</div>
<Dialog v-model:open="open">
<DialogTrigger as-child>
<Button>
<DigIcon name="plus" />
دعوت عضو
</Button>
</DialogTrigger>
<ControlSize size="xl" as-child>
<DialogContent>
<DialogHeader>
<DialogTitle>دعوت عضو تازه</DialogTitle>
<DialogDescription>لینک دعوت به ایمیل او فرستاده میشود.</DialogDescription>
</DialogHeader>
<form id="invite" class="flex flex-col gap-4" @submit.prevent="submitInvite">
<TextField label="ایمیل" name="email" type="email" dir="ltr" required :validate="validateEmail" />
<div class="flex flex-col gap-2">
<Label id="invite-role">نقش</Label>
<Select name="role" default-value="viewer">
<SelectTrigger aria-labelledby="invite-role" class="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="item in ROLE_KEYS" :key="item" :value="item">{{ ROLES[item] }}</SelectItem>
</SelectContent>
</Select>
</div>
</form>
<DialogFooter>
<Button type="submit" form="invite">ارسال دعوت</Button>
</DialogFooter>
</DialogContent>
</ControlSize>
</Dialog>
</header>
<!-- جدول، نوارِ ابزار و صفحهبندی یک سطحاند: هر سه داخلِ همان کارت. -->
<!-- ابزارها بیرونِ قاب و ۳۲ پیکسل بالای جدول؛ فقط خودِ جدول قاب دارد، صفحهبندی زیرش. -->
<section aria-label="فهرست اعضا" class="flex flex-col gap-8">
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
<SearchField aria-label="جستوجوی عضو" placeholder="جستوجوی نام یا ایمیل" :model-value="query" class="min-w-0 flex-1 sm:max-w-xs" @update:model-value="onSearch" />
<Select :value="role" @update:value="onRole">
<SelectTrigger aria-label="فیلتر نقش" class="w-full sm:ms-auto sm:w-40">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">همهٔ نقشها</SelectItem>
<SelectItem v-for="item in ROLE_KEYS" :key="item" :value="item">{{ ROLES[item] }}</SelectItem>
</SelectContent>
</Select>
</div>
<EmptyState v-if="rows.length === 0" variant="bordered" class="py-14">
<DigIcon name="users" aria-hidden="true" class="size-8 text-placeholder" />
<EmptyStateTitle>عضوی با این مشخصات نیست</EmptyStateTitle>
<EmptyStateDescription>نام دیگری جستوجو کنید یا فیلتر نقش را بردارید.</EmptyStateDescription>
</EmptyState>
<div v-else class="flex flex-col gap-4">
<div class="overflow-x-auto rounded-xl border border-border bg-card">
<!-- table-fixed با عرضِ ستونهای ثابت: مرتبسازی و فیلتر ستونها را جابهجا نمیکند. -->
<Table
v-model:selected-keys="selected"
v-model:sort-descriptor="sort"
stack-on-mobile
layout="fixed"
class="min-w-[44rem]"
selection-mode="multiple"
>
<TableHeader class="bg-muted">
<TableRow>
<TableSelectAllCheckbox />
<TableHead sort-key="name" class="w-[34%]">عضو</TableHead>
<TableHead class="w-[14%]">نقش</TableHead>
<TableHead sort-key="lastSeen" class="w-[24%]">آخرین فعالیت</TableHead>
<TableHead class="w-[16%]">وضعیت</TableHead>
<TableHead align="end" class="w-16 pe-4">
<span class="sr-only">عملیات</span>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="user in rows" :key="user.id" :value="user.id">
<TableCheckboxCell />
<TableCell>
<!-- آواتار همیشه آیکون است، نه حروفِ اول؛ alt نام را برای صفحهخوان نگه میدارد. -->
<TableCellStack :title="user.name" :description="user.email" description-dir="ltr">
<template #media>
<Avatar size="sm" :alt="user.name" :src="avatarPhoto(user.name, user.gender)" class="ring-1 ring-border">
<template #icon><DigIcon :name="user.gender === 'male' ? 'avatar-male' : 'avatar-female'" :class="AVATAR_ICON" /></template>
</Avatar>
</template>
</TableCellStack>
</TableCell>
<TableCell>{{ ROLES[user.role] }}</TableCell>
<TableCell>
<TableCellStack :title="formatRelativeTime(user.lastSeen)" :description="formatJalaliDateTime(user.lastSeen)" class="[&_span:first-child]:font-normal" />
</TableCell>
<TableCell>
<Badge variant="soft" :color="STATUS[user.status].color" class="gap-1.5">
<span aria-hidden="true" class="size-1.5 rounded-full bg-current" />
{{ STATUS[user.status].label }}
</Badge>
</TableCell>
<TableCell align="end" class="pe-4">
<DropdownMenu>
<DropdownMenuTrigger as-child>
<Button variant="ghost" size="icon" :aria-label="`عملیات ${user.name}`">
<DigIcon name="more-horizontal" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem>
<DigIcon name="edit" />
تغییر نقش
</DropdownMenuItem>
<DropdownMenuItem>
<DigIcon name="users" />
{{ user.status === "inactive" ? "فعالکردن" : "غیرفعالکردن" }}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" @select="remove([user.id])">
<DigIcon name="trash" />
حذف از تیم
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
</TableBody>
</Table>
</div>
<footer class="flex flex-wrap items-center justify-between gap-3">
<span class="text-sm text-muted-foreground">نمایش {{ toFaDigits(from) }} تا {{ toFaDigits(to) }} از {{ toFaDigits(filtered.length) }} عضو</span>
<Pagination class="mx-0 w-auto">
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" :aria-disabled="currentPage === 1" @click.prevent="page = Math.max(1, currentPage - 1)" />
</PaginationItem>
<PaginationItem v-for="number in pageCount" :key="number">
<PaginationLink href="#" :is-active="number === currentPage" @click.prevent="page = number">{{ toFaDigits(number) }}</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" :aria-disabled="currentPage === pageCount" @click.prevent="page = Math.min(pageCount, currentPage + 1)" />
</PaginationItem>
</PaginationContent>
</Pagination>
</footer>
</div>
</section>
</ControlSize>
<!-- اقدامهای گروهی نزدیکِ دست، فقط وقتی چیزی انتخاب شده. -->
<ActionBar :open="selected.size > 0" aria-label="اقدامهای گروهی">
<ActionBarCount>
<strong>{{ toFaDigits(selected.size) }}</strong>
از {{ toFaDigits(users.length) }} انتخاب شد
</ActionBarCount>
<ActionBarAction @click="bulk('نقش اعضا تغییر کرد.')">
<DigIcon name="edit" />
تغییر نقش
</ActionBarAction>
<ActionBarAction @click="bulk('اعضا غیرفعال شدند.')">
<DigIcon name="users" />
غیرفعالکردن
</ActionBarAction>
<ActionBarSeparator />
<ActionBarAction variant="destructive" @click="remove([...selected])">
<DigIcon name="trash" />
حذف
</ActionBarAction>
<ActionBarClose @click="selected = new Set()" />
</ActionBar>
</main>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: action-baravatarbadgecontrol-sizedialogdropdown-menuempty-statelabelpaginationpersiansearch-fieldselecttabletext-fieldtoastآیکون avatar-genderآیکون editآیکون more-horizontalآیکون plusآیکون trashآیکون users
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"
import { DigControlSize } from "@/components/ui/control-size"
import {
DigDialog,
DigDialogTrigger,
DigDialogContent,
DigDialogHeader,
DigDialogTitle,
DigDialogDescription,
DigDialogFooter,
} from "@/components/ui/dialog"
import { DigButton } from "@/components/ui/button"
import { DigIcon } from "@/lib/icons"
import { DigTextField } from "@/components/ui/text-field"
import { DigInput, DigInputField } from "@/components/ui/input"
import { DigLabel } from "@/components/ui/label"
import { DigSelect, DigSelectTrigger, DigSelectValue, DigSelectContent, DigSelectItem } from "@/components/ui/select"
import { DigSearchField } from "@/components/ui/search-field"
import { DigEmptyState, DigEmptyStateTitle, DigEmptyStateDescription } from "@/components/ui/empty-state"
import {
DigTable,
DigTableHeader,
DigTableRow,
DigTableSelectAllCheckbox,
DigTableHead,
DigTableBody,
DigTableCheckboxCell,
DigTableCell,
DigTableCellStack,
DigTableCellStackMedia,
} from "@/components/ui/table"
import { DigAvatar } from "@/components/ui/avatar"
import { DigBadge } from "@/components/ui/badge"
import {
DigDropdownMenu,
DigDropdownMenuTrigger,
DigDropdownMenuContent,
DigDropdownMenuItem,
DigDropdownMenuSeparator,
} from "@/components/ui/dropdown-menu"
import {
DigPagination,
DigPaginationContent,
DigPaginationItem,
DigPaginationPrevious,
DigPaginationLink,
DigPaginationNext,
} from "@/components/ui/pagination"
import {
DigActionBar,
DigActionBarCount,
DigActionBarAction,
DigActionBarSeparator,
DigActionBarClose,
} from "@/components/ui/action-bar"
import { toast } from "@/components/ui/toast"
import { formatJalaliDateTime, formatRelativeTime, isValidEmail, toFaDigits, toSearchKey } from "@/lib/persian"
const stockImages: Record<string, { src: string; alt: string }> = {
personWoman1: {
src: "https://docs.digdesign.ir/images/person-woman-1.webp",
alt: "پرترهٔ زنی با روسری",
},
personWoman2: {
src: "https://docs.digdesign.ir/images/person-woman-2.webp",
alt: "پرترهٔ زنی با کتِ طوسی",
},
personWoman3: {
src: "https://docs.digdesign.ir/images/person-woman-3.webp",
alt: "پرترهٔ زنی خندان",
},
personMan1: {
src: "https://docs.digdesign.ir/images/person-man-1.webp",
alt: "پرترهٔ مردی با لبخند",
},
personMan2: {
src: "https://docs.digdesign.ir/images/person-man-2.webp",
alt: "پرترهٔ مردی با تیشرتِ سفید",
},
}
const AVATAR_ICON = "size-[95%] translate-y-1 text-[color-mix(in_oklab,var(--muted-foreground)_55%,var(--muted))]"
function avatarPhoto(name: string, gender: "male" | "female"): string | undefined {
let hash = 0
for (const char of name) hash = (hash * 31 + char.charCodeAt(0)) >>> 0
if (hash % 4 === 3) return undefined
const pool = gender === "female" ? ["personWoman1", "personWoman2", "personWoman3"] : ["personMan1", "personMan2"]
return stockImages[pool[hash % pool.length]].src
}
type Role = "admin" | "editor" | "viewer"
type Status = "active" | "away" | "inactive"
const ROLES: Record<Role, string> = {
admin: "مدیر",
editor: "ویرایشگر",
viewer: "بیننده",
}
const ROLE_KEYS = Object.keys(ROLES) as Role[]
const STATUS: Record<Status, { label: string; color: "success" | "warning" | "default" }> = {
active: { label: "فعال", color: "success" },
away: { label: "مرخصی", color: "warning" },
inactive: { label: "غیرفعال", color: "default" },
}
type User = {
id: string
name: string
email: string
gender: "male" | "female"
role: Role
lastSeen: string
status: Status
}
const USERS: User[] = [
{
id: "1",
name: "آرمیتا رستگار",
email: "armita@dig.ir",
gender: "female",
role: "admin",
lastSeen: "2026-10-05T09:40:00",
status: "active",
},
{
id: "2",
name: "کیان مرادی",
email: "kian@dig.ir",
gender: "male",
role: "editor",
lastSeen: "2026-10-05T08:15:00",
status: "active",
},
{
id: "3",
name: "نیلوفر احمدی",
email: "niloofar@dig.ir",
gender: "female",
role: "viewer",
lastSeen: "2026-09-20T10:00:00",
status: "inactive",
},
{
id: "4",
name: "سامان کریمی",
email: "saman@dig.ir",
gender: "male",
role: "editor",
lastSeen: "2026-10-04T16:20:00",
status: "away",
},
{
id: "5",
name: "مهسا توکلی",
email: "mahsa@dig.ir",
gender: "female",
role: "viewer",
lastSeen: "2026-10-03T11:45:00",
status: "active",
},
{
id: "6",
name: "پرهام نوری",
email: "parham@dig.ir",
gender: "male",
role: "editor",
lastSeen: "2026-10-01T13:10:00",
status: "active",
},
{
id: "7",
name: "ترانه شریفی",
email: "taraneh@dig.ir",
gender: "female",
role: "admin",
lastSeen: "2026-09-28T09:30:00",
status: "away",
},
{
id: "8",
name: "بهراد صالحی",
email: "behrad@dig.ir",
gender: "male",
role: "viewer",
lastSeen: "2026-09-25T18:05:00",
status: "active",
},
]
const PAGE_SIZE = 5
type SortDescriptor = { column: string; direction: "ascending" | "descending" }
function validateEmail(value: string) {
return isValidEmail(value) ? undefined : "ایمیل معتبر نیست؛ مثل name@example.com"
}
@Component({
selector: "dig-block-user-management",
imports: [
DigControlSize,
DigDialog,
DigDialogTrigger,
DigDialogContent,
DigDialogHeader,
DigDialogTitle,
DigDialogDescription,
DigDialogFooter,
DigButton,
DigIcon,
DigTextField,
DigInput,
DigInputField,
DigLabel,
DigSelect,
DigSelectTrigger,
DigSelectValue,
DigSelectContent,
DigSelectItem,
DigSearchField,
DigEmptyState,
DigEmptyStateTitle,
DigEmptyStateDescription,
DigTable,
DigTableHeader,
DigTableRow,
DigTableSelectAllCheckbox,
DigTableHead,
DigTableBody,
DigTableCheckboxCell,
DigTableCell,
DigTableCellStack,
DigTableCellStackMedia,
DigAvatar,
DigBadge,
DigDropdownMenu,
DigDropdownMenuTrigger,
DigDropdownMenuContent,
DigDropdownMenuItem,
DigDropdownMenuSeparator,
DigPagination,
DigPaginationContent,
DigPaginationItem,
DigPaginationPrevious,
DigPaginationLink,
DigPaginationNext,
DigActionBar,
DigActionBarCount,
DigActionBarAction,
DigActionBarSeparator,
DigActionBarClose,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<main digControlSize="xl" class="mx-auto flex w-full min-w-0 max-w-5xl flex-col gap-6 p-4 pb-28 sm:p-6 sm:pb-28">
<div digControlSize="xl">
<!-- سلسلهمراتب: عنوان و توضیح نزدیک، اکشنِ اصلی همردیفِ عنوان. -->
<header class="flex flex-wrap items-end justify-between gap-x-4 gap-y-8">
<div class="flex flex-col gap-1">
<h1 class="text-2xl font-bold">اعضای تیم</h1>
<p class="text-sm text-muted-foreground">
{{ toFaDigits(users().length) }} عضو؛ نقش هر نفر مشخص میکند به چه بخشهایی دسترسی دارد.
</p>
</div>
<ng-container digDialog [open]="open()" (openChange)="open.set($event)"
><button digDialogTrigger digButton type="button">
<svg digIcon="plus"></svg>
دعوت عضو
</button>
<div digControlSize="xl" digDialogContent>
<div digDialogHeader>
<h2 digDialogTitle>دعوت عضو تازه</h2>
<p digDialogDescription>لینک دعوت به ایمیل او فرستاده میشود.</p>
</div>
<form id="invite" class="flex flex-col gap-4" (submit)="$event.preventDefault(); submitInvite()">
<div digTextField label="ایمیل" required [validate]="validateEmail">
<dig-input><input digInput name="email" type="email" dir="ltr" /></dig-input>
</div>
<div class="flex flex-col gap-2">
<label digLabel id="invite-role">نقش</label>
<ng-container digSelect name="role" value="viewer"
><button digSelectTrigger aria-labelledby="invite-role" class="w-full">
<span digSelectValue></span>
</button>
<div digSelectContent>
@for (item of ROLE_KEYS; track item) {
<div digSelectItem [value]="item">
{{ ROLES[item] }}
</div>
}
</div></ng-container
>
</div>
</form>
<div digDialogFooter>
<button digButton type="submit" form="invite">ارسال دعوت</button>
</div>
</div></ng-container
>
</header>
<!-- جدول، نوارِ ابزار و صفحهبندی یک سطحاند: هر سه داخلِ همان کارت. -->
<!-- ابزارها بیرونِ قاب و ۳۲ پیکسل بالای جدول؛ فقط خودِ جدول قاب دارد، صفحهبندی زیرش. -->
<section aria-label="فهرست اعضا" class="flex flex-col gap-8">
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
<div
digSearchField
aria-label="جستوجوی عضو"
placeholder="جستوجوی نام یا ایمیل"
[value]="query()"
class="min-w-0 flex-1 sm:max-w-xs"
(valueChange)="onSearch($event)"
></div>
<ng-container digSelect [value]="role()" (valueChange)="onRole($event)"
><button digSelectTrigger aria-label="فیلتر نقش" class="w-full sm:ms-auto sm:w-40">
<span digSelectValue></span>
</button>
<div digSelectContent>
<div digSelectItem value="all">همهٔ نقشها</div>
@for (item of ROLE_KEYS; track item) {
<div digSelectItem [value]="item">{{ ROLES[item] }}</div>
}
</div></ng-container
>
</div>
@if (rows().length === 0) {
<div digEmptyState variant="bordered" class="py-14">
<svg digIcon="users" aria-hidden="true" class="size-8 text-placeholder"></svg>
<h3 digEmptyStateTitle>عضوی با این مشخصات نیست</h3>
<p digEmptyStateDescription>نام دیگری جستوجو کنید یا فیلتر نقش را بردارید.</p>
</div>
} @else {
<div class="flex flex-col gap-4">
<div class="overflow-x-auto rounded-xl border border-border bg-card">
<!-- table-fixed با عرضِ ستونهای ثابت: مرتبسازی و فیلتر ستونها را جابهجا نمیکند. -->
<dig-table
[selectedKeys]="selected()"
(selectedKeysChange)="selected.set($event)"
[sortDescriptor]="sort()"
(sortDescriptorChange)="setSort($event)"
stackOnMobile
layout="fixed"
class="min-w-[44rem]"
selectionMode="multiple"
><thead digTableHeader class="bg-muted">
<tr digTableRow>
<th digTableSelectAllCheckbox></th>
<th digTableHead sortKey="name" class="w-[34%]">عضو</th>
<th digTableHead class="w-[14%]">نقش</th>
<th digTableHead sortKey="lastSeen" class="w-[24%]">آخرین فعالیت</th>
<th digTableHead class="w-[16%]">وضعیت</th>
<th digTableHead align="end" class="w-16 pe-4">
<span class="sr-only">عملیات</span>
</th>
</tr>
</thead>
<tbody digTableBody>
@for (user of rows(); track user.id) {
<tr digTableRow [value]="user.id">
<td digTableCheckboxCell></td>
<td digTableCell>
<!-- آواتار همیشه آیکون است، نه حروفِ اول؛ alt نام را برای صفحهخوان نگه میدارد. -->
<div digTableCellStack [title]="user.name" [description]="user.email" descriptionDir="ltr">
<span digTableCellStackMedia
><span
digAvatar
size="sm"
[alt]="user.name"
[src]="avatarPhoto(user.name, user.gender)"
class="ring-1 ring-border"
[iconName]="user.gender === 'male' ? 'avatar-male' : 'avatar-female'"
></span
></span>
</div>
</td>
<td digTableCell>{{ ROLES[user.role] }}</td>
<td digTableCell>
<div
digTableCellStack
[title]="formatRelativeTime(user.lastSeen)"
[description]="formatJalaliDateTime(user.lastSeen)"
class="[&_span:first-child]:font-normal"
></div>
</td>
<td digTableCell>
<span digBadge variant="soft" [color]="STATUS[user.status].color" class="gap-1.5"
><span aria-hidden="true" class="size-1.5 rounded-full bg-current"></span>
{{ STATUS[user.status].label }}</span
>
</td>
<td digTableCell align="end" class="pe-4">
<ng-container digDropdownMenu
><button
digDropdownMenuTrigger
digButton
type="button"
variant="ghost"
size="icon"
[attr.aria-label]="\`عملیات \${user.name}\`"
>
<svg digIcon="more-horizontal"></svg>
</button>
<div digDropdownMenuContent align="end">
<div digDropdownMenuItem>
<svg digIcon="edit"></svg>
تغییر نقش
</div>
<div digDropdownMenuItem>
<svg digIcon="users"></svg>
{{ user.status === "inactive" ? "فعالکردن" : "غیرفعالکردن" }}
</div>
<div digDropdownMenuSeparator></div>
<div digDropdownMenuItem variant="destructive" (select)="remove([user.id])">
<svg digIcon="trash"></svg>
حذف از تیم
</div>
</div></ng-container
>
</td>
</tr>
}
</tbody></dig-table
>
</div>
<footer class="flex flex-wrap items-center justify-between gap-3">
<span class="text-sm text-muted-foreground"
>نمایش {{ toFaDigits(from()) }} تا {{ toFaDigits(to()) }} از
{{ toFaDigits(filtered().length) }} عضو</span
>
<nav digPagination class="mx-0 w-auto">
<ul digPaginationContent>
<li digPaginationItem>
<a
digPaginationPrevious
href="#"
[attr.aria-disabled]="currentPage() === 1"
(click)="$event.preventDefault(); page.set(math.max(1, currentPage() - 1))"
></a>
</li>
@for (number of range(pageCount()); track number) {
<li digPaginationItem>
<a
digPaginationLink
href="#"
[isActive]="number === currentPage()"
(click)="$event.preventDefault(); page.set(number)"
>{{ toFaDigits(number) }}</a
>
</li>
}
<li digPaginationItem>
<a
digPaginationNext
href="#"
[attr.aria-disabled]="currentPage() === pageCount()"
(click)="$event.preventDefault(); page.set(math.min(pageCount(), currentPage() + 1))"
></a>
</li>
</ul>
</nav>
</footer>
</div>
}
</section>
</div>
<!-- اقدامهای گروهی نزدیکِ دست، فقط وقتی چیزی انتخاب شده. -->
<div digActionBar [open]="selected().size > 0" aria-label="اقدامهای گروهی">
<span digActionBarCount
><strong>{{ toFaDigits(selected().size) }}</strong> از {{ toFaDigits(users().length) }} انتخاب شد
</span>
<button digActionBarAction (click)="bulk('نقش اعضا تغییر کرد.')">
<svg digIcon="edit"></svg>
تغییر نقش
</button>
<button digActionBarAction (click)="bulk('اعضا غیرفعال شدند.')">
<svg digIcon="users"></svg>
غیرفعالکردن
</button>
<span digActionBarSeparator></span>
<button digActionBarAction variant="destructive" (click)="remove([...selected()])">
<svg digIcon="trash"></svg>
حذف
</button>
<button digActionBarClose (click)="clearSelection()"></button>
</div>
</main>
`,
})
export class UserManagementBlock {
range(count: number) {
return Array.from({ length: count }, (_, index) => index + 1)
}
readonly math = Math
readonly toFaDigits = toFaDigits
readonly formatRelativeTime = formatRelativeTime
readonly formatJalaliDateTime = formatJalaliDateTime
readonly validateEmail = validateEmail
readonly STATUS = STATUS
readonly ROLE_KEYS = ROLE_KEYS
readonly ROLES = ROLES
readonly avatarPhoto = avatarPhoto
readonly users = signal<User[]>([...USERS])
readonly query = signal("")
readonly role = signal<"all" | Role>("all")
readonly open = signal(false)
readonly selected = signal<Set<string>>(new Set())
readonly sort = signal<SortDescriptor>({
column: "lastSeen",
direction: "descending",
})
readonly page = signal(1)
readonly filtered = computed(() => {
const key = toSearchKey(this.query())
return this.users()
.filter(
(user) =>
(this.role() === "all" || user.role === this.role()) && toSearchKey(user.name + user.email).includes(key)
)
.sort((a, b) => {
const order =
this.sort().column === "name" ? a.name.localeCompare(b.name, "fa") : a.lastSeen.localeCompare(b.lastSeen)
return this.sort().direction === "ascending" ? order : -order
})
})
readonly pageCount = computed(() => Math.max(1, Math.ceil(this.filtered().length / PAGE_SIZE)))
readonly currentPage = computed(() => Math.min(this.page(), this.pageCount()))
readonly rows = computed(() =>
this.filtered().slice((this.currentPage() - 1) * PAGE_SIZE, this.currentPage() * PAGE_SIZE)
)
readonly from = computed(() => (this.filtered().length === 0 ? 0 : (this.currentPage() - 1) * PAGE_SIZE + 1))
readonly to = computed(() => Math.min(this.currentPage() * PAGE_SIZE, this.filtered().length))
remove(ids: string[]) {
const before = this.users()
this.users.set(this.users().filter((user) => !ids.includes(user.id)))
this.selected.set(new Set())
toast(ids.length === 1 ? "عضو از تیم حذف شد." : `${toFaDigits(ids.length)} عضو از تیم حذف شدند.`, {
action: { label: "برگردان", onClick: () => this.users.set(before) },
})
}
bulk(message: string) {
toast.success(message, {
description: `${toFaDigits(this.selected().size)} عضو`,
})
this.selected.set(new Set())
}
onSearch(value: string) {
this.query.set(value)
this.page.set(1)
}
onRole(value: string | string[] | undefined) {
this.role.set(value as "all" | Role)
this.page.set(1)
}
submitInvite() {
this.open.set(false)
toast.success("دعوتنامه ارسال شد.")
}
setSort(value: SortDescriptor | undefined) {
if (value) this.sort.set(value)
}
clearSelection() {
this.selected.set(new Set())
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
همهٔ کامپوننتهای لازم برای Android آمادهاند؛ با MCP میتوانید همین صفحه را از روی نسخهٔ React بسازید.
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.