Skip to content

Commit 4a65ba9

Browse files
committed
feat(fade): detect overflow directions and dynamically detect overflow
release-npm
1 parent 3cb0853 commit 4a65ba9

File tree

5 files changed

+62
-143
lines changed

5 files changed

+62
-143
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Add a gradient-based dynamic fade effect to elements with scrollable overflow.
88

99
- ⚛️ React JSX based
10-
- 🔄 Works with either horizontal or vertical overflow
10+
- 🔄 Automatically detects and supports horizontal and vertical overflow.
1111
- ❗ Requires the [ScrollTimeline](https://caniuse.com/mdn-api_scrolltimeline) API
1212
- Currently works in Chrome, Edge and Opera
1313
- ⚠️ Published as TypeScript and JSX see [this post on 𝕏](https://twitter.com/matthiasgiger/status/1766443368567971946) for the reasoning
@@ -21,7 +21,7 @@ Add a gradient-based dynamic fade effect to elements with scrollable overflow.
2121
import { Scroll } from 'overflow-scroll-fade'
2222

2323
const MyScroll = () => (
24-
<Scroll direction="horizontal">
24+
<Scroll>
2525
<p>overflow-scroll-fade</p>
2626
<p>overflow-scroll-fade</p>
2727
</Scroll>

demo/ConfigurationTable.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ export function Configuration() {
2828
<Header>Default value</Header>
2929
<Header>Type</Header>
3030
<Header>Description</Header>
31-
<span>direction</span>
32-
<Code>horizontal</Code>
33-
<Code>'horizontal' | 'vertical'</Code>
34-
<span>Scroll direction of the container.</span>
3531
<span>color</span>
3632
<Code>#FFF</Code>
3733
<Code>string</Code>

demo/configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const biome = {
2626
style: {
2727
useFilenamingConvention: 'off',
2828
},
29+
suspicious: {
30+
noArrayIndexKey: 'off',
31+
},
2932
},
3033
},
3134
files: {

demo/index.tsx

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ const Color = {
3333
boxes: ['#0075ff', '#ff002e', '#00ba6c', '#eb00ff', '#ffb800', '#09d3c7'],
3434
}
3535

36-
const checkeredBackground = (color: string): CSSProperties => ({
37-
backgroundImage: `linear-gradient(45deg, ${color} 25%, transparent 25%), linear-gradient(-45deg, ${color} 25%, transparent 25%), linear-gradient(45deg, transparent 75%, ${color} 75%), linear-gradient(-45deg, transparent 75%, ${color} 75%)`,
38-
backgroundSize: '20px 20px',
39-
backgroundPosition: '0 0, 0 10px, 10px -10px, -10px 0px',
40-
})
41-
4236
const headingStyles = (as: 'h1' | 'h2' | 'h3'): CSSProperties => ({
4337
margin: 0,
4438
fontSize: as === 'h1' ? scale(36) : scale(24),
@@ -76,15 +70,14 @@ function Paragraph({ style, ...props }: JSX.IntrinsicElements['p']) {
7670

7771
function Code({ children }: { children: string }) {
7872
return (
79-
<Scroll>
73+
<Scroll overflowStyle={{ borderRadius: scale(20) }}>
8074
<div
8175
style={{
8276
display: 'flex',
8377
flex: 1,
8478
flexDirection: 'column',
8579
padding: scale(20),
8680
background: Color.blue.ultralight,
87-
borderRadius: scale(20),
8881
fontFamily: 'monospace',
8982
whiteSpace: 'pre',
9083
fontSize: scale(16),
@@ -137,7 +130,7 @@ function DynamicContent({ children }) {
137130
function animateHeight() {
138131
const element = document.getElementById('animated-box')
139132
const startHeight = element.offsetHeight
140-
let startTime = null
133+
let startTime = 0
141134
const increase = startHeight < 200
142135
const duration = 3000
143136
const targetHeight = increase ? 250 : 50
@@ -237,7 +230,18 @@ const MyGrid = () => (
237230
</Scroll>
238231
)`}</Code>
239232
<Heading as="h2">Examples</Heading>
240-
<Scroll style={{ maxWidth: 360 }} overflowStyle={{ gap: scale(10) }}>
233+
<Heading as="h3">Vertical & Horizontal</Heading>
234+
<Scroll as="main" style={{ maxHeight: 150, maxWidth: 340 }} overflowStyle={{ gap: scale(10), flexDirection: 'column' }}>
235+
{Array.from({ length: 6 }).map((_, i) => (
236+
<div style={{ display: 'flex', gap: scale(10) }} key={i}>
237+
{Array.from({ length: 6 }).map((_, j) => (
238+
<Box key={j} />
239+
))}
240+
</div>
241+
))}
242+
</Scroll>
243+
<Heading as="h3">Horizontal</Heading>
244+
<Scroll style={{ maxWidth: 340 }} overflowStyle={{ gap: scale(10) }}>
241245
<Box />
242246
<Box />
243247
<Box />
@@ -246,7 +250,7 @@ const MyGrid = () => (
246250
<Box />
247251
</Scroll>
248252
<Heading as="h3">Vertical</Heading>
249-
<Scroll as="main" style={{ maxHeight: 160 }} direction="vertical" overflowStyle={{ gap: scale(10), flexDirection: 'column' }}>
253+
<Scroll as="main" style={{ maxHeight: 150 }} overflowStyle={{ gap: scale(10), flexDirection: 'column' }}>
250254
<Box />
251255
<Box />
252256
<Box />
@@ -317,7 +321,7 @@ const MyGrid = () => (
317321
))}
318322
</Scroll>
319323
<Heading as="h3">Dynamic Content Size</Heading>
320-
<Scroll style={{ maxWidth: 360 }} overflowStyle={{ gap: scale(10) }}>
324+
<Scroll style={{ maxWidth: 340 }} overflowStyle={{ gap: scale(10) }}>
321325
<DynamicContent>
322326
{(frame: number) => (
323327
<>
@@ -333,7 +337,7 @@ const MyGrid = () => (
333337
)}
334338
</DynamicContent>
335339
</Scroll>
336-
<Scroll style={{ maxWidth: 360 }} overflowStyle={{ gap: scale(10) }}>
340+
<Scroll style={{ maxWidth: 340 }} overflowStyle={{ gap: scale(10) }}>
337341
<DynamicContent>
338342
{(frame: number) => (
339343
<>
@@ -351,7 +355,7 @@ const MyGrid = () => (
351355
)}
352356
</DynamicContent>
353357
</Scroll>
354-
<Scroll style={{ maxWidth: 360 }}>
358+
<Scroll style={{ maxWidth: 340 }}>
355359
<DynamicContent>
356360
{(frame: number) => (
357361
<div style={{ display: 'flex', gap: scale(10) }}>
@@ -372,11 +376,7 @@ const MyGrid = () => (
372376
</DynamicContent>
373377
</Scroll>
374378
<Heading as="h3">Dynamic Vertical Content Size</Heading>
375-
<Scroll
376-
style={{ height: 200 }}
377-
direction="vertical"
378-
overflowStyle={{ gap: scale(10), flexDirection: 'column' }}
379-
>
379+
<Scroll style={{ height: 200 }} overflowStyle={{ gap: scale(10), flexDirection: 'column' }}>
380380
<AddMoreContent />
381381
</Scroll>
382382
<Heading as="h2">Configuration</Heading>
@@ -411,27 +411,6 @@ const ResultingStructure = () => (
411411
</div>
412412
</div>
413413
)`}</Code>
414-
<Heading as="h2">Development Playground</Heading>
415-
<Scroll style={{ maxWidth: 300 }} overflowStyle={{ gap: scale(10) }}>
416-
<div
417-
style={{
418-
width: 1000,
419-
height: 50,
420-
...checkeredBackground(Color.boxes[0]),
421-
flex: '0 0 auto',
422-
}}
423-
/>
424-
</Scroll>
425-
<Scroll direction="vertical" style={{ maxHeight: 100 }} overflowStyle={{ gap: scale(20) }}>
426-
<div
427-
style={{
428-
width: 200,
429-
height: 300,
430-
...checkeredBackground(Color.boxes[1]),
431-
flex: '0 0 auto',
432-
}}
433-
/>
434-
</Scroll>
435414
</div>
436415
)
437416
}

0 commit comments

Comments
 (0)