UNPKG

@tmnrp/react-progressbar

Version:

React progressbar is a component that can be used to display progressbar menu.

41 lines 1.85 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /* eslint-disable react/display-name */ import React, { forwardRef, useImperativeHandle, useState } from "react"; // export const Progressbar = forwardRef((_a, ref) => { var { className = "", frequency = 100, height = 10, style } = _a, props = __rest(_a, ["className", "frequency", "height", "style"]); const [width, setWidth] = useState(0); const [intervalID, setIntervalID] = useState(); // useImperativeHandle(ref, () => ({ // activate: () => { const id = window.setInterval(() => { setWidth((width) => { width === 75 && clearInterval(id); return ++width; }); }, frequency); setIntervalID(id); }, // kill: () => { clearInterval(intervalID); setWidth(100); setTimeout(() => setWidth(0), 1000); }, }), [frequency, intervalID]); // return (React.createElement("div", Object.assign({ className: `tm-progressbar ${className}`, style: Object.assign({ transition: "1s width, 2s opacity", opacity: `${width === 0 || width === 100 ? 0 : 1}`, width: `${width}%`, height: height, position: "absolute", top: "0px", left: "0px", zIndex: "10" }, style) }, props))); }); //# sourceMappingURL=index.js.map