@fluentui/react-positioning 9.0.0-alpha.9 → 9.0.0-beta.4
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +1279 -1
- package/CHANGELOG.md +577 -2
- package/dist/react-positioning.d.ts +95 -27
- package/lib/createArrowStyles.d.ts +27 -0
- package/lib/createArrowStyles.js +75 -0
- package/lib/createArrowStyles.js.map +1 -0
- package/lib/createVirtualElementFromClick.d.ts +6 -0
- package/lib/createVirtualElementFromClick.js +26 -0
- package/lib/createVirtualElementFromClick.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +19 -29
- package/lib/types.js +1 -0
- package/lib/types.js.map +1 -1
- package/lib/usePopper.d.ts +21 -1
- package/lib/usePopper.js +364 -284
- package/lib/usePopper.js.map +1 -1
- package/lib/usePopperMouseTarget.d.ts +11 -0
- package/lib/usePopperMouseTarget.js +40 -0
- package/lib/usePopperMouseTarget.js.map +1 -0
- package/lib/utils/getBasePlacement.d.ts +8 -0
- package/lib/utils/getBasePlacement.js +10 -0
- package/lib/utils/getBasePlacement.js.map +1 -0
- package/lib/utils/getBoundary.d.ts +1 -1
- package/lib/utils/getBoundary.js +15 -11
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getReactFiberFromNode.d.ts +0 -1
- package/lib/utils/getReactFiberFromNode.js +39 -35
- package/lib/utils/getReactFiberFromNode.js.map +1 -1
- package/lib/utils/getScrollParent.js +46 -32
- package/lib/utils/getScrollParent.js.map +1 -1
- package/lib/utils/index.d.ts +5 -3
- package/lib/utils/index.js +5 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.d.ts +10 -0
- package/lib/utils/mergeArrowOffset.js +42 -0
- package/lib/utils/mergeArrowOffset.js.map +1 -0
- package/lib/utils/positioningHelper.d.ts +3 -3
- package/lib/utils/positioningHelper.js +42 -34
- package/lib/utils/positioningHelper.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.d.ts +2 -0
- package/lib/utils/resolvePositioningShorthand.js +63 -0
- package/lib/utils/resolvePositioningShorthand.js.map +1 -0
- package/lib/utils/useCallbackRef.js +35 -29
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/createArrowStyles.d.ts +27 -0
- package/lib-commonjs/createArrowStyles.js +84 -0
- package/lib-commonjs/createArrowStyles.js.map +1 -0
- package/lib-commonjs/createVirtualElementFromClick.d.ts +6 -0
- package/lib-commonjs/createVirtualElementFromClick.js +35 -0
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -0
- package/lib-commonjs/index.d.ts +4 -0
- package/lib-commonjs/index.js +31 -2
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.d.ts +19 -29
- package/lib-commonjs/types.js +4 -1
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePopper.d.ts +21 -1
- package/lib-commonjs/usePopper.js +378 -287
- package/lib-commonjs/usePopper.js.map +1 -1
- package/lib-commonjs/usePopperMouseTarget.d.ts +11 -0
- package/lib-commonjs/usePopperMouseTarget.js +51 -0
- package/lib-commonjs/usePopperMouseTarget.js.map +1 -0
- package/lib-commonjs/utils/getBasePlacement.d.ts +8 -0
- package/lib-commonjs/utils/getBasePlacement.js +19 -0
- package/lib-commonjs/utils/getBasePlacement.js.map +1 -0
- package/lib-commonjs/utils/getBoundary.d.ts +1 -1
- package/lib-commonjs/utils/getBoundary.js +24 -13
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -1
- package/lib-commonjs/utils/getReactFiberFromNode.js +45 -36
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js +56 -33
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/index.d.ts +5 -3
- package/lib-commonjs/utils/index.js +19 -5
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.d.ts +10 -0
- package/lib-commonjs/utils/mergeArrowOffset.js +51 -0
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -0
- package/lib-commonjs/utils/positioningHelper.d.ts +3 -3
- package/lib-commonjs/utils/positioningHelper.js +53 -35
- package/lib-commonjs/utils/positioningHelper.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +2 -0
- package/lib-commonjs/utils/resolvePositioningShorthand.js +72 -0
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -0
- package/lib-commonjs/utils/useCallbackRef.js +46 -32
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/package.json +13 -10
- package/config/api-extractor.json +0 -3
- package/etc/react-positioning.api.md +0 -70
- package/just.config.ts +0 -3
- package/lib/utils/isBrowser.d.ts +0 -1
- package/lib/utils/isBrowser.js +0 -4
- package/lib/utils/isBrowser.js.map +0 -1
- package/lib-amd/index.d.ts +0 -2
- package/lib-amd/index.js +0 -6
- package/lib-amd/index.js.map +0 -1
- package/lib-amd/types.d.ts +0 -78
- package/lib-amd/types.js +0 -5
- package/lib-amd/types.js.map +0 -1
- package/lib-amd/usePopper.d.ts +0 -15
- package/lib-amd/usePopper.js +0 -281
- package/lib-amd/usePopper.js.map +0 -1
- package/lib-amd/utils/getBoundary.d.ts +0 -6
- package/lib-amd/utils/getBoundary.js +0 -23
- package/lib-amd/utils/getBoundary.js.map +0 -1
- package/lib-amd/utils/getReactFiberFromNode.d.ts +0 -109
- package/lib-amd/utils/getReactFiberFromNode.js +0 -47
- package/lib-amd/utils/getReactFiberFromNode.js.map +0 -1
- package/lib-amd/utils/getScrollParent.d.ts +0 -12
- package/lib-amd/utils/getScrollParent.js +0 -55
- package/lib-amd/utils/getScrollParent.js.map +0 -1
- package/lib-amd/utils/index.d.ts +0 -6
- package/lib-amd/utils/index.js +0 -11
- package/lib-amd/utils/index.js.map +0 -1
- package/lib-amd/utils/isBrowser.d.ts +0 -1
- package/lib-amd/utils/isBrowser.js +0 -8
- package/lib-amd/utils/isBrowser.js.map +0 -1
- package/lib-amd/utils/positioningHelper.d.ts +0 -7
- package/lib-amd/utils/positioningHelper.js +0 -45
- package/lib-amd/utils/positioningHelper.js.map +0 -1
- package/lib-amd/utils/useCallbackRef.d.ts +0 -19
- package/lib-amd/utils/useCallbackRef.js +0 -54
- package/lib-amd/utils/useCallbackRef.js.map +0 -1
- package/lib-commonjs/utils/isBrowser.d.ts +0 -1
- package/lib-commonjs/utils/isBrowser.js +0 -6
- package/lib-commonjs/utils/isBrowser.js.map +0 -1
@@ -1,10 +1,56 @@
|
|
1
|
+
import type { MakeStylesStyleRule } from '@fluentui/make-styles';
|
1
2
|
import * as PopperJs from '@popperjs/core';
|
2
|
-
import * as
|
3
|
+
import * as React_2 from 'react';
|
4
|
+
import type { Theme } from '@fluentui/react-theme';
|
3
5
|
|
4
6
|
export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
5
7
|
|
8
|
+
export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
|
9
|
+
|
6
10
|
export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
|
7
11
|
|
12
|
+
/**
|
13
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
14
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
15
|
+
*
|
16
|
+
* ```ts
|
17
|
+
* makeStyles({
|
18
|
+
* arrowWithSize: createArrowStyles(5),
|
19
|
+
*
|
20
|
+
* arrowWithoutSize: createArrowStyles(),
|
21
|
+
* mediumArrow: { aspectRatio: 1, width: '4px' }
|
22
|
+
* smallArrow: { aspectRatio: 1, width: '2px' }
|
23
|
+
* })
|
24
|
+
* ...
|
25
|
+
*
|
26
|
+
* state.arrowWithSize.clasName = styles.arrowWithSize
|
27
|
+
* state.arrowWithoutSize.className = mergeClases(
|
28
|
+
* styles.arrowWithoutSize,
|
29
|
+
* state.smallArrow && styles.smallArrow,
|
30
|
+
* state.mediumArrow && styles.mediumArrow,
|
31
|
+
* )
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
* @param size - dimensions of the square arrow element in pixels.
|
35
|
+
*/
|
36
|
+
export declare function createArrowStyles(size?: number): MakeStylesStyleRule<Theme>;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Creates a virtual element based on the position of a click event
|
40
|
+
* Can be used as a target for popper in scenarios such as context menus
|
41
|
+
*/
|
42
|
+
export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
|
46
|
+
* height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
|
47
|
+
*
|
48
|
+
* @param userOffset - The offset provided by the user
|
49
|
+
* @param arrowHeight - The height of the arrow in px
|
50
|
+
* @returns User offset augmented with arrow height
|
51
|
+
*/
|
52
|
+
export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
|
53
|
+
|
8
54
|
export declare type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];
|
9
55
|
|
10
56
|
export declare type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];
|
@@ -15,36 +61,42 @@ export declare type OffsetFunctionParam = {
|
|
15
61
|
placement: PopperJs.Placement;
|
16
62
|
};
|
17
63
|
|
18
|
-
|
64
|
+
declare interface PopperOptions extends PositioningProps {
|
19
65
|
/**
|
20
66
|
* If false, delays Popper's creation.
|
21
67
|
* @default true
|
22
68
|
*/
|
23
69
|
enabled?: boolean;
|
70
|
+
onStateUpdate?: (state: Partial<PopperJs.State>) => void;
|
24
71
|
/**
|
25
|
-
*
|
72
|
+
* Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
|
73
|
+
* @default false
|
26
74
|
*/
|
27
|
-
|
28
|
-
|
75
|
+
positionFixed?: boolean;
|
76
|
+
/**
|
77
|
+
* When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
|
78
|
+
* "all" enables this behavior for all axis.
|
79
|
+
*/
|
80
|
+
unstable_disableTether?: boolean | 'all';
|
29
81
|
}
|
30
82
|
|
31
83
|
export declare type PopperRefHandle = {
|
32
84
|
updatePosition: () => void;
|
33
85
|
};
|
34
86
|
|
87
|
+
export declare type PopperVirtualElement = PopperJs.VirtualElement;
|
88
|
+
|
35
89
|
export declare type Position = 'above' | 'below' | 'before' | 'after';
|
36
90
|
|
37
91
|
export declare interface PositioningProps {
|
38
|
-
/**
|
39
|
-
* Alignment for the component.
|
40
|
-
*/
|
92
|
+
/** Alignment for the component. Only has an effect if used with the @see position option */
|
41
93
|
align?: Alignment;
|
42
94
|
/** The element which will define the boundaries of the popper position for the flip behavior. */
|
43
95
|
flipBoundary?: Boundary;
|
44
96
|
/** The element which will define the boundaries of the popper position for the overflow behavior. */
|
45
97
|
overflowBoundary?: Boundary;
|
46
98
|
/** An imperative handle to Popper methods. */
|
47
|
-
|
99
|
+
popperRef?: React_2.Ref<PopperRefHandle>;
|
48
100
|
/**
|
49
101
|
* Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
|
50
102
|
* and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
|
@@ -52,11 +104,6 @@ export declare interface PositioningProps {
|
|
52
104
|
* then provided value for 'align' will be ignored and 'center' will be used instead.
|
53
105
|
*/
|
54
106
|
position?: Position;
|
55
|
-
/**
|
56
|
-
* Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
|
57
|
-
* @default false
|
58
|
-
*/
|
59
|
-
positionFixed?: boolean;
|
60
107
|
/**
|
61
108
|
* Lets you displace a popper element from its reference element.
|
62
109
|
* This can be useful if you need to apply some margin between them or if you need to fine tune the
|
@@ -69,23 +116,34 @@ export declare interface PositioningProps {
|
|
69
116
|
*/
|
70
117
|
arrowPadding?: number;
|
71
118
|
/**
|
72
|
-
*
|
73
|
-
*
|
119
|
+
* Applies max-height and max-width on popper to fit it within the available space in viewport.
|
120
|
+
* true enables this for both width and height when overflow happens.
|
121
|
+
* 'always' applies `max-height`/`max-width` regardless of overflow.
|
122
|
+
* 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
|
123
|
+
* `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
|
74
124
|
*/
|
75
|
-
|
125
|
+
autoSize?: AutoSize;
|
76
126
|
/**
|
77
|
-
*
|
78
|
-
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
127
|
+
* Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
|
79
128
|
*/
|
80
|
-
|
129
|
+
target?: HTMLElement | PopperVirtualElement | null;
|
81
130
|
/**
|
82
|
-
*
|
83
|
-
|
84
|
-
|
131
|
+
* Modifies position and alignment to cover the target
|
132
|
+
*/
|
133
|
+
coverTarget?: boolean;
|
134
|
+
/**
|
135
|
+
* Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
|
136
|
+
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
85
137
|
*/
|
86
|
-
|
138
|
+
pinned?: boolean;
|
87
139
|
}
|
88
140
|
|
141
|
+
export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
|
142
|
+
|
143
|
+
export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
|
144
|
+
|
145
|
+
export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
|
146
|
+
|
89
147
|
/**
|
90
148
|
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
91
149
|
* package:
|
@@ -95,9 +153,19 @@ export declare interface PositioningProps {
|
|
95
153
|
* to avoid focus jumps
|
96
154
|
*/
|
97
155
|
export declare function usePopper(options?: PopperOptions): {
|
98
|
-
targetRef:
|
99
|
-
containerRef:
|
100
|
-
arrowRef:
|
156
|
+
targetRef: React_2.MutableRefObject<any>;
|
157
|
+
containerRef: React_2.MutableRefObject<any>;
|
158
|
+
arrowRef: React_2.MutableRefObject<any>;
|
101
159
|
};
|
102
160
|
|
161
|
+
/**
|
162
|
+
* A state hook that manages a popper virtual element from mouseevents.
|
163
|
+
* Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
|
164
|
+
* React synthetic events are not persisted by this hook
|
165
|
+
*
|
166
|
+
* @param initialState - initializes a user provided state similare to useState
|
167
|
+
* @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
|
168
|
+
*/
|
169
|
+
export declare const usePopperMouseTarget: (initialState?: PopperJs.VirtualElement | (() => PopperJs.VirtualElement) | undefined) => readonly [PopperJs.VirtualElement | undefined, (event: React_2.MouseEvent | MouseEvent | undefined | null) => void];
|
170
|
+
|
103
171
|
export { }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import type { MakeStylesStyleRule } from '@fluentui/make-styles';
|
2
|
+
import type { Theme } from '@fluentui/react-theme';
|
3
|
+
/**
|
4
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
5
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
6
|
+
*
|
7
|
+
* ```ts
|
8
|
+
* makeStyles({
|
9
|
+
* arrowWithSize: createArrowStyles(5),
|
10
|
+
*
|
11
|
+
* arrowWithoutSize: createArrowStyles(),
|
12
|
+
* mediumArrow: { aspectRatio: 1, width: '4px' }
|
13
|
+
* smallArrow: { aspectRatio: 1, width: '2px' }
|
14
|
+
* })
|
15
|
+
* ...
|
16
|
+
*
|
17
|
+
* state.arrowWithSize.clasName = styles.arrowWithSize
|
18
|
+
* state.arrowWithoutSize.className = mergeClases(
|
19
|
+
* styles.arrowWithoutSize,
|
20
|
+
* state.smallArrow && styles.smallArrow,
|
21
|
+
* state.mediumArrow && styles.mediumArrow,
|
22
|
+
* )
|
23
|
+
* ```
|
24
|
+
*
|
25
|
+
* @param size - dimensions of the square arrow element in pixels.
|
26
|
+
*/
|
27
|
+
export declare function createArrowStyles(size?: number): MakeStylesStyleRule<Theme>;
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/**
|
2
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
3
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
4
|
+
*
|
5
|
+
* ```ts
|
6
|
+
* makeStyles({
|
7
|
+
* arrowWithSize: createArrowStyles(5),
|
8
|
+
*
|
9
|
+
* arrowWithoutSize: createArrowStyles(),
|
10
|
+
* mediumArrow: { aspectRatio: 1, width: '4px' }
|
11
|
+
* smallArrow: { aspectRatio: 1, width: '2px' }
|
12
|
+
* })
|
13
|
+
* ...
|
14
|
+
*
|
15
|
+
* state.arrowWithSize.clasName = styles.arrowWithSize
|
16
|
+
* state.arrowWithoutSize.className = mergeClases(
|
17
|
+
* styles.arrowWithoutSize,
|
18
|
+
* state.smallArrow && styles.smallArrow,
|
19
|
+
* state.mediumArrow && styles.mediumArrow,
|
20
|
+
* )
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* @param size - dimensions of the square arrow element in pixels.
|
24
|
+
*/
|
25
|
+
export function createArrowStyles(size) {
|
26
|
+
return theme => {
|
27
|
+
const arrowHCBorderStyle = `1px solid transparent`;
|
28
|
+
const arrowHCBorder = {
|
29
|
+
borderRight: arrowHCBorderStyle,
|
30
|
+
borderBottom: arrowHCBorderStyle
|
31
|
+
};
|
32
|
+
return {
|
33
|
+
position: 'absolute',
|
34
|
+
background: 'inherit',
|
35
|
+
visibility: 'hidden',
|
36
|
+
zIndex: -1,
|
37
|
+
...(size && {
|
38
|
+
aspectRatio: 1,
|
39
|
+
width: `${size}px`
|
40
|
+
}),
|
41
|
+
':before': {
|
42
|
+
content: '""',
|
43
|
+
borderRadius: '4px',
|
44
|
+
position: 'absolute',
|
45
|
+
width: 'inherit',
|
46
|
+
height: 'inherit',
|
47
|
+
background: 'inherit',
|
48
|
+
visibility: 'visible',
|
49
|
+
borderBottomRightRadius: theme.borderRadiusSmall,
|
50
|
+
transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
|
51
|
+
},
|
52
|
+
':global([data-popper-placement])': {
|
53
|
+
':before': arrowHCBorder
|
54
|
+
},
|
55
|
+
// Popper sets data-popper-placement on the root element, which is used to align the arrow
|
56
|
+
':global([data-popper-placement^="top"])': {
|
57
|
+
bottom: 0,
|
58
|
+
'--angle': '0'
|
59
|
+
},
|
60
|
+
':global([data-popper-placement^="right"])': {
|
61
|
+
left: 0,
|
62
|
+
'--angle': '90deg'
|
63
|
+
},
|
64
|
+
':global([data-popper-placement^="bottom"])': {
|
65
|
+
top: 0,
|
66
|
+
'--angle': '180deg'
|
67
|
+
},
|
68
|
+
':global([data-popper-placement^="left"])': {
|
69
|
+
right: 0,
|
70
|
+
'--angle': '270deg'
|
71
|
+
}
|
72
|
+
};
|
73
|
+
};
|
74
|
+
}
|
75
|
+
//# sourceMappingURL=createArrowStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createArrowStyles.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACH,OAAM,SAAU,iBAAV,CAA4B,IAA5B,EAAyC;AAC7C,SAAO,KAAK,IAAG;AACb,UAAM,kBAAkB,GAAG,uBAA3B;AACA,UAAM,aAAa,GAAG;AACpB,MAAA,WAAW,EAAE,kBADO;AAEpB,MAAA,YAAY,EAAE;AAFM,KAAtB;AAKA,WAAO;AACL,MAAA,QAAQ,EAAE,UADL;AAEL,MAAA,UAAU,EAAE,SAFP;AAGL,MAAA,UAAU,EAAE,QAHP;AAIL,MAAA,MAAM,EAAE,CAAC,CAJJ;AAML,UAAI,IAAI,IAAI;AACV,QAAA,WAAW,EAAE,CADH;AAEV,QAAA,KAAK,EAAE,GAAG,IAAI;AAFJ,OAAZ,CANK;AAWL,iBAAW;AACT,QAAA,OAAO,EAAE,IADA;AAET,QAAA,YAAY,EAAE,KAFL;AAGT,QAAA,QAAQ,EAAE,UAHD;AAIT,QAAA,KAAK,EAAE,SAJE;AAKT,QAAA,MAAM,EAAE,SALC;AAMT,QAAA,UAAU,EAAE,SANH;AAOT,QAAA,UAAU,EAAE,SAPH;AAQT,QAAA,uBAAuB,EAAE,KAAK,CAAC,iBARtB;AAST,QAAA,SAAS,EAAE;AATF,OAXN;AAuBL,0CAAoC;AAClC,mBAAW;AADuB,OAvB/B;AA2BL;AACA,iDAA2C;AACzC,QAAA,MAAM,EAAE,CADiC;AAEzC,mBAAW;AAF8B,OA5BtC;AAiCL,mDAA6C;AAC3C,QAAA,IAAI,EAAE,CADqC;AAE3C,mBAAW;AAFgC,OAjCxC;AAqCL,oDAA8C;AAC5C,QAAA,GAAG,EAAE,CADuC;AAE5C,mBAAW;AAFiC,OArCzC;AAyCL,kDAA4C;AAC1C,QAAA,KAAK,EAAE,CADmC;AAE1C,mBAAW;AAF+B;AAzCvC,KAAP;AA8CD,GArDD;AAsDD","sourceRoot":""}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { PopperVirtualElement } from './types';
|
2
|
+
/**
|
3
|
+
* Creates a virtual element based on the position of a click event
|
4
|
+
* Can be used as a target for popper in scenarios such as context menus
|
5
|
+
*/
|
6
|
+
export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* Creates a virtual element based on the position of a click event
|
3
|
+
* Can be used as a target for popper in scenarios such as context menus
|
4
|
+
*/
|
5
|
+
export function createVirtualElementFromClick(nativeEvent) {
|
6
|
+
const left = nativeEvent.clientX;
|
7
|
+
const top = nativeEvent.clientY;
|
8
|
+
const right = left + 1;
|
9
|
+
const bottom = top + 1;
|
10
|
+
|
11
|
+
function getBoundingClientRect() {
|
12
|
+
return {
|
13
|
+
left,
|
14
|
+
top,
|
15
|
+
right,
|
16
|
+
bottom,
|
17
|
+
height: 1,
|
18
|
+
width: 1
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
return {
|
23
|
+
getBoundingClientRect
|
24
|
+
};
|
25
|
+
}
|
26
|
+
//# sourceMappingURL=createVirtualElementFromClick.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;AAGG;AACH,OAAM,SAAU,6BAAV,CAAwC,WAAxC,EAA+D;AACnE,QAAM,IAAI,GAAG,WAAW,CAAC,OAAzB;AACA,QAAM,GAAG,GAAG,WAAW,CAAC,OAAxB;AACA,QAAM,KAAK,GAAG,IAAI,GAAG,CAArB;AACA,QAAM,MAAM,GAAG,GAAG,GAAG,CAArB;;AAEA,WAAS,qBAAT,GAA8B;AAC5B,WAAO;AACL,MAAA,IADK;AAEL,MAAA,GAFK;AAGL,MAAA,KAHK;AAIL,MAAA,MAJK;AAML,MAAA,MAAM,EAAE,CANH;AAOL,MAAA,KAAK,EAAE;AAPF,KAAP;AASD;;AAED,SAAO;AACL,IAAA;AADK,GAAP;AAGD","sourceRoot":""}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -1,2 +1,7 @@
|
|
1
|
+
export * from './createVirtualElementFromClick';
|
2
|
+
export * from './createArrowStyles';
|
1
3
|
export * from './usePopper';
|
4
|
+
export * from './usePopperMouseTarget';
|
5
|
+
export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
|
6
|
+
export * from './types';
|
2
7
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,cAAc,SAAS,CAAC"}
|
package/lib/tsdoc-metadata.json
CHANGED
package/lib/types.d.ts
CHANGED
@@ -9,21 +9,21 @@ export declare type OffsetFunction = (param: OffsetFunctionParam) => [number | n
|
|
9
9
|
export declare type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];
|
10
10
|
export declare type Position = 'above' | 'below' | 'before' | 'after';
|
11
11
|
export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
12
|
+
export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
|
12
13
|
export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
|
13
14
|
export declare type PopperRefHandle = {
|
14
15
|
updatePosition: () => void;
|
15
16
|
};
|
17
|
+
export declare type PopperVirtualElement = PopperJs.VirtualElement;
|
16
18
|
export interface PositioningProps {
|
17
|
-
/**
|
18
|
-
* Alignment for the component.
|
19
|
-
*/
|
19
|
+
/** Alignment for the component. Only has an effect if used with the @see position option */
|
20
20
|
align?: Alignment;
|
21
21
|
/** The element which will define the boundaries of the popper position for the flip behavior. */
|
22
22
|
flipBoundary?: Boundary;
|
23
23
|
/** The element which will define the boundaries of the popper position for the overflow behavior. */
|
24
24
|
overflowBoundary?: Boundary;
|
25
25
|
/** An imperative handle to Popper methods. */
|
26
|
-
|
26
|
+
popperRef?: React.Ref<PopperRefHandle>;
|
27
27
|
/**
|
28
28
|
* Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
|
29
29
|
* and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
|
@@ -31,11 +31,6 @@ export interface PositioningProps {
|
|
31
31
|
* then provided value for 'align' will be ignored and 'center' will be used instead.
|
32
32
|
*/
|
33
33
|
position?: Position;
|
34
|
-
/**
|
35
|
-
* Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
|
36
|
-
* @default false
|
37
|
-
*/
|
38
|
-
positionFixed?: boolean;
|
39
34
|
/**
|
40
35
|
* Lets you displace a popper element from its reference element.
|
41
36
|
* This can be useful if you need to apply some margin between them or if you need to fine tune the
|
@@ -48,31 +43,26 @@ export interface PositioningProps {
|
|
48
43
|
*/
|
49
44
|
arrowPadding?: number;
|
50
45
|
/**
|
51
|
-
*
|
52
|
-
*
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
* Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
|
57
|
-
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
46
|
+
* Applies max-height and max-width on popper to fit it within the available space in viewport.
|
47
|
+
* true enables this for both width and height when overflow happens.
|
48
|
+
* 'always' applies `max-height`/`max-width` regardless of overflow.
|
49
|
+
* 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
|
50
|
+
* `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
|
58
51
|
*/
|
59
|
-
|
52
|
+
autoSize?: AutoSize;
|
60
53
|
/**
|
61
|
-
*
|
62
|
-
* true enables this for both width and height.
|
63
|
-
* 'height' applies only `max-height` and 'width' for `max-width`
|
54
|
+
* Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
|
64
55
|
*/
|
65
|
-
|
66
|
-
}
|
67
|
-
export interface PopperOptions extends PositioningProps {
|
56
|
+
target?: HTMLElement | PopperVirtualElement | null;
|
68
57
|
/**
|
69
|
-
*
|
70
|
-
* @default true
|
58
|
+
* Modifies position and alignment to cover the target
|
71
59
|
*/
|
72
|
-
|
60
|
+
coverTarget?: boolean;
|
73
61
|
/**
|
74
|
-
*
|
62
|
+
* Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
|
63
|
+
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
75
64
|
*/
|
76
|
-
|
77
|
-
onStateUpdate?: (state: Partial<PopperJs.State>) => void;
|
65
|
+
pinned?: boolean;
|
78
66
|
}
|
67
|
+
export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
|
68
|
+
export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
|
package/lib/types.js
CHANGED
package/lib/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/lib/usePopper.d.ts
CHANGED
@@ -1,5 +1,24 @@
|
|
1
|
+
import * as PopperJs from '@popperjs/core';
|
1
2
|
import * as React from 'react';
|
2
|
-
import {
|
3
|
+
import type { PositioningProps } from './types';
|
4
|
+
interface PopperOptions extends PositioningProps {
|
5
|
+
/**
|
6
|
+
* If false, delays Popper's creation.
|
7
|
+
* @default true
|
8
|
+
*/
|
9
|
+
enabled?: boolean;
|
10
|
+
onStateUpdate?: (state: Partial<PopperJs.State>) => void;
|
11
|
+
/**
|
12
|
+
* Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
|
13
|
+
* @default false
|
14
|
+
*/
|
15
|
+
positionFixed?: boolean;
|
16
|
+
/**
|
17
|
+
* When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
|
18
|
+
* "all" enables this behavior for all axis.
|
19
|
+
*/
|
20
|
+
unstable_disableTether?: boolean | 'all';
|
21
|
+
}
|
3
22
|
/**
|
4
23
|
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
5
24
|
* package:
|
@@ -13,3 +32,4 @@ export declare function usePopper(options?: PopperOptions): {
|
|
13
32
|
containerRef: React.MutableRefObject<any>;
|
14
33
|
arrowRef: React.MutableRefObject<any>;
|
15
34
|
};
|
35
|
+
export {};
|