@gpa-gemstone/react-forms
Version:
React Form modules for gpa webapps
59 lines (58 loc) • 4.71 kB
JavaScript
"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 });
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 helper_functions_1 = require("@gpa-gemstone/helper-functions");
//TODO: this eventually should be moved into a css class
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, "%"); });
//This is merely used to provide a class name for the popup for indentification purposes
var DateTimePopupClass = "gpa-gemstone-datetime-popup";
function DateTimePopup(props, ref) {
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 refToUse = ref !== null && ref !== void 0 ? ref : divRef;
var width = (0, helper_functions_1.useGetContainerPosition)(refToUse).width;
var left = Math.max(props.Center - 0.5 * width, 0);
React.useEffect(function () {
setShowTime(props.Type !== 'date');
setShowDate(props.Type !== 'time');
}, [props.Type]);
if (!props.Show)
return null;
return (React.createElement(react_portal_1.Portal, null,
React.createElement(WrapperDiv, { Top: props.Top, Left: left, Indicator: 50, ref: refToUse, className: DateTimePopupClass },
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)));
}
exports.default = React.forwardRef(DateTimePopup);
var templateObject_1;