UNPKG

@arche-mc2/arche-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

157 lines 7.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var ContextMenu_1 = require("../../Display/ContextMenu"); var SvgIcon_1 = require("../../Display/SvgIcon"); var Box_1 = require("../../Containers/Box"); var typestyle_1 = require("typestyle"); var classnames = require("classnames"); var utils_1 = require("../../../Common/utils"); var eventListener_1 = require("../../../Common/utils/eventListener"); var UpTimePicker = (function (_super) { tslib_1.__extends(UpTimePicker, _super); function UpTimePicker(p, c) { var _this = _super.call(this, p, c) || this; _this.hourContextMenuId = "hour-time-picker-" + utils_1.generateId(); _this.minuteContextMenuId = "minute-time-picker-" + utils_1.generateId(); _this.setHour = function (e, selectedOption) { _this.onchangeHour(selectedOption.value); }; _this.setMinute = function (e, selectedOption) { _this.onchangeMin(selectedOption.value); }; _this.onFocusMinute = function (e) { _this.setState({ focusedMinute: true }); }; _this.onchangeHourEvent = function (e) { _this.onchangeHour(e.target.value); }; _this.onchangeHour = function (value) { var hour = Number(value); if (isNaN(hour)) { hour = 0; } else if (hour < 0) { hour = 23; } else if (hour > 23) { hour = 0; } _this.setState({ hour: hour }, _this.sendChange); }; _this.onKeyDownHour = function (e) { if (e.keyCode == 38) { _this.onchangeHour(Number(e.target.value) + 1); } else if (e.keyCode == 40) { _this.onchangeHour(Number(e.target.value) - 1); } }; _this.onchangeMinEvent = function (e) { _this.onchangeMin(e.target.value); }; _this.onchangeMin = function (value) { var minute = Number(value); if (isNaN(minute)) { minute = 0; } else if (minute < 0) { minute = 59; } else if (minute > 59) { minute = 0; } _this.setState({ minute: minute }, _this.sendChange); }; _this.onKeyDownMin = function (e) { if (e.keyCode == 38) { _this.onchangeMin(Number(e.target.value) + 1); } else if (e.keyCode == 40) { _this.onchangeMin(Number(e.target.value) - 1); } }; _this.sendChange = function () { if (_this.props.onChange != null) { var value = _this.state.hour + ":" + _this.state.minute; _this.props.onChange(eventListener_1.eventFactory(_this.props.name, value), value); } }; _this.state = { hour: _this.props.value ? parseInt(_this.props.value.split(':')[0]) : 0, minute: _this.props.value ? parseInt(_this.props.value.split(':')[1]) : 0 }; return _this; } UpTimePicker.prototype.render = function () { var _this = this; var minuteSteps = []; var currentStep = 0; while (currentStep < 60) { minuteSteps.push(currentStep); currentStep += this.props.minuteStep; } var hourSteps = []; currentStep = 1; while (currentStep < 24) { hourSteps.push(currentStep); currentStep += 1; } var wrapperStyles = typestyle_1.style({ $nest: { "& div": { display: "inline-block" }, "& .up-time-separator": { marginLeft: 10, marginRight: 10 }, "& input, & .up-time-separator": { fontSize: "14px", color: "#354052" }, "& svg, & svg g, & svg path, & svg polygon, & svg polyline": { fill: "#354052" } } }); return (React.createElement(React.Fragment, null, React.createElement(Box_1.default, { className: classnames(wrapperStyles, 'up-timepicker up-form-control'), flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'flex-end', style: { borderColor: this.props.hasError === true ? 'red' : 'inherit', borderBottomWidth: '1px', borderBottomStyle: 'solid', width: "160px", padding: "2px", display: 'flex', } }, React.createElement("input", { type: "text", value: this.state.hour.toString(), onKeyDown: this.onKeyDownHour, onChange: this.onchangeHourEvent, style: { "border": "none", "width": "2em", "textAlign": "center" } }), React.createElement(ContextMenu_1.UpContextMenuTrigger, { rightClick: false, id: this.hourContextMenuId, holdToDisplay: 1000 }, React.createElement(SvgIcon_1.default, { iconName: 'chevron-down', style: { cursor: 'pointer' } })), React.createElement("div", { className: 'up-time-separator' }, ":"), React.createElement("input", { type: "text", value: this.state.minute.toString(), onKeyDown: this.onKeyDownMin, onChange: this.onchangeMinEvent, onFocus: this.onFocusMinute, tabIndex: this.props.tabIndex, style: { "border": "none", "width": "2em", "textAlign": "center" } }), React.createElement(ContextMenu_1.UpContextMenuTrigger, { rightClick: false, id: this.minuteContextMenuId, holdToDisplay: 1000 }, React.createElement(SvgIcon_1.default, { iconName: 'chevron-down', style: { cursor: 'pointer' } })), React.createElement(SvgIcon_1.default, { iconName: 'clock', style: { marginLeft: 10, marginTop: 5, } })), React.createElement(ContextMenu_1.UpContextMenu, { id: this.minuteContextMenuId }, minuteSteps.map(function (step, i) { return React.createElement(ContextMenu_1.UpContextMenuItem, { key: i, onClick: _this.setMinute, data: { value: step } }, step); })), React.createElement(ContextMenu_1.UpContextMenu, { id: this.hourContextMenuId }, hourSteps.map(function (step, i) { return React.createElement(ContextMenu_1.UpContextMenuItem, { key: i, onClick: _this.setHour, data: { value: step } }, step); })))); }; UpTimePicker.defaultProps = { minuteStep: 5, withIcon: true, }; return UpTimePicker; }(React.Component)); exports.default = UpTimePicker; //# sourceMappingURL=UpTimePicker.js.map