Installation
Install the component
Run the following command to install the component and its dependencies:
npx @motion-core/cli add flip-gridImport the component
Import the component into your Svelte file:
import { FlipGrid, FlipGridItem } from "$lib/motion-core";import { FlipGrid, FlipGridItem } from "$lib/motion-core";Usage




<script lang="ts">
import { FlipGrid, FlipGridItem } from "motion-core";
import { cn } from "$lib/utils/cn";
let columns = $state(4);
const images = [
"/images/demos/sample-8.jpg",
"/images/demos/sample-9.jpg",
"/images/demos/sample-10.jpg",
"/images/demos/sample-11.jpg",
];
</script>
<div class="relative h-full min-h-96 w-full">
<div class="h-full p-4">
<FlipGrid class="w-full gap-4" {columns} duration={0.5} stagger={0.1}>
{#each images as src, i (src)}
<FlipGridItem
id={`img-${i}`}
class="relative aspect-square w-full overflow-hidden rounded-lg shadow-md"
>
<img {src} alt="Demo {i}" class="h-full w-full object-cover" />
</FlipGridItem>
{/each}
</FlipGrid>
</div>
<div
class="inset-shadow absolute bottom-4 left-1/2 z-10 flex w-fit -translate-x-1/2 justify-center gap-1 rounded-sm bg-background-inset p-1"
>
{#each [1, 2, 4] as col (col)}
<button
class={cn(
"gap-1.5 rounded px-3 py-1 text-xs font-medium tracking-wide whitespace-nowrap uppercase transition-all duration-150 ease-out",
columns === col
? "light:text-card card bg-background-muted dark:text-foreground"
: "text-foreground-muted hover:text-foreground",
)}
onclick={() => (columns = col)}
>
{col} Cols
</button>
{/each}
</div>
</div>
Props
FlipGrid
| Prop | Type | Default |
|---|---|---|
children | Snippet | — |
columns | number | undefined |
class | string | undefined |
style | string | undefined |
duration | number | 0.5 |
ease | string | "power2.inOut" |
stagger | number | 0 |
FlipGridItem
| Prop | Type | Default |
|---|---|---|
children | Snippet | — |
id | string | — |
class | string | undefined |