Skip to content

Commit 855bc54

Browse files
author
Adam Plesnik
committed
Add home anim
1 parent b507f1a commit 855bc54

File tree

9 files changed

+143
-4
lines changed

9 files changed

+143
-4
lines changed

docs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"localforage": "^1.10.0",
14+
"lucide-react": "^0.367.0",
1415
"match-sorter": "^6.3.4",
1516
"react": "^18.2.0",
1617
"react-dom": "^18.2.0",
@@ -19,6 +20,7 @@
1920
"tailwindcss": "^3.4.3"
2021
},
2122
"devDependencies": {
23+
"@adam.plesnik/tailwindcss-scroll-driven-animations": "^0.1.1",
2224
"@types/react": "^18.2.66",
2325
"@types/react-dom": "^18.2.22",
2426
"@typescript-eslint/eslint-plugin": "^7.2.0",

docs/src/components/Banner.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { WandSparkles } from 'lucide-react'
2+
3+
const Banner = () => {
4+
return (
5+
<div className="mb-4 mt-8 flex items-center gap-4 rounded-lg border border-amber-400 bg-amber-50 px-4 py-3 text-sm dark:border-amber-600 dark:bg-stone-700/30">
6+
<WandSparkles
7+
className="size-6 shrink-0 text-amber-500 dark:text-amber-600"
8+
strokeWidth="1"
9+
/>
10+
Scroll-driven animations are not yet supported by your browser. Use Chrome 116 or newer to see
11+
the demos working correctly.
12+
</div>
13+
)
14+
}
15+
16+
export default Banner

docs/src/components/Heading.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ArrowRight } from 'lucide-react'
2+
import { PropsWithChildren } from 'react'
3+
import { NavLink } from 'react-router-dom'
4+
5+
const Heading = ({
6+
size = 1,
7+
className = '',
8+
children,
9+
id = '',
10+
href = '',
11+
hrefType = 'documentation',
12+
}: PropsWithChildren<TitleProps>) => {
13+
const defaultClasses = 'relative w-full' + (className && ` ${className}`)
14+
const anchor = id ? <a id={id} className={'absolute -top-32'} /> : ''
15+
const link = href ? (
16+
<NavLink to={href} className="group flex gap-1 text-xs text-fuchsia-500 dark:text-cyan-500">
17+
<span className="border-b border-b-transparent transition-colors group-hover:border-b-current">
18+
{hrefType === 'documentation' ? 'Documentation' : 'Demo'}
19+
</span>
20+
<ArrowRight className={'size-4' + (hrefType === 'demo' ? ' rotate-90' : '')} />
21+
</NavLink>
22+
) : (
23+
''
24+
)
25+
if (size === 1) {
26+
return (
27+
<h1 className={defaultClasses + ' py-4 text-3xl font-semibold md:py-8'}>
28+
{children}
29+
{anchor}
30+
</h1>
31+
)
32+
} else if (size === 2) {
33+
return (
34+
<h2 className={defaultClasses + ' pb-4 pt-12 text-4xl font-semibold'}>
35+
{children}
36+
{anchor}
37+
</h2>
38+
)
39+
} else if (size === 3) {
40+
return (
41+
<h3 className={defaultClasses + ' flex items-center gap-4 pb-4 pt-8 text-xl font-bold'}>
42+
{children}
43+
{anchor}
44+
{link}
45+
</h3>
46+
)
47+
} else {
48+
return (
49+
<h4 className={defaultClasses + ' pb-6 text-sm opacity-50'}>
50+
{children}
51+
{anchor}
52+
</h4>
53+
)
54+
}
55+
}
56+
57+
export interface TitleProps {
58+
children: PropsWithChildren
59+
size: 1 | 2 | 3 | 4
60+
className?: string
61+
href?: string
62+
hrefType?: 'documentation' | 'demo'
63+
id?: string
64+
}
65+
66+
export default Heading

docs/src/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@keyframes appear {
6+
to {
7+
width: auto;
8+
}
9+
}

docs/src/layouts/MainLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import { PropsWithChildren } from 'react'
22
import { ScrollRestoration } from 'react-router-dom'
33
import Footer from '../partials/Footer'
44
import PageBackground from '../partials/PageBackground'
5+
import Nav from '../partials/Nav'
6+
import Banner from '../components/Banner'
57

68
function MainLayout({ children }: PropsWithChildren<MainLayoutProps>) {
79
return (
810
<div className="flex flex-col items-center justify-center">
911
<PageBackground />
10-
<div className="relative z-10 w-full max-w-screen-lg p-8 md:p-16 lg:p-20">
12+
<Nav />
13+
<div className="relative z-10 w-full max-w-screen-xl p-8 md:p-16 lg:p-20">
14+
<div className="supports-no-animations:block hidden">
15+
<Banner />
16+
</div>
1117
<div className="w-full">{children}</div>
1218
<Footer />
1319
</div>

docs/src/pages/Home.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import Heading from '../components/Heading.tsx'
12
import MainLayout from '../layouts/MainLayout.tsx'
3+
import HomeIntroAnimation from '../partials/HomeIntroAnimation.tsx'
24

35
function Home() {
46
return (
57
<MainLayout>
6-
<div>Silence.</div>
8+
<Heading size={1}>Tailwind CSS Scroll-driven Animations</Heading>
9+
<Heading size={4}>Silence.</Heading>
10+
<HomeIntroAnimation />
711
</MainLayout>
812
)
913
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const HomeIntroAnimation = () => {
2+
const text = Array.from('Scroll. Your next superpower.')
3+
return (
4+
<div className="h-[1920px] w-full">
5+
<div className="flex w-full font-bold text-3xl sm:text-7xl sticky top-32">
6+
{text.map((letter, index) => (
7+
<span
8+
className="inline-block w-0 animate-appear overflow-hidden timeline"
9+
style={{
10+
animationRangeEnd: (index * 64 + 128).toString() + 'px',
11+
}}
12+
key={index}
13+
>
14+
{letter === ' ' ? '\u00A0' : letter}
15+
</span>
16+
))}
17+
</div>
18+
</div>
19+
)
20+
}
21+
22+
export default HomeIntroAnimation

docs/src/partials/Nav.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Nav = () => {
2+
return (
3+
<div className="w-full flex justify-center sticky top-0">
4+
<div className="max-w-screen-xl px-8 md:px-16 lg:px-20 w-full">Nav</div>
5+
</div>
6+
)
7+
}
8+
9+
export default Nav

docs/tailwind.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ export default {
44
files: ['./src/**/*.{js,ts,jsx,tsx}', './index.html'],
55
},
66
theme: {
7-
extend: {},
7+
extend: {
8+
animation: {
9+
appear: 'appear auto linear forwards',
10+
},
11+
},
12+
supports: {
13+
animations: 'animation-timeline: scroll(y)',
14+
'no-animations': 'not(animation-timeline: scroll(y))',
15+
},
816
},
9-
plugins: [],
17+
plugins: [require('@adam.plesnik/tailwindcss-scroll-driven-animations')],
1018
}

0 commit comments

Comments
 (0)