UNPKG

@dugongjs/cli

Version:

20 lines (19 loc) 873 B
import figures from "figures"; import { Box, Text, measureElement } from "ink"; import React, { useState } from "react"; export function ProgressBar({ value }) { const [width, setWidth] = useState(0); const [ref, setRef] = useState(null); if (ref) { const dimensions = measureElement(ref); if (dimensions.width !== width) { setWidth(dimensions.width); } } const progress = Math.min(100, Math.max(0, value)); const complete = Math.round((progress / 100) * width); const remaining = width - complete; return (React.createElement(Box, { ref: setRef, flexGrow: 1, minWidth: 20 }, complete > 0 && React.createElement(Text, { color: "cyanBright" }, figures.square.repeat(complete)), remaining > 0 && React.createElement(Text, { dimColor: true }, figures.squareLightShade.repeat(remaining)))); }