ریلِ عکسهای همپوشان
پیشنمایش تمامصفحهبخشِ گالری: کارتهای عکس روی هم مینشینند و کارتِ فعال با هاور، فوکوس یا لمس باز میشود تا عکس و اسمِ داستان دیده شود؛ خودکار جلو میرود و در موبایل ریلِ افقی است.
۱. نصب کامپوننتها
این بلاک از ۴ آیتم دیگ استفاده میکند: buttoncontrol-sizeiconsreveal
npx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/reveal.jsonpnpm dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/reveal.jsonyarn dlx digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/reveal.jsonbunx --bun digdesign@latest add https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/reveal.jsonnpx digdesign@latest add button control-size reveal --framework vuepnpm dlx digdesign@latest add button control-size reveal --framework vueyarn dlx digdesign@latest add button control-size reveal --framework vuebunx --bun digdesign@latest add button control-size reveal --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 button control-size icons reveal utils --framework angularpnpm dlx digdesign@latest add button control-size icons reveal utils --framework angularyarn dlx digdesign@latest add button control-size icons reveal utils --framework angularbunx --bun digdesign@latest add button control-size icons reveal utils --framework angularnpx digdesign@latest add button control-size --framework androidpnpm dlx digdesign@latest add button control-size --framework androidyarn dlx digdesign@latest add button control-size --framework androidbunx --bun digdesign@latest add button control-size --framework android۲. کد صفحه
کد را در صفحهٔ پروژهتان بگذارید (React: app/<route>/page.tsx) و متنها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریمورک کدِ همین صفحه در فریمورک دیگر را ببینید.
"use client"
import * as React from "react"
import { ArrowUpIcon } from "@/components/icons"
import { Button } from "@/components/ui/button"
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 STORIES: { photo: StockImageName; title: string; place: string }[] = [
{ photo: "studioSunlit", title: "کارگاهِ سفالِ نور", place: "اصفهان" },
{ photo: "personWoman1", title: "بوتیکِ لباسِ تابستانی", place: "شیراز" },
{ photo: "personWoman2", title: "کافهکتابِ سرو", place: "تهران" },
{ photo: "foodDish", title: "آشپزخانهٔ خانگیِ مهتاب", place: "رشت" },
{ photo: "personMan1", title: "استودیوی عکاسیِ آینه", place: "تبریز" },
{ photo: "productVase", title: "گالریِ دکورِ کاشی", place: "یزد" },
{ photo: "restaurant", title: "رستورانِ حیاط", place: "کاشان" },
]
/**
* ریلِ عکسهای همپوشان: کارتها روی هم مینشینند و کارتِ فعال باز میشود تا عکس و
* اسمِ داستان کامل دیده شود. با هاور، فوکوسِ کیبورد یا لمس عوض میشود و هر چند ثانیه
* خودش جلو میرود؛ در موبایل ریلِ افقیِ قابلِ کشیدن است.
*/
export default function GalleryReelBlock() {
const [active, setActive] = React.useState(2)
const [paused, setPaused] = React.useState(false)
React.useEffect(() => {
if (paused || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return
const timer = window.setInterval(() => setActive((current) => (current + 1) % STORIES.length), 3200)
return () => window.clearInterval(timer)
}, [paused])
return (
<ControlSizeProvider size="xl" asChild>
<section aria-labelledby="reel-title" className="flex w-full flex-col gap-12 overflow-hidden py-24">
<div className="mx-auto flex w-full max-w-6xl flex-col items-start justify-between gap-6 px-4 sm:px-6 md:flex-row md:items-end">
<div className="flex max-w-xl flex-col gap-3">
<span className="text-sm font-semibold text-brand-secondary">ساختهشده با پیشخوان</span>
<h2 id="reel-title" className="text-3xl leading-snug font-black text-balance sm:text-4xl">
کسبوکارهای کوچک، داستانهای بزرگ
</h2>
<p className="leading-7 text-muted-foreground">بیش از سه هزار فروشگاهِ مستقل با پیشخوان فروش آنلاین را شروع کردهاند.</p>
</div>
<Button variant="outline">
همهٔ داستانها
<ArrowUpIcon aria-hidden className="-rotate-45" />
</Button>
</div>
<Reveal
className="mx-auto flex w-full max-w-6xl snap-x snap-mandatory gap-3 overflow-x-auto px-4 pb-2 [scrollbar-width:none] sm:px-6 md:gap-0 md:overflow-visible md:pb-0 [&::-webkit-scrollbar]:hidden"
onMouseEnter={() => setPaused(true)}
onMouseLeave={() => setPaused(false)}
onFocus={() => setPaused(true)}
onBlur={() => setPaused(false)}
>
{STORIES.map((story, index) => {
const open = index === active
return (
<a
key={story.title}
href="#"
aria-current={open ? "true" : undefined}
aria-label={`داستانِ ${story.title}، ${story.place}`}
onMouseEnter={() => setActive(index)}
onFocus={() => setActive(index)}
style={{ zIndex: open ? STORIES.length + 1 : STORIES.length - Math.abs(index - active) }}
className={cn(
"group relative h-96 shrink-0 snap-center overflow-hidden rounded-xl bg-muted text-start shadow-lg outline-none ring-4 ring-background transition-[flex-grow,flex-basis,transform,width] duration-500 ease-out focus-visible:ring-ring",
"w-64 md:w-auto md:basis-0",
index > 0 && "md:-ms-10",
open ? "md:grow-[3.2]" : "md:grow md:scale-[0.94]"
)}
>
{/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
<img src={stockImages[story.photo].src} alt="" className="absolute inset-0 size-full object-cover transition-transform duration-700 group-hover:scale-105" />
<span
aria-hidden
className={cn(
"absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-5 pt-20 text-[var(--dig-white)] transition-[translate] duration-500",
open ? "translate-y-0" : "md:translate-y-full"
)}
>
<span className="text-lg font-bold">{story.title}</span>
<span className="text-sm text-[var(--dig-neutral-300)]">{story.place}</span>
</span>
</a>
)
})}
</Reveal>
</section>
</ControlSizeProvider>
)
}
<script setup lang="ts">
import { onBeforeUnmount, ref, watch } from "vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import Reveal from "@/components/ui/Reveal.vue"
import { DigIcon } from "@/lib/icons"
import { cn } from "@/lib/utils"
// تصویرها از کتابخانهٔ تصویرِ دیگ (همان آدرسهای نسخهٔ React)
const stockImages = {
studioSunlit: { src: "https://docs.digdesign.ir/images/studio-sunlit.webp", alt: "استودیوی آفتابگیر با میزِ چوبی و چهارپایه" },
personWoman1: { src: "https://docs.digdesign.ir/images/person-woman-1.webp", alt: "پرترهٔ زنی با روسری" },
personWoman2: { src: "https://docs.digdesign.ir/images/person-woman-2.webp", alt: "پرترهٔ زنی با کتِ طوسی" },
foodDish: { src: "https://docs.digdesign.ir/images/food-dish.webp", alt: "بشقابِ غذا با ماهی، کینوا و سبزیجات" },
personMan1: { src: "https://docs.digdesign.ir/images/person-man-1.webp", alt: "پرترهٔ مردی با لبخند" },
productVase: { src: "https://docs.digdesign.ir/images/product-vase.webp", alt: "دو گلدانِ سرامیکیِ سفید کنارِ پارچهٔ کرم" },
restaurant: { src: "https://docs.digdesign.ir/images/restaurant.webp", alt: "فضای داخلیِ رستوران با میز و صندلی" },
}
const STORIES: { photo: keyof typeof stockImages; title: string; place: string }[] = [
{ photo: "studioSunlit", title: "کارگاهِ سفالِ نور", place: "اصفهان" },
{ photo: "personWoman1", title: "بوتیکِ لباسِ تابستانی", place: "شیراز" },
{ photo: "personWoman2", title: "کافهکتابِ سرو", place: "تهران" },
{ photo: "foodDish", title: "آشپزخانهٔ خانگیِ مهتاب", place: "رشت" },
{ photo: "personMan1", title: "استودیوی عکاسیِ آینه", place: "تبریز" },
{ photo: "productVase", title: "گالریِ دکورِ کاشی", place: "یزد" },
{ photo: "restaurant", title: "رستورانِ حیاط", place: "کاشان" },
]
/**
* ریلِ عکسهای همپوشان: کارتها روی هم مینشینند و کارتِ فعال باز میشود تا عکس و
* اسمِ داستان کامل دیده شود. با هاور، فوکوسِ کیبورد یا لمس عوض میشود و هر چند ثانیه
* خودش جلو میرود؛ در موبایل ریلِ افقیِ قابلِ کشیدن است.
* همان صفحهٔ `gallery-reel` نسخهٔ React.
*/
const active = ref(2)
const paused = ref(false)
let timer: ReturnType<typeof setInterval> | undefined
function stop() {
if (timer) clearInterval(timer)
timer = undefined
}
watch(
paused,
(value) => {
stop()
if (value || (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)) return
timer = setInterval(() => {
active.value = (active.value + 1) % STORIES.length
}, 3200)
},
{ immediate: true, flush: "post" }
)
onBeforeUnmount(stop)
</script>
<template>
<ControlSize size="xl" as-child>
<section aria-labelledby="reel-title" class="flex w-full flex-col gap-12 overflow-hidden py-24">
<div class="mx-auto flex w-full max-w-6xl flex-col items-start justify-between gap-6 px-4 sm:px-6 md:flex-row md:items-end">
<div class="flex max-w-xl flex-col gap-3">
<span class="text-sm font-semibold text-brand-secondary">ساختهشده با پیشخوان</span>
<h2 id="reel-title" class="text-3xl leading-snug font-black text-balance sm:text-4xl">کسبوکارهای کوچک، داستانهای بزرگ</h2>
<p class="leading-7 text-muted-foreground">بیش از سه هزار فروشگاهِ مستقل با پیشخوان فروش آنلاین را شروع کردهاند.</p>
</div>
<Button variant="outline">
همهٔ داستانها
<DigIcon name="arrow-up" class="-rotate-45" />
</Button>
</div>
<Reveal
class="mx-auto flex w-full max-w-6xl snap-x snap-mandatory gap-3 overflow-x-auto px-4 pb-2 [scrollbar-width:none] sm:px-6 md:gap-0 md:overflow-visible md:pb-0 [&::-webkit-scrollbar]:hidden"
@mouseenter="paused = true"
@mouseleave="paused = false"
@focusin="paused = true"
@focusout="paused = false"
>
<a
v-for="(story, index) in STORIES"
:key="story.title"
href="#"
:aria-current="index === active ? 'true' : undefined"
:aria-label="`داستانِ ${story.title}، ${story.place}`"
:style="{ zIndex: index === active ? STORIES.length + 1 : STORIES.length - Math.abs(index - active) }"
:class="
cn(
'group relative h-96 shrink-0 snap-center overflow-hidden rounded-xl bg-muted text-start shadow-lg outline-none ring-4 ring-background transition-[flex-grow,flex-basis,transform,width] duration-500 ease-out focus-visible:ring-ring',
'w-64 md:w-auto md:basis-0',
index > 0 && 'md:-ms-10',
index === active ? 'md:grow-[3.2]' : 'md:grow md:scale-[0.94]'
)
"
@mouseenter="active = index"
@focus="active = index"
>
<img :src="stockImages[story.photo].src" alt="" class="absolute inset-0 size-full object-cover transition-transform duration-700 group-hover:scale-105" />
<span
aria-hidden="true"
:class="
cn(
'absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-5 pt-20 text-[var(--dig-white)] transition-[translate] duration-500',
index === active ? 'translate-y-0' : 'md:translate-y-full'
)
"
>
<span class="text-lg font-bold">{{ story.title }}</span>
<span class="text-sm text-[var(--dig-neutral-300)]">{{ story.place }}</span>
</span>
</a>
</Reveal>
</section>
</ControlSize>
</template>
کدِ این بلاک هنوز برای Svelte نوشته نشده است.
این موارد هنوز برای Svelte آماده نیستند: control-sizerevealآیکون arrow-up
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننتهای Svelte میسازد.
import {
ChangeDetectionStrategy,
Component,
afterNextRender,
effect,
signal,
} from "@angular/core"
import { DigIcon } from "@/lib/icons"
import { cn } from "@/lib/utils"
import { DigButton } from "@/components/ui/button"
import { DigControlSize } from "@/components/ui/control-size"
import { DigReveal } from "@/components/ui/reveal"
const stockImages = {
studioSunlit: {
src: "https://docs.digdesign.ir/images/studio-sunlit.webp",
alt: "استودیوی آفتابگیر با میزِ چوبی و چهارپایه",
},
personWoman1: {
src: "https://docs.digdesign.ir/images/person-woman-1.webp",
alt: "پرترهٔ زنی با روسری",
},
personWoman2: {
src: "https://docs.digdesign.ir/images/person-woman-2.webp",
alt: "پرترهٔ زنی با کتِ طوسی",
},
foodDish: {
src: "https://docs.digdesign.ir/images/food-dish.webp",
alt: "بشقابِ غذا با ماهی، کینوا و سبزیجات",
},
personMan1: {
src: "https://docs.digdesign.ir/images/person-man-1.webp",
alt: "پرترهٔ مردی با لبخند",
},
productVase: {
src: "https://docs.digdesign.ir/images/product-vase.webp",
alt: "دو گلدانِ سرامیکیِ سفید کنارِ پارچهٔ کرم",
},
restaurant: {
src: "https://docs.digdesign.ir/images/restaurant.webp",
alt: "فضای داخلیِ رستوران با میز و صندلی",
},
}
const STORIES: {
photo: keyof typeof stockImages
title: string
place: string
}[] = [
{ photo: "studioSunlit", title: "کارگاهِ سفالِ نور", place: "اصفهان" },
{ photo: "personWoman1", title: "بوتیکِ لباسِ تابستانی", place: "شیراز" },
{ photo: "personWoman2", title: "کافهکتابِ سرو", place: "تهران" },
{ photo: "foodDish", title: "آشپزخانهٔ خانگیِ مهتاب", place: "رشت" },
{ photo: "personMan1", title: "استودیوی عکاسیِ آینه", place: "تبریز" },
{ photo: "productVase", title: "گالریِ دکورِ کاشی", place: "یزد" },
{ photo: "restaurant", title: "رستورانِ حیاط", place: "کاشان" },
]
@Component({
selector: "dig-block-gallery-reel",
imports: [DigButton, DigControlSize, DigIcon, DigReveal],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<section
digControlSize="xl"
aria-labelledby="reel-title"
class="flex w-full flex-col gap-12 overflow-hidden py-24"
>
<div
class="mx-auto flex w-full max-w-6xl flex-col items-start justify-between gap-6 px-4 sm:px-6 md:flex-row md:items-end"
>
<div class="flex max-w-xl flex-col gap-3">
<span class="text-sm font-semibold text-brand-secondary"
>ساختهشده با پیشخوان</span
>
<h2
id="reel-title"
class="text-3xl leading-snug font-black text-balance sm:text-4xl"
>
کسبوکارهای کوچک، داستانهای بزرگ
</h2>
<p class="leading-7 text-muted-foreground">
بیش از سه هزار فروشگاهِ مستقل با پیشخوان فروش آنلاین را شروع
کردهاند.
</p>
</div>
<button digButton type="button" variant="outline">
همهٔ داستانها
<svg digIcon="arrow-up" class="-rotate-45"></svg>
</button>
</div>
<div
digReveal
class="mx-auto flex w-full max-w-6xl snap-x snap-mandatory gap-3 overflow-x-auto px-4 pb-2 [scrollbar-width:none] sm:px-6 md:gap-0 md:overflow-visible md:pb-0 [&::-webkit-scrollbar]:hidden"
(mouseenter)="hovering.set(true)"
(mouseleave)="hovering.set(false)"
(focusin)="onFocusIn()"
(focusout)="onFocusOut($event)"
>
@for (story of STORIES; track story.title; let index = $index) {
<a
href="#"
[attr.aria-current]="index === active() ? 'true' : undefined"
[attr.aria-label]="'داستانِ ' + story.title + '، ' + story.place"
[style.z-index]="
index === active()
? STORIES.length + 1
: STORIES.length - math.abs(index - active())
"
[class]="
cn(
'group relative h-96 shrink-0 snap-center overflow-hidden rounded-xl bg-muted text-start shadow-lg outline-none ring-4 ring-background transition-[flex-grow,flex-basis,transform,width] duration-500 ease-out focus-visible:ring-ring',
'w-64 md:w-auto md:basis-0',
index > 0 && 'md:-ms-10',
index === active() ? 'md:grow-[3.2]' : 'md:grow md:scale-[0.94]'
)
"
(mouseenter)="active.set(index)"
(focus)="active.set(index)"
(click)="active.set(index)"
>
<img
[src]="stockImages[story.photo].src"
alt=""
class="absolute inset-0 size-full object-cover transition-transform duration-700 group-hover:scale-105"
/>
<span
aria-hidden="true"
[class]="
cn(
'absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-linear-to-t from-[var(--dig-graphite-950)] to-transparent p-5 pt-20 text-[var(--dig-white)] transition-[translate] duration-500',
index === active() ? 'translate-y-0' : 'md:translate-y-full'
)
"
>
<span class="text-lg font-bold">{{ story.title }}</span>
<span class="text-sm text-[var(--dig-neutral-300)]">{{
story.place
}}</span>
</span>
</a>
}
</div>
</section>
`,
})
export class GalleryReelBlock {
readonly stockImages = stockImages
readonly STORIES = STORIES
readonly cn = cn
readonly math = Math
readonly active = signal(2)
readonly hovering = signal(false)
private readonly focused = signal(false)
private readonly motion = signal(false)
constructor() {
afterNextRender(() =>
this.motion.set(
!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
)
)
effect((onCleanup) => {
if (!this.motion() || this.hovering() || this.focused()) return
const timer = setInterval(
() => this.active.update((index) => (index + 1) % STORIES.length),
3200
)
onCleanup(() => clearInterval(timer))
})
}
onFocusIn() {
this.focused.set(true)
}
onFocusOut(event: FocusEvent) {
const rail = event.currentTarget as HTMLElement
if (!rail.contains(event.relatedTarget as Node | null))
this.focused.set(false)
}
}
کدِ این بلاک هنوز برای Android نوشته نشده است.
این موارد هنوز برای Android آماده نیستند: reveal
کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننتهای Android میسازد.