@box/blueprint-web 19.6.0 → 20.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_LICENSES +119 -0
- package/dist/lib-esm/accordion/accordion.js +6 -6
- package/dist/lib-esm/accordion/types.d.ts +1 -1
- package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
- package/dist/lib-esm/checkbox/types.d.ts +1 -1
- package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
- package/dist/lib-esm/collapsible/types.d.ts +1 -1
- package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
- package/dist/lib-esm/date-picker/date-picker.js +8 -7
- package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
- package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
- package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
- package/dist/lib-esm/modal/modal-close.js +2 -2
- package/dist/lib-esm/modal/modal-content.d.ts +1 -1
- package/dist/lib-esm/modal/modal-content.js +4 -4
- package/dist/lib-esm/modal/modal-description.js +2 -2
- package/dist/lib-esm/modal/modal-title.js +2 -2
- package/dist/lib-esm/modal/modal-trigger.js +2 -2
- package/dist/lib-esm/modal/modal.d.ts +1 -1
- package/dist/lib-esm/modal/modal.js +1 -1
- package/dist/lib-esm/modal/types.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
- package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
- package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/chip.js +2 -2
- package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
- package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
- package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
- package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
- package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
- package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
- package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
- package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
- package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
- package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
- package/dist/lib-esm/radio-group/index.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.js +2 -2
- package/dist/lib-esm/radio-group/radio-item.js +3 -3
- package/dist/lib-esm/radio-group/types.d.ts +1 -1
- package/dist/lib-esm/select/select.js +12 -12
- package/dist/lib-esm/select/types.d.ts +1 -1
- package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
- package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
- package/dist/lib-esm/side-panel/side-panel.js +1 -1
- package/dist/lib-esm/side-panel/types.d.ts +1 -1
- package/dist/lib-esm/switch/switch-item.js +3 -3
- package/dist/lib-esm/switch/types.d.ts +1 -1
- package/dist/lib-esm/toolbar/index.d.ts +2 -2
- package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
- package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
- package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/types.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.js +6 -6
- package/dist/lib-esm/tooltip/types.d.ts +1 -1
- package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
- package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
- package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
- package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
- package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
- package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
- package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
- package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
- package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
- package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
- package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
- package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
- package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
- package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
- package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
- package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
- package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
- package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
- package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
- package/dist/lib-esm/utils/radix-compat/select.js +901 -0
- package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
- package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
- package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
- package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
- package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
- package/package.json +8 -19
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type PopperArrowProps } from './popper';
|
|
3
|
+
import { type DismissableLayerProps, type FocusScopeProps, type PopperContentProps, type PortalProps, type PrimitiveProps } from './types';
|
|
4
|
+
export interface PopoverProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
defaultOpen?: boolean;
|
|
8
|
+
onOpenChange?: (open: boolean) => void;
|
|
9
|
+
modal?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Popover with the Radix API and DOM, rendered by the Ariakit `Popover`. Positioning, focus management and
|
|
13
|
+
* dismiss callbacks follow Radix; modality (inert outside content, scroll lock) is Ariakit's.
|
|
14
|
+
*/
|
|
15
|
+
export declare const Root: {
|
|
16
|
+
(props: PopoverProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
19
|
+
export type PopoverAnchorProps = PrimitiveProps<'div'>;
|
|
20
|
+
export declare const Anchor: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
21
|
+
asChild?: boolean;
|
|
22
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
23
|
+
export type PopoverTriggerProps = PrimitiveProps<'button'>;
|
|
24
|
+
export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
25
|
+
asChild?: boolean;
|
|
26
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
27
|
+
export interface PopoverPortalProps extends PortalProps {
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export declare const Portal: {
|
|
31
|
+
({ forceMount, children, container }: PopoverPortalProps): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
displayName: string;
|
|
33
|
+
};
|
|
34
|
+
export interface PopoverContentProps extends PrimitiveProps<'div'>, PopperContentProps, DismissableLayerProps, FocusScopeProps {
|
|
35
|
+
/** Keeps the content mounted when closed, for animations controlled from the outside. */
|
|
36
|
+
forceMount?: true;
|
|
37
|
+
}
|
|
38
|
+
export declare const Content: import("react").ForwardRefExoticComponent<PopoverContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
39
|
+
export type PopoverCloseProps = PrimitiveProps<'button'>;
|
|
40
|
+
export declare const Close: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
41
|
+
asChild?: boolean;
|
|
42
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
43
|
+
export type PopoverArrowProps = PopperArrowProps;
|
|
44
|
+
export declare const Arrow: import("react").ForwardRefExoticComponent<Omit<PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { useStoreState, Popover, usePopoverStore } from '@ariakit/react';
|
|
3
|
+
import { forwardRef, useEffect, useContext, createContext, useRef, useCallback, useState, useId, useMemo } from 'react';
|
|
4
|
+
import { RemoveScroll } from 'react-remove-scroll';
|
|
5
|
+
import { composeEventHandlers } from '../composeEventHandlers.js';
|
|
6
|
+
import { useControllableState } from '../useControllableState.js';
|
|
7
|
+
import { AllowAutoFocus } from './allow-auto-focus.js';
|
|
8
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
9
|
+
import { DismissMarker } from './dismiss-marker.js';
|
|
10
|
+
import { useDismissable } from './dismissable.js';
|
|
11
|
+
import { useFocusScope } from './focus-scope.js';
|
|
12
|
+
import { useHideOthers } from './hide-others.js';
|
|
13
|
+
import { getPersistentElements } from './layers.js';
|
|
14
|
+
import { PopperArrow, usePopper, PopperArrowProvider, getPopperCssVariables } from './popper.js';
|
|
15
|
+
import { Portal as Portal$1 } from './portal.js';
|
|
16
|
+
import { Presence } from './presence.js';
|
|
17
|
+
import { Slot, getAsChildRender } from './slot.js';
|
|
18
|
+
import { overlayStoreOptions } from './store-options.js';
|
|
19
|
+
import { useStripViewportHeight } from './viewport-height.js';
|
|
20
|
+
|
|
21
|
+
const getState = open => open ? 'open' : 'closed';
|
|
22
|
+
const noopUpdatePosition = () => undefined;
|
|
23
|
+
const PopoverContext = /*#__PURE__*/createContext(null);
|
|
24
|
+
function usePopoverContext(consumerName) {
|
|
25
|
+
const context = useContext(PopoverContext);
|
|
26
|
+
if (!context) {
|
|
27
|
+
throw new Error(`\`${consumerName}\` must be used within \`Popover\``);
|
|
28
|
+
}
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Popover with the Radix API and DOM, rendered by the Ariakit `Popover`. Positioning, focus management and
|
|
33
|
+
* dismiss callbacks follow Radix; modality (inert outside content, scroll lock) is Ariakit's.
|
|
34
|
+
*/
|
|
35
|
+
const Root = props => {
|
|
36
|
+
const {
|
|
37
|
+
children,
|
|
38
|
+
open: openProp,
|
|
39
|
+
defaultOpen,
|
|
40
|
+
onOpenChange,
|
|
41
|
+
modal = false
|
|
42
|
+
} = props;
|
|
43
|
+
const triggerRef = useRef(null);
|
|
44
|
+
const [hasCustomAnchor, setHasCustomAnchor] = useState(false);
|
|
45
|
+
const [trigger, setTrigger] = useState(null);
|
|
46
|
+
const [customAnchor, setCustomAnchor] = useState(null);
|
|
47
|
+
const anchor = hasCustomAnchor ? customAnchor : trigger;
|
|
48
|
+
const contentId = useId();
|
|
49
|
+
const [open = false, setOpen] = useControllableState({
|
|
50
|
+
prop: openProp,
|
|
51
|
+
defaultProp: defaultOpen,
|
|
52
|
+
onChange: onOpenChange
|
|
53
|
+
});
|
|
54
|
+
const store = usePopoverStore({
|
|
55
|
+
...overlayStoreOptions,
|
|
56
|
+
open,
|
|
57
|
+
setOpen: nextOpen => {
|
|
58
|
+
if (!nextOpen) {
|
|
59
|
+
setOpen(false);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const onOpenToggle = useCallback(() => setOpen(prevOpen => !prevOpen), [setOpen]);
|
|
64
|
+
const onCustomAnchorAdd = useCallback(() => setHasCustomAnchor(true), []);
|
|
65
|
+
const onCustomAnchorRemove = useCallback(() => setHasCustomAnchor(false), []);
|
|
66
|
+
const onOpenChangeCallback = useCallback(nextOpen => setOpen(nextOpen), [setOpen]);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
store.setAnchorElement(anchor);
|
|
69
|
+
}, [store, anchor]);
|
|
70
|
+
const value = useMemo(() => ({
|
|
71
|
+
contentId,
|
|
72
|
+
triggerRef,
|
|
73
|
+
open,
|
|
74
|
+
onOpenChange: onOpenChangeCallback,
|
|
75
|
+
onOpenToggle,
|
|
76
|
+
hasCustomAnchor,
|
|
77
|
+
onCustomAnchorAdd,
|
|
78
|
+
onCustomAnchorRemove,
|
|
79
|
+
onCustomAnchorChange: setCustomAnchor,
|
|
80
|
+
onTriggerChange: setTrigger,
|
|
81
|
+
anchor,
|
|
82
|
+
modal,
|
|
83
|
+
store
|
|
84
|
+
}), [contentId, open, onOpenChangeCallback, onOpenToggle, hasCustomAnchor, onCustomAnchorAdd, onCustomAnchorRemove, anchor, modal, store]);
|
|
85
|
+
return jsx(PopoverContext.Provider, {
|
|
86
|
+
value: value,
|
|
87
|
+
children: children
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
Root.displayName = 'Popover';
|
|
91
|
+
const Anchor = /*#__PURE__*/forwardRef(({
|
|
92
|
+
asChild,
|
|
93
|
+
...anchorProps
|
|
94
|
+
}, forwardedRef) => {
|
|
95
|
+
const context = usePopoverContext('PopoverAnchor');
|
|
96
|
+
const {
|
|
97
|
+
onCustomAnchorAdd,
|
|
98
|
+
onCustomAnchorRemove
|
|
99
|
+
} = context;
|
|
100
|
+
const composedRefs = useComposedRefs(forwardedRef, context.onCustomAnchorChange);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
onCustomAnchorAdd();
|
|
103
|
+
return () => onCustomAnchorRemove();
|
|
104
|
+
}, [onCustomAnchorAdd, onCustomAnchorRemove]);
|
|
105
|
+
const Comp = asChild ? Slot : 'div';
|
|
106
|
+
return jsx(Comp, {
|
|
107
|
+
...anchorProps,
|
|
108
|
+
ref: composedRefs
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
Anchor.displayName = 'PopoverAnchor';
|
|
112
|
+
const Trigger = /*#__PURE__*/forwardRef(({
|
|
113
|
+
asChild,
|
|
114
|
+
...triggerProps
|
|
115
|
+
}, forwardedRef) => {
|
|
116
|
+
const context = usePopoverContext('PopoverTrigger');
|
|
117
|
+
const composedRefs = useComposedRefs(forwardedRef, context.triggerRef, context.onTriggerChange);
|
|
118
|
+
const Comp = asChild ? Slot : 'button';
|
|
119
|
+
return jsx(Comp, {
|
|
120
|
+
"aria-controls": context.contentId,
|
|
121
|
+
"aria-expanded": context.open,
|
|
122
|
+
"aria-haspopup": "dialog",
|
|
123
|
+
"data-state": getState(context.open),
|
|
124
|
+
type: "button",
|
|
125
|
+
...triggerProps,
|
|
126
|
+
ref: composedRefs,
|
|
127
|
+
onClick: composeEventHandlers(triggerProps.onClick, context.onOpenToggle)
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
Trigger.displayName = 'PopoverTrigger';
|
|
131
|
+
/* -------------------------------------------------------------------------------------------------
|
|
132
|
+
* Portal
|
|
133
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
134
|
+
const PortalContext = /*#__PURE__*/createContext({
|
|
135
|
+
forceMount: undefined
|
|
136
|
+
});
|
|
137
|
+
const Portal = ({
|
|
138
|
+
forceMount,
|
|
139
|
+
children,
|
|
140
|
+
container
|
|
141
|
+
}) => {
|
|
142
|
+
const context = usePopoverContext('PopoverPortal');
|
|
143
|
+
return jsx(PortalContext.Provider, {
|
|
144
|
+
value: {
|
|
145
|
+
forceMount
|
|
146
|
+
},
|
|
147
|
+
children: jsx(Presence, {
|
|
148
|
+
present: Boolean(forceMount) || context.open,
|
|
149
|
+
children: jsx(Portal$1, {
|
|
150
|
+
container: container,
|
|
151
|
+
children: children
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
Portal.displayName = 'PopoverPortal';
|
|
157
|
+
const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
158
|
+
const portalContext = useContext(PortalContext);
|
|
159
|
+
const {
|
|
160
|
+
forceMount = portalContext.forceMount,
|
|
161
|
+
...contentProps
|
|
162
|
+
} = props;
|
|
163
|
+
const context = usePopoverContext('PopoverContent');
|
|
164
|
+
return jsx(Presence, {
|
|
165
|
+
present: Boolean(forceMount) || context.open,
|
|
166
|
+
children: context.modal ? jsx(ContentModal, {
|
|
167
|
+
...contentProps,
|
|
168
|
+
ref: forwardedRef
|
|
169
|
+
}) : jsx(ContentNonModal, {
|
|
170
|
+
...contentProps,
|
|
171
|
+
ref: forwardedRef
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
Content.displayName = 'PopoverContent';
|
|
176
|
+
const ContentModal = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
177
|
+
const context = usePopoverContext('PopoverContent');
|
|
178
|
+
const isRightClickOutsideRef = useRef(false);
|
|
179
|
+
return jsx(RemoveScroll, {
|
|
180
|
+
allowPinchZoom: true,
|
|
181
|
+
as: Slot,
|
|
182
|
+
children: jsx(ContentImpl, {
|
|
183
|
+
...props,
|
|
184
|
+
ref: forwardedRef,
|
|
185
|
+
// Focus is only trapped while open, so it can leave during the exit animation.
|
|
186
|
+
trapFocus: context.open,
|
|
187
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
if (!isRightClickOutsideRef.current) {
|
|
190
|
+
context.triggerRef.current?.focus();
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, event => {
|
|
194
|
+
const {
|
|
195
|
+
originalEvent
|
|
196
|
+
} = event.detail;
|
|
197
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
198
|
+
isRightClickOutsideRef.current = originalEvent.button === 2 || ctrlLeftClick;
|
|
199
|
+
}, {
|
|
200
|
+
checkForDefaultPrevented: false
|
|
201
|
+
}),
|
|
202
|
+
// A `focusout` event may still happen while focus is trapped.
|
|
203
|
+
onFocusOutside: composeEventHandlers(props.onFocusOutside, event => event.preventDefault(), {
|
|
204
|
+
checkForDefaultPrevented: false
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
const ContentNonModal = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
210
|
+
const {
|
|
211
|
+
onCloseAutoFocus,
|
|
212
|
+
onInteractOutside
|
|
213
|
+
} = props;
|
|
214
|
+
const {
|
|
215
|
+
triggerRef
|
|
216
|
+
} = usePopoverContext('PopoverContent');
|
|
217
|
+
const hasInteractedOutsideRef = useRef(false);
|
|
218
|
+
const hasPointerDownOutsideRef = useRef(false);
|
|
219
|
+
const handleCloseAutoFocus = useCallback(event => {
|
|
220
|
+
onCloseAutoFocus?.(event);
|
|
221
|
+
if (!event.defaultPrevented) {
|
|
222
|
+
if (!hasInteractedOutsideRef.current) {
|
|
223
|
+
triggerRef.current?.focus();
|
|
224
|
+
}
|
|
225
|
+
// Always prevent auto focus because we either focus manually or want user agent focus.
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
}
|
|
228
|
+
hasInteractedOutsideRef.current = false;
|
|
229
|
+
hasPointerDownOutsideRef.current = false;
|
|
230
|
+
}, [onCloseAutoFocus, triggerRef]);
|
|
231
|
+
const handleInteractOutside = useCallback(event => {
|
|
232
|
+
onInteractOutside?.(event);
|
|
233
|
+
if (!event.defaultPrevented) {
|
|
234
|
+
hasInteractedOutsideRef.current = true;
|
|
235
|
+
if (event.detail.originalEvent.type === 'pointerdown') {
|
|
236
|
+
hasPointerDownOutsideRef.current = true;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// The trigger toggles the popover itself, so it must not dismiss it as an outside interaction.
|
|
240
|
+
const target = event.target;
|
|
241
|
+
if (triggerRef.current?.contains(target)) {
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
}
|
|
244
|
+
// Safari reports a focus outside after a pointer down outside on a focusable container.
|
|
245
|
+
if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
}
|
|
248
|
+
}, [onInteractOutside, triggerRef]);
|
|
249
|
+
return jsx(ContentImpl, {
|
|
250
|
+
...props,
|
|
251
|
+
ref: forwardedRef,
|
|
252
|
+
onCloseAutoFocus: handleCloseAutoFocus,
|
|
253
|
+
onInteractOutside: handleInteractOutside,
|
|
254
|
+
trapFocus: false
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
const ContentImpl = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
258
|
+
const {
|
|
259
|
+
trapFocus,
|
|
260
|
+
onOpenAutoFocus,
|
|
261
|
+
onCloseAutoFocus,
|
|
262
|
+
onEscapeKeyDown,
|
|
263
|
+
onPointerDownOutside,
|
|
264
|
+
onFocusOutside,
|
|
265
|
+
onInteractOutside,
|
|
266
|
+
side,
|
|
267
|
+
sideOffset,
|
|
268
|
+
align,
|
|
269
|
+
alignOffset,
|
|
270
|
+
arrowPadding,
|
|
271
|
+
avoidCollisions,
|
|
272
|
+
collisionBoundary,
|
|
273
|
+
collisionPadding,
|
|
274
|
+
sticky,
|
|
275
|
+
hideWhenDetached,
|
|
276
|
+
updatePositionStrategy,
|
|
277
|
+
onPlaced,
|
|
278
|
+
asChild,
|
|
279
|
+
style,
|
|
280
|
+
children,
|
|
281
|
+
...contentProps
|
|
282
|
+
} = props;
|
|
283
|
+
const context = usePopoverContext('PopoverContent');
|
|
284
|
+
const [content, setContent] = useState(null);
|
|
285
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
286
|
+
const wrapper = useStoreState(context.store, 'popoverElement');
|
|
287
|
+
useHideOthers(content, context.modal);
|
|
288
|
+
useStripViewportHeight(content);
|
|
289
|
+
const focusScope = useFocusScope({
|
|
290
|
+
container: content,
|
|
291
|
+
loop: true,
|
|
292
|
+
trapped: trapFocus,
|
|
293
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
294
|
+
onUnmountAutoFocus: onCloseAutoFocus
|
|
295
|
+
});
|
|
296
|
+
const dismissable = useDismissable({
|
|
297
|
+
open: context.open,
|
|
298
|
+
disableOutsidePointerEvents: context.modal,
|
|
299
|
+
onDismiss: () => context.onOpenChange(false),
|
|
300
|
+
onEscapeKeyDown,
|
|
301
|
+
onPointerDownOutside,
|
|
302
|
+
onFocusOutside,
|
|
303
|
+
onInteractOutside
|
|
304
|
+
});
|
|
305
|
+
const popper = usePopper({
|
|
306
|
+
anchor: context.anchor,
|
|
307
|
+
wrapper,
|
|
308
|
+
content,
|
|
309
|
+
side,
|
|
310
|
+
sideOffset,
|
|
311
|
+
align,
|
|
312
|
+
alignOffset,
|
|
313
|
+
arrowPadding,
|
|
314
|
+
avoidCollisions,
|
|
315
|
+
collisionBoundary,
|
|
316
|
+
collisionPadding,
|
|
317
|
+
sticky,
|
|
318
|
+
hideWhenDetached,
|
|
319
|
+
updatePositionStrategy,
|
|
320
|
+
onPlaced
|
|
321
|
+
});
|
|
322
|
+
const asChildRender = getAsChildRender(asChild, children, contentChildren => jsxs(Fragment, {
|
|
323
|
+
children: [jsx(AllowAutoFocus, {
|
|
324
|
+
children: contentChildren
|
|
325
|
+
}), context.modal && jsx(DismissMarker, {})]
|
|
326
|
+
}));
|
|
327
|
+
return jsx(PopperArrowProvider, {
|
|
328
|
+
value: popper.arrowContext,
|
|
329
|
+
children: jsx(Popover, {
|
|
330
|
+
alwaysVisible: true,
|
|
331
|
+
autoFocusOnHide: false,
|
|
332
|
+
autoFocusOnShow: false,
|
|
333
|
+
backdrop: false,
|
|
334
|
+
"data-align": popper.contentProps['data-align'],
|
|
335
|
+
"data-side": popper.contentProps['data-side'],
|
|
336
|
+
"data-state": getState(context.open),
|
|
337
|
+
getPersistentElements: getPersistentElements,
|
|
338
|
+
hideOnEscape: false,
|
|
339
|
+
hideOnInteractOutside: dismissable.hideOnInteractOutside,
|
|
340
|
+
id: context.contentId,
|
|
341
|
+
modal: context.modal,
|
|
342
|
+
portal: false,
|
|
343
|
+
// Modal content locks scrolling with `RemoveScroll`, like in Radix.
|
|
344
|
+
preventBodyScroll: false,
|
|
345
|
+
render: asChildRender.render,
|
|
346
|
+
role: "dialog",
|
|
347
|
+
store: context.store,
|
|
348
|
+
updatePosition: noopUpdatePosition,
|
|
349
|
+
...contentProps,
|
|
350
|
+
// `wrapperProps` isn't Radix API, so a consumer's mustn't replace the positioning ones.
|
|
351
|
+
wrapperProps: popper.wrapperProps,
|
|
352
|
+
ref: composedRefs,
|
|
353
|
+
onKeyDown: composeEventHandlers(contentProps.onKeyDown, focusScope.onKeyDown),
|
|
354
|
+
onBlurCapture: composeEventHandlers(contentProps.onBlurCapture, dismissable.contentProps.onBlurCapture),
|
|
355
|
+
onFocusCapture: composeEventHandlers(contentProps.onFocusCapture, dismissable.contentProps.onFocusCapture),
|
|
356
|
+
onPointerDownCapture: composeEventHandlers(contentProps.onPointerDownCapture, dismissable.contentProps.onPointerDownCapture),
|
|
357
|
+
style: {
|
|
358
|
+
...style,
|
|
359
|
+
...getPopperCssVariables('popover'),
|
|
360
|
+
...popper.contentProps.style
|
|
361
|
+
},
|
|
362
|
+
children: asChildRender.children
|
|
363
|
+
})
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
const Close = /*#__PURE__*/forwardRef(({
|
|
367
|
+
asChild,
|
|
368
|
+
...closeProps
|
|
369
|
+
}, forwardedRef) => {
|
|
370
|
+
const context = usePopoverContext('PopoverClose');
|
|
371
|
+
const Comp = asChild ? Slot : 'button';
|
|
372
|
+
return jsx(Comp, {
|
|
373
|
+
type: "button",
|
|
374
|
+
...closeProps,
|
|
375
|
+
ref: forwardedRef,
|
|
376
|
+
onClick: composeEventHandlers(closeProps.onClick, _event => context.onOpenChange(false))
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
Close.displayName = 'PopoverClose';
|
|
380
|
+
const Arrow = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(PopperArrow, {
|
|
381
|
+
...props,
|
|
382
|
+
ref: forwardedRef
|
|
383
|
+
}));
|
|
384
|
+
Arrow.displayName = 'PopoverArrow';
|
|
385
|
+
|
|
386
|
+
export { Anchor, Arrow, Close, Content, Portal, Root, Trigger };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type VirtualElement } from '@floating-ui/dom';
|
|
2
|
+
import { type CSSProperties, type ReactNode, type SVGProps } from 'react';
|
|
3
|
+
import { type Align, type PopperContentProps, type Side } from './types';
|
|
4
|
+
export declare const POPPER_WRAPPER_ATTRIBUTE = "data-radix-popper-content-wrapper";
|
|
5
|
+
export type PopperAnchor = Element | VirtualElement;
|
|
6
|
+
interface PopperArrowContextValue {
|
|
7
|
+
placedSide: Side;
|
|
8
|
+
onArrowChange(arrow: HTMLSpanElement | null): void;
|
|
9
|
+
arrowX?: number;
|
|
10
|
+
arrowY?: number;
|
|
11
|
+
shouldHideArrow: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface UsePopperOptions extends PopperContentProps {
|
|
14
|
+
/** The element (or virtual element) the content is positioned against. */
|
|
15
|
+
anchor: PopperAnchor | null;
|
|
16
|
+
/** The positioned wrapper element. */
|
|
17
|
+
wrapper: HTMLElement | null;
|
|
18
|
+
/** The content element inside the wrapper; its `z-index` is copied to the wrapper. */
|
|
19
|
+
content: HTMLElement | null;
|
|
20
|
+
dir?: 'ltr' | 'rtl';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Positions overlay content exactly like the Radix `Popper` (same floating-ui middleware and order,
|
|
24
|
+
* `fixed` strategy, `--radix-popper-*` CSS variables), so existing styles and screenshots don't change.
|
|
25
|
+
*
|
|
26
|
+
* Returns the props for the wrapper element and the content element, and an arrow provider.
|
|
27
|
+
*/
|
|
28
|
+
export declare function usePopper({ anchor, wrapper, content, dir, side, sideOffset, align, alignOffset, arrowPadding, avoidCollisions, collisionBoundary, collisionPadding: collisionPaddingProp, sticky, hideWhenDetached, updatePositionStrategy, onPlaced, }: UsePopperOptions): {
|
|
29
|
+
placedSide: Side;
|
|
30
|
+
placedAlign: Align;
|
|
31
|
+
isPositioned: boolean;
|
|
32
|
+
wrapperProps: {
|
|
33
|
+
"data-radix-popper-content-wrapper": string;
|
|
34
|
+
dir: "ltr" | "rtl" | undefined;
|
|
35
|
+
style: CSSProperties & Record<string, string | number | undefined>;
|
|
36
|
+
};
|
|
37
|
+
contentProps: {
|
|
38
|
+
'data-side': Side;
|
|
39
|
+
'data-align': Align;
|
|
40
|
+
style: CSSProperties;
|
|
41
|
+
};
|
|
42
|
+
arrowContext: PopperArrowContextValue;
|
|
43
|
+
};
|
|
44
|
+
export declare const PopperArrowProvider: ({ value, children }: {
|
|
45
|
+
value: PopperArrowContextValue;
|
|
46
|
+
children: ReactNode;
|
|
47
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
export interface PopperArrowProps extends SVGProps<SVGSVGElement> {
|
|
49
|
+
asChild?: boolean;
|
|
50
|
+
children?: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The arrow of positioned content, placed like the Radix `Popper.Arrow`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const PopperArrow: import("react").ForwardRefExoticComponent<Omit<PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>;
|
|
56
|
+
/**
|
|
57
|
+
* Aliases of the popper CSS variables used by a component, e.g. `--radix-popover-content-available-height`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function getPopperCssVariables(component: string, anchorName?: string): Record<string, string>;
|
|
60
|
+
export {};
|