Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/docs/demos/flow.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
sidebar_position: 14
---

import { SourceTabs } from "@site/src/components/source-tabs/source-tabs"
import { FlowGallery } from "@site/src/components/demos/flow-gallery/flow-gallery"
import { OpenInCodePen } from "@site/src/components/codepen/open-in-codepen"

import flowSource from "!!raw-loader!@site/src/components/demos/flow-gallery/flow-gallery.tsx"
import flowStyles from "!!raw-loader!@site/src/components/demos/flow-gallery/flow-gallery.module.scss"
import flowJs from "!!ts-to-js!@site/src/components/demos/flow-gallery/flow-gallery.tsx"
import flowPen from "!!ts-to-js?codepen!@site/src/components/demos/flow-gallery/flow-gallery.tsx"

# Flow Gallery

Flow Gallery using custom css tranform calculations.

<FlowGallery />

<OpenInCodePen title="Flow Gallery" source={flowPen} />

## Source

<SourceTabs file="flow-gallery" ts={flowSource} js={flowJs} />

## Styles

The demos on this site are styled with [SCSS modules](https://github.com/css-modules/css-modules).

<SourceTabs file="flow-gallery" scss={flowStyles} />
214 changes: 214 additions & 0 deletions docs/src/components/demos/flow-gallery/flow-gallery.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
.root {
--perspective: 100px;
--xoffset: min(500px, 40vw);
--yoffset: min(200px, 10vh);
--rotation: 16deg;
--blur: 2px;

padding: 3rem 0 2rem;
overflow: clip;
background: rgba(128, 128, 128, 0.1);
border-radius: 10px;
margin-block-end: 16px;
}

.slideArea {
--item-width: min(640px, 72vw);

position: relative;

.item {
transform: translateX(0);
}

ul {
display: grid;
grid-template-areas: "item";
list-style: none;
margin: 0;
padding: 0;
position: relative;
}

li {
grid-area: item;
margin: 0 auto;
padding: 0;
transform: translateX(var(--x));
transition: transform var(--duration);
width: var(--item-width);
z-index: calc(var(--total) - var(--center-offset));
}
}

.slide {
aspect-ratio: 16 / 9;
border-radius: 10px;
overflow: hidden;
position: relative;
transition:
transform var(--duration, 0.5s),
filter var(--duration, 0.5s),
opacity var(--duration, 0.5s);
width: 100%;

img {
display: block;
height: 100%;
object-fit: cover;
width: 100%;
}
}

[data-side="active"] .slide {
filter: none;
opacity: 1;
transform: perspective(var(--perspective, 1000px));
}

[data-side="prev"] {
.slide {
filter: blur(calc(var(--center-offset, 0) * var(--blur, 2px)));
opacity: calc(1 - var(--center-offset, 0) * 0.68);
transform: perspective(var(--perspective, 1000px))
translateX(calc(var(--center-offset, 0) * -1 * var(--xoffset, 600px)))
translateY(calc(var(--center-offset, 0) * -1 * var(--yoffset, 200px)))
translateZ(calc(var(--center-offset, 0) * 40px))
rotateZ(
calc(
var(--center-offset, 0) * -1 * var(--rotation, 16deg) +
sin(calc(var(--i, 0) * 1rad)) * 6deg
)
);
}

&.item {
z-index: calc(20 - var(--center-offset, 0));
}
}

[data-side="next"] {
.slide {
filter: blur(calc(var(--center-offset, 0) * var(--blur, 2px)));
opacity: calc(1 - var(--center-offset, 0) * 0.3);
transform: perspective(var(--perspective, 1000px))
translateX(calc(var(--center-offset, 0) * var(--xoffset, 600px)))
translateY(calc(var(--center-offset, 0) * var(--yoffset, 200px)))
translateZ(calc(var(--center-offset, 0) * -80px))
rotateZ(
calc(
var(--center-offset, 0) * var(--rotation, 16deg) +
sin(calc(var(--i, 0) * 1.7rad)) * 6deg
)
);
}
}

.navPrev,
.navNext {
align-items: center;
appearance: none;
background: rgb(255 255 255 / 12%);
backdrop-filter: blur(8px);
border: 1px solid rgb(255 255 255 / 20%);
border-radius: 50%;
color: #fff;
cursor: pointer;
display: flex;
height: 3rem;
justify-content: center;
position: absolute;
top: 50%;
transform: translateY(-50%);
transition:
background 0.2s,
border-color 0.2s;
width: 3rem;
z-index: 1000;

&:hover {
background: rgb(255 255 255 / 25%);
border-color: rgb(255 255 255 / 40%);
}

&:disabled {
opacity: 0.3;
pointer-events: none;
}
}

.navPrev {
left: 1rem;
}

.navNext {
right: 1rem;
}

.thumbs {
display: flex;
gap: 0.5rem;
justify-content: center;
list-style: none;
margin-block-start: 24px;
overflow-x: auto;
padding: 0 1.5rem;
position: relative;
z-index: 10;
}

.thumbItem {
flex-shrink: 0;
line-height: 0;
margin-block: 0;
}

.thumbButton {
appearance: none;
background: none;
border: 2px solid transparent;
border-radius: 5px;
cursor: pointer;
display: block;
height: 52px;
opacity: 0.45;
overflow: hidden;
padding: 0;
transition:
opacity 0.2s,
border-color 0.2s;
width: 88px;

&[aria-current="true"] {
border-color: #fff;
opacity: 1;
}

img {
display: block;
height: 100%;
object-fit: cover;
width: 100%;
}

&:hover {
opacity: 0.8;
}
}

.srOnly {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}

@media (prefers-reduced-motion: reduce) {
.slide {
transition: none;
}
}
88 changes: 88 additions & 0 deletions docs/src/components/demos/flow-gallery/flow-gallery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { PropsWithChildren } from "react"
import {
Gallery,
GalleryNav,
GalleryMain,
GalleryItem,
GalleryPagination,
GalleryPaginationItem,
} from "@wethegit/react-gallery"
import "@wethegit/react-gallery/style.css"

import styles from "./flow-gallery.module.scss"

import { SLIDES, type Slide } from "../../../data/shared-data"

export function FlowGallery() {
return (
<div className={styles.root}>
<Gallery items={SLIDES} loop draggable={false} visibleRange={2}>
<GalleryMain<Slide>
className={styles.slideArea}
renderGalleryItem={({ item, index, activeIndex, active }) => {
const isPrev = activeIndex > index

return (
<GalleryItem
key={item.id}
index={index}
active={active}
className={styles.item}
data-side={active ? "active" : isPrev ? "prev" : "next"}
>
<div className={styles.slide}>
<img src={item.image} alt={item.alt} />
</div>
</GalleryItem>
)
}}
/>
<GalleryNav direction={0} className={styles.navPrev}>
<SvgIcon>
<polyline points="15 18 9 12 15 6" />
</SvgIcon>
<span className={styles.srOnly}>Previous</span>
</GalleryNav>
<GalleryNav direction={1} className={styles.navNext}>
<SvgIcon>
<polyline points="9 18 15 12 9 6" />
</SvgIcon>
<span className={styles.srOnly}>Next</span>
</GalleryNav>

<GalleryPagination<Slide>
className={styles.thumbs}
renderPaginationItem={({ item, index, active }) => (
<GalleryPaginationItem
key={item.id}
index={index}
active={active}
className={styles.thumbItem}
buttonClassName={styles.thumbButton}
>
<img src={item.image} alt={item.alt} />
</GalleryPaginationItem>
)}
/>
</Gallery>
</div>
)
}

function SvgIcon({ children }: PropsWithChildren) {
return (
<svg
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
{children}
</svg>
)
}
Loading