Skip to content

Commit 508bcf6

Browse files
committed
feat: add linear-gradient demo
1 parent ddff58b commit 508bcf6

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React, { useCallback } from 'react'
2+
import ReactDOM from 'react-dom'
3+
import { useSpring, animated } 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,
12+
to: async next => {
13+
let i = 500
14+
let reverse = false
15+
while (--i > 0) {
16+
reverse = !reverse
17+
await next({
18+
to,
19+
from,
20+
reverse,
21+
onAnimate: console.log,
22+
onChange: console.log,
23+
})
24+
console.log('done')
25+
}
26+
},
27+
}))
28+
}
29+
30+
export default function App() {
31+
// The background gradient
32+
const [gradient] = useLinearGradient(
33+
{
34+
background: linearGradient(
35+
135,
36+
'rgb(185, 198, 109)',
37+
'0%',
38+
'rgb(34, 48, 17)',
39+
'100%'
40+
),
41+
},
42+
{
43+
background: linearGradient(
44+
135,
45+
'rgb(85, 69, 47)',
46+
'0%',
47+
'rgb(218, 102, 92)',
48+
'100%'
49+
),
50+
}
51+
)
52+
53+
return <animated.div style={{ ...gradient, height: 100, width: 100 }} />
54+
}

0 commit comments

Comments
 (0)