UNPKG

lazycrypto-cli

Version:

A simple CLI app to view cryptocurrency indicators

56 lines 1.35 kB
import React from "react"; import { Box, Text } from "ink"; const RowVisualizer = ({ value, prevValue, factor = 10, width, baseColor = "grey", marksColor = "yellow", marks = [0, 5, 9], fill = false, valueColor = "yellow" }) => { const index = Math.abs((value / factor - 1).toFixed(0)); const base = new Array(10).fill(null).map(() => ({ color: baseColor })).map((element, index) => { if (marks.includes(index)) return { color: marksColor }; return element; }); if (index > 9 || index < 0 || isNaN(index)) { return /*#__PURE__*/React.createElement(Text, { color: "red" }, "Woops!"); } if (index && base) { base[index].color = "red"; } const setBaseColor = () => { if (fill) { return base.map((element, _index) => { if (_index <= index) return { color: valueColor }; return element; }); } else { return base; } }; const setSymbol = () => { if (value > prevValue) return "/"; if (value === prevValue) return "|"; return `\\`; }; return /*#__PURE__*/React.createElement(Box, { flexDirection: "row", width: width }, setBaseColor().map((element, index) => /*#__PURE__*/React.createElement(Text, { color: element.color, key: index }, setSymbol()))); }; export default RowVisualizer;