Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 5d38f33

Browse files
committed
Implement folder collapse/expand animation
1 parent 156ec27 commit 5d38f33

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Changes to the library code should hot reload in the demo app
261261
262262
## What's missing
263263

264-
There are still a few features from the original implementation missing from this package. These are mainly related to saving and loading data as well as local storage. Animations for folder expanding/collapsing is also not currently implemented, but shouldn't be too hard to do.
264+
There are still a few features from the original implementation missing from this package. These are mainly related to saving and loading data as well as local storage.
265265

266266
For the first, I think the fact that this is now an NPM module sort of goes against it handling this sort of stuff. Google's original concept was basically a plug and play controller that could do everything if you just slam it into the browser and pass it an object. However, in module form, it's expected that you'll most likely be integrating this with an existing application. In that case, you'll probably have pretty specific needs around how you would like to save/load data into your GUI and so it's been left out for now.
267267
@@ -270,7 +270,6 @@ Local storage however is in the roadmap and will probably be done very soon.
270270
## Roadmap
271271
272272
- Loading and storing both default and preset data via `localStorage`
273-
- Animations for `DatFolder` expanding/collapsing
274273
- Time travel with undo/redo buttons
275274
- Better support for floating point `DatNumber`s (rounding etc.)
276275

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
"lodash.isundefined": "^3.0.1",
8585
"lodash.result": "^4.4.0",
8686
"lodash.set": "^4.2.0",
87-
"react-color": "^2.13.8"
87+
"react-color": "^2.13.8",
88+
"react-spring": "^8.0.27"
8889
},
8990
"devDependencies": {
9091
"@babel/core": "^7.5.4",

src/components/DatFolder.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, cloneElement } from 'react';
22
import PropTypes from 'prop-types';
33
import cx from 'classnames';
4+
import { Spring, animated } from 'react-spring/renderprops.cjs';
45

56
export default class DatFolder extends Component {
67
static propTypes = {
@@ -20,24 +21,34 @@ export default class DatFolder extends Component {
2021

2122
constructor(props) {
2223
super(props);
23-
this.state = { closed: props.closed };
24+
this.state = {
25+
initialRender: true,
26+
closed: props.closed
27+
};
2428
}
2529

30+
componentDidMount = () =>
31+
this.setState({
32+
initialRender: false
33+
});
34+
2635
handleClick = () =>
27-
this.setState(prevState => ({ closed: !prevState.closed }));
36+
this.setState(prevState => ({
37+
closed: !prevState.closed
38+
}));
2839

29-
renderChildren() {
40+
renderChildren = () => {
3041
// Disable this rule to take title out of the props so nested folders can have unique titles.
3142
// eslint-disable-next-line no-unused-vars
3243
const { children, title, ...rest } = this.props;
3344

3445
return React.Children.map(children, child =>
3546
cloneElement(child, { ...rest })
3647
);
37-
}
48+
};
3849

3950
render() {
40-
const { closed } = this.state;
51+
const { closed, initialRender } = this.state;
4152
const { title, className, style } = this.props;
4253

4354
return (
@@ -52,7 +63,18 @@ export default class DatFolder extends Component {
5263
>
5364
{title}
5465
</div>
55-
<ul>{this.renderChildren()}</ul>
66+
<Spring
67+
native
68+
immediate={initialRender}
69+
to={{ height: closed ? 0 : 'auto' }}
70+
from={{ height: closed ? 'auto' : 0 }}
71+
>
72+
{animStyles => (
73+
<animated.ul style={animStyles}>
74+
{this.renderChildren()}
75+
</animated.ul>
76+
)}
77+
</Spring>
5678
</div>
5779
</li>
5880
);

src/style/_folder.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@
2020
.title {
2121
background: $folder-closed;
2222
}
23-
24-
ul {
25-
display: none;
26-
}
2723
}
2824
}

yarn.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@
693693
"@babel/plugin-transform-react-jsx-self" "^7.0.0"
694694
"@babel/plugin-transform-react-jsx-source" "^7.0.0"
695695

696-
"@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.5.5":
696+
"@babel/runtime@^7.3.1", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.1", "@babel/runtime@^7.5.5":
697697
version "7.5.5"
698698
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
699699
integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==
@@ -6320,7 +6320,7 @@ prompts@^2.0.1:
63206320
kleur "^3.0.3"
63216321
sisteransi "^1.0.3"
63226322

6323-
prop-types@^15.5.10, prop-types@^15.6.2, prop-types@^15.7.2:
6323+
prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.2, prop-types@^15.7.2:
63246324
version "15.7.2"
63256325
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
63266326
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -6409,6 +6409,14 @@ react-is@^16.8.1, react-is@^16.8.4:
64096409
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.9.0.tgz#21ca9561399aad0ff1a7701c01683e8ca981edcb"
64106410
integrity sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==
64116411

6412+
react-spring@^8.0.27:
6413+
version "8.0.27"
6414+
resolved "https://registry.yarnpkg.com/react-spring/-/react-spring-8.0.27.tgz#97d4dee677f41e0b2adcb696f3839680a3aa356a"
6415+
integrity sha512-nDpWBe3ZVezukNRandTeLSPcwwTMjNVu1IDq9qA/AMiUqHuRN4BeSWvKr3eIxxg1vtiYiOLy4FqdfCP5IoP77g==
6416+
dependencies:
6417+
"@babel/runtime" "^7.3.1"
6418+
prop-types "^15.5.8"
6419+
64126420
react@^16.8.4:
64136421
version "16.9.0"
64146422
resolved "https://registry.yarnpkg.com/react/-/react-16.9.0.tgz#40ba2f9af13bc1a38d75dbf2f4359a5185c4f7aa"

0 commit comments

Comments
 (0)