Add animation for app actions toggling

This commit is contained in:
SleepWalker 2018-11-04 08:07:04 +02:00
parent acbf61ab40
commit 439453c258
2 changed files with 54 additions and 12 deletions

View File

@ -182,6 +182,8 @@
background: #F5F5F5; background: #F5F5F5;
border-top: 1px solid #eee; border-top: 1px solid #eee;
padding: 5px 30px; padding: 5px 30px;
position: relative;
transition: transform 0.2s ease-in;
} }
.appDetailsInfoField { .appDetailsInfoField {
@ -226,6 +228,11 @@
} }
} }
.appActionContainer {
position: absolute;
top: 100%;
}
.appActionDescription { .appActionDescription {
composes: appDetailsDescription; composes: appDetailsDescription;

View File

@ -41,18 +41,22 @@ export default class ApplicationItem extends Component<
{ {
selectedAction: ?string, selectedAction: ?string,
isActionPerforming: bool, isActionPerforming: bool,
detailsHeight: number detailsHeight: number,
translateY: number
} }
> { > {
state = { state = {
selectedAction: null, selectedAction: null,
isActionPerforming: false, isActionPerforming: false,
translateY: 0,
detailsHeight: 0 detailsHeight: 0
}; };
actionContainer: ?HTMLDivElement;
render() { render() {
const { application: app, expand } = this.props; const { application: app, expand } = this.props;
const { selectedAction } = this.state; const { selectedAction, translateY } = this.state;
return ( return (
<div <div
@ -84,7 +88,10 @@ export default class ApplicationItem extends Component<
</div> </div>
<Collapse isOpened={expand} onRest={this.onCollapseRest}> <Collapse isOpened={expand} onRest={this.onCollapseRest}>
<div className={styles.appDetailsContainer}> <div
className={styles.appDetailsContainer}
style={{ transform: `translateY(-${translateY}px)` }}
>
<div className={styles.appDetailsInfoField}> <div className={styles.appDetailsInfoField}>
<Link <Link
to={`/dev/applications/${app.clientId}`} to={`/dev/applications/${app.clientId}`}
@ -143,7 +150,14 @@ export default class ApplicationItem extends Component<
))} ))}
</div> </div>
{this.getActionContent()} <div
className={styles.appActionContainer}
ref={(el) => {
this.actionContainer = el;
}}
>
{this.getActionContent()}
</div>
</div> </div>
</Collapse> </Collapse>
</div> </div>
@ -238,42 +252,63 @@ export default class ApplicationItem extends Component<
} }
} }
setActiveAction = (type: ?string) => {
const { actionContainer } = this;
if (!actionContainer) {
return;
}
this.setState(
{
selectedAction: type
},
() => {
const translateY = actionContainer.offsetHeight;
this.setState({ translateY });
}
);
};
onTileToggle = () => { onTileToggle = () => {
const { onTileClick, application } = this.props; const { onTileClick, application } = this.props;
onTileClick(application.clientId); onTileClick(application.clientId);
}; };
onCollapseRest = () => { onCollapseRest = () => {
if (!this.props.expand && this.state.selectedAction) { if (!this.props.expand && this.state.selectedAction) {
this.setState({ this.setActiveAction(null);
selectedAction: null
});
} }
}; };
onActionButtonClick = (type: ?string) => () => { onActionButtonClick = (type: ?string) => () => {
this.setState({ this.setActiveAction(type === this.state.selectedAction ? null : type);
selectedAction: type === this.state.selectedAction ? null : type
});
}; };
onResetSubmit = (resetClientSecret: bool) => async () => { onResetSubmit = (resetClientSecret: bool) => async () => {
const { onResetSubmit, application } = this.props; const { onResetSubmit, application } = this.props;
this.setState({ this.setState({
isActionPerforming: true isActionPerforming: true
}); });
await onResetSubmit(application.clientId, resetClientSecret); await onResetSubmit(application.clientId, resetClientSecret);
this.setState({ this.setState({
isActionPerforming: false, isActionPerforming: false
selectedAction: null
}); });
this.setActiveAction(null);
}; };
onSubmitDelete = () => { onSubmitDelete = () => {
const { onDeleteSubmit, application } = this.props; const { onDeleteSubmit, application } = this.props;
this.setState({ this.setState({
isActionPerforming: true isActionPerforming: true
}); });
onDeleteSubmit(application.clientId); onDeleteSubmit(application.clientId);
}; };
} }