UNPKG

@base-ui/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.

21 lines (20 loc) 775 B
'use client'; import _formatErrorMessage from "@base-ui/utils/formatErrorMessage"; import * as React from 'react'; export const OTPFieldRootContext = /*#__PURE__*/React.createContext(undefined); if (process.env.NODE_ENV !== "production") OTPFieldRootContext.displayName = "OTPFieldRootContext"; export function useOTPFieldRootContext() { const context = React.useContext(OTPFieldRootContext); if (context === undefined) { throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: OTPFieldRootContext is missing. OTPField parts must be placed within <OTPField.Root>.' : _formatErrorMessage(98)); } return context; } export function getOTPFieldInputState(state, value, index) { return { ...state, value, index, filled: value !== '' }; }