UNPKG

react-awesome-toggle-switch

Version:

React toggle switch with more than 19 different designs

53 lines 2.6 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 SmileySwitch = /** @class */ (function (_super) { __extends(SmileySwitch, _super); function SmileySwitch(props) { var _this = _super.call(this, props) || this; _this.state = { nodeRef: React.createRef(), val: props.value ? props.value : false }; return _this; } SmileySwitch.prototype.componentDidMount = function () { var nodeRef = this.state.nodeRef; nodeRef.current.checked = this.state.val; this.setState({ nodeRef: nodeRef }); }; SmileySwitch.prototype.onChange = function (e) { this.props.onValueChange(e.currentTarget.checked); }; SmileySwitch.prototype.render = function () { var _this = this; return (React.createElement("div", { className: "smileySwitch" }, React.createElement("div", { id: "container" }, React.createElement("div", { className: "toggle" }, React.createElement("input", { type: "checkbox", name: "toggle", className: "check-checkbox", id: "mytoggle", ref: this.state.nodeRef, onChange: function (e) { return _this.onChange(e); } }), React.createElement("label", { className: "check-label", htmlFor: "mytoggle" }, React.createElement("div", { id: "background" }), React.createElement("span", { className: "face" }, React.createElement("span", { className: "face-container" }, React.createElement("span", { className: "eye left" }), React.createElement("span", { className: "eye right" }), React.createElement("span", { className: "mouth" })))))))); }; return SmileySwitch; }(React.Component)); exports.default = SmileySwitch; //# sourceMappingURL=index.js.map