react-awesome-toggle-switch
Version:
React toggle switch with more than 19 different designs
54 lines • 2.4 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
require("../../assets/style.scss");
var Neon2Switch = /** @class */ (function (_super) {
__extends(Neon2Switch, _super);
function Neon2Switch(props) {
var _this = _super.call(this, props) || this;
_this.state = {
nodeRef: React.createRef(),
val: props.value ? props.value : false
};
return _this;
}
Neon2Switch.prototype.componentDidMount = function () {
};
Neon2Switch.prototype.onChange = function (e) {
this.setState({
val: e.currentTarget.checked
});
if (e.currentTarget.checked) {
this.state.nodeRef.current.className = 'toggle toggle-on';
}
else {
this.state.nodeRef.current.className = 'toggle';
}
this.props.onValueChange(e.currentTarget.checked);
};
Neon2Switch.prototype.render = function () {
var _this = this;
return (React.createElement("div", { className: "neon2Switch" },
React.createElement("div", { className: 'toggle ' + this.state.val ? 'toggle-on' : '', id: 'switch', ref: this.state.nodeRef, onClick: function (e) { return _this.onChange({ currentTarget: { checked: !_this.state.val } }); } },
React.createElement("div", { className: 'toggle-text-off' }, this.props.config.rightText),
React.createElement("div", { className: 'glow-comp' }),
React.createElement("div", { className: 'toggle-button' }),
React.createElement("div", { className: 'toggle-text-on' }, this.props.config.leftText))));
};
return Neon2Switch;
}(React.Component));
exports.default = Neon2Switch;
//# sourceMappingURL=index.js.map