Files
v10/dist/dev/ui/slider/slider-value.js

30 lines
1.0 KiB
JavaScript

"use client";
import { renderElement } from "../../utils/use-render.js";
import { useSliderContext } from "./context.js";
import { forwardRef } from "react";
//#region src/ui/slider/slider-value.tsx
/** Displays a formatted text representation of the slider value. Renders an `<output>` element. */
const SliderValue = forwardRef(function SliderValue(componentProps, forwardedRef) {
const { render, className, style, type = "current", format, ...elementProps } = componentProps;
const context = useSliderContext();
const { state, pointerValue, formatValue } = context;
const rawValue = type === "pointer" ? pointerValue : state.value;
const text = format ? format(rawValue) : formatValue ? formatValue(rawValue, type) : String(Math.round(rawValue));
return renderElement("output", {
render,
className,
style
}, {
state,
stateAttrMap: context.stateAttrMap,
ref: forwardedRef,
props: [{
"aria-live": "off",
children: text
}, elementProps]
});
});
//#endregion
export { SliderValue };
//# sourceMappingURL=slider-value.js.map