Skip to content

Commit 7acc702

Browse files
committed
feat: add linear-gradient demo
1 parent ddff58b commit 7acc702

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

components/examples-tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export default [
1010
link: 'https://codesandbox.io/embed/j0y0vpz59',
1111
tags: ['useChain', 'useTransition'],
1212
},
13+
{
14+
name: 'tests/issue-827',
15+
title: 'Issue #827 - Linear gradient',
16+
tags: ['useTransition'],
17+
},
1318
{
1419
name: 'tests/issue-461',
1520
title: 'Issue #461 - Remove multiple items',

demos/tests/issue-827/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useCallback } from 'react'
2+
import ReactDOM from 'react-dom'
3+
import { useSpring, animated, config } from 'react-spring'
4+
5+
function linearGradient(deg, startColor, startPosition, endColor, endPosition) {
6+
return `linear-gradient(${deg}deg, ${startColor} ${startPosition}, ${endColor} ${endPosition})`
7+
}
8+
9+
function useLinearGradient(from, to) {
10+
return useSpring(() => ({
11+
from: { background: from },
12+
to: async next => {
13+
let i = 500
14+
let reverse = false
15+
while (--i > 0) {
16+
reverse = !reverse
17+
await next({
18+
to: { background: to },
19+
from: { background: from },
20+
reverse,
21+
config: config.slow,
22+
})
23+
}
24+
},
25+
}))
26+
}
27+
28+
export default function App() {
29+
// The background gradient
30+
const [gradient] = useLinearGradient(
31+
linearGradient(135, 'rgb(185, 198, 109)', '0%', 'rgb(34, 48, 17)', '100%'),
32+
linearGradient(45, 'rgb(85, 69, 47)', '0%', 'rgb(218, 102, 92)', '100%')
33+
)
34+
35+
return (
36+
<animated.div
37+
style={{
38+
...gradient,
39+
height: '100%',
40+
width: '100%',
41+
}}
42+
/>
43+
)
44+
}

0 commit comments

Comments
 (0)