@gpa-gemstone/react-interactive
Version: 
Interactive UI Components for GPA products
140 lines (139 loc) • 6.49 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
    __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;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// ******************************************************************************************************
//  Step.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:
//  ----------------------------------------------------------------------------------------------------
//  12/13/2022 - A. Hagemeyer
//       Generated original version of source code.
//
// ******************************************************************************************************
var React = __importStar(require("react"));
// Styles for all circles
var circleStyle = {
    height: '25px',
    width: '25px',
    borderRadius: '50%',
    borderWidth: '2px',
    borderStyle: 'solid',
    display: 'inline-block',
    backgroundColor: '#fff',
};
/**
* Functional component representing a progress bar with steps.
* @param props - Props for configuring the progress bar.
* @returns JSX elements for the progress bar.
*/
function ProgressBar(props) {
    var _a = React.useState(0), activeStep = _a[0], setActiveStep = _a[1];
    React.useEffect(function () {
        if (props.steps.length < 2) {
            setActiveStep(0);
            return;
        }
        var index = props.steps.findIndex(function (s) { return s.id === props.activeStep; });
        if (index === -1)
            setActiveStep(0);
        else
            setActiveStep(index);
    }, [props.activeStep, props.steps]);
    var clickhandle = React.useCallback(function (step) {
        if (props.onClick !== undefined)
            props.onClick(props.activeStep, step);
    }, [props.activeStep, props.onClick]);
    /// Styles for overall div
    var stepsStyle = {
        height: props.height === undefined ? '100%' : props.height,
        width: props.width === undefined ? '100%' : props.width,
        paddingTop: 17,
        minWidth: '210px',
        justifyContent: 'space-evenly',
    };
    /// Styles for gray bar
    var stepsContainerStyle = {
        width: '100%',
        backgroundColor: '#DDD',
        height: '10px',
        top: '50%',
        borderRadius: '10px 0 0 10px'
    };
    var descriptionStyles = {
        fontSize: '15px',
        fontStyle: 'italic',
        color: '#538897',
        width: '100%',
        display: 'inline-block'
    };
    return (React.createElement("div", { id: 'steps', style: stepsStyle },
        React.createElement("div", { style: stepsContainerStyle }),
        React.createElement("div", { style: {
                width: ((((activeStep === 0 ? 0 : ((activeStep === (props.steps.length - 1)) ? 1 : 0.5))) + activeStep) * (100.0 / props.steps.length)).toString() + '%',
                backgroundColor: '#5DC177',
                height: 10,
                top: '50%',
                borderRadius: '10px 0 0 10px',
                marginTop: -10
            } }),
        React.createElement("div", { style: {
                height: '100px',
                width: '100%',
                top: '46%',
                display: 'flex',
                justifyContent: 'space-between'
            } }, props.steps.map(function (x, i) { return React.createElement("div", { style: {
                height: '60px',
                width: 'calc(' + (100 / props.steps.length).toString() + '%)',
                marginTop: -17
            }, key: x.id },
            React.createElement("span", { onClick: function () { return clickhandle(x.id); }, style: __assign(__assign({}, circleStyle), { borderColor: i <= activeStep ? '#5DC177' : '#D3D3D3', cursor: (i === activeStep || props.onClick === undefined) ? undefined : 'pointer', marginLeft: (i === (props.steps.length - 1) ? 'calc(100% - 25px)' : (i === 0 ? undefined : 'calc(50% - 12px)')), marginRight: (i === 0 ? 'calc(100% - 25px)' : (i === (props.steps.length - 1) ? undefined : 'calc(50% - 12px)')) }) }),
            React.createElement("span", { onClick: function () { return clickhandle(x.id); }, style: __assign(__assign({}, descriptionStyles), { cursor: (i === activeStep || props.onClick === undefined) ? undefined : 'pointer', textAlign: (i === 0 ? 'left' : (i === (props.steps.length - 1) ? 'right' : 'center')) }) }, x.id === props.activeStep ? x.long : x.short)); }))));
}
exports.default = ProgressBar;