{"version":3,"file":"Slider.cjs","names":[],"sources":["../../../src/components/Slider/Slider.tsx"],"sourcesContent":["/**\n * @tempest-limits props-count — min, max, step, value, onChange, formatValue plus\n * the field chrome (label, helperText, disabled, className). Every one is used by\n * the range variant too — the pair is deliberately the same API.\n */\nimport { useCallback, useMemo } from \"react\";\nimport { cn } from \"@/utils/cn\";\nimport styles from \"./Slider.module.css\";\n\nexport interface SliderProps {\n    /** Current value. */\n    value: number;\n    /** Called with the new value on every change. */\n    onChange: (value: number) => void;\n    min?: number;\n    max?: number;\n    step?: number;\n    label?: string;\n    helperText?: string;\n    disabled?: boolean;\n    /** Formatter for the value badge next to the label. Defaults to the raw number. */\n    formatValue?: (value: number) => string;\n    /**\n     * Accessible name, for when the visible `label` block does not fit.\n     *\n     * A slider in a one-line footer, a table cell or a toolbar has no room for the\n     * label row above the track, and without this every such control announces\n     * itself as \"Slider\" — several on the same screen become indistinguishable to a\n     * screen reader. Takes precedence over `label`; wrapping the field in an outer\n     * `<label>` does not work, because an explicit `aria-label` on the input wins\n     * the accessible-name precedence order.\n     */\n    \"aria-label\"?: string;\n    className?: string;\n}\n\n/**\n * Single-thumb slider built on a native `<input type=\"range\">`, so it stays\n * accessible (keyboard + screen reader) with no positioning libs. The active\n * fill is a percentage-width bar. For a two-thumb range, use `RangeSlider`.\n */\nexport function Slider({\n    value,\n    onChange,\n    min = 0,\n    max = 100,\n    step = 1,\n    label,\n    helperText,\n    disabled = false,\n    formatValue,\n    \"aria-label\": ariaLabel,\n    className,\n}: SliderProps) {\n    const pct = useMemo(() => {\n        const range = max - min;\n        if (range <= 0) return 0;\n        return Math.min(100, Math.max(0, ((value - min) / range) * 100));\n    }, [value, min, max]);\n\n    const valueText = formatValue?.(value) ?? String(value);\n\n    const handleChange = useCallback(\n        (event: React.ChangeEvent<HTMLInputElement>): void => {\n            onChange(Number(event.target.value));\n        },\n        [onChange],\n    );\n\n    return (\n        <div className={cn(styles.wrapper, className)}>\n            {label && (\n                <div className={styles.label}>\n                    <span>{label}</span>\n                    <span className={styles.value}>{valueText}</span>\n                </div>\n            )}\n            <div className={styles.field}>\n                <div className={styles.track} />\n                <div className={styles.fill} style={{ width: `${pct}%` }} />\n                <input\n                    type=\"range\"\n                    className={styles.input}\n                    min={min}\n                    max={max}\n                    step={step}\n                    value={value}\n                    onChange={handleChange}\n                    disabled={disabled}\n                    aria-label={ariaLabel ?? label ?? \"Slider\"}\n                    aria-valuetext={valueText}\n                />\n            </div>\n            {helperText && <span className={styles.helper}>{helperText}</span>}\n        </div>\n    );\n}\n"],"mappings":"6HAyCA,SAAgB,EAAO,CACnB,QACA,WACA,MAAM,EACN,MAAM,IACN,OAAO,EACP,QACA,aACA,WAAW,GACX,cACA,aAAc,EACd,aACY,CACZ,IAAM,GAAA,EAAM,EAAA,QAAA,KAAc,CACtB,IAAM,EAAQ,EAAM,EAEpB,OADI,GAAS,EAAU,EAChB,KAAK,IAAI,IAAK,KAAK,IAAI,GAAK,EAAQ,GAAO,EAAS,GAAG,CAAC,CACnE,EAAG,CAAC,EAAO,EAAK,CAAG,CAAC,EAEd,EAAY,IAAc,CAAK,GAAK,OAAO,CAAK,EAEhD,GAAA,EAAe,EAAA,YAAA,CAChB,GAAqD,CAClD,EAAS,OAAO,EAAM,OAAO,KAAK,CAAC,CACvC,EACA,CAAC,CAAQ,CACb,EAEA,OACI,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,GAAG,EAAA,QAAO,QAAS,CAAS,EAA5C,SAAA,CACK,IACG,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,MAAvB,SAAA,EACI,EAAA,EAAA,IAAA,CAAC,OAAD,CAAA,SAAO,CAAY,CAAA,GACnB,EAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAW,EAAA,QAAO,MAAQ,SAAA,CAAgB,CAAA,CAC/C,KAET,EAAA,EAAA,KAAA,CAAC,MAAD,CAAK,UAAW,EAAA,QAAO,MAAvB,SAAA,E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