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.

49 lines (47 loc) 1.43 kB
'use client'; import * as React from 'react'; import { usePopoverPositionerContext } from "../positioner/PopoverPositionerContext.js"; import { usePopoverRootContext } from "../root/PopoverRootContext.js"; import { popupStateMapping } from "../../utils/popupStateMapping.js"; import { useRenderElement } from "../../utils/useRenderElement.js"; /** * Displays an element positioned against the popover anchor. * Renders a `<div>` element. * * Documentation: [Base UI Popover](https://base-ui.com/react/components/popover) */ export const PopoverArrow = /*#__PURE__*/React.forwardRef(function PopoverArrow(componentProps, forwardedRef) { const { className, render, ...elementProps } = componentProps; const { store } = usePopoverRootContext(); const open = store.useState('open'); const { arrowRef, side, align, arrowUncentered, arrowStyles } = usePopoverPositionerContext(); const state = React.useMemo(() => ({ open, side, align, uncentered: arrowUncentered }), [open, side, align, arrowUncentered]); const element = useRenderElement('div', componentProps, { state, ref: [forwardedRef, arrowRef], props: [{ style: arrowStyles, 'aria-hidden': true }, elementProps], stateAttributesMapping: popupStateMapping }); return element; }); if (process.env.NODE_ENV !== "production") PopoverArrow.displayName = "PopoverArrow";