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.

72 lines (70 loc) 3.02 kB
'use client'; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import { useNumberFieldRootContext } from '../root/NumberFieldRootContext.js'; import { isWebKit } from '../../utils/detectBrowser.js'; import { useComponentRenderer } from '../../utils/useComponentRenderer.js'; import { useForkRef } from '../../utils/useForkRef.js'; import { ownerDocument } from '../../utils/owner.js'; /** * A custom element to display instead of the native cursor while using the scrub area. * Renders a `<span>` element. * * This component uses the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API), which may prompt the browser to display a related notification. It is disabled * in Safari to avoid a layout shift that this notification causes there. * * Documentation: [Base UI Number Field](https://base-ui.com/react/components/number-field) */ const NumberFieldScrubAreaCursor = /*#__PURE__*/React.forwardRef(function NumberFieldScrubAreaCursor(props, forwardedRef) { const { render, className, ...otherProps } = props; const { isScrubbing, scrubAreaCursorRef, state, getScrubAreaCursorProps } = useNumberFieldRootContext(); const [element, setElement] = React.useState(null); const mergedRef = useForkRef(forwardedRef, scrubAreaCursorRef, setElement); const { renderElement } = useComponentRenderer({ propGetter: getScrubAreaCursorProps, ref: mergedRef, render: render ?? 'span', state, className, extraProps: otherProps }); if (!isScrubbing || isWebKit()) { return null; } return /*#__PURE__*/ReactDOM.createPortal(renderElement(), ownerDocument(element).body); }); process.env.NODE_ENV !== "production" ? NumberFieldScrubAreaCursor.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * @ignore */ children: PropTypes.node, /** * CSS class applied to the element, or a function that * returns a class based on the component’s state. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), /** * Allows you to replace the component’s HTML element * with a different tag, or compose it with another component. * * Accepts a `ReactElement` or a function that returns the element to render. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]) } : void 0; export { NumberFieldScrubAreaCursor };