UNPKG

react-awesome-toggle-switch

Version:

React toggle switch with more than 19 different designs

50 lines 2.31 kB
"use strict"; 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 RadialSwitch = /** @class */ (function (_super) { __extends(RadialSwitch, _super); function RadialSwitch(props) { var _this = _super.call(this, props) || this; _this.state = { nodeRef: React.createRef(), val: props.value ? props.value : false, title: props.title ? props.title : '', }; return _this; } RadialSwitch.prototype.componentDidMount = function () { var nodeRef = this.state.nodeRef; nodeRef.current.checked = this.state.val; this.setState({ nodeRef: nodeRef }); }; RadialSwitch.prototype.onChange = function (e) { this.props.onValueChange(e.currentTarget.checked); }; RadialSwitch.prototype.render = function () { var _this = this; return (React.createElement("div", { className: "radialSwitch" }, React.createElement("div", { className: "container" }, React.createElement("h3", null, this.props.config && this.props.config.title ? this.props.config.title : ''), React.createElement("div", { className: "checkbox-container yellow" }, React.createElement("input", { ref: this.state.nodeRef, type: "checkbox", id: "toggle1", onChange: function (e) { return _this.onChange(e); } }), React.createElement("label", { htmlFor: "toggle1" }), React.createElement("div", { className: "active-circle" }))))); }; return RadialSwitch; }(React.Component)); exports.default = RadialSwitch; //# sourceMappingURL=index.js.map