gallery/02-item-orientation
Gallery items can be oriented vertically (stacked view + body) or horizontally (side-by-side view + body).
Loading interactive preview
"use client";
import type { CSSProperties } from 'react';
import { Gallery } from 'ui-lab-components/gallery';
import { Frame } from 'ui-lab-components/frame';
const BASE_CELL_STYLE = {
'--fill': 'var(--background-900)',
'--stroke-color': 'var(--background-600)',
} as CSSProperties;
function GalleryViewFrame({ orientation }: { orientation: 'vertical' | 'horizontal' }) {
return (
<Frame
className={orientation === 'horizontal' ? 'shrink-0 p-px' : 'p-px'}
pathStroke="dashed"
strokeAlign="inside"
style={{
...BASE_CELL_STYLE,
...(orientation === 'horizontal' ? { width: 'var(--view-width)', flexShrink: 0 } : {}),
}}
>
<Gallery.View
aspectRatio={orientation === 'horizontal' ? '1/1' : '4/3'}
className="overflow-hidden rounded-sm bg-background-900"
style={orientation === 'horizontal' ? { width: '100%' } : undefined}
/>
</Frame>
);
}
function GalleryBodyFrame({ orientation }: { orientation: 'vertical' | 'horizontal' }) {
return (
<Frame
className={orientation === 'horizontal' ? 'min-w-0 flex-1 w-auto' : undefined}
pathStroke="dashed"
strokeAlign="inside"
style={BASE_CELL_STYLE}
>
<Gallery.Body>
</Gallery.Body>
</Frame>
);
}
export default function Example() {
return (
<div className="flex h-full w-[min(100%,640px)] min-h-0 min-w-0 flex-col gap-4">
<Gallery columns={3} gap="sm" className="w-full">
{Array.from({ length: 3 }, (_, index) => (
<Gallery.Item key={index} orientation="vertical" className="bg-background-950 border-background-700 p-2" styles={{ root: 'gap-2' }}>
<GalleryViewFrame orientation="vertical" />
<GalleryBodyFrame orientation="vertical" />
</Gallery.Item>
))}
</Gallery>
<Gallery columns={1} gap="sm" className="w-full">
{Array.from({ length: 3 }, (_, index) => (
<Gallery.Item
key={index}
orientation="horizontal"
className="bg-background-950 border-background-700 p-2"
styles={{ root: 'gap-2' }}
style={{ '--view-width': '160px' } as CSSProperties}
>
<GalleryViewFrame orientation="horizontal" />
<GalleryBodyFrame orientation="horizontal" />
</Gallery.Item>
))}
</Gallery>
</div>
);
}