react-sublime-video
Version:
A sublime video player in React.
148 lines (118 loc) • 5.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _rcTweenOne = require('rc-tween-one');
var _rcTweenOne2 = _interopRequireDefault(_rcTweenOne);
var _SvgMorphPlugin = require('rc-tween-one/lib/plugin/SvgMorphPlugin');
var _SvgMorphPlugin2 = _interopRequireDefault(_SvgMorphPlugin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
_rcTweenOne2["default"].plugins.push(_SvgMorphPlugin2["default"]);
var maskStyle = {
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.35)',
cursor: 'pointer'
};
var buttonStyle = {
position: 'absolute',
top: '50%',
left: '50%',
margin: -30,
borderRadius: 30,
backgroundColor: '#fff'
};
var Mask = function (_React$Component) {
_inherits(Mask, _React$Component);
function Mask(props) {
_classCallCheck(this, Mask);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.state = {
visible: props.defaultVisible,
animation: []
};
_this.childrenToRender = _this.getIconChildren();
_this.handleClick = _this.handleClick.bind(_this);
return _this;
}
Mask.prototype.getAnimation = function getAnimation(visible) {
return visible ? [[{ style: { rotate: 90 }, duration: 0 }, {
d: 'M20 15L20 45L45 30Z', style: { rotate: 0 },
delay: 150, duration: 300, ease: 'easeOutQuint'
}], [{ style: { rotate: 90 }, duration: 0 }, {
d: 'M20 15L20 45L45 30Z', style: { rotate: 0 },
delay: 150, duration: 300, ease: 'easeOutQuint'
}]] : [[{ style: { rotate: 0 }, duration: 0 }, {
d: 'M15 18L15 27L45 27L45 18Z', style: { rotate: 90 },
duration: 300, ease: 'easeOutQuint'
}], [{ style: { rotate: 0 }, duration: 0 }, {
d: 'M15 33L15 42L45 42L45 33Z', style: { rotate: 90 },
duration: 300, ease: 'easeOutQuint'
}]];
};
Mask.prototype.getIconChildren = function getIconChildren() {
return this.state.visible ? ['M20 15L20 45L45 30Z', 'M20 15L20 45L45 30Z'] : ['M15 18L15 27L45 27L45 18Z', 'M15 33L15 42L45 42L45 33Z'];
};
Mask.prototype.handleClick = function handleClick() {
var visible = this.state.visible;
var animation = this.getAnimation(!visible);
this.setState({
visible: !visible,
animation: animation
});
// If mask is visible now, the video is going to play. Otherwise...
var shouldPlay = visible;
this.props.onClick(shouldPlay);
};
Mask.prototype.render = function render() {
var style = _extends({}, maskStyle, {
opacity: this.state.visible ? 1 : 0,
transition: this.state.visible ? 'opacity 0.3s cubic-bezier(0.215, 0.61, 0.355, 1)' : 'opacity 0.3s cubic-bezier(0.215, 0.61, 0.355, 1) 0.2s'
});
return _react2["default"].createElement(
'section',
{ style: style, onClick: this.handleClick },
_react2["default"].createElement(
'svg',
{
version: '1.2',
viewBox: '0 0 60 60',
width: '60',
height: '60',
style: buttonStyle
},
_react2["default"].createElement(_rcTweenOne2["default"], { d: this.childrenToRender[0], fill: '#999',
style: { transformOrigin: '30px 30px' },
animation: this.state.animation[0],
component: 'path',
attr: 'attr'
}),
_react2["default"].createElement(_rcTweenOne2["default"], { d: this.childrenToRender[1], fill: '#999',
style: { transformOrigin: '30px 30px' },
animation: this.state.animation[1],
component: 'path',
attr: 'attr'
})
)
);
};
return Mask;
}(_react2["default"].Component);
exports["default"] = Mask;
Mask.propTypes = {
defaultVisible: _propTypes2["default"].bool,
onClick: _propTypes2["default"].func
};
module.exports = exports['default'];