گالریِ قاب و نوار
پیشنمایش تمامصفحهبخشِ گالری: قابِ بزرگ با تیتر و توضیح و نوارِ تصاویرِ کوچک زیرش؛ انتخابِ هر تصویر قاب را عوض میکند و نوارِ زمان خودکار به بعدی میرود.
۱. نصب کامپوننتها
این بلاک از ۳ آیتم دیگ استفاده میکند: chipcontrol-sizereveal
npx digdesign@latest add https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/reveal.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/reveal.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/reveal.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/chip.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/reveal.jsonnpx digdesign@latest add chip control-size reveal --framework vuepnpm dlx digdesign@latest add chip control-size reveal --framework vueyarn dlx digdesign@latest add chip control-size reveal --framework vuebunx --bun digdesign@latest add chip control-size reveal --framework vueهیچکدام از کامپوننتهای این بلاک هنوز برای Svelte پورت نشده است.
npx digdesign@latest add chip control-size reveal utils --framework angularpnpm dlx digdesign@latest add chip control-size reveal utils --framework angularyarn dlx digdesign@latest add chip control-size reveal utils --framework angularbunx --bun digdesign@latest add chip control-size reveal utils --framework angularnpx digdesign@latest add chip control-size --framework androidpnpm dlx digdesign@latest add chip control-size --framework androidyarn dlx digdesign@latest add chip control-size --framework androidbunx --bun digdesign@latest add chip control-size --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client";
import * as React from "react";
import { Chip } from "@/components/ui/chip";
import { ControlSizeProvider } from "@/components/ui/control-size";
import { Reveal } from "@/components/ui/reveal";
import { cn } from "@/lib/utils";
import { stockImages, type StockImageName } from "@/lib/stock-images";
const FRAMES: { photo: StockImageName; title: string; text: string }[] = [
{
photo: "projectDashboard",
title: "داشبوردِ فروش",
text: "گزارشِ روزانه در یک نگاه، بدونِ خروجیِ اکسل.",
},
{
photo: "projectMobileApp",
title: "اپِ موبایل",
text: "سفارشها و پیامها را در راه هم جواب بدهید.",
},
{
photo: "projectCafeBrand",
title: "هویتِ بصری",
text: "منو، بستهبندی و تابلو با یک زبانِ بصری.",
},
{
photo: "coverWorkspace",
title: "کارِ تیمی",
text: "هر کس میداند امروز نوبتِ کدام کار است.",
},
];
/**
* گالریِ قاب و نوار: عکسِ بزرگ با تیتر و توضیحِ روی آن، و زیرش نوارِ تصاویرِ کوچک که
* با انتخاب، قابِ بزرگ عوض میشود؛ نوارِ زمان روی تصویرِ کوچکِ فعال پر میشود و
* خودکار به بعدی میرود.
*/
export default function GalleryFilmstripBlock() {
const [active, setActive] = React.useState(0);
const [paused, setPaused] = React.useState(false);
const frame = FRAMES[active];
React.useEffect(() => {
if (
paused ||
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
)
return;
const timer = window.setTimeout(
() => setActive((current) => (current + 1) % FRAMES.length),
5000,
);
return () => window.clearTimeout(timer);
}, [active, paused]);
return (
<ControlSizeProvider size="xl" asChild>
<section
aria-labelledby="fs-title"
className="mx-auto flex w-full max-w-6xl flex-col gap-10 px-4 py-24 sm:px-6"
>
<div className="flex max-w-2xl flex-col gap-3">
<span className="text-sm font-semibold text-brand-secondary">
محصول
</span>
<h2
id="fs-title"
className="text-3xl leading-snug font-black text-balance sm:text-4xl"
>
همهچیزِ کسبوکار، در چهار قاب
</h2>
</div>
<Reveal
className="flex flex-col gap-4"
onMouseEnter={() => setPaused(true)}
onMouseLeave={() => setPaused(false)}
>
<div className="relative aspect-[4/5] overflow-hidden rounded-xl bg-muted sm:aspect-[16/8]">
{FRAMES.map((item, index) => (
// eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ
<img
key={item.photo}
src={stockImages[item.photo].src}
alt={index === active ? stockImages[item.photo].alt : ""}
aria-hidden={index !== active}
className={cn(
"absolute inset-0 size-full object-cover transition-[opacity,scale] duration-700",
index === active ? "scale-100" : "scale-105 [opacity:0]",
)}
/>
))}
<div
aria-live="polite"
className="absolute inset-x-0 bottom-0 flex flex-col gap-2 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-6 pt-24 text-[var(--dig-white)] sm:p-10 sm:pt-32"
>
<h3 className="text-2xl font-black sm:text-3xl">{frame.title}</h3>
<p className="max-w-md leading-7 text-[var(--dig-neutral-300)]">
{frame.text}
</p>
</div>
</div>
<div
role="tablist"
aria-label="قابها"
className="grid grid-cols-4 gap-2 sm:gap-4"
>
{FRAMES.map((item, index) => (
<Chip asChild key={item.photo} variant="secondary">
<button
type="button"
role="tab"
aria-selected={index === active}
aria-label={item.title}
onClick={() => setActive(index)}
className={cn(
"group relative block h-auto w-full overflow-hidden rounded-lg border-0 bg-transparent p-0 text-start text-base whitespace-normal outline-none ring-offset-2 ring-offset-background focus-visible:ring-2 focus-visible:ring-ring",
index === active ? "ring-2 ring-foreground" : "",
)}
>
{/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
<img
src={stockImages[item.photo].src}
alt=""
className={cn(
"aspect-[16/10] w-full object-cover transition-[filter]",
index !== active && "grayscale group-hover:grayscale-0",
)}
/>
<span
aria-hidden
className="absolute inset-x-0 bottom-0 h-1 bg-[color-mix(in_oklab,var(--dig-white)_40%,transparent)]"
>
{index === active && (
<span
key={`${active}-${paused}`}
className={cn(
"block h-full origin-right bg-[var(--dig-white)]",
!paused && "animate-[fs-fill_5s_linear_forwards]",
)}
/>
)}
</span>
<span className="hidden p-2 text-start text-sm font-semibold sm:block">
{item.title}
</span>
</button>
</Chip>
))}
</div>
</Reveal>
<style>
{
"@keyframes fs-fill{from{transform:scaleX(0)}to{transform:scaleX(1)}}"
}
</style>
</section>
</ControlSizeProvider>
);
}
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from "vue"
import Chip from "@/components/ui/Chip.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Reveal from "@/components/ui/Reveal.vue"
import { cn } from "@/lib/utils"
// تصویرها از کتابخانهٔ تصویرِ دیگ (همان آدرسهای نسخهٔ React)
const stockImages = {
projectDashboard: { src: "https://docs.digdesign.ir/images/project-dashboard.webp", alt: "لپتاپ با نمودارهای تحلیلی" },
projectMobileApp: { src: "https://docs.digdesign.ir/images/project-mobile-app.webp", alt: "گوشیِ موبایل با رابطِ یک اپ روی سطحِ سفید" },
projectCafeBrand: { src: "https://docs.digdesign.ir/images/project-cafe-brand.webp", alt: "لیوانهای کاغذیِ قهوه با درِ سیاه و سفید" },
coverWorkspace: { src: "https://docs.digdesign.ir/images/cover-workspace.webp", alt: "میزِ کار با مانیتور کنارِ پنجرهٔ روشن" },
}
const FRAMES: { photo: keyof typeof stockImages; title: string; text: string }[] = [
{ photo: "projectDashboard", title: "داشبوردِ فروش", text: "گزارشِ روزانه در یک نگاه، بدونِ خروجیِ اکسل." },
{ photo: "projectMobileApp", title: "اپِ موبایل", text: "سفارشها و پیامها را در راه هم جواب بدهید." },
{ photo: "projectCafeBrand", title: "هویتِ بصری", text: "منو، بستهبندی و تابلو با یک زبانِ بصری." },
{ photo: "coverWorkspace", title: "کارِ تیمی", text: "هر کس میداند امروز نوبتِ کدام کار است." },
]
/**
* گالریِ قاب و نوار: عکسِ بزرگ با تیتر و توضیحِ روی آن، و زیرش نوارِ تصاویرِ کوچک که
* با انتخاب، قابِ بزرگ عوض میشود؛ نوارِ زمان روی تصویرِ کوچکِ فعال پر میشود و
* خودکار به بعدی میرود.
* همان صفحهٔ `gallery-filmstrip` نسخهٔ React.
*/
const active = ref(0)
const paused = ref(false)
const frame = computed(() => FRAMES[active.value])
let timer: ReturnType<typeof setTimeout> | undefined
watch(
[active, paused],
([, isPaused]) => {
if (timer) clearTimeout(timer)
timer = undefined
if (isPaused || (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)) return
timer = setTimeout(() => {
active.value = (active.value + 1) % FRAMES.length
}, 5000)
},
{ immediate: true, flush: "post" }
)
onBeforeUnmount(() => timer && clearTimeout(timer))
</script>
<template>
<ControlSize size="xl" as-child>
<section aria-labelledby="fs-title" class="mx-auto flex w-full max-w-6xl flex-col gap-10 px-4 py-24 sm:px-6">
<div class="flex max-w-2xl flex-col gap-3">
<span class="text-sm font-semibold text-brand-secondary">محصول</span>
<h2 id="fs-title" class="text-3xl leading-snug font-black text-balance sm:text-4xl">همهچیزِ کسبوکار، در چهار قاب</h2>
</div>
<Reveal class="flex flex-col gap-4" @mouseenter="paused = true" @mouseleave="paused = false">
<div class="relative aspect-[4/5] overflow-hidden rounded-xl bg-muted sm:aspect-[16/8]">
<img
v-for="(item, index) in FRAMES"
:key="item.photo"
:src="stockImages[item.photo].src"
:alt="index === active ? stockImages[item.photo].alt : ''"
:aria-hidden="index !== active"
:class="cn('absolute inset-0 size-full object-cover transition-[opacity,scale] duration-700', index === active ? 'scale-100' : 'scale-105 [opacity:0]')"
/>
<div aria-live="polite" class="absolute inset-x-0 bottom-0 flex flex-col gap-2 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-6 pt-24 text-[var(--dig-white)] sm:p-10 sm:pt-32">
<h3 class="text-2xl font-black sm:text-3xl">{{ frame.title }}</h3>
<p class="max-w-md leading-7 text-[var(--dig-neutral-300)]">{{ frame.text }}</p>
</div>
</div>
<div role="tablist" aria-label="قابها" class="grid grid-cols-4 gap-2 sm:gap-4">
<Chip v-for="(item, index) in FRAMES" :key="item.photo" as-child variant="secondary">
<button
type="button"
role="tab"
:aria-selected="index === active"
:aria-label="item.title"
:class="
cn(
'group relative block h-auto w-full overflow-hidden rounded-lg border-0 bg-transparent p-0 text-start text-base whitespace-normal outline-none ring-offset-2 ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
index === active ? 'ring-2 ring-foreground' : ''
)
"
@click="active = index"
>
<img :src="stockImages[item.photo].src" alt="" :class="cn('aspect-[16/10] w-full object-cover transition-[filter]', index !== active && 'grayscale group-hover:grayscale-0')" />
<span aria-hidden="true" class="absolute inset-x-0 bottom-0 h-1 bg-[color-mix(in_oklab,var(--dig-white)_40%,transparent)]">
<span v-if="index === active" :key="`${active}-${paused}`" :class="cn('block h-full origin-right bg-[var(--dig-white)]', !paused && 'animate-[fs-fill_5s_linear_forwards]')" />
</span>
<span class="hidden p-2 text-start text-sm font-semibold sm:block">{{ item.title }}</span>
</button>
</Chip>
</div>
</Reveal>
</section>
</ControlSize>
</template>
<style>
@keyframes fs-fill {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
</style>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: chipcontrol-sizereveal
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import {
ChangeDetectionStrategy,
Component,
afterNextRender,
computed,
effect,
signal,
} from "@angular/core"
import { cn } from "@/lib/utils"
import { DigChip } from "@/components/ui/chip"
import { DigControlSize } from "@/components/ui/control-size"
import { DigReveal } from "@/components/ui/reveal"
const stockImages = {
projectDashboard: {
src: "https://docs.digdesign.ir/images/project-dashboard.webp",
alt: "لپتاپ با نمودارهای تحلیلی",
},
projectMobileApp: {
src: "https://docs.digdesign.ir/images/project-mobile-app.webp",
alt: "گوشیِ موبایل با رابطِ یک اپ روی سطحِ سفید",
},
projectCafeBrand: {
src: "https://docs.digdesign.ir/images/project-cafe-brand.webp",
alt: "لیوانهای کاغذیِ قهوه با درِ سیاه و سفید",
},
coverWorkspace: {
src: "https://docs.digdesign.ir/images/cover-workspace.webp",
alt: "میزِ کار با مانیتور کنارِ پنجرهٔ روشن",
},
}
const FRAMES: {
photo: keyof typeof stockImages
title: string
text: string
}[] = [
{
photo: "projectDashboard",
title: "داشبوردِ فروش",
text: "گزارشِ روزانه در یک نگاه، بدونِ خروجیِ اکسل.",
},
{
photo: "projectMobileApp",
title: "اپِ موبایل",
text: "سفارشها و پیامها را در راه هم جواب بدهید.",
},
{
photo: "projectCafeBrand",
title: "هویتِ بصری",
text: "منو، بستهبندی و تابلو با یک زبانِ بصری.",
},
{
photo: "coverWorkspace",
title: "کارِ تیمی",
text: "هر کس میداند امروز نوبتِ کدام کار است.",
},
]
@Component({
selector: "dig-block-gallery-filmstrip",
imports: [DigChip, DigControlSize, DigReveal],
changeDetection: ChangeDetectionStrategy.OnPush,
styles: [
`
@keyframes fs-fill {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
.frame-progress-playing {
animation: fs-fill 5s linear forwards;
}
`,
],
template: `
<section
digControlSize="xl"
aria-labelledby="fs-title"
class="mx-auto flex w-full max-w-6xl flex-col gap-10 px-4 py-24 sm:px-6"
>
<div class="flex max-w-2xl flex-col gap-3">
<span class="text-sm font-semibold text-brand-secondary">محصول</span>
<h2
id="fs-title"
class="text-3xl leading-snug font-black text-balance sm:text-4xl"
>
همهچیزِ کسبوکار، در چهار قاب
</h2>
</div>
<div
digReveal
class="flex flex-col gap-4"
(mouseenter)="hovering.set(true)"
(mouseleave)="hovering.set(false)"
(focusin)="onFocusIn()"
(focusout)="onFocusOut($event)"
>
<div
class="relative aspect-[4/5] overflow-hidden rounded-xl bg-muted sm:aspect-[16/8]"
>
@for (item of FRAMES; track item.photo; let index = $index) {
<img
[src]="stockImages[item.photo].src"
[alt]="index === active() ? stockImages[item.photo].alt : ''"
[attr.aria-hidden]="index !== active()"
[class]="
cn(
'absolute inset-0 size-full object-cover transition-[opacity,scale] duration-700',
index === active() ? 'scale-100' : 'scale-105 [opacity:0]'
)
"
/>
}
<div
aria-live="polite"
class="absolute inset-x-0 bottom-0 flex flex-col gap-2 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-6 pt-24 text-[var(--dig-white)] sm:p-10 sm:pt-32"
>
<h3 class="text-2xl font-black sm:text-3xl">{{ frame().title }}</h3>
<p class="max-w-md leading-7 text-[var(--dig-neutral-300)]">
{{ frame().text }}
</p>
</div>
</div>
<div
role="tablist"
aria-label="قابها"
class="grid grid-cols-4 gap-2 sm:gap-4"
>
@for (item of FRAMES; track item.photo; let index = $index) {
<button
variant="secondary"
digChip
type="button"
role="tab"
[attr.aria-selected]="index === active()"
[attr.aria-label]="item.title"
[class]="
cn(
'group relative block h-auto w-full overflow-hidden rounded-lg border-0 bg-transparent p-0 text-start text-base whitespace-normal outline-none ring-offset-2 ring-offset-background focus-visible:ring-2 focus-visible:ring-ring',
index === active() ? 'ring-2 ring-foreground' : ''
)
"
(click)="active.set(index)"
>
<img
[src]="stockImages[item.photo].src"
alt=""
[class]="
cn(
'aspect-[16/10] w-full object-cover transition-[filter]',
index !== active() && 'grayscale group-hover:grayscale-0'
)
"
/>
<span
aria-hidden="true"
class="absolute inset-x-0 bottom-0 h-1 bg-[color-mix(in_oklab,var(--dig-white)_40%,transparent)]"
>
@if (index === active()) {
<span
class="block h-full origin-right bg-[var(--dig-white)]"
[class.frame-progress-playing]="playing()"
></span>
}
</span>
<span
class="hidden p-2 text-start text-sm font-semibold sm:block"
>{{ item.title }}</span
>
</button>
}
</div>
</div>
</section>
`,
})
export class GalleryFilmstripBlock {
readonly stockImages = stockImages
readonly FRAMES = FRAMES
readonly cn = cn
readonly active = signal(0)
readonly hovering = signal(false)
private readonly focused = signal(false)
private readonly motion = signal(false)
readonly frame = computed(() => FRAMES[this.active()])
readonly playing = computed(
() => this.motion() && !this.hovering() && !this.focused()
)
constructor() {
afterNextRender(() =>
this.motion.set(
!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
)
)
effect((onCleanup) => {
const index = this.active()
if (!this.playing()) return
const timer = setTimeout(
() => this.active.set((index + 1) % FRAMES.length),
5000
)
onCleanup(() => clearTimeout(timer))
})
}
onFocusIn() {
this.focused.set(true)
}
onFocusOut(event: FocusEvent) {
const strip = event.currentTarget as HTMLElement
if (!strip.contains(event.relatedTarget as Node | null))
this.focused.set(false)
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
این موارد هنوز برای Android آماده نیستند: reveal
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.