@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
33 lines (31 loc) • 1.07 kB
JavaScript
'use client';
import * as React from 'react';
import { valueToPercent } from "../../utils/valueToPercent.js";
import { useMeterRootContext } from "../root/MeterRootContext.js";
import { useRenderElement } from "../../utils/useRenderElement.js";
/**
* Visualizes the position of the value along the range.
* Renders a `<div>` element.
*
* Documentation: [Base UI Meter](https://base-ui.com/react/components/meter)
*/
export const MeterIndicator = /*#__PURE__*/React.forwardRef(function MeterIndicator(componentProps, forwardedRef) {
const {
render,
className,
...elementProps
} = componentProps;
const context = useMeterRootContext();
const percentageWidth = valueToPercent(context.value, context.min, context.max);
return useRenderElement('div', componentProps, {
ref: forwardedRef,
props: [{
style: {
insetInlineStart: 0,
height: 'inherit',
width: `${percentageWidth}%`
}
}, elementProps]
});
});
if (process.env.NODE_ENV !== "production") MeterIndicator.displayName = "MeterIndicator";