UNPKG

reactware

Version:

Reactware is an open source toolkit for developing desktop PWA with HTML, CSS, and JS

270 lines (209 loc) 10.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _styledComponents = _interopRequireWildcard(require("styled-components")); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _templateObject9() { var data = _taggedTemplateLiteral(["\n\n -webkit-appearance: none;\n width: 100%;\n height: 5px;\n margin: 0;\n outline: none;\n border-radius: 9px;\n border: 1px solid #232323;\n background-image: linear-gradient(#2b2b2b,#4b4b4b);\n box-sizing: border-box;\n\n\n \n &::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 15px;\n height: 15px;\n border: 1px solid gray;\n background: white;\n background-image: linear-gradient(#cacaca, #747474);\n cursor: pointer;\n border-radius: 15px;\n border: 1px solid #3b3b3b;\n }\n\n"]); _templateObject9 = function _templateObject9() { return data; }; return data; } function _templateObject8() { var data = _taggedTemplateLiteral(["\n &:after {\n left: -6px;\n top: calc(50% - 1px);\n transform: rotate(90deg);\n }\n "]); _templateObject8 = function _templateObject8() { return data; }; return data; } function _templateObject7() { var data = _taggedTemplateLiteral(["\n transform: rotate(90deg);\n text-align: left;\n margin-top: 6px;\n height: 20px;\n "]); _templateObject7 = function _templateObject7() { return data; }; return data; } function _templateObject6() { var data = _taggedTemplateLiteral(["\n font-size: 0px;\n line-height: 0px;\n "]); _templateObject6 = function _templateObject6() { return data; }; return data; } function _templateObject5() { var data = _taggedTemplateLiteral(["\n &:after {\n content: \" \";\n height: 4px;\n width: 1px;\n background: #b8b8b8;\n position: absolute;\n left: calc(50% - 1px);\n top: -4px;\n }\n "]); _templateObject5 = function _templateObject5() { return data; }; return data; } function _templateObject4() { var data = _taggedTemplateLiteral(["\n font-size: 10px;\n padding: 0;\n width: 15px;\n text-align: center;\n position: relative;\n margin-top: 4px;\n color: white;\n opacity: 0.5;\n text-shadow: 1px 1px 0px rgba(0, 0, 0, 1);\n\n ", "\n\n ", "\n\n ", " \n\n ", " \n"]); _templateObject4 = function _templateObject4() { return data; }; return data; } function _templateObject3() { var data = _taggedTemplateLiteral(["\n display: flex;\n justify-content: space-between;\n padding-left: 2px;\n"]); _templateObject3 = function _templateObject3() { return data; }; return data; } function _templateObject2() { var data = _taggedTemplateLiteral(["\n position: relative;\n height: ", ";\n display: inline-block;\n transform: rotate(-90deg);\n "]); _templateObject2 = function _templateObject2() { return data; }; return data; } function _templateObject() { var data = _taggedTemplateLiteral(["\n ", "\n"]); _templateObject = function _templateObject() { return data; }; return data; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } var ContainerSyled = _styledComponents.default.div(_templateObject(), function (props) { return props.vertical && (0, _styledComponents.css)(_templateObject2(), props.height); }); var DatalistStyled = _styledComponents.default.datalist(_templateObject3()); var OptionsSyled = _styledComponents.default.option(_templateObject4(), function (props) { return props.dashes && (0, _styledComponents.css)(_templateObject5()); }, function (props) { return props.dashes && !props.labels && (0, _styledComponents.css)(_templateObject6()); }, function (props) { return props.vertical && (0, _styledComponents.css)(_templateObject7()); }, function (props) { return props.vertical && props.dashes && (0, _styledComponents.css)(_templateObject8()); }); var InputSyled = _styledComponents.default.input(_templateObject9()); // ${props => props.vertical && css` // position: absolute; // top: 50%; // left: 50%; // margin: 0; // padding: 0; // width: ${props.height}; // transform: translate(-50%, -50%) rotate(-90deg); // `} var Slider = /*#__PURE__*/ function (_React$Component) { _inherits(Slider, _React$Component); function Slider(props) { var _this; _classCallCheck(this, Slider); _this = _possibleConstructorReturn(this, _getPrototypeOf(Slider).call(this, props)); _this.state = { id: Math.random(), value: props.value }; return _this; } _createClass(Slider, [{ key: "onChange", value: function onChange(event) { var onChange = this.props.onChange; var value = event.target.value; this.setState({ value: value }); onChange(value, event); } }, { key: "renderDatalist", value: function renderDatalist() { var _this$props = this.props, step = _this$props.step, max = _this$props.max, dashes = _this$props.dashes, labels = _this$props.labels, vertical = _this$props.vertical; var list = []; var count = max / step; for (var i = 0; i <= count; i += 1) { list.push(_react.default.createElement(OptionsSyled, { key: "options-".concat(i), vertical: vertical, dashes: dashes, labels: labels }, i * step)); } return list; } }, { key: "render", value: function render() { var _this2 = this; var _this$props2 = this.props, min = _this$props2.min, max = _this$props2.max, step = _this$props2.step, vertical = _this$props2.vertical, height = _this$props2.height, labels = _this$props2.labels, dashes = _this$props2.dashes, _this$state = this.state, id = _this$state.id, value = _this$state.value; return _react.default.createElement(ContainerSyled, { vertical: vertical, height: height }, _react.default.createElement(InputSyled, { type: "range", value: value, onChange: function onChange(event) { return _this2.onChange(event); }, orient: vertical ? 'vertical' : null, list: "dl-".concat(id), vertical: vertical, height: height, sstep: step, min: min, max: max }), (labels || dashes) && _react.default.createElement(DatalistStyled, { list: "dl-".concat(id) }, this.renderDatalist())); } }]); return Slider; }(_react.default.Component); exports.default = Slider; _defineProperty(Slider, "propTypes", { min: _propTypes.default.string, max: _propTypes.default.string.isRequired, value: _propTypes.default.string, step: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]), vertical: _propTypes.default.bool, height: _propTypes.default.string, labels: _propTypes.default.bool, dashes: _propTypes.default.bool }); _defineProperty(Slider, "defaultProps", { min: '0', value: '0', step: '1', vertical: null, height: '100px', labels: null, dashes: null });