UNPKG

@gpa-gemstone/react-forms

Version:
60 lines (59 loc) 4.76 kB
"use strict"; // ****************************************************************************************************** // DateTimePopup.tsx - Gbtc // // Copyright © 2023, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 05/15/2023 - C. Lackner // Generated original version of source code. // // ****************************************************************************************************** var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = DateTimePopup; var React = require("react"); var react_portal_1 = require("react-portal"); var styled_components_1 = require("styled-components"); var Calender_1 = require("./Calender"); var Clock_1 = require("./Clock"); var WrapperDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 9999;\n opacity: 0.9;\n background: #222;\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n &::before {\n border-left: 8px solid transparent;\n border-right: 8px solid transparent;\n border-bottom: 8px solid #222;\n left: ", ";\n top: -6px;\n margin-left: -8px;\n content: \"\";\n width: 0px;\n height: 0px;\n position: absolute\n }"], ["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px 21px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 9999;\n opacity: 0.9;\n background: #222;\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n &::before {\n border-left: 8px solid transparent;\n border-right: 8px solid transparent;\n border-bottom: 8px solid #222;\n left: ", ";\n top: -6px;\n margin-left: -8px;\n content: \"\";\n width: 0px;\n height: 0px;\n position: absolute\n }"])), function (props) { return "".concat(props.Top, "px"); }, function (props) { return "".concat(props.Left, "px"); }, function (props) { return "".concat(props.Indicator, "%"); }); function DateTimePopup(props) { var divRef = React.useRef(null); var _a = React.useState(props.Type !== 'date'), showTime = _a[0], setShowTime = _a[1]; var _b = React.useState(props.Type !== 'time'), showDate = _b[0], setShowDate = _b[1]; var _c = React.useState(0), width = _c[0], setWidth = _c[1]; var _d = React.useState(0), height = _d[0], setHeight = _d[1]; React.useLayoutEffect(function () { var _a, _b, _c, _d; setWidth((_b = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : width); setHeight((_d = (_c = divRef.current) === null || _c === void 0 ? void 0 : _c.offsetHeight) !== null && _d !== void 0 ? _d : height); }); React.useEffect(function () { setShowTime(props.Type !== 'date'); setShowDate(props.Type !== 'time'); }, [props.Type]); if (!props.Show) return null; var left = Math.max(props.Center - 0.5 * width, 0); return (React.createElement(react_portal_1.Portal, null, React.createElement(WrapperDiv, { Top: props.Top, Left: left, Indicator: 50, ref: divRef, className: 'gpa-gemstone-datetime' }, showDate ? React.createElement(Calender_1.default, { DateTime: props.DateTime, Setter: props.Setter }) : null, showTime ? React.createElement(Clock_1.default, { DateTime: props.DateTime, Setter: props.Setter, Accuracy: props.Accuracy }) : null))); } var templateObject_1;