react-awesome-toggle-switch
Version:
React toggle switch with more than 19 different designs
48 lines • 2.21 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 DefaultSwitch = /** @class */ (function (_super) {
__extends(DefaultSwitch, _super);
function DefaultSwitch(props) {
var _this = _super.call(this, props) || this;
_this.state = {
nodeRef: React.createRef(),
val: props.value ? props.value : false
};
return _this;
}
DefaultSwitch.prototype.componentDidMount = function () {
var nodeRef = this.state.nodeRef;
nodeRef.current.checked = this.state.val;
this.setState({ nodeRef: nodeRef });
};
DefaultSwitch.prototype.onChange = function (e) {
this.props.onValueChange(e.currentTarget.checked);
};
DefaultSwitch.prototype.render = function () {
var _this = this;
return (React.createElement("label", { className: "checker" },
React.createElement("input", { ref: this.state.nodeRef, className: "checkbox", type: "checkbox", onChange: function (e) { return _this.onChange(e); } }),
React.createElement("div", { className: "check-bg" }),
React.createElement("div", { className: "checkmark" },
React.createElement("svg", { viewBox: "0 0 100 100" },
React.createElement("path", { d: "M20,55 L40,75 L77,27", fill: "none", stroke: "#FFF", strokeWidth: "15", strokeLinecap: "round", strokeLinejoin: "round" })))));
};
return DefaultSwitch;
}(React.Component));
exports.default = DefaultSwitch;
//# sourceMappingURL=index.js.map