UNPKG

@up-group/react-controls

Version:

We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get

122 lines 5.85 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var 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 function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var BaseControl_1 = require("../_Common/BaseControl/BaseControl"); var UpSwitch = (function (_super) { __extends(UpSwitch, _super); function UpSwitch(p, c) { var _this = _super.call(this, p, c) || this; _this.onBoolClick = function (a) { _this.handleChangeEvent(a); }; return _this; } UpSwitch.prototype.renderControl = function () { var maxWidth = this.props.isNullable ? "50%" : "75%"; var btnBool = { display: "inline-block", cursor: "pointer", borderRadius: "4px", width: "100%" }; if (this.props.isNullable === true) { return React.createElement("span", { style: btnBool }, React.createElement(UpSwitchBtn, { displayFalse: this.props.displayFalse, displayNull: this.props.displayNull, displayTrue: this.props.displayTrue, SelectedValue: this.state.value, value: false, isNullable: this.props.isNullable, onclick: this.onBoolClick }), React.createElement(UpSwitchBtn, { displayFalse: this.props.displayFalse, displayNull: this.props.displayNull, displayTrue: this.props.displayTrue, SelectedValue: this.state.value, value: null, isNullable: this.props.isNullable, onclick: this.onBoolClick }), React.createElement(UpSwitchBtn, { displayFalse: this.props.displayFalse, displayNull: this.props.displayNull, displayTrue: this.props.displayTrue, SelectedValue: this.state.value, value: true, isNullable: this.props.isNullable, onclick: this.onBoolClick })); } else { return React.createElement("span", { style: btnBool }, React.createElement(UpSwitchBtn, { displayFalse: this.props.displayFalse, displayNull: this.props.displayNull, displayTrue: this.props.displayTrue, SelectedValue: this.state.value, value: false, isNullable: this.props.isNullable, onclick: this.onBoolClick }), React.createElement(UpSwitchBtn, { displayFalse: this.props.displayFalse, displayNull: this.props.displayNull, displayTrue: this.props.displayTrue, SelectedValue: this.state.value, value: true, isNullable: this.props.isNullable, onclick: this.onBoolClick })); } }; UpSwitch.prototype.getValue = function (event) { return event; }; return UpSwitch; }(BaseControl_1.BaseControlComponent)); exports.default = UpSwitch; var UpSwitchBtn = (function (_super) { __extends(UpSwitchBtn, _super); function UpSwitchBtn(p, c) { var _this = _super.call(this, p, c) || this; _this.onClick = function () { _this.props.onclick(_this.props.value); }; _this.state = {}; return _this; } UpSwitchBtn.prototype.render = function () { var maxWidth = this.props.isNullable ? "50%" : "75%"; var btnBool = { display: "inline-block", cursor: "pointer", borderRadius: "4px", width: "100%" }; var btnBoolSpan = { textAlign: "center", color: "#e5e5e5", width: "25%", fontSize: "17px", padding: "2px" }; var btnFalse = { borderTopLeftRadius: "4px", borderBottomLeftRadius: "4px", float: "left", backgroundColor: this.props.SelectedValue === false ? "#FF1A1A" : "#eba8a6", width: this.props.SelectedValue === false ? maxWidth : "25%" }; var btnTrue = { borderTopRightRadius: "4px", borderBottomRightRadius: "4px", float: "right", backgroundColor: this.props.SelectedValue === true ? "#009b00" : "#afd5af", width: this.props.SelectedValue === true ? maxWidth : "25%" }; var btnNull = { backgroundColor: "#b2b2b2", float: "left", width: this.props.SelectedValue === null ? maxWidth : "25%" }; var btnStyle = this.props.value == null ? btnNull : this.props.value === true ? btnTrue : btnFalse; var btnStr = ""; switch (this.props.value) { case null: btnStr = this.props.displayNull != null ? this.props.displayNull : "Indiférent"; break; case true: btnStr = this.props.displayTrue != null ? this.props.displayTrue : "Oui"; break; case false: btnStr = this.props.displayFalse != null ? this.props.displayFalse : "Non"; break; default: btnStr = "err"; } return React.createElement("span", { style: __assign({}, btnBoolSpan, btnStyle), onClick: this.onClick }, btnStr); }; return UpSwitchBtn; }(React.Component)); exports.UpSwitchBtn = UpSwitchBtn; //# sourceMappingURL=UpSwitch.js.map