package.dist.components.popover.use-popover.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.
The newest version!
'use client';
import * as popover from '@zag-js/popover';
import { useMachine, normalizeProps } from '@zag-js/react';
import { useId } from 'react';
import { useEnvironmentContext } from '../../providers/environment/use-environment-context.js';
import { useLocaleContext } from '../../providers/locale/use-locale-context.js';
import { useEvent } from '../../utils/use-event.js';
const usePopover = (props = {}) => {
const { getRootNode } = useEnvironmentContext();
const { dir } = useLocaleContext();
const initialContext = {
id: useId(),
dir,
getRootNode,
open: props.defaultOpen,
"open.controlled": props.open !== void 0,
...props
};
const context = {
...initialContext,
open: props.open,
onOpenChange: useEvent(props.onOpenChange, { sync: true })
};
const [state, send] = useMachine(popover.machine(initialContext), { context });
return popover.connect(state, send, normalizeProps);
};
export { usePopover };
© 2015 - 2025 Weber Informatics LLC | Privacy Policy