@box/blueprint-web 19.5.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 +14 -6
- package/dist/lib-esm/accordion/accordion.module.js +1 -1
- package/dist/lib-esm/accordion/types.d.ts +1 -1
- package/dist/lib-esm/blueprint-configuration-context/consts.d.ts +1 -1
- package/dist/lib-esm/blueprint-configuration-context/consts.js +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/components.css +400 -280
- 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/index.css +400 -280
- 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/small-list-item/small-list.js +8 -0
- 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/util-components/base-grid-list-item/base-grid-list-item.module.js +1 -1
- package/dist/lib-esm/utils/TooltipWrapper.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,416 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { computePosition, autoUpdate, offset, shift, limitShift, flip, size, arrow, hide } from '@floating-ui/dom';
|
|
3
|
+
import { forwardRef, useContext, useState, useMemo, useCallback, createContext, useRef } from 'react';
|
|
4
|
+
import { flushSync } from 'react-dom';
|
|
5
|
+
import { useCallbackRef } from '../useCallbackRef.js';
|
|
6
|
+
import { useEnhancedEffect } from '../useEnhancedEffect.js';
|
|
7
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
8
|
+
import { Slot } from './slot.js';
|
|
9
|
+
|
|
10
|
+
const POPPER_WRAPPER_ATTRIBUTE = 'data-radix-popper-content-wrapper';
|
|
11
|
+
function getSideAndAlignFromPlacement(placement) {
|
|
12
|
+
const [side, align = 'center'] = placement.split('-');
|
|
13
|
+
return [side, align];
|
|
14
|
+
}
|
|
15
|
+
function getDevicePixelRatio(element) {
|
|
16
|
+
return element.ownerDocument.defaultView?.devicePixelRatio || 1;
|
|
17
|
+
}
|
|
18
|
+
function roundByDevicePixelRatio(element, value) {
|
|
19
|
+
const dpr = getDevicePixelRatio(element);
|
|
20
|
+
return Math.round(value * dpr) / dpr;
|
|
21
|
+
}
|
|
22
|
+
function useSize(element) {
|
|
23
|
+
const [elementSize, setElementSize] = useState();
|
|
24
|
+
useEnhancedEffect(() => {
|
|
25
|
+
if (!element) {
|
|
26
|
+
setElementSize(undefined);
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
setElementSize({
|
|
30
|
+
width: element.offsetWidth,
|
|
31
|
+
height: element.offsetHeight
|
|
32
|
+
});
|
|
33
|
+
const resizeObserver = new ResizeObserver(entries => {
|
|
34
|
+
const entry = entries[entries.length - 1];
|
|
35
|
+
if (!entry) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let width;
|
|
39
|
+
let height;
|
|
40
|
+
if ('borderBoxSize' in entry) {
|
|
41
|
+
const borderSize = Array.isArray(entry.borderBoxSize) ? entry.borderBoxSize[0] : entry.borderBoxSize;
|
|
42
|
+
width = borderSize.inlineSize;
|
|
43
|
+
height = borderSize.blockSize;
|
|
44
|
+
} else {
|
|
45
|
+
width = element.offsetWidth;
|
|
46
|
+
height = element.offsetHeight;
|
|
47
|
+
}
|
|
48
|
+
setElementSize({
|
|
49
|
+
width,
|
|
50
|
+
height
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
resizeObserver.observe(element, {
|
|
54
|
+
box: 'border-box'
|
|
55
|
+
});
|
|
56
|
+
return () => resizeObserver.unobserve(element);
|
|
57
|
+
}, [element]);
|
|
58
|
+
return elementSize;
|
|
59
|
+
}
|
|
60
|
+
const transformOrigin = options => ({
|
|
61
|
+
name: 'transformOrigin',
|
|
62
|
+
options,
|
|
63
|
+
fn(data) {
|
|
64
|
+
const {
|
|
65
|
+
placement,
|
|
66
|
+
rects,
|
|
67
|
+
middlewareData
|
|
68
|
+
} = data;
|
|
69
|
+
const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
|
|
70
|
+
const isArrowHidden = cannotCenterArrow;
|
|
71
|
+
const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
|
|
72
|
+
const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
|
|
73
|
+
const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
|
|
74
|
+
const noArrowAlign = {
|
|
75
|
+
start: '0%',
|
|
76
|
+
center: '50%',
|
|
77
|
+
end: '100%'
|
|
78
|
+
}[placedAlign];
|
|
79
|
+
const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
|
|
80
|
+
const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
|
|
81
|
+
let x = '';
|
|
82
|
+
let y = '';
|
|
83
|
+
if (placedSide === 'bottom') {
|
|
84
|
+
x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
|
|
85
|
+
y = `${-arrowHeight}px`;
|
|
86
|
+
} else if (placedSide === 'top') {
|
|
87
|
+
x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
|
|
88
|
+
y = `${rects.floating.height + arrowHeight}px`;
|
|
89
|
+
} else if (placedSide === 'right') {
|
|
90
|
+
x = `${-arrowHeight}px`;
|
|
91
|
+
y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
|
|
92
|
+
} else if (placedSide === 'left') {
|
|
93
|
+
x = `${rects.floating.width + arrowHeight}px`;
|
|
94
|
+
y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
data: {
|
|
98
|
+
x,
|
|
99
|
+
y
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
function getMiddleware(options) {
|
|
105
|
+
const collisionPadding = typeof options.collisionPadding === 'number' ? options.collisionPadding : {
|
|
106
|
+
top: 0,
|
|
107
|
+
right: 0,
|
|
108
|
+
bottom: 0,
|
|
109
|
+
left: 0,
|
|
110
|
+
...options.collisionPadding
|
|
111
|
+
};
|
|
112
|
+
const detectOverflowOptions = {
|
|
113
|
+
padding: collisionPadding,
|
|
114
|
+
boundary: options.boundary.filter(element => element !== null),
|
|
115
|
+
// With the `fixed` strategy, this is the only way to respect boundaries.
|
|
116
|
+
altBoundary: options.boundary.length > 0
|
|
117
|
+
};
|
|
118
|
+
return [offset({
|
|
119
|
+
mainAxis: options.sideOffset + options.arrowHeight,
|
|
120
|
+
alignmentAxis: options.alignOffset
|
|
121
|
+
}), options.avoidCollisions && shift({
|
|
122
|
+
mainAxis: true,
|
|
123
|
+
crossAxis: false,
|
|
124
|
+
limiter: options.sticky === 'partial' ? limitShift() : undefined,
|
|
125
|
+
...detectOverflowOptions
|
|
126
|
+
}), options.avoidCollisions && flip({
|
|
127
|
+
...detectOverflowOptions
|
|
128
|
+
}), size({
|
|
129
|
+
...detectOverflowOptions,
|
|
130
|
+
apply: ({
|
|
131
|
+
elements,
|
|
132
|
+
rects,
|
|
133
|
+
availableWidth,
|
|
134
|
+
availableHeight
|
|
135
|
+
}) => {
|
|
136
|
+
const {
|
|
137
|
+
width: anchorWidth,
|
|
138
|
+
height: anchorHeight
|
|
139
|
+
} = rects.reference;
|
|
140
|
+
const wrapperStyle = elements.floating.style;
|
|
141
|
+
wrapperStyle.setProperty('--radix-popper-available-width', `${availableWidth}px`);
|
|
142
|
+
wrapperStyle.setProperty('--radix-popper-available-height', `${availableHeight}px`);
|
|
143
|
+
wrapperStyle.setProperty('--radix-popper-anchor-width', `${anchorWidth}px`);
|
|
144
|
+
wrapperStyle.setProperty('--radix-popper-anchor-height', `${anchorHeight}px`);
|
|
145
|
+
}
|
|
146
|
+
}), options.arrow && arrow({
|
|
147
|
+
element: options.arrow,
|
|
148
|
+
padding: options.arrowPadding
|
|
149
|
+
}), transformOrigin({
|
|
150
|
+
arrowWidth: options.arrowWidth,
|
|
151
|
+
arrowHeight: options.arrowHeight
|
|
152
|
+
}), options.hideWhenDetached && hide({
|
|
153
|
+
strategy: 'referenceHidden',
|
|
154
|
+
...detectOverflowOptions
|
|
155
|
+
})].filter(Boolean);
|
|
156
|
+
}
|
|
157
|
+
const isPlainObject = value => typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
158
|
+
/** Compares arrays and plain objects by value, and other objects, like elements, by identity. */
|
|
159
|
+
function isDeepEqual(a, b) {
|
|
160
|
+
if (Object.is(a, b)) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
164
|
+
return a.length === b.length && a.every((item, index) => isDeepEqual(item, b[index]));
|
|
165
|
+
}
|
|
166
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
167
|
+
const keys = Object.keys(a);
|
|
168
|
+
return keys.length === Object.keys(b).length && keys.every(key => isDeepEqual(a[key], b[key]));
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
function useDeepCompareMemo(value) {
|
|
173
|
+
const ref = useRef(value);
|
|
174
|
+
if (!isDeepEqual(ref.current, value)) {
|
|
175
|
+
ref.current = value;
|
|
176
|
+
}
|
|
177
|
+
return ref.current;
|
|
178
|
+
}
|
|
179
|
+
const PopperArrowContext = /*#__PURE__*/createContext(null);
|
|
180
|
+
/**
|
|
181
|
+
* Positions overlay content exactly like the Radix `Popper` (same floating-ui middleware and order,
|
|
182
|
+
* `fixed` strategy, `--radix-popper-*` CSS variables), so existing styles and screenshots don't change.
|
|
183
|
+
*
|
|
184
|
+
* Returns the props for the wrapper element and the content element, and an arrow provider.
|
|
185
|
+
*/
|
|
186
|
+
function usePopper({
|
|
187
|
+
anchor,
|
|
188
|
+
wrapper,
|
|
189
|
+
content,
|
|
190
|
+
dir,
|
|
191
|
+
side = 'bottom',
|
|
192
|
+
sideOffset = 0,
|
|
193
|
+
align = 'center',
|
|
194
|
+
alignOffset = 0,
|
|
195
|
+
arrowPadding = 0,
|
|
196
|
+
avoidCollisions = true,
|
|
197
|
+
collisionBoundary = [],
|
|
198
|
+
collisionPadding: collisionPaddingProp = 0,
|
|
199
|
+
sticky = 'partial',
|
|
200
|
+
hideWhenDetached = false,
|
|
201
|
+
updatePositionStrategy = 'optimized',
|
|
202
|
+
onPlaced
|
|
203
|
+
}) {
|
|
204
|
+
const [arrow, setArrow] = useState(null);
|
|
205
|
+
const arrowSize = useSize(arrow);
|
|
206
|
+
const arrowWidth = arrowSize?.width ?? 0;
|
|
207
|
+
const arrowHeight = arrowSize?.height ?? 0;
|
|
208
|
+
const desiredPlacement = side + (align !== 'center' ? `-${align}` : '');
|
|
209
|
+
const [state, setState] = useState({
|
|
210
|
+
x: 0,
|
|
211
|
+
y: 0,
|
|
212
|
+
placement: desiredPlacement,
|
|
213
|
+
isPositioned: false,
|
|
214
|
+
cannotCenterArrow: true,
|
|
215
|
+
referenceHidden: false
|
|
216
|
+
});
|
|
217
|
+
const [contentZIndex, setContentZIndex] = useState();
|
|
218
|
+
const positionOptions = useDeepCompareMemo({
|
|
219
|
+
placement: desiredPlacement,
|
|
220
|
+
sideOffset,
|
|
221
|
+
alignOffset,
|
|
222
|
+
arrow,
|
|
223
|
+
arrowWidth,
|
|
224
|
+
arrowHeight,
|
|
225
|
+
arrowPadding,
|
|
226
|
+
avoidCollisions,
|
|
227
|
+
sticky,
|
|
228
|
+
collisionPadding: collisionPaddingProp,
|
|
229
|
+
boundary: Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary],
|
|
230
|
+
hideWhenDetached
|
|
231
|
+
});
|
|
232
|
+
const middleware = useMemo(() => getMiddleware(positionOptions), [positionOptions]);
|
|
233
|
+
const {
|
|
234
|
+
placement: positionPlacement
|
|
235
|
+
} = positionOptions;
|
|
236
|
+
const update = useCallback(() => {
|
|
237
|
+
if (!anchor || !wrapper) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
computePosition(anchor, wrapper, {
|
|
241
|
+
strategy: 'fixed',
|
|
242
|
+
placement: positionPlacement,
|
|
243
|
+
middleware
|
|
244
|
+
}).then(data => {
|
|
245
|
+
if (!wrapper.isConnected) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const nextState = {
|
|
249
|
+
x: roundByDevicePixelRatio(wrapper, data.x),
|
|
250
|
+
y: roundByDevicePixelRatio(wrapper, data.y),
|
|
251
|
+
placement: data.placement,
|
|
252
|
+
isPositioned: true,
|
|
253
|
+
arrowX: data.middlewareData.arrow?.x,
|
|
254
|
+
arrowY: data.middlewareData.arrow?.y,
|
|
255
|
+
cannotCenterArrow: data.middlewareData.arrow?.centerOffset !== 0,
|
|
256
|
+
transformOrigin: data.middlewareData.transformOrigin,
|
|
257
|
+
referenceHidden: Boolean(data.middlewareData.hide?.referenceHidden)
|
|
258
|
+
};
|
|
259
|
+
flushSync(() => {
|
|
260
|
+
setState(current => JSON.stringify(current) === JSON.stringify(nextState) ? current : nextState);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}, [anchor, wrapper, positionPlacement, middleware]);
|
|
264
|
+
// `autoUpdate` also calls `update` when it subscribes, so it positions the content on mount and on option changes.
|
|
265
|
+
useEnhancedEffect(() => {
|
|
266
|
+
if (!anchor || !wrapper) {
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
return autoUpdate(anchor, wrapper, update, {
|
|
270
|
+
animationFrame: updatePositionStrategy === 'always'
|
|
271
|
+
});
|
|
272
|
+
}, [anchor, wrapper, update, updatePositionStrategy]);
|
|
273
|
+
useEnhancedEffect(() => {
|
|
274
|
+
if (content) {
|
|
275
|
+
setContentZIndex(window.getComputedStyle(content).zIndex);
|
|
276
|
+
}
|
|
277
|
+
}, [content]);
|
|
278
|
+
const handlePlaced = useCallbackRef(onPlaced);
|
|
279
|
+
useEnhancedEffect(() => {
|
|
280
|
+
if (state.isPositioned) {
|
|
281
|
+
handlePlaced();
|
|
282
|
+
}
|
|
283
|
+
}, [state.isPositioned, handlePlaced]);
|
|
284
|
+
const [placedSide, placedAlign] = getSideAndAlignFromPlacement(state.placement);
|
|
285
|
+
const dpr = wrapper ? getDevicePixelRatio(wrapper) : 1;
|
|
286
|
+
const wrapperStyle = {
|
|
287
|
+
position: 'fixed',
|
|
288
|
+
left: 0,
|
|
289
|
+
top: 0,
|
|
290
|
+
width: undefined,
|
|
291
|
+
transform: state.isPositioned ? `translate(${state.x}px, ${state.y}px)` : 'translate(0, -200%)',
|
|
292
|
+
willChange: state.isPositioned && dpr >= 1.5 ? 'transform' : undefined,
|
|
293
|
+
minWidth: 'max-content',
|
|
294
|
+
zIndex: contentZIndex,
|
|
295
|
+
'--radix-popper-transform-origin': [state.transformOrigin?.x, state.transformOrigin?.y].join(' ')
|
|
296
|
+
};
|
|
297
|
+
const contentStyle = {
|
|
298
|
+
// Prevent animations until the content is placed, so they don't refer to the wrong side.
|
|
299
|
+
animation: !state.isPositioned ? 'none' : undefined,
|
|
300
|
+
opacity: state.referenceHidden ? 0 : undefined,
|
|
301
|
+
// Ariakit sets a relative position on the popover element, which Radix content didn't have.
|
|
302
|
+
position: undefined
|
|
303
|
+
};
|
|
304
|
+
const arrowContext = {
|
|
305
|
+
placedSide,
|
|
306
|
+
onArrowChange: setArrow,
|
|
307
|
+
arrowX: state.arrowX,
|
|
308
|
+
arrowY: state.arrowY,
|
|
309
|
+
shouldHideArrow: state.cannotCenterArrow
|
|
310
|
+
};
|
|
311
|
+
return {
|
|
312
|
+
placedSide,
|
|
313
|
+
placedAlign,
|
|
314
|
+
isPositioned: state.isPositioned,
|
|
315
|
+
wrapperProps: {
|
|
316
|
+
[POPPER_WRAPPER_ATTRIBUTE]: '',
|
|
317
|
+
dir,
|
|
318
|
+
style: wrapperStyle
|
|
319
|
+
},
|
|
320
|
+
contentProps: {
|
|
321
|
+
'data-side': placedSide,
|
|
322
|
+
'data-align': placedAlign,
|
|
323
|
+
style: contentStyle
|
|
324
|
+
},
|
|
325
|
+
arrowContext
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
const PopperArrowProvider = ({
|
|
329
|
+
value,
|
|
330
|
+
children
|
|
331
|
+
}) => jsx(PopperArrowContext.Provider, {
|
|
332
|
+
value: value,
|
|
333
|
+
children: children
|
|
334
|
+
});
|
|
335
|
+
const OPPOSITE_SIDE = {
|
|
336
|
+
top: 'bottom',
|
|
337
|
+
right: 'left',
|
|
338
|
+
bottom: 'top',
|
|
339
|
+
left: 'right'
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* The arrow of positioned content, placed like the Radix `Popper.Arrow`.
|
|
343
|
+
*/
|
|
344
|
+
const PopperArrow = /*#__PURE__*/forwardRef(({
|
|
345
|
+
asChild,
|
|
346
|
+
children,
|
|
347
|
+
width = 10,
|
|
348
|
+
height = 5,
|
|
349
|
+
style,
|
|
350
|
+
...arrowProps
|
|
351
|
+
}, forwardedRef) => {
|
|
352
|
+
const context = useContext(PopperArrowContext);
|
|
353
|
+
if (!context) {
|
|
354
|
+
throw new Error('PopperArrow must be used within positioned content');
|
|
355
|
+
}
|
|
356
|
+
const baseSide = OPPOSITE_SIDE[context.placedSide];
|
|
357
|
+
const composedRef = useComposedRefs(forwardedRef);
|
|
358
|
+
const svgProps = {
|
|
359
|
+
...arrowProps,
|
|
360
|
+
width,
|
|
361
|
+
height,
|
|
362
|
+
viewBox: '0 0 30 10',
|
|
363
|
+
preserveAspectRatio: 'none',
|
|
364
|
+
style: {
|
|
365
|
+
...style,
|
|
366
|
+
display: 'block'
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
return jsx("span", {
|
|
370
|
+
ref: context.onArrowChange,
|
|
371
|
+
style: {
|
|
372
|
+
position: 'absolute',
|
|
373
|
+
left: context.arrowX,
|
|
374
|
+
top: context.arrowY,
|
|
375
|
+
[baseSide]: 0,
|
|
376
|
+
transformOrigin: {
|
|
377
|
+
top: '',
|
|
378
|
+
right: '0 0',
|
|
379
|
+
bottom: 'center 0',
|
|
380
|
+
left: '100% 0'
|
|
381
|
+
}[context.placedSide],
|
|
382
|
+
transform: {
|
|
383
|
+
top: 'translateY(100%)',
|
|
384
|
+
right: 'translateY(50%) rotate(90deg) translateX(-50%)',
|
|
385
|
+
bottom: 'rotate(180deg)',
|
|
386
|
+
left: 'translateY(50%) rotate(-90deg) translateX(50%)'
|
|
387
|
+
}[context.placedSide],
|
|
388
|
+
visibility: context.shouldHideArrow ? 'hidden' : undefined
|
|
389
|
+
},
|
|
390
|
+
children: asChild ? jsx(Slot, {
|
|
391
|
+
ref: composedRef,
|
|
392
|
+
...svgProps,
|
|
393
|
+
children: children
|
|
394
|
+
}) : jsx("svg", {
|
|
395
|
+
ref: composedRef,
|
|
396
|
+
...svgProps,
|
|
397
|
+
children: jsx("polygon", {
|
|
398
|
+
points: "0,0 30,0 15,10"
|
|
399
|
+
})
|
|
400
|
+
})
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
/**
|
|
404
|
+
* Aliases of the popper CSS variables used by a component, e.g. `--radix-popover-content-available-height`.
|
|
405
|
+
*/
|
|
406
|
+
function getPopperCssVariables(component, anchorName = 'trigger') {
|
|
407
|
+
return {
|
|
408
|
+
[`--radix-${component}-content-transform-origin`]: 'var(--radix-popper-transform-origin)',
|
|
409
|
+
[`--radix-${component}-content-available-width`]: 'var(--radix-popper-available-width)',
|
|
410
|
+
[`--radix-${component}-content-available-height`]: 'var(--radix-popper-available-height)',
|
|
411
|
+
[`--radix-${component}-${anchorName}-width`]: 'var(--radix-popper-anchor-width)',
|
|
412
|
+
[`--radix-${component}-${anchorName}-height`]: 'var(--radix-popper-anchor-height)'
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export { POPPER_WRAPPER_ATTRIBUTE, PopperArrow, PopperArrowProvider, getPopperCssVariables, usePopper };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface PortalComponentProps extends HTMLAttributes<HTMLElement> {
|
|
3
|
+
/** Element to portal into. Defaults to `document.body`; `null` renders nothing. */
|
|
4
|
+
container?: Element | DocumentFragment | null;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders its only child as a direct child of `container`, like the Radix `Portal` with `asChild`
|
|
9
|
+
* (Ariakit portals add an extra wrapper element, which consumers' selectors don't expect).
|
|
10
|
+
*/
|
|
11
|
+
export declare const Portal: import("react").ForwardRefExoticComponent<PortalComponentProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
import { Slot } from './slot.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders its only child as a direct child of `container`, like the Radix `Portal` with `asChild`
|
|
8
|
+
* (Ariakit portals add an extra wrapper element, which consumers' selectors don't expect).
|
|
9
|
+
*/
|
|
10
|
+
const Portal = /*#__PURE__*/forwardRef(({
|
|
11
|
+
container = globalThis?.document?.body,
|
|
12
|
+
children,
|
|
13
|
+
...portalProps
|
|
14
|
+
}, forwardedRef) => container ? /*#__PURE__*/createPortal(jsx(Slot, {
|
|
15
|
+
ref: forwardedRef,
|
|
16
|
+
...portalProps,
|
|
17
|
+
children: children
|
|
18
|
+
}), container) : null);
|
|
19
|
+
|
|
20
|
+
export { Portal };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Keeps an element mounted until its CSS exit animation (started by the `present` change) ends.
|
|
4
|
+
*/
|
|
5
|
+
export declare function usePresence(present: boolean): {
|
|
6
|
+
isPresent: boolean;
|
|
7
|
+
ref: (element: HTMLElement | null) => void;
|
|
8
|
+
};
|
|
9
|
+
interface PresenceProps {
|
|
10
|
+
present: boolean;
|
|
11
|
+
children: ReactElement | ((props: {
|
|
12
|
+
present: boolean;
|
|
13
|
+
}) => ReactElement);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Mounts its child while `present`, and keeps it mounted until the exit animation finishes.
|
|
17
|
+
* A function child is always rendered and receives the presence state.
|
|
18
|
+
*/
|
|
19
|
+
export declare const Presence: ({ present, children }: PresenceProps) => ReactElement<any, string | import("react").JSXElementConstructor<any>> | null;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Children, isValidElement, cloneElement, useState, useRef, useReducer, useEffect, useCallback } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { useEnhancedEffect } from '../useEnhancedEffect.js';
|
|
4
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
5
|
+
import { getElementRef } from './slot.js';
|
|
6
|
+
|
|
7
|
+
const machine = {
|
|
8
|
+
mounted: {
|
|
9
|
+
UNMOUNT: 'unmounted',
|
|
10
|
+
ANIMATION_OUT: 'unmountSuspended'
|
|
11
|
+
},
|
|
12
|
+
unmountSuspended: {
|
|
13
|
+
MOUNT: 'mounted',
|
|
14
|
+
ANIMATION_END: 'unmounted'
|
|
15
|
+
},
|
|
16
|
+
unmounted: {
|
|
17
|
+
MOUNT: 'mounted'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function getAnimationName(styles) {
|
|
21
|
+
return styles?.animationName || 'none';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Keeps an element mounted until its CSS exit animation (started by the `present` change) ends.
|
|
25
|
+
*/
|
|
26
|
+
function usePresence(present) {
|
|
27
|
+
const [node, setNode] = useState();
|
|
28
|
+
const stylesRef = useRef(undefined);
|
|
29
|
+
const prevPresentRef = useRef(present);
|
|
30
|
+
const prevAnimationNameRef = useRef('none');
|
|
31
|
+
const [state, send] = useReducer((current, event) => machine[current][event] ?? current, present ? 'mounted' : 'unmounted');
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
34
|
+
prevAnimationNameRef.current = state === 'mounted' ? currentAnimationName : 'none';
|
|
35
|
+
}, [state]);
|
|
36
|
+
useEnhancedEffect(() => {
|
|
37
|
+
const styles = stylesRef.current;
|
|
38
|
+
const wasPresent = prevPresentRef.current;
|
|
39
|
+
const hasPresentChanged = wasPresent !== present;
|
|
40
|
+
if (hasPresentChanged) {
|
|
41
|
+
const prevAnimationName = prevAnimationNameRef.current;
|
|
42
|
+
const currentAnimationName = getAnimationName(styles);
|
|
43
|
+
if (present) {
|
|
44
|
+
send('MOUNT');
|
|
45
|
+
} else if (currentAnimationName === 'none' || styles?.display === 'none') {
|
|
46
|
+
send('UNMOUNT');
|
|
47
|
+
} else {
|
|
48
|
+
const isAnimating = prevAnimationName !== currentAnimationName;
|
|
49
|
+
send(wasPresent && isAnimating ? 'ANIMATION_OUT' : 'UNMOUNT');
|
|
50
|
+
}
|
|
51
|
+
prevPresentRef.current = present;
|
|
52
|
+
}
|
|
53
|
+
}, [present]);
|
|
54
|
+
useEnhancedEffect(() => {
|
|
55
|
+
if (node) {
|
|
56
|
+
const handleAnimationEnd = event => {
|
|
57
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
58
|
+
const isCurrentAnimation = currentAnimationName.includes(event.animationName);
|
|
59
|
+
if (event.target === node && isCurrentAnimation) {
|
|
60
|
+
flushSync(() => send('ANIMATION_END'));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handleAnimationStart = event => {
|
|
64
|
+
if (event.target === node) {
|
|
65
|
+
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
node.addEventListener('animationstart', handleAnimationStart);
|
|
69
|
+
node.addEventListener('animationcancel', handleAnimationEnd);
|
|
70
|
+
node.addEventListener('animationend', handleAnimationEnd);
|
|
71
|
+
return () => {
|
|
72
|
+
node.removeEventListener('animationstart', handleAnimationStart);
|
|
73
|
+
node.removeEventListener('animationcancel', handleAnimationEnd);
|
|
74
|
+
node.removeEventListener('animationend', handleAnimationEnd);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
send('ANIMATION_END');
|
|
78
|
+
return undefined;
|
|
79
|
+
}, [node]);
|
|
80
|
+
return {
|
|
81
|
+
isPresent: state === 'mounted' || state === 'unmountSuspended',
|
|
82
|
+
ref: useCallback(element => {
|
|
83
|
+
if (element) {
|
|
84
|
+
stylesRef.current = getComputedStyle(element);
|
|
85
|
+
}
|
|
86
|
+
setNode(element ?? undefined);
|
|
87
|
+
}, [])
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Mounts its child while `present`, and keeps it mounted until the exit animation finishes.
|
|
92
|
+
* A function child is always rendered and receives the presence state.
|
|
93
|
+
*/
|
|
94
|
+
const Presence = ({
|
|
95
|
+
present,
|
|
96
|
+
children
|
|
97
|
+
}) => {
|
|
98
|
+
const presence = usePresence(present);
|
|
99
|
+
const child = typeof children === 'function' ? children({
|
|
100
|
+
present: presence.isPresent
|
|
101
|
+
}) : Children.only(children);
|
|
102
|
+
const childRef = /*#__PURE__*/isValidElement(child) ? getElementRef(child) : undefined;
|
|
103
|
+
const ref = useComposedRefs(presence.ref, childRef);
|
|
104
|
+
const forceMount = typeof children === 'function';
|
|
105
|
+
return forceMount || presence.isPresent ? /*#__PURE__*/cloneElement(child, {
|
|
106
|
+
ref
|
|
107
|
+
}) : null;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { Presence, usePresence };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Direction, type Orientation, type PrimitiveProps } from './types';
|
|
2
|
+
export interface RadioGroupProps extends PrimitiveProps<'div'> {
|
|
3
|
+
name?: string;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
dir?: Direction;
|
|
7
|
+
orientation?: Orientation;
|
|
8
|
+
loop?: boolean;
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
value?: string;
|
|
11
|
+
onValueChange?(value: string): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Radio group with the Radix keyboard model: the group is the tab stop and moves focus to the checked
|
|
15
|
+
* radio, arrow keys move focus (and check while the key is pressed), Home/End move focus only.
|
|
16
|
+
*/
|
|
17
|
+
export declare const Root: import("react").ForwardRefExoticComponent<RadioGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
18
|
+
export interface RadioGroupItemProps extends Omit<PrimitiveProps<'button'>, 'checked' | 'name'> {
|
|
19
|
+
value: string;
|
|
20
|
+
checked?: boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const Item: import("react").ForwardRefExoticComponent<RadioGroupItemProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
24
|
+
export interface RadioGroupIndicatorProps extends PrimitiveProps<'span'> {
|
|
25
|
+
forceMount?: true;
|
|
26
|
+
}
|
|
27
|
+
export declare const Indicator: import("react").ForwardRefExoticComponent<RadioGroupIndicatorProps & import("react").RefAttributes<HTMLSpanElement>>;
|