All files / snackbar index.js

100% Statements 8/8
100% Branches 8/8
100% Functions 2/2
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60  1x 1x                 20x           5x 4x                                                                                  
 
import React from 'react'
import {Motion, spring} from 'react-motion'
 
/**
 * Snackbar component
 */
 
// 1. 'Snackbar' makes sure all children are centered on page
// 2. 'Snackbar-background' creates dark background
// 3. 'Snackbar-content' wraps content so it can animate opacity independently from background
var Snackbar = ({text, action, onAction, visible}) => (
  <Motion style={{
    transform: spring(visible ? 0 : 48),
    opacity: spring(visible ? 1 : 0)
  }}>
    {style => {
      if (style.opacity === 0) { return <span /> }
      return (
        <div className='Snackbar' style={{
          transform: `translate3d(0, ${style.transform}px, 0)`
        }}>
          <div className='Snackbar-background'>
            <div className='Snackbar-content' style={{
              opacity: style.opacity
            }}>
              <span className='Snackbar-text'>
                {text}
              </span>
              {action &&
                <input
                  type='button'
                  className='Snackbar-action'
                  onClick={onAction}
                  value={action}
                />
              }
            </div>
          </div>
        </div>
      )
    }}
  </Motion>
)
 
/**
 * Snackbar property types
 */
Snackbar.propTypes = {
  text: React.PropTypes.string,
  action: React.PropTypes.string,
  onAction: React.PropTypes.func,
  visible: React.PropTypes.bool
}
 
/**
 * Export Snackbar component
 */
export default Snackbar