Browse Source

Merge pull request #100 from smiclea/reload-animation

Add `Reload` button animation to lists
Dorin Paslaru 8 years ago
parent
commit
f9b7e552e9
1 changed files with 30 additions and 2 deletions
  1. 30 2
      src/components/atoms/ReloadButton/ReloadButton.jsx

+ 30 - 2
src/components/atoms/ReloadButton/ReloadButton.jsx

@@ -13,7 +13,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 import React from 'react'
-import styled from 'styled-components'
+import styled, { injectGlobal } from 'styled-components'
+import PropTypes from 'prop-types'
 
 import reloadImage from './images/reload.svg'
 
@@ -24,10 +25,37 @@ const Wrapper = styled.div`
   cursor: pointer;
 `
 
+injectGlobal`
+  .reload-animation {
+    transform: rotate(360deg);
+    transition: transform 1s cubic-bezier(0, 1.4, 1, 1);
+  }
+`
+
 class ReloadButton extends React.Component {
+  static propTypes = {
+    onClick: PropTypes.func,
+  }
+
+  onClick() {
+    if (this.timeout) {
+      return
+    }
+
+    if (this.props.onClick) {
+      this.props.onClick()
+    }
+
+    this.wrapper.className += ' reload-animation'
+    this.timeout = setTimeout(() => {
+      this.wrapper.className = this.wrapper.className.substr(0, this.wrapper.className.indexOf(' reload-animation'))
+      this.timeout = null
+    }, 1000)
+  }
+
   render() {
     return (
-      <Wrapper {...this.props} />
+      <Wrapper innerRef={div => { this.wrapper = div }} {...this.props} onClick={() => { this.onClick() }} />
     )
   }
 }