@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.
36 lines (34 loc) • 1.13 kB
JavaScript
'use client';
import * as React from 'react';
import { useSwitchRootContext } from "../root/SwitchRootContext.js";
import { useRenderElement } from "../../utils/useRenderElement.js";
import { useFieldRootContext } from "../../field/root/FieldRootContext.js";
import { stateAttributesMapping } from "../stateAttributesMapping.js";
/**
* The movable part of the switch that indicates whether the switch is on or off.
* Renders a `<span>`.
*
* Documentation: [Base UI Switch](https://base-ui.com/react/components/switch)
*/
export const SwitchThumb = /*#__PURE__*/React.forwardRef(function SwitchThumb(componentProps, forwardedRef) {
const {
render,
className,
...elementProps
} = componentProps;
const {
state: fieldState
} = useFieldRootContext();
const state = useSwitchRootContext();
const extendedState = {
...fieldState,
...state
};
return useRenderElement('span', componentProps, {
state: extendedState,
ref: forwardedRef,
stateAttributesMapping,
props: elementProps
});
});
if (process.env.NODE_ENV !== "production") SwitchThumb.displayName = "SwitchThumb";