UNPKG

@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.

24 lines (23 loc) 693 B
'use client'; import * as React from 'react'; import { CheckboxRootDataAttributes } from "../root/CheckboxRootDataAttributes.js"; import { fieldValidityMapping } from "../../field/utils/constants.js"; export function useStateAttributesMapping(state) { return React.useMemo(() => ({ checked(value) { if (state.indeterminate) { // `data-indeterminate` is already handled by the `indeterminate` prop. return {}; } if (value) { return { [CheckboxRootDataAttributes.checked]: '' }; } return { [CheckboxRootDataAttributes.unchecked]: '' }; }, ...fieldValidityMapping }), [state.indeterminate]); }