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.

51 lines (50 loc) 2.04 kB
'use client'; import * as React from 'react'; import PropTypes from 'prop-types'; import { useFieldRootContext } from '../root/FieldRootContext.js'; import { getCombinedFieldValidityData } from '../utils/getCombinedFieldValidityData.js'; import { jsx as _jsx } from "react/jsx-runtime"; /** * Used to display a custom message based on the field’s validity. * Requires `children` to be a function that accepts field validity state as an argument. * * Documentation: [Base UI Field](https://base-ui.com/react/components/field) */ const FieldValidity = function FieldValidity(props) { const { children } = props; const { validityData, invalid } = useFieldRootContext(false); const fieldValidityState = React.useMemo(() => { const combinedFieldValidityData = getCombinedFieldValidityData(validityData, invalid); return { ...combinedFieldValidityData, validity: combinedFieldValidityData.state }; }, [validityData, invalid]); return /*#__PURE__*/_jsx(React.Fragment, { children: children(fieldValidityState) }); }; process.env.NODE_ENV !== "production" ? FieldValidity.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * A function that accepts the field validity state as an argument. * * ```jsx * <Field.Validity> * {(validity) => { * return <div>...</div> * }} * </Field.Validity> * ``` */ children: PropTypes.func.isRequired } : void 0; export { FieldValidity };