react-chiptan
Version:
React component renders chipTAN flicker code
109 lines (81 loc) • 3.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _flicker = require('./flicker');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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) : subClass.__proto__ = superClass; }
var ChipTAN = function (_React$Component) {
_inherits(ChipTAN, _React$Component);
function ChipTAN(props) {
_classCallCheck(this, ChipTAN);
var _this = _possibleConstructorReturn(this, (ChipTAN.__proto__ || Object.getPrototypeOf(ChipTAN)).call(this, props));
var data = props.data,
width = props.width,
height = props.height,
bgColor = props.bgColor,
barColor = props.barColor;
_this.state = {
canvas: new _flicker.flickerCanvas(width, height, bgColor, barColor),
code: new _flicker.flickerCode(data)
};
_this.stopFlicker();
return _this;
}
_createClass(ChipTAN, [{
key: 'componentDidMount',
value: function componentDidMount() {
var data = this.props.data;
var _state = this.state,
canvas = _state.canvas,
code = _state.code;
if (!data) return;
document.getElementById('flickercontainer').appendChild(canvas.getCanvas());
canvas.setCode(code);
this.startFlicker();
}
}, {
key: 'startFlicker',
value: function startFlicker() {
this.interval = setInterval(this.step.bind(this), 50);
}
}, {
key: 'stopFlicker',
value: function stopFlicker() {
clearInterval(this.interval);
}
}, {
key: 'step',
value: function step() {
this.state.canvas.step();
}
}, {
key: 'render',
value: function render() {
return _react2.default.createElement('div', { id: 'flickercontainer' });
}
}]);
return ChipTAN;
}(_react2.default.Component);
ChipTAN.propTypes = {
data: _propTypes2.default.string,
width: _propTypes2.default.number,
height: _propTypes2.default.number,
bgColor: _propTypes2.default.string,
barColor: _propTypes2.default.string
};
ChipTAN.defaultProps = {
data: '',
width: 205,
height: 100,
bgColor: '#000',
barColor: '#fff'
};
exports.default = ChipTAN;