Skip to content

Commit 9b08af9

Browse files
committed
createAnimatedComponent/hooks (thanks to vincent riemer)
1 parent 3809bd9 commit 9b08af9

File tree

14 files changed

+7841
-17063
lines changed

14 files changed

+7841
-17063
lines changed

.size-snapshot.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@
113113
}
114114
},
115115
"dist/web-hooks.js": {
116-
"bundled": 72998,
117-
"minified": 33639,
118-
"gzipped": 11242,
116+
"bundled": 74335,
117+
"minified": 34138,
118+
"gzipped": 11370,
119119
"treeshaked": {
120120
"rollup": {
121-
"code": 13089,
122-
"import_statements": 262
121+
"code": 23654,
122+
"import_statements": 354
123123
},
124124
"webpack": {
125-
"code": 14298
125+
"code": 14682
126126
}
127127
}
128128
}

documentation/introduction.mdx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
name: Introduction
3+
route: /
4+
order: 1000
5+
---
6+
7+
import { Tweet } from 'react-twitter-widgets'
8+
9+
# Introduction
10+
11+
<p>
12+
<span className="highlight">react-spring is a set of simple, spring-physics based primitives</span> (as in building blocks) that should cover most of your UI related animation needs once plain CSS can't cope any longer. Forget easings, durations, timeouts and so on as you fluidly move data from one state to another. This isn't meant to solve each and every problem but rather to give you tools flexible enough to confidently cast ideas into moving interfaces.
13+
</p>
14+
15+
Our goal is to bridge Christopher Chedeau's [animated](https://github.com/animatedjs/animated) (which is used in react-native by default) with Cheng Lou's [react-motion](https://github.com/chenglou/react-motion). Although both are similarily spring-physics based they are still polar opposites. For a more detailed explanation read [Why React needed yet another animation library](https://medium.com/@drcmda/why-react-needed-yet-another-animation-library-introducing-react-spring-8212e424c5ce).
16+
17+
| | Declarative | Primitives | Interpolations | Performance |
18+
| -------------- | ----------- | ---------- | -------------- | ----------- |
19+
| React-motion |||||
20+
| Animated |||||
21+
| React-spring |||||
22+
23+
## Installation
24+
25+
npm install react-spring
26+
27+
## People say
28+
29+
<div style={{ display: "grid",
30+
gridGap: 20,
31+
gridTemplateColumns: "repeat(auto-fill, minmax(200px, 1fr))",
32+
gridAutoRows: "minmax(200px, auto)" }}>
33+
<Tweet tweetId='1006931395003015170' options={{ width: '400' }}/>
34+
<Tweet tweetId='1033962041298509824' options={{ conversation: 'none', cards: 'hidden', width: '400' }}/>
35+
<Tweet tweetId='1007560091430801409' options={{ conversation: 'none', width: '400' }}/>
36+
<Tweet tweetId='1033964001246543872' options={{ conversation: 'none', width: '400' }} />
37+
<Tweet tweetId='1030826919124590597' options={{ conversation: 'none', width: '400' }}/>
38+
<Tweet tweetId='1005463922772664320' options={{ conversation: 'none', width: '400' }}/>
39+
<Tweet tweetId='1032284123161931778' options={{ conversation: 'none', width: '400', cards: 'hidden' }}/>
40+
<Tweet tweetId='983054609353707520' options={{ conversation: 'none', width: '400' }}/>
41+
<Tweet tweetId='1087456685080358918' options={{ conversation: 'none', width: '400' }}/>
42+
</div>
43+
44+
## Used by
45+
46+
<div style={{ display: "grid",
47+
gridGap: 20,
48+
gridTemplateColumns: "repeat(auto-fill, minmax(200px, 1fr))",
49+
gridAutoRows: "minmax(200px, auto)" }}>
50+
<a href="https://nextjs.org/"><img width="280" src="https://process.filestackapi.com/cache=expiry:max/resize=width:1050/compress/FloGbmnXSe3Gd49LAWXQ"/></a>
51+
<a href="https://codesandbox.io/"><img width="280" src="https://camo.githubusercontent.com/a67bdde6bc5d15103e2516099107980790c0f11f/68747470733a2f2f636f646573616e64626f782e696f2f7374617469632f696d672f62616e6e65722e706e67"/></a>
52+
<a href="https://aragon.org/"><img width="280" src="https://github.com/aragon/design/blob/master/readme-logo.png?raw=true"/></a>
53+
<a href="https://devhubapp.com"><img width="280" src="https://user-images.githubusercontent.com/619186/49823485-eed18480-fd66-11e8-88c0-700d840ad4f1.png"/></a>
54+
<a href="https://quill.chat"><img width="280" src="https://quill.chat/079e00e7e0cbbeaa3aae571d657ca75b.png"/></a>
55+
</div>
56+
57+
And [many others](https://github.com/drcmda/react-spring/network/dependents) ...
58+
59+
## Gold sponsors
60+
61+
<a href="https://aragon.org/">
62+
<img width="300" src="https://wiki.aragon.org/design/logo/svg/imagetype.svg"/>
63+
</a>
64+
65+
## Sponsors
66+
67+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
68+
69+
<a href="https://opencollective.com/react-spring/sponsor/0/website" target="_blank">
70+
<img src="https://opencollective.com/react-spring/sponsor/0/avatar.svg"/>
71+
</a>
72+
<a href="https://opencollective.com/react-spring/sponsor/1/website" target="_blank">
73+
<img src="https://opencollective.com/react-spring/sponsor/1/avatar.svg"/>
74+
</a>
75+
76+
## Backers
77+
78+
Thank you to all our backers! 🙏
79+
80+
<a href="https://opencollective.com/react-spring#backers" target="_blank">
81+
<img src="https://opencollective.com/react-spring/backers.svg?width=890"/>
82+
</a>

documentation/test.mdx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
name: useSpring
3+
route: /useSpring
4+
order: 7
5+
---
6+
7+
import DemoGrid from '../examples/components/DemoGrid'
8+
import Demo from '../examples/components/Demo'
9+
import examples from '../examples/components/examples-hooks'
10+
11+
# useSpring
12+
13+
```js
14+
import { useSpring, animated } from 'react-spring'
15+
16+
// Update props by overwrite
17+
const props = useSpring(config)
18+
// Or, update props by calling an updater-function
19+
const [props, set] = useSpring(() => config)
20+
```
21+
22+
blabla
23+
24+
## Interpolation
25+
26+
* colors (names, rgb, rgba, hsl, hsla, gradients)
27+
* absolute lengths (cm, mm, in, px, pt, pc)
28+
* relative lengths (em, ex, ch, rem, vw, vh, vmin, vmax, %)
29+
* angles (deg, rad, grad, turn)
30+
* flex and grid units (fr, etc)
31+
* all HTML attributes
32+
* SVG paths (as long as the number of points matches, otherwise use [custom interpolation](https://codesandbox.io/embed/lwpkp46om))
33+
* arrays
34+
* string patterns (transform, border, boxShadow, etc)
35+
* auto is valid
36+
* non-animatable string values (visibility, pointerEvents, etc)
37+
* scrollTop/scrollLeft ([native only](/perf), since these aren't actual dom properties)
38+
39+
<br />
40+
41+
Of course the only properties that the browser can animate relatively cheaply are [composite properties](https://www.html5rocks.com/en/tutorials/speed/high-performance-animations/) (opacity, transform), so you might want to watch out for that.
42+
43+
## Config
44+
45+
<p>
46+
<span className="highlight">Spring are configurable</span>, delays, tension, friction, resets, everything can be tuned. There are also a couple of generic presets that will cover some common ground.
47+
</p>
48+
49+
```jsx
50+
import { Spring, config } from 'react-spring'
51+
52+
<Spring config={config.default} />
53+
````
54+
55+
| Property | Value |
56+
| ------------------------- | ------- |
57+
| config.default | { tension: 170, friction: 26 } |
58+
| config.gentle | { tension: 120, friction: 14 } |
59+
| config.wobbly | { tension: 180, friction: 12 } |
60+
| config.stiff | { tension: 210, friction: 20 } |
61+
| config.slow | { tension: 280, friction: 60 } |
62+
| config.molasses | { tension: 280, friction: 120 } |
63+
64+
## Properties
65+
66+
bla
67+
68+
| Property | Type | Description |
69+
| -------- | ---- | -------- | ------- | ----------- |
70+
| from | obj | Base values, optional |
71+
| to | obj/fn/array(obj) | Animates to ... |
72+
| delay | number/fn | Delay in ms before the animation starts. Also valid as a function for individual keys: key => delay |
73+
| immediate | bool/fn | Prevents animation if true. Also valid as a function for individual keys: key => immediate |
74+
| config | obj/fn | Spring config (contains mass, tension, friction, etc). Also valid as a function for individual keys: key => config |
75+
| reset | bool | The spring starts to animate from scratch (from -> to) if set true |
76+
| reverse | bool | "from" and "to" are switched if set true, this will only make sense in combination with the "reset" flag |
77+
| onStart | fn | Callback when the animation starts to animate |
78+
| onRest | fn | Callback when the animation comes to a still-stand |
79+
| onFrame | fn | Frame by frame callback, first argument passed is the animated value |
80+
81+
## Demos
82+
83+
bla
84+
85+
<DemoGrid padding={0}>
86+
{examples.filter(data => data.tags.includes('useSpring')).map(data => (
87+
<Demo
88+
key={data.name}
89+
{...data}
90+
import={import('../examples/demos/' + data.name)}
91+
/>
92+
))}
93+
</DemoGrid>

doczrc.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
const path = require('path')
2+
const css = require('docz-plugin-css').css
3+
4+
export default {
5+
protocol: 'http',
6+
title: '✌️ react-spring',
7+
hashRouter: true,
8+
htmlContext: {
9+
head: {
10+
links: [
11+
{
12+
rel: 'stylesheet',
13+
href: 'https://codemirror.net/theme/dracula.css',
14+
},
15+
],
16+
raw: `
17+
<style>
18+
#root > div > div:first-of-type {
19+
width: 350px;
20+
min-width: 350px;
21+
}
22+
#root > div > div:first-of-type > div:first-of-type {
23+
padding: 30px;
24+
width: 350px;
25+
min-width: 350px;
26+
}
27+
#root > div > div:first-of-type > div:first-of-type > div:last-of-type {
28+
display: none;
29+
}
30+
#root > div > div:first-of-type > div:first-of-type > div:nth-child(2):before {
31+
background: transparent;
32+
}
33+
#root > div > div:first-of-type > div:first-of-type > div:nth-child(2) h1 {
34+
font-size: 2.5em;
35+
font-weight: 100;
36+
}
37+
#root > div > div:nth-of-type(3) > div:first-of-type > a:first-of-type {
38+
display: none;
39+
}
40+
.scrollbar-container {
41+
max-height: unset!important;
42+
}
43+
.CodeMirror {
44+
font-size: 14px;
45+
height: 100%!important;
46+
}
47+
.CodeMirror pre {
48+
line-height: 20.8px!important;
49+
}
50+
.CodeMirror-line {
51+
padding: 0 10px!important;
52+
}
53+
.CodeMirror-lines {
54+
padding: 10px 0!important;
55+
}
56+
.CodeMirror-linenumber {
57+
padding: 0 7px 0 5px!important;
58+
}
59+
.code-table {
60+
display: flex;
61+
}
62+
.code-table {
63+
margin-bottom: 1em;
64+
}
65+
.code-table > div:first-of-type {
66+
flex: 1.5;
67+
}
68+
.code-table > div:last-of-type {
69+
flex: 1;
70+
}
71+
.code-table > div:last-child {
72+
position: relative;
73+
display: flex;
74+
align-items: center;
75+
justify-content: center;
76+
background: #f4f6f9;
77+
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto,
78+
segoe ui, arial, sans-serif;
79+
font-size: 4em;
80+
font-weight: 600;
81+
color: white;
82+
}
83+
.highlight {
84+
background: #ea567c;
85+
color: white;
86+
margin: 0 3px;
87+
padding: 4px 6px;
88+
border-radius: 3px;
89+
}
90+
.grommetux-meter {
91+
height: 70px;
92+
}
93+
.grommetux-meter__graphic {
94+
fill: transparent;
95+
stroke-linecap: round;
96+
stroke-linejoin: round;
97+
stroke-width: 15px;
98+
width: 70px;
99+
height: 70px;
100+
}
101+
.grommetux-meter__tracks {
102+
stroke: white;
103+
}
104+
.grommetux-meter__values {
105+
stroke: rgb(45, 55, 71);
106+
}
107+
code {
108+
background: #f4f6f9;
109+
color: #7D899C;
110+
margin: 0 3px;
111+
padding: 4px 6px;
112+
border-radius: 3px;
113+
font-family: "Source Code Pro",monospace;
114+
font-size: 14px;
115+
}
116+
a, a:visited, a:active {
117+
color: rgb(31, 182, 255);
118+
text-decoration: none;
119+
cursor: pointer;
120+
}
121+
</style>
122+
`,
123+
},
124+
},
125+
themeConfig: {
126+
//mode: 'dark',
127+
codemirrorTheme: 'dracula',
128+
colors: {
129+
primary: '#ea567c',
130+
sidebarBg: 'white',
131+
},
132+
styles: {
133+
body: {
134+
fontFamily:
135+
'-apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif',
136+
},
137+
h1: {
138+
fontSize: '4em',
139+
fontWeight: 800,
140+
},
141+
},
142+
},
143+
plugins: [css()],
144+
modifyBundlerConfig: (config, dev, args) => {
145+
return {
146+
...config,
147+
module: {
148+
...config.module,
149+
rules: [
150+
...config.module.rules,
151+
//{ test: () => true, sideEffects: true },
152+
],
153+
},
154+
resolve: {
155+
...config.resolve,
156+
alias: {
157+
...config.resolve.alias,
158+
'react-spring': path.resolve('./src/targets/web'),
159+
},
160+
},
161+
}
162+
},
163+
}

examples/components/examples-hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default [
33
name: 'goo',
44
title: 'Goo blobs',
55
link: 'https://codesandbox.io/embed/8zx4ppk01l',
6-
tags: ['useSpring'],
6+
tags: ['useTrail'],
77
code: {
88
useSpring: `const [trail, set] = useTrail(3, () => ({ xy: [0, 0] }))
99
const tr = (x, y) => \`translate3d(\${x}px,\${y}px,0)\`

0 commit comments

Comments
 (0)