UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

43 lines 1.52 kB
import React from "react"; import { Flex, Text, TextMicro, TextSmall } from "@netdata/netdata-ui"; import { useValueWithUnit } from "../../provider"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; var getDisplayUnit = function getDisplayUnit(unit, integrated) { return integrated && typeof unit === "string" && unit.endsWith("/s") ? unit.slice(0, -2) : unit; }; var StatValue = function StatValue(_ref) { var value = _ref.value, valueKey = _ref.valueKey, prominent = _ref.prominent, justifyContent = _ref.justifyContent; var _useValueWithUnit = useValueWithUnit(value, { valueKey: valueKey, scaleByValue: true }), convertedValue = _useValueWithUnit.convertedValue, convertedUnit = _useValueWithUnit.convertedUnit; var displayUnit = getDisplayUnit(convertedUnit, valueKey === "volume"); var Value = prominent ? Text : TextSmall; return /*#__PURE__*/_jsxs(Flex, { alignItems: "end", gap: 1, justifyContent: justifyContent, width: { min: "0px" }, "data-testid": "comparison-stat-value", children: [/*#__PURE__*/_jsx(Value, { strong: true, textAlign: justifyContent === "end" ? "right" : undefined, whiteSpace: "nowrap", children: convertedValue }), !!displayUnit && /*#__PURE__*/_jsx(TextMicro, { color: "textDescription", whiteSpace: "nowrap", truncate: true, "data-testid": "comparison-stat-unit", children: displayUnit })] }); }; export default StatValue;