UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

88 lines (86 loc) 2.85 kB
import { cn } from "./chunk-53ICLDGS.mjs"; // src/components/RangeGauge/RangeGauge.tsx import { jsx, jsxs } from "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 = 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 = max ?? lastBounded?.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__ */ jsxs( "div", { "data-component": "RangeGauge", className: cn("flex flex-col gap-1 w-full", className), "aria-hidden": "true", ...props, children: [ /* @__PURE__ */ jsx("div", { className: "relative h-2 w-full", children: showPointer && /* @__PURE__ */ jsx( "span", { "data-testid": "range-gauge-pointer", className: "absolute top-0 -translate-x-1/2", style: { left: `${percent}%` }, children: /* @__PURE__ */ jsx("svg", { width: "12", height: "8", viewBox: "0 0 12 8", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M6 8 0 0h12L6 8Z", className: "fill-text-600" }) }) } ) }), /* @__PURE__ */ jsx( "div", { className: cn( "flex w-full h-1.5 overflow-hidden rounded-full", barClassName ), children: zones.map((zone, index) => /* @__PURE__ */ jsx( "span", { className: cn("flex-1", zone.colorClass) }, zone.label ?? `${zone.colorClass}-${index}` )) } ) ] } ) ); }; var RangeGauge_default = RangeGauge; export { pointerPercent, RangeGauge, RangeGauge_default }; //# sourceMappingURL=chunk-JDLWM24U.mjs.map