@fluentui/react-positioning 9.0.0-nightly.d730088d7f.0 → 9.0.0-rc.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/CHANGELOG.json +457 -12
  2. package/CHANGELOG.md +209 -72
  3. package/dist/index.d.ts +247 -0
  4. package/{lib → dist}/tsdoc-metadata.json +0 -0
  5. package/lib/createArrowStyles.js +87 -0
  6. package/lib/createArrowStyles.js.map +1 -0
  7. package/lib/createVirtualElementFromClick.js +19 -15
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.js +4 -4
  10. package/lib/index.js.map +1 -1
  11. package/lib/isIntersectingModifier.js +26 -0
  12. package/lib/isIntersectingModifier.js.map +1 -0
  13. package/lib/types.js.map +1 -1
  14. package/lib/usePositioning.js +408 -0
  15. package/lib/usePositioning.js.map +1 -0
  16. package/lib/usePositioningMouseTarget.js +40 -0
  17. package/lib/usePositioningMouseTarget.js.map +1 -0
  18. package/lib/utils/fromPopperPlacement.js +40 -0
  19. package/lib/utils/fromPopperPlacement.js.map +1 -0
  20. package/lib/utils/getBoundary.js +15 -10
  21. package/lib/utils/getBoundary.js.map +1 -1
  22. package/lib/utils/getPopperOffset.js +44 -0
  23. package/lib/utils/getPopperOffset.js.map +1 -0
  24. package/lib/utils/getReactFiberFromNode.js +39 -35
  25. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  26. package/lib/utils/getScrollParent.js +46 -32
  27. package/lib/utils/getScrollParent.js.map +1 -1
  28. package/lib/utils/index.js +1 -1
  29. package/lib/utils/index.js.map +1 -1
  30. package/lib/utils/mergeArrowOffset.js +31 -25
  31. package/lib/utils/mergeArrowOffset.js.map +1 -1
  32. package/lib/utils/parsePopperPlacement.js +14 -0
  33. package/lib/utils/parsePopperPlacement.js.map +1 -0
  34. package/lib/utils/positioningHelper.js +42 -34
  35. package/lib/utils/positioningHelper.js.map +1 -1
  36. package/lib/utils/resolvePositioningShorthand.js +58 -20
  37. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  38. package/lib/utils/useCallbackRef.js +35 -29
  39. package/lib/utils/useCallbackRef.js.map +1 -1
  40. package/lib-commonjs/createArrowStyles.js +100 -0
  41. package/lib-commonjs/createArrowStyles.js.map +1 -0
  42. package/lib-commonjs/createVirtualElementFromClick.js +25 -16
  43. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  44. package/lib-commonjs/index.js +62 -10
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/isIntersectingModifier.js +34 -0
  47. package/lib-commonjs/isIntersectingModifier.js.map +1 -0
  48. package/lib-commonjs/types.js +4 -1
  49. package/lib-commonjs/types.js.map +1 -1
  50. package/lib-commonjs/usePositioning.js +424 -0
  51. package/lib-commonjs/usePositioning.js.map +1 -0
  52. package/lib-commonjs/usePositioningMouseTarget.js +51 -0
  53. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -0
  54. package/lib-commonjs/utils/fromPopperPlacement.js +50 -0
  55. package/lib-commonjs/utils/fromPopperPlacement.js.map +1 -0
  56. package/lib-commonjs/utils/getBoundary.js +23 -12
  57. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  58. package/lib-commonjs/utils/getPopperOffset.js +54 -0
  59. package/lib-commonjs/utils/getPopperOffset.js.map +1 -0
  60. package/lib-commonjs/utils/getReactFiberFromNode.js +44 -36
  61. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  62. package/lib-commonjs/utils/getScrollParent.js +53 -33
  63. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  64. package/lib-commonjs/utils/index.js +15 -3
  65. package/lib-commonjs/utils/index.js.map +1 -1
  66. package/lib-commonjs/utils/mergeArrowOffset.js +37 -26
  67. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  68. package/lib-commonjs/utils/parsePopperPlacement.js +23 -0
  69. package/lib-commonjs/utils/parsePopperPlacement.js.map +1 -0
  70. package/lib-commonjs/utils/positioningHelper.js +50 -35
  71. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  72. package/lib-commonjs/utils/resolvePositioningShorthand.js +66 -23
  73. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  74. package/lib-commonjs/utils/useCallbackRef.js +45 -32
  75. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  76. package/package.json +17 -14
  77. package/dist/react-positioning.d.ts +0 -143
  78. package/lib/createVirtualElementFromClick.d.ts +0 -6
  79. package/lib/index.d.ts +0 -5
  80. package/lib/types.d.ts +0 -68
  81. package/lib/usePopper.d.ts +0 -35
  82. package/lib/usePopper.js +0 -357
  83. package/lib/usePopper.js.map +0 -1
  84. package/lib/usePopperMouseTarget.d.ts +0 -11
  85. package/lib/usePopperMouseTarget.js +0 -34
  86. package/lib/usePopperMouseTarget.js.map +0 -1
  87. package/lib/utils/getBasePlacement.d.ts +0 -8
  88. package/lib/utils/getBasePlacement.js +0 -10
  89. package/lib/utils/getBasePlacement.js.map +0 -1
  90. package/lib/utils/getBoundary.d.ts +0 -6
  91. package/lib/utils/getReactFiberFromNode.d.ts +0 -109
  92. package/lib/utils/getScrollParent.d.ts +0 -12
  93. package/lib/utils/index.d.ts +0 -8
  94. package/lib/utils/mergeArrowOffset.d.ts +0 -10
  95. package/lib/utils/positioningHelper.d.ts +0 -7
  96. package/lib/utils/resolvePositioningShorthand.d.ts +0 -2
  97. package/lib/utils/useCallbackRef.d.ts +0 -19
  98. package/lib-commonjs/createVirtualElementFromClick.d.ts +0 -6
  99. package/lib-commonjs/index.d.ts +0 -5
  100. package/lib-commonjs/types.d.ts +0 -68
  101. package/lib-commonjs/usePopper.d.ts +0 -35
  102. package/lib-commonjs/usePopper.js +0 -361
  103. package/lib-commonjs/usePopper.js.map +0 -1
  104. package/lib-commonjs/usePopperMouseTarget.d.ts +0 -11
  105. package/lib-commonjs/usePopperMouseTarget.js +0 -38
  106. package/lib-commonjs/usePopperMouseTarget.js.map +0 -1
  107. package/lib-commonjs/utils/getBasePlacement.d.ts +0 -8
  108. package/lib-commonjs/utils/getBasePlacement.js +0 -14
  109. package/lib-commonjs/utils/getBasePlacement.js.map +0 -1
  110. package/lib-commonjs/utils/getBoundary.d.ts +0 -6
  111. package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -109
  112. package/lib-commonjs/utils/getScrollParent.d.ts +0 -12
  113. package/lib-commonjs/utils/index.d.ts +0 -8
  114. package/lib-commonjs/utils/mergeArrowOffset.d.ts +0 -10
  115. package/lib-commonjs/utils/positioningHelper.d.ts +0 -7
  116. package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +0 -2
  117. package/lib-commonjs/utils/useCallbackRef.d.ts +0 -19
@@ -0,0 +1,247 @@
1
+ import type { GriffelStyle } from '@griffel/react';
2
+ import * as React_2 from 'react';
3
+
4
+ export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
5
+
6
+ export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
7
+
8
+ export declare type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';
9
+
10
+ /**
11
+ * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
12
+ *
13
+ * Use this when you need to create classes for several different arrow sizes. If you only need a
14
+ * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
15
+ */
16
+ export declare function createArrowHeightStyles(arrowHeight: number): {
17
+ width: string;
18
+ height: string;
19
+ };
20
+
21
+ /**
22
+ * Helper that creates a makeStyles rule for an arrow element.
23
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
24
+ *
25
+ * ```ts
26
+ * makeStyles({
27
+ * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
28
+ *
29
+ * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
30
+ * mediumArrow: createArrowHeightStyles(4),
31
+ * smallArrow: createArrowHeightStyles(2),
32
+ * })
33
+ * ...
34
+ *
35
+ * state.arrowWithSize.className = styles.arrowWithSize;
36
+ * state.arrowWithoutSize.className = mergeClasses(
37
+ * styles.arrowWithoutSize,
38
+ * state.smallArrow && styles.smallArrow,
39
+ * state.mediumArrow && styles.mediumArrow,
40
+ * )
41
+ * ```
42
+ */
43
+ export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
44
+
45
+ /**
46
+ * Options parameter for the createArrowStyles function
47
+ */
48
+ export declare type CreateArrowStylesOptions = {
49
+ /**
50
+ * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.
51
+ *
52
+ * This can be undefined to leave out the arrow size styles. You must then add styles created by
53
+ * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.
54
+ */
55
+ arrowHeight: number | undefined;
56
+ /**
57
+ * The borderWidth of the arrow. Should be the same borderWidth as the parent element.
58
+ *
59
+ * @defaultvalue 1px
60
+ */
61
+ borderWidth?: GriffelStyle['borderBottomWidth'];
62
+ /**
63
+ * The borderStyle for the arrow. Should be the same borderStyle as the parent element.
64
+ *
65
+ * @defaultvalue solid
66
+ */
67
+ borderStyle?: GriffelStyle['borderBottomStyle'];
68
+ /**
69
+ * The borderColor of the arrow. Should be the same borderColor as the parent element.
70
+ *
71
+ * @defaultvalue tokens.colorTransparentStroke
72
+ */
73
+ borderColor?: GriffelStyle['borderBottomColor'];
74
+ };
75
+
76
+ /**
77
+ * Creates a virtual element based on the position of a click event
78
+ * Can be used as a target for popper in scenarios such as context menus
79
+ */
80
+ export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement;
81
+
82
+ /**
83
+ * Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
84
+ * height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
85
+ *
86
+ * @param userOffset - The offset provided by the user
87
+ * @param arrowHeight - The height of the arrow in px
88
+ * @returns User offset augmented with arrow height
89
+ */
90
+ export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
91
+
92
+ export declare type Offset = OffsetFunction | OffsetObject | OffsetShorthand;
93
+
94
+ export declare type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;
95
+
96
+ export declare type OffsetFunctionParam = {
97
+ positionedRect: Rect;
98
+ targetRect: Rect;
99
+ position: Position;
100
+ alignment?: Alignment;
101
+ };
102
+
103
+ export declare type OffsetObject = {
104
+ crossAxis?: number;
105
+ mainAxis: number;
106
+ };
107
+
108
+ export declare type OffsetShorthand = number;
109
+
110
+ export declare type Position = 'above' | 'below' | 'before' | 'after';
111
+
112
+ export declare type PositioningImperativeRef = {
113
+ /**
114
+ * Updates the position imperatively.
115
+ * Useful when the position of the target changes from other factors than scrolling of window resize.
116
+ */
117
+ updatePosition: () => void;
118
+ /**
119
+ * Sets the target and updates positioning imperatively.
120
+ * Useful for avoiding double renders with the target option.
121
+ */
122
+ setTarget: (target: HTMLElement | PositioningVirtualElement) => void;
123
+ };
124
+
125
+ declare interface PositioningOptions {
126
+ /** Alignment for the component. Only has an effect if used with the @see position option */
127
+ align?: Alignment;
128
+ /** The element which will define the boundaries of the positioned element for the flip behavior. */
129
+ flipBoundary?: Boundary;
130
+ /** The element which will define the boundaries of the positioned element for the overflow behavior. */
131
+ overflowBoundary?: Boundary;
132
+ /**
133
+ * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
134
+ * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
135
+ * and 'start' | 'end' respectively),
136
+ * then provided value for 'align' will be ignored and 'center' will be used instead.
137
+ */
138
+ position?: Position;
139
+ /**
140
+ * Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')
141
+ * @default false
142
+ */
143
+ positionFixed?: boolean;
144
+ /**
145
+ * Lets you displace a positioned element from its reference element.
146
+ * This can be useful if you need to apply some margin between them or if you need to fine tune the
147
+ * position according to some custom logic.
148
+ */
149
+ offset?: Offset;
150
+ /**
151
+ * Defines padding between the corner of the popup element and the arrow.
152
+ * Use to prevent the arrow from overlapping a rounded corner, for example.
153
+ */
154
+ arrowPadding?: number;
155
+ /**
156
+ * Applies max-height and max-width on the positioned element to fit it within the available space in viewport.
157
+ * true enables this for both width and height when overflow happens.
158
+ * 'always' applies `max-height`/`max-width` regardless of overflow.
159
+ * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
160
+ * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
161
+ */
162
+ autoSize?: AutoSize;
163
+ /**
164
+ * Modifies position and alignment to cover the target
165
+ */
166
+ coverTarget?: boolean;
167
+ /**
168
+ * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
169
+ * `position` props, regardless of the size of the component, the reference element or the viewport.
170
+ */
171
+ pinned?: boolean;
172
+ /**
173
+ * When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.
174
+ * "all" enables this behavior for all axis.
175
+ */
176
+ unstable_disableTether?: boolean | 'all';
177
+ }
178
+
179
+ export declare interface PositioningProps extends Omit<PositioningOptions, 'positionFixed' | 'unstable_disableTether'> {
180
+ /** An imperative handle to Popper methods. */
181
+ positioningRef?: React_2.Ref<PositioningImperativeRef>;
182
+ /**
183
+ * Manual override for the target element. Useful for scenarios where a component accepts user prop to override target
184
+ */
185
+ target?: HTMLElement | PositioningVirtualElement | null;
186
+ }
187
+
188
+ export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
189
+
190
+ export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
191
+
192
+ export declare type PositioningVirtualElement = {
193
+ getBoundingClientRect: () => {
194
+ x: number;
195
+ y: number;
196
+ top: number;
197
+ left: number;
198
+ bottom: number;
199
+ right: number;
200
+ width: number;
201
+ height: number;
202
+ };
203
+ contextElement?: Element;
204
+ };
205
+
206
+ declare type Rect = {
207
+ width: number;
208
+ height: number;
209
+ x: number;
210
+ y: number;
211
+ };
212
+
213
+ export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
214
+
215
+ declare interface UsePopperOptions extends PositioningProps {
216
+ /**
217
+ * If false, delays Popper's creation.
218
+ * @default true
219
+ */
220
+ enabled?: boolean;
221
+ }
222
+
223
+ /**
224
+ * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
225
+ * package:
226
+ * - style attributes are applied directly on DOM to avoid re-renders
227
+ * - refs changes and resolution is handled properly without re-renders
228
+ * - contains a specific to React fix related to initial positioning when containers have components with managed focus
229
+ * to avoid focus jumps
230
+ */
231
+ export declare function usePositioning(options?: UsePopperOptions): {
232
+ targetRef: React_2.MutableRefObject<any>;
233
+ containerRef: React_2.MutableRefObject<any>;
234
+ arrowRef: React_2.MutableRefObject<any>;
235
+ };
236
+
237
+ /**
238
+ * A state hook that manages a popper virtual element from mouseevents.
239
+ * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
240
+ * React synthetic events are not persisted by this hook
241
+ *
242
+ * @param initialState - initializes a user provided state similare to useState
243
+ * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
244
+ */
245
+ export declare const usePositioningMouseTarget: (initialState?: PositioningVirtualElement | (() => PositioningVirtualElement) | undefined) => readonly [PositioningVirtualElement | undefined, (event: React_2.MouseEvent | MouseEvent | undefined | null) => void];
246
+
247
+ export { }
File without changes
@@ -0,0 +1,87 @@
1
+ import { shorthands } from '@griffel/react';
2
+ import { tokens } 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({ arrowHeight: 6 }),
10
+ *
11
+ * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
12
+ * mediumArrow: createArrowHeightStyles(4),
13
+ * smallArrow: createArrowHeightStyles(2),
14
+ * })
15
+ * ...
16
+ *
17
+ * state.arrowWithSize.className = styles.arrowWithSize;
18
+ * state.arrowWithoutSize.className = mergeClasses(
19
+ * styles.arrowWithoutSize,
20
+ * state.smallArrow && styles.smallArrow,
21
+ * state.mediumArrow && styles.mediumArrow,
22
+ * )
23
+ * ```
24
+ */
25
+
26
+ export function createArrowStyles(options) {
27
+ const {
28
+ arrowHeight,
29
+ borderWidth = '1px',
30
+ borderStyle = 'solid',
31
+ borderColor = tokens.colorTransparentStroke
32
+ } = options;
33
+ return {
34
+ position: 'absolute',
35
+ backgroundColor: 'inherit',
36
+ visibility: 'hidden',
37
+ zIndex: -1,
38
+ ...(arrowHeight && createArrowHeightStyles(arrowHeight)),
39
+ ':before': {
40
+ content: '""',
41
+ visibility: 'visible',
42
+ position: 'absolute',
43
+ boxSizing: 'border-box',
44
+ width: 'inherit',
45
+ height: 'inherit',
46
+ backgroundColor: 'inherit',
47
+ ...shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
48
+ ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),
49
+ borderBottomRightRadius: tokens.borderRadiusSmall,
50
+ transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
51
+ },
52
+ // Popper sets data-popper-placement on the root element, which is used to align the arrow
53
+ ':global([data-popper-placement^="top"])': {
54
+ bottom: `-${borderWidth}`,
55
+ '--angle': '0'
56
+ },
57
+ ':global([data-popper-placement^="right"])': {
58
+ left: `-${borderWidth} /* @noflip */`,
59
+ '--angle': '90deg'
60
+ },
61
+ ':global([data-popper-placement^="bottom"])': {
62
+ top: `-${borderWidth}`,
63
+ '--angle': '180deg'
64
+ },
65
+ ':global([data-popper-placement^="left"])': {
66
+ right: `-${borderWidth} /* @noflip */`,
67
+ '--angle': '270deg'
68
+ }
69
+ };
70
+ }
71
+ /**
72
+ * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
73
+ *
74
+ * Use this when you need to create classes for several different arrow sizes. If you only need a
75
+ * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
76
+ */
77
+
78
+ export function createArrowHeightStyles(arrowHeight) {
79
+ // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
80
+ // Multiply the triangle's height by sqrt(2) to get length of its edges.
81
+ const edgeLength = `${1.414 * arrowHeight}px`;
82
+ return {
83
+ width: edgeLength,
84
+ height: edgeLength
85
+ };
86
+ }
87
+ //# sourceMappingURL=createArrowStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createArrowStyles.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,gBAA3B;AACA,SAAS,MAAT,QAAuB,uBAAvB;AAqCA;;;;;;;;;;;;;;;;;;;;;AAqBG;;AACH,OAAM,SAAU,iBAAV,CAA4B,OAA5B,EAA6D;AACjE,QAAM;AACJ,IAAA,WADI;AAEJ,IAAA,WAAW,GAAG,KAFV;AAGJ,IAAA,WAAW,GAAG,OAHV;AAIJ,IAAA,WAAW,GAAG,MAAM,CAAC;AAJjB,MAKF,OALJ;AAOA,SAAO;AACL,IAAA,QAAQ,EAAE,UADL;AAEL,IAAA,eAAe,EAAE,SAFZ;AAGL,IAAA,UAAU,EAAE,QAHP;AAIL,IAAA,MAAM,EAAE,CAAC,CAJJ;AAML,QAAI,WAAW,IAAI,uBAAuB,CAAC,WAAD,CAA1C,CANK;AAQL,eAAW;AACT,MAAA,OAAO,EAAE,IADA;AAET,MAAA,UAAU,EAAE,SAFH;AAGT,MAAA,QAAQ,EAAE,UAHD;AAIT,MAAA,SAAS,EAAE,YAJF;AAKT,MAAA,KAAK,EAAE,SALE;AAMT,MAAA,MAAM,EAAE,SANC;AAOT,MAAA,eAAe,EAAE,SAPR;AAQT,SAAG,UAAU,CAAC,WAAX,CACD,GAAG,WAAW,gBADb,EAED,GAAG,WAAW,gBAFb,EAGD,GAAG,WAAW,gBAHb,CARM;AAaT,SAAG,UAAU,CAAC,YAAX,CAAwB,WAAxB,EAAqC,WAArC,EAAkD,WAAlD,CAbM;AAcT,MAAA,uBAAuB,EAAE,MAAM,CAAC,iBAdvB;AAeT,MAAA,SAAS,EAAE;AAfF,KARN;AA0BL;AACA,+CAA2C;AACzC,MAAA,MAAM,EAAE,IAAI,WAAW,EADkB;AAEzC,iBAAW;AAF8B,KA3BtC;AA+BL,iDAA6C;AAC3C,MAAA,IAAI,EAAE,IAAI,WAAW,gBADsB;AAE3C,iBAAW;AAFgC,KA/BxC;AAmCL,kDAA8C;AAC5C,MAAA,GAAG,EAAE,IAAI,WAAW,EADwB;AAE5C,iBAAW;AAFiC,KAnCzC;AAuCL,gDAA4C;AAC1C,MAAA,KAAK,EAAE,IAAI,WAAW,gBADoB;AAE1C,iBAAW;AAF+B;AAvCvC,GAAP;AA4CD;AAED;;;;;AAKG;;AACH,OAAM,SAAU,uBAAV,CAAkC,WAAlC,EAAqD;AACzD;AACA;AACA,QAAM,UAAU,GAAG,GAAG,QAAQ,WAAW,IAAzC;AACA,SAAO;AAAE,IAAA,KAAK,EAAE,UAAT;AAAqB,IAAA,MAAM,EAAE;AAA7B,GAAP;AACD","sourcesContent":["import { shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n ':before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"sourceRoot":"../src/"}
@@ -3,22 +3,26 @@
3
3
  * Can be used as a target for popper in scenarios such as context menus
4
4
  */
5
5
  export function createVirtualElementFromClick(nativeEvent) {
6
- var left = nativeEvent.clientX;
7
- var top = nativeEvent.clientY;
8
- var right = left + 1;
9
- var bottom = top + 1;
10
- function getBoundingClientRect() {
11
- return {
12
- left: left,
13
- top: top,
14
- right: right,
15
- bottom: bottom,
16
- height: 1,
17
- width: 1,
18
- };
19
- }
6
+ const left = nativeEvent.clientX;
7
+ const top = nativeEvent.clientY;
8
+ const right = left + 1;
9
+ const bottom = top + 1;
10
+
11
+ function getBoundingClientRect() {
20
12
  return {
21
- getBoundingClientRect: getBoundingClientRect,
13
+ left,
14
+ top,
15
+ right,
16
+ bottom,
17
+ x: left,
18
+ y: top,
19
+ height: 1,
20
+ width: 1
22
21
  };
22
+ }
23
+
24
+ return {
25
+ getBoundingClientRect
26
+ };
23
27
  }
24
28
  //# sourceMappingURL=createVirtualElementFromClick.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createVirtualElementFromClick.js","sourceRoot":"","sources":["../src/createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,WAAuB;IACnE,IAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IACjC,IAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC;IAChC,IAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,IAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;IAEvB,SAAS,qBAAqB;QAC5B,OAAO;YACL,IAAI,MAAA;YACJ,GAAG,KAAA;YACH,KAAK,OAAA;YACL,MAAM,QAAA;YAEN,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;IAED,OAAO;QACL,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"sources":["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;AAKL,MAAA,CAAC,EAAE,IALE;AAML,MAAA,CAAC,EAAE,GANE;AAOL,MAAA,MAAM,EAAE,CAPH;AAQL,MAAA,KAAK,EAAE;AARF,KAAP;AAUD;;AAED,SAAO;AACL,IAAA;AADK,GAAP;AAGD","sourcesContent":["import type { PositioningVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect() {\n return {\n left,\n top,\n right,\n bottom,\n x: left,\n y: top,\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"sourceRoot":"../src/"}
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from './usePopper';
2
- export * from './createVirtualElementFromClick';
3
- export * from './usePopperMouseTarget';
1
+ export { createVirtualElementFromClick } from './createVirtualElementFromClick';
2
+ export { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';
3
+ export { usePositioning } from './usePositioning';
4
+ export { usePositioningMouseTarget } from './usePositioningMouseTarget';
4
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
5
- export * from './types';
6
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport type {\n Alignment,\n AutoSize,\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningImperativeRef,\n PositioningProps,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n} from './types';\n"]}
@@ -0,0 +1,26 @@
1
+ import { detectOverflow } from '@popperjs/core';
2
+ export const isIntersectingModifier = {
3
+ name: 'is-intersecting-modifier',
4
+ enabled: true,
5
+ phase: 'main',
6
+ requires: ['preventOverflow'],
7
+ fn: ({
8
+ state,
9
+ name
10
+ }) => {
11
+ const popperRect = state.rects.popper;
12
+ const popperAltOverflow = detectOverflow(state, {
13
+ altBoundary: true
14
+ });
15
+ const isIntersectingTop = popperAltOverflow.top < popperRect.height && popperAltOverflow.top > 0;
16
+ const isIntersectingBottom = popperAltOverflow.bottom < popperRect.height && popperAltOverflow.bottom > 0;
17
+ const isIntersecting = isIntersectingTop || isIntersectingBottom;
18
+ state.modifiersData[name] = {
19
+ isIntersecting
20
+ };
21
+ state.attributes.popper = { ...state.attributes.popper,
22
+ 'data-popper-is-intersecting': isIntersecting
23
+ };
24
+ }
25
+ };
26
+ //# sourceMappingURL=isIntersectingModifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["isIntersectingModifier.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAAyC,gBAAzC;AAEA,OAAO,MAAM,sBAAsB,GAA2B;AAC5D,EAAA,IAAI,EAAE,0BADsD;AAE5D,EAAA,OAAO,EAAE,IAFmD;AAG5D,EAAA,KAAK,EAAE,MAHqD;AAI5D,EAAA,QAAQ,EAAE,CAAC,iBAAD,CAJkD;AAK5D,EAAA,EAAE,EAAE,CAAC;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,GAAD,KAAoB;AACtB,UAAM,UAAU,GAAG,KAAK,CAAC,KAAN,CAAY,MAA/B;AACA,UAAM,iBAAiB,GAAG,cAAc,CAAC,KAAD,EAAQ;AAAE,MAAA,WAAW,EAAE;AAAf,KAAR,CAAxC;AAEA,UAAM,iBAAiB,GAAG,iBAAiB,CAAC,GAAlB,GAAwB,UAAU,CAAC,MAAnC,IAA6C,iBAAiB,CAAC,GAAlB,GAAwB,CAA/F;AACA,UAAM,oBAAoB,GAAG,iBAAiB,CAAC,MAAlB,GAA2B,UAAU,CAAC,MAAtC,IAAgD,iBAAiB,CAAC,MAAlB,GAA2B,CAAxG;AAEA,UAAM,cAAc,GAAG,iBAAiB,IAAI,oBAA5C;AAEA,IAAA,KAAK,CAAC,aAAN,CAAoB,IAApB,IAA4B;AAC1B,MAAA;AAD0B,KAA5B;AAGA,IAAA,KAAK,CAAC,UAAN,CAAiB,MAAjB,GAA0B,EACxB,GAAG,KAAK,CAAC,UAAN,CAAiB,MADI;AAExB,qCAA+B;AAFP,KAA1B;AAID;AArB2D,CAAvD","sourcesContent":["import { detectOverflow, Modifier } from '@popperjs/core';\n\nexport const isIntersectingModifier: IsIntersectingModifier = {\n name: 'is-intersecting-modifier',\n enabled: true,\n phase: 'main',\n requires: ['preventOverflow'],\n fn: ({ state, name }) => {\n const popperRect = state.rects.popper;\n const popperAltOverflow = detectOverflow(state, { altBoundary: true });\n\n const isIntersectingTop = popperAltOverflow.top < popperRect.height && popperAltOverflow.top > 0;\n const isIntersectingBottom = popperAltOverflow.bottom < popperRect.height && popperAltOverflow.bottom > 0;\n\n const isIntersecting = isIntersectingTop || isIntersectingBottom;\n\n state.modifiersData[name] = {\n isIntersecting,\n };\n state.attributes.popper = {\n ...state.attributes.popper,\n 'data-popper-is-intersecting': isIntersecting,\n };\n },\n};\n\ntype IsIntersectingModifier = Modifier<'is-intersecting-modifier', never>;\n"],"sourceRoot":"../src/"}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\ntype Rect = {\n width: number;\n height: number;\n x: number;\n y: number;\n};\n\nexport type OffsetFunctionParam = {\n positionedRect: Rect;\n targetRect: Rect;\n position: Position;\n alignment?: Alignment;\n};\n\nexport type OffsetObject = { crossAxis?: number; mainAxis: number };\n\nexport type OffsetShorthand = number;\n\nexport type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;\n\nexport type Offset = OffsetFunction | OffsetObject | OffsetShorthand;\n\nexport type Position = 'above' | 'below' | 'before' | 'after';\nexport type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';\n\nexport type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;\n\nexport type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';\n\nexport type PositioningImperativeRef = {\n /**\n * Updates the position imperatively.\n * Useful when the position of the target changes from other factors than scrolling of window resize.\n */\n updatePosition: () => void;\n\n /**\n * Sets the target and updates positioning imperatively.\n * Useful for avoiding double renders with the target option.\n */\n setTarget: (target: HTMLElement | PositioningVirtualElement) => void;\n};\n\nexport type PositioningVirtualElement = {\n getBoundingClientRect: () => {\n x: number;\n y: number;\n top: number;\n left: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n };\n contextElement?: Element;\n};\n\nexport interface PositioningOptions {\n /** Alignment for the component. Only has an effect if used with the @see position option */\n align?: Alignment;\n\n /** The element which will define the boundaries of the positioned element for the flip behavior. */\n flipBoundary?: Boundary;\n\n /** The element which will define the boundaries of the positioned element for the overflow behavior. */\n overflowBoundary?: Boundary;\n\n /**\n * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')\n * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'\n * and 'start' | 'end' respectively),\n * then provided value for 'align' will be ignored and 'center' will be used instead.\n */\n position?: Position;\n\n /**\n * Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')\n * @default false\n */\n positionFixed?: boolean;\n\n /**\n * Lets you displace a positioned element from its reference element.\n * This can be useful if you need to apply some margin between them or if you need to fine tune the\n * position according to some custom logic.\n */\n offset?: Offset;\n\n /**\n * Defines padding between the corner of the popup element and the arrow.\n * Use to prevent the arrow from overlapping a rounded corner, for example.\n */\n arrowPadding?: number;\n\n /**\n * Applies max-height and max-width on the positioned element to fit it within the available space in viewport.\n * true enables this for both width and height when overflow happens.\n * 'always' applies `max-height`/`max-width` regardless of overflow.\n * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`\n * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`\n */\n autoSize?: AutoSize;\n\n /**\n * Modifies position and alignment to cover the target\n */\n coverTarget?: boolean;\n\n /**\n * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and\n * `position` props, regardless of the size of the component, the reference element or the viewport.\n */\n pinned?: boolean;\n\n /**\n * When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.\n * \"all\" enables this behavior for all axis.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether?: boolean | 'all';\n}\n\nexport interface PositioningProps\n // \"positionFixed\" & \"unstable_disableTether\" are not exported as public API (yet)\n extends Omit<PositioningOptions, 'positionFixed' | 'unstable_disableTether'> {\n /** An imperative handle to Popper methods. */\n positioningRef?: React.Ref<PositioningImperativeRef>;\n\n /**\n * Manual override for the target element. Useful for scenarios where a component accepts user prop to override target\n */\n target?: HTMLElement | PositioningVirtualElement | null;\n}\n\nexport type PositioningShorthandValue =\n | 'above'\n | 'above-start'\n | 'above-end'\n | 'below'\n | 'below-start'\n | 'below-end'\n | 'before'\n | 'before-top'\n | 'before-bottom'\n | 'after'\n | 'after-top'\n | 'after-bottom';\n\nexport type PositioningShorthand = PositioningProps | PositioningShorthandValue;\n"]}