analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
88 lines (81 loc) • 4.02 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js');
// src/components/RangeGauge/RangeGauge.tsx
var _jsxruntime = require('react/jsx-runtime');
var zoneIndexOf = (value, zones) => {
const index = zones.findIndex(
(zone) => zone.to !== void 0 && value < zone.to
);
return index === -1 ? zones.length - 1 : index;
};
var pointerPercent = (value, zones, min, max) => {
if (zones.length === 0) return 0;
if (value <= min) return 0;
if (value >= max) return 100;
const index = zoneIndexOf(value, zones);
const lower = index === 0 ? min : zones[index - 1].to;
const upper = _nullishCoalesce(zones[index].to, () => ( max));
const span = upper - lower;
const ratio = span > 0 ? (value - lower) / span : 0;
const clamped = Math.min(Math.max(ratio, 0), 1);
return (index + clamped) / zones.length * 100;
};
var RangeGauge = ({
value,
zones,
min = 0,
max,
showPointer = true,
className = "",
barClassName = "",
...props
}) => {
const lastBounded = [...zones].reverse().find((zone) => zone.to !== void 0);
const scaleMax = _nullishCoalesce(_nullishCoalesce(max, () => ( _optionalChain([lastBounded, 'optionalAccess', _ => _.to]))), () => ( min));
const percent = pointerPercent(value, zones, min, scaleMax);
return (
// Decorative: the measurement and its band are always rendered as adjacent
// text ("38 palavras/min" / "Abaixo do esperado"), so announcing the bar
// too would just repeat them. Wrap it with your own label if you render it
// without that text.
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
"div",
{
"data-component": "RangeGauge",
className: _chunkTN3AYOMVjs.cn.call(void 0, "flex flex-col gap-1 w-full", className),
"aria-hidden": "true",
...props,
children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "relative h-2 w-full", children: showPointer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"span",
{
"data-testid": "range-gauge-pointer",
className: "absolute top-0 -translate-x-1/2",
style: { left: `${percent}%` },
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "12", height: "8", viewBox: "0 0 12 8", fill: "none", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M6 8 0 0h12L6 8Z", className: "fill-text-600" }) })
}
) }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"div",
{
className: _chunkTN3AYOMVjs.cn.call(void 0,
"flex w-full h-1.5 overflow-hidden rounded-full",
barClassName
),
children: zones.map((zone, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"span",
{
className: _chunkTN3AYOMVjs.cn.call(void 0, "flex-1", zone.colorClass)
},
_nullishCoalesce(zone.label, () => ( `${zone.colorClass}-${index}`))
))
}
)
]
}
)
);
};
var RangeGauge_default = RangeGauge;
exports.pointerPercent = pointerPercent; exports.RangeGauge = RangeGauge; exports.RangeGauge_default = RangeGauge_default;
//# sourceMappingURL=chunk-QYFABANE.js.map