Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
[138] Reduced animation speed, hover effect + disabling actions while…
Browse files Browse the repository at this point in the history
… animating
  • Loading branch information
piotrgrundas committed Dec 17, 2018
1 parent 5d41595 commit e7f4662
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ All notable, unreleased changes to this project will be documented in this file.
## [Unreleased]
Hide filters and sorting when there are no search results, add trending products to empty search, categories #151 by @piotrgrundas
Add fetching menus from the API #127 by @piotrgrundas
Add add to cart indicator #138 by @piotrgrundas
30 changes: 20 additions & 10 deletions src/components/ProductDescription/AddToCartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@ import * as React from "react";

import classNames from "classnames";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
import { Button, ButtonProps } from "..";
import { Button, ButtonProps, Debounce } from "..";

interface AddToCartButtonState {
animate: boolean;
disabled: boolean;
}

class AddToCartButton extends React.PureComponent<
ButtonProps,
AddToCartButtonState
> {
state = { animate: false };
state = { animate: false, disabled: false };
animationTimeout = 800;
timeout;

handleAnimation = (evt: React.MouseEvent<HTMLButtonElement>) => {
clearTimeout(this.timeout);
this.props.onClick(evt);

this.setState({ animate: true }, () => {
this.timeout = setTimeout(() => {
this.setState({ animate: false });
}, this.animationTimeout);
});
if (!this.state.disabled) {
this.props.onClick(evt);

this.setState({ animate: true, disabled: true }, () => {
setTimeout(() => {
this.setState({ animate: false }, () => {
setTimeout(
() => this.setState({ disabled: false }),
this.animationTimeout
);
});
}, this.animationTimeout);
});
}
};

render() {
Expand All @@ -33,6 +40,9 @@ class AddToCartButton extends React.PureComponent<
return (
<Button
{...this.props}
className={classNames(this.props.className, {
"product-description__action--fade": animate
})}
onClick={this.handleAnimation}
>
<ReactCSSTransitionGroup
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProductDescription/scss/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
min-height: 49px;

&--fade {
$animation-speed: 500ms;
$animation-speed: 200ms;
background-color: $turquoise-dark;

&-enter {
opacity: 0;
Expand Down

0 comments on commit e7f4662

Please sign in to comment.