Skip to content

Commit f9b9794

Browse files
committed
Added better param and return foldout animations
1 parent 728d49d commit f9b9794

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@testing-library/user-event": "^12.1.10",
1313
"node-sass": "4.14.1",
1414
"react": "^17.0.2",
15+
"react-animate-height": "^2.0.23",
1516
"react-copy-to-clipboard": "^5.0.3",
1617
"react-device-detect": "^2.1.2",
1718
"react-dom": "^17.0.2",

src/components/viewer/Editor.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
&_folding {
5252
overflow: hidden;
5353
& * {
54-
opacity: 0;
55-
height: 0px;
54+
user-select: none;
55+
pointer-events: none;
5656
}
5757

5858
&::before {

src/components/viewer/drawers/FunctionView.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import overview from './../Overview.module.scss';
44
import functionStyle from './../Function.module.scss';
55
import editor from './../Editor.module.scss';
66

7-
import FunctionRender from './FunctionRender'
7+
import FunctionRender from './FunctionRender';
8+
import AnimateHeight from 'react-animate-height';
89

910
// TODO: Maybe tint function boxes depending on the sandbox
1011

1112
class FunctionView extends React.Component {
1213
constructor(props) {
1314
super(props);
1415
let data = props.data;
15-
this.state = {data: props.data, menu: false};
16+
this.state = {
17+
data: props.data,
18+
menu: false,
19+
paramFoldout: false,
20+
returnFoldout: false
21+
};
1622
this.id = `${data.namespace}_${data.name}_${data.isLocal}`;
1723
this.onSandboxChanged = this.onSandboxChanged.bind(this);
1824
this.onDescriptionChange = this.onDescriptionChange.bind(this);
@@ -21,7 +27,12 @@ class FunctionView extends React.Component {
2127
}
2228

2329
componentWillReceiveProps(nextProps) {
24-
this.setState({data: nextProps.data, menu: false});
30+
this.setState({
31+
data: nextProps.data,
32+
menu: false,
33+
paramFoldout: false,
34+
returnFoldout: false
35+
});
2536
}
2637

2738
onSandboxChanged(event) {
@@ -118,7 +129,7 @@ class FunctionView extends React.Component {
118129
}
119130

120131
refresh() {
121-
this.setState({data: this.state.data, menu: true});
132+
this.setState({data: this.state.data});
122133
}
123134

124135
createSandboxSelection() {
@@ -267,9 +278,18 @@ class FunctionView extends React.Component {
267278
let descriptionEditor = this.createDescriptionEditor();
268279
let returnParamEditor = this.createReturnParams();
269280

270-
let folding = (event) => {
281+
let isParamFoldout = this.state.paramFoldout;
282+
let isReturnFoldout = this.state.returnFoldout;
283+
284+
let foldingParam = (event) => {
285+
if(event.currentTarget === event.target) {
286+
this.setState({paramFoldout: !isParamFoldout});
287+
}
288+
};
289+
290+
let foldingReturn = (event) => {
271291
if(event.currentTarget === event.target) {
272-
event.currentTarget.classList.toggle(`${editor.Param_folding}`);
292+
this.setState({returnFoldout: !isReturnFoldout});
273293
}
274294
};
275295

@@ -279,13 +299,17 @@ class FunctionView extends React.Component {
279299
Sandbox:
280300
{sandboxSelection}
281301
</div>
282-
<div className={`${editor.Param_label} ${editor.Param_folding}`} onClick={folding}>
302+
<div className={`${editor.Param_label} ${isParamFoldout ? '':editor.Param_folding}`} onClick={foldingParam}>
283303
Params:
284-
{paramsEditor}
304+
<AnimateHeight duration={300} height={isParamFoldout ? 'auto':0}>
305+
{paramsEditor}
306+
</AnimateHeight>
285307
</div>
286-
<div className={`${editor.Param_label} ${editor.Param_folding}`} onClick={folding}>
308+
<div className={`${editor.Param_label} ${isReturnFoldout ? '':editor.Param_folding}`} onClick={foldingReturn}>
287309
Return:
288-
{returnParamEditor}
310+
<AnimateHeight duration={300} height={isReturnFoldout ? 'auto':0}>
311+
{returnParamEditor}
312+
</AnimateHeight>
289313
</div>
290314
<div className={`${editor.Param_label_single}`}>
291315
Description:

yarn.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,11 @@ class-utils@^0.3.5:
34423442
isobject "^3.0.0"
34433443
static-extend "^0.1.1"
34443444

3445+
classnames@^2.2.5:
3446+
version "2.3.1"
3447+
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.1.tgz#dfcfa3891e306ec1dad105d0e88f4417b8535e8e"
3448+
integrity sha512-OlQdbZ7gLfGarSqxesMesDa5uz7KFbID8Kpq/SxIoNGDqY8lSYs0D+hhtBXhcdB3rcbXArFr7vlHheLk1voeNA==
3449+
34453450
clean-css@^4.2.3:
34463451
version "4.2.3"
34473452
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.3.tgz#507b5de7d97b48ee53d84adb0160ff6216380f78"
@@ -9577,6 +9582,15 @@ prop-types@^15.5.8, prop-types@^15.6.2, prop-types@^15.7.2:
95779582
object-assign "^4.1.1"
95789583
react-is "^16.8.1"
95799584

9585+
prop-types@^15.6.1:
9586+
version "15.8.0"
9587+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.0.tgz#d237e624c45a9846e469f5f31117f970017ff588"
9588+
integrity sha512-fDGekdaHh65eI3lMi5OnErU6a8Ighg2KjcjQxO7m8VHyWjcPyj5kiOgV1LQDOOOgVy3+5FgjXvdSSX7B8/5/4g==
9589+
dependencies:
9590+
loose-envify "^1.4.0"
9591+
object-assign "^4.1.1"
9592+
react-is "^16.13.1"
9593+
95809594
property-information@^5.0.0:
95819595
version "5.6.0"
95829596
resolved "https://registry.yarnpkg.com/property-information/-/property-information-5.6.0.tgz#61675545fb23002f245c6540ec46077d4da3ed69"
@@ -9744,6 +9758,14 @@ raw-body@2.4.0:
97449758
iconv-lite "0.4.24"
97459759
unpipe "1.0.0"
97469760

9761+
react-animate-height@^2.0.23:
9762+
version "2.0.23"
9763+
resolved "https://registry.yarnpkg.com/react-animate-height/-/react-animate-height-2.0.23.tgz#2e14ac707b20ae67b87766ccfd581e693e0e7ec7"
9764+
integrity sha512-DucSC/1QuxWEFzR9IsHMzrf2nrcZ6qAmLIFoENa2kLK7h72XybcMA9o073z7aHccFzdMEW0/fhAdnQG7a4rDow==
9765+
dependencies:
9766+
classnames "^2.2.5"
9767+
prop-types "^15.6.1"
9768+
97479769
react-app-polyfill@^2.0.0:
97489770
version "2.0.0"
97499771
resolved "https://registry.yarnpkg.com/react-app-polyfill/-/react-app-polyfill-2.0.0.tgz#a0bea50f078b8a082970a9d853dc34b6dcc6a3cf"
@@ -9820,7 +9842,7 @@ react-ga@^3.3.0:
98209842
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.0.tgz#c91f407198adcb3b49e2bc5c12b3fe460039b3ca"
98219843
integrity sha512-o8RScHj6Lb8cwy3GMrVH6NJvL+y0zpJvKtc0+wmH7Bt23rszJmnqEQxRbyrqUzk9DTJIHoP42bfO5rswC9SWBQ==
98229844

9823-
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1:
9845+
react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1:
98249846
version "16.13.1"
98259847
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
98269848
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

0 commit comments

Comments
 (0)