@fluentui/react-positioning 0.0.0-nightly65dd5f749420211213.1 → 0.0.0-nightly695230dc7220220301.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +133 -14
- package/CHANGELOG.md +46 -9
- package/dist/react-positioning.d.ts +95 -45
- package/lib/createArrowStyles.d.ts +46 -9
- package/lib/createArrowStyles.js +42 -28
- package/lib/createArrowStyles.js.map +1 -1
- package/lib/createVirtualElementFromClick.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/isIntersectingModifier.d.ts +4 -0
- package/lib/isIntersectingModifier.js +26 -0
- package/lib/isIntersectingModifier.js.map +1 -0
- package/lib/types.d.ts +28 -7
- package/lib/types.js.map +1 -1
- package/lib/usePopper.d.ts +2 -14
- package/lib/usePopper.js +42 -35
- package/lib/usePopper.js.map +1 -1
- package/lib/usePopperMouseTarget.js.map +1 -1
- package/lib/utils/getBasePlacement.js.map +1 -1
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getReactFiberFromNode.js.map +1 -1
- package/lib/utils/getScrollParent.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeArrowOffset.js.map +1 -1
- package/lib/utils/positioningHelper.js.map +1 -1
- package/lib/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/createArrowStyles.d.ts +46 -9
- package/lib-commonjs/createArrowStyles.js +46 -29
- package/lib-commonjs/createArrowStyles.js.map +1 -1
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/isIntersectingModifier.d.ts +4 -0
- package/lib-commonjs/isIntersectingModifier.js +34 -0
- package/lib-commonjs/isIntersectingModifier.js.map +1 -0
- package/lib-commonjs/types.d.ts +28 -7
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/usePopper.d.ts +2 -14
- package/lib-commonjs/usePopper.js +44 -36
- package/lib-commonjs/usePopper.js.map +1 -1
- package/lib-commonjs/usePopperMouseTarget.js.map +1 -1
- package/lib-commonjs/utils/getBasePlacement.js.map +1 -1
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
- package/lib-commonjs/utils/positioningHelper.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/package.json +7 -7
@@ -1,27 +1,64 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type { GriffelStyle } from '@griffel/react';
|
2
|
+
/**
|
3
|
+
* Options parameter for the createArrowStyles function
|
4
|
+
*/
|
5
|
+
export declare type CreateArrowStylesOptions = {
|
6
|
+
/**
|
7
|
+
* The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.
|
8
|
+
*
|
9
|
+
* This can be undefined to leave out the arrow size styles. You must then add styles created by
|
10
|
+
* createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.
|
11
|
+
*/
|
12
|
+
arrowHeight: number | undefined;
|
13
|
+
/**
|
14
|
+
* The borderWidth of the arrow. Should be the same borderWidth as the parent element.
|
15
|
+
*
|
16
|
+
* @defaultvalue 1px
|
17
|
+
*/
|
18
|
+
borderWidth?: GriffelStyle['borderBottomWidth'];
|
19
|
+
/**
|
20
|
+
* The borderStyle for the arrow. Should be the same borderStyle as the parent element.
|
21
|
+
*
|
22
|
+
* @defaultvalue solid
|
23
|
+
*/
|
24
|
+
borderStyle?: GriffelStyle['borderBottomStyle'];
|
25
|
+
/**
|
26
|
+
* The borderColor of the arrow. Should be the same borderColor as the parent element.
|
27
|
+
*
|
28
|
+
* @defaultvalue tokens.colorTransparentStroke
|
29
|
+
*/
|
30
|
+
borderColor?: GriffelStyle['borderBottomColor'];
|
31
|
+
};
|
3
32
|
/**
|
4
33
|
* Helper that creates a makeStyles rule for an arrow element.
|
5
34
|
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
6
35
|
*
|
7
36
|
* ```ts
|
8
37
|
* makeStyles({
|
9
|
-
* arrowWithSize: createArrowStyles(
|
38
|
+
* arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
|
10
39
|
*
|
11
|
-
* arrowWithoutSize: createArrowStyles(),
|
12
|
-
* mediumArrow:
|
13
|
-
* smallArrow:
|
40
|
+
* arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
|
41
|
+
* mediumArrow: createArrowHeightStyles(4),
|
42
|
+
* smallArrow: createArrowHeightStyles(2),
|
14
43
|
* })
|
15
44
|
* ...
|
16
45
|
*
|
17
|
-
* state.arrowWithSize.className = styles.arrowWithSize
|
46
|
+
* state.arrowWithSize.className = styles.arrowWithSize;
|
18
47
|
* state.arrowWithoutSize.className = mergeClasses(
|
19
48
|
* styles.arrowWithoutSize,
|
20
49
|
* state.smallArrow && styles.smallArrow,
|
21
50
|
* state.mediumArrow && styles.mediumArrow,
|
22
51
|
* )
|
23
52
|
* ```
|
53
|
+
*/
|
54
|
+
export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
|
55
|
+
/**
|
56
|
+
* Creates CSS styles to size the arrow created by createArrowStyles to the given height.
|
24
57
|
*
|
25
|
-
*
|
58
|
+
* Use this when you need to create classes for several different arrow sizes. If you only need a
|
59
|
+
* constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
|
26
60
|
*/
|
27
|
-
export declare function
|
61
|
+
export declare function createArrowHeightStyles(arrowHeight: number): {
|
62
|
+
width: string;
|
63
|
+
height: string;
|
64
|
+
};
|
@@ -3,81 +3,98 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.createArrowStyles = void 0;
|
6
|
+
exports.createArrowHeightStyles = exports.createArrowStyles = void 0;
|
7
7
|
|
8
|
-
const
|
8
|
+
const react_1 = /*#__PURE__*/require("@griffel/react");
|
9
|
+
|
10
|
+
const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
|
9
11
|
/**
|
10
12
|
* Helper that creates a makeStyles rule for an arrow element.
|
11
13
|
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
12
14
|
*
|
13
15
|
* ```ts
|
14
16
|
* makeStyles({
|
15
|
-
* arrowWithSize: createArrowStyles(
|
17
|
+
* arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
|
16
18
|
*
|
17
|
-
* arrowWithoutSize: createArrowStyles(),
|
18
|
-
* mediumArrow:
|
19
|
-
* smallArrow:
|
19
|
+
* arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
|
20
|
+
* mediumArrow: createArrowHeightStyles(4),
|
21
|
+
* smallArrow: createArrowHeightStyles(2),
|
20
22
|
* })
|
21
23
|
* ...
|
22
24
|
*
|
23
|
-
* state.arrowWithSize.className = styles.arrowWithSize
|
25
|
+
* state.arrowWithSize.className = styles.arrowWithSize;
|
24
26
|
* state.arrowWithoutSize.className = mergeClasses(
|
25
27
|
* styles.arrowWithoutSize,
|
26
28
|
* state.smallArrow && styles.smallArrow,
|
27
29
|
* state.mediumArrow && styles.mediumArrow,
|
28
30
|
* )
|
29
31
|
* ```
|
30
|
-
*
|
31
|
-
* @param size - dimensions of the square arrow element in pixels.
|
32
32
|
*/
|
33
33
|
|
34
34
|
|
35
|
-
function createArrowStyles(
|
36
|
-
|
35
|
+
function createArrowStyles(options) {
|
36
|
+
const {
|
37
|
+
arrowHeight,
|
38
|
+
borderWidth = '1px',
|
39
|
+
borderStyle = 'solid',
|
40
|
+
borderColor = react_theme_1.tokens.colorTransparentStroke
|
41
|
+
} = options;
|
42
|
+
return {
|
37
43
|
position: 'absolute',
|
38
44
|
backgroundColor: 'inherit',
|
39
45
|
visibility: 'hidden',
|
40
46
|
zIndex: -1,
|
41
|
-
...(
|
42
|
-
aspectRatio: '1',
|
43
|
-
width: `${size}px`
|
44
|
-
}),
|
47
|
+
...(arrowHeight && createArrowHeightStyles(arrowHeight)),
|
45
48
|
':before': {
|
46
49
|
content: '""',
|
47
|
-
|
50
|
+
visibility: 'visible',
|
48
51
|
position: 'absolute',
|
52
|
+
boxSizing: 'border-box',
|
49
53
|
width: 'inherit',
|
50
54
|
height: 'inherit',
|
51
55
|
backgroundColor: 'inherit',
|
52
|
-
|
53
|
-
|
56
|
+
...react_1.shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
|
57
|
+
...react_1.shorthands.borderBottom(borderWidth, borderStyle, borderColor),
|
58
|
+
borderBottomRightRadius: react_theme_1.tokens.borderRadiusSmall,
|
54
59
|
transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
|
55
60
|
},
|
56
|
-
':global([data-popper-placement])': {
|
57
|
-
':before': { // Special border for High Contrast mode
|
58
|
-
...react_make_styles_1.shorthands.borderRight('1px', 'solid', 'transparent'),
|
59
|
-
...react_make_styles_1.shorthands.borderBottom('1px', 'solid', 'transparent')
|
60
|
-
}
|
61
|
-
},
|
62
61
|
// Popper sets data-popper-placement on the root element, which is used to align the arrow
|
63
62
|
':global([data-popper-placement^="top"])': {
|
64
|
-
bottom:
|
63
|
+
bottom: `-${borderWidth}`,
|
65
64
|
'--angle': '0'
|
66
65
|
},
|
67
66
|
':global([data-popper-placement^="right"])': {
|
68
|
-
left:
|
67
|
+
left: `-${borderWidth} /* @noflip */`,
|
69
68
|
'--angle': '90deg'
|
70
69
|
},
|
71
70
|
':global([data-popper-placement^="bottom"])': {
|
72
|
-
top:
|
71
|
+
top: `-${borderWidth}`,
|
73
72
|
'--angle': '180deg'
|
74
73
|
},
|
75
74
|
':global([data-popper-placement^="left"])': {
|
76
|
-
right:
|
75
|
+
right: `-${borderWidth} /* @noflip */`,
|
77
76
|
'--angle': '270deg'
|
78
77
|
}
|
79
|
-
}
|
78
|
+
};
|
80
79
|
}
|
81
80
|
|
82
81
|
exports.createArrowStyles = createArrowStyles;
|
82
|
+
/**
|
83
|
+
* Creates CSS styles to size the arrow created by createArrowStyles to the given height.
|
84
|
+
*
|
85
|
+
* Use this when you need to create classes for several different arrow sizes. If you only need a
|
86
|
+
* constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
|
87
|
+
*/
|
88
|
+
|
89
|
+
function createArrowHeightStyles(arrowHeight) {
|
90
|
+
// The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
|
91
|
+
// Multiply the triangle's height by sqrt(2) to get length of its edges.
|
92
|
+
const edgeLength = `${1.414 * arrowHeight}px`;
|
93
|
+
return {
|
94
|
+
width: edgeLength,
|
95
|
+
height: edgeLength
|
96
|
+
};
|
97
|
+
}
|
98
|
+
|
99
|
+
exports.createArrowHeightStyles = createArrowHeightStyles;
|
83
100
|
//# sourceMappingURL=createArrowStyles.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["createArrowStyles.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AACA,MAAA,aAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;AAqCA;;;;;;;;;;;;;;;;;;;;;AAqBG;;;AACH,SAAgB,iBAAhB,CAAkC,OAAlC,EAAmE;AACjE,QAAM;AACJ,IAAA,WADI;AAEJ,IAAA,WAAW,GAAG,KAFV;AAGJ,IAAA,WAAW,GAAG,OAHV;AAIJ,IAAA,WAAW,GAAG,aAAA,CAAA,MAAA,CAAO;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,OAAA,CAAA,UAAA,CAAW,WAAX,CACD,GAAG,WAAW,gBADb,EAED,GAAG,WAAW,gBAFb,EAGD,GAAG,WAAW,gBAHb,CARM;AAaT,SAAG,OAAA,CAAA,UAAA,CAAW,YAAX,CAAwB,WAAxB,EAAqC,WAArC,EAAkD,WAAlD,CAbM;AAcT,MAAA,uBAAuB,EAAE,aAAA,CAAA,MAAA,CAAO,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;;AApDD,OAAA,CAAA,iBAAA,GAAA,iBAAA;AAsDA;;;;;AAKG;;AACH,SAAgB,uBAAhB,CAAwC,WAAxC,EAA2D;AACzD;AACA;AACA,QAAM,UAAU,GAAG,GAAG,QAAQ,WAAW,IAAzC;AACA,SAAO;AAAE,IAAA,KAAK,EAAE,UAAT;AAAqB,IAAA,MAAM,EAAE;AAA7B,GAAP;AACD;;AALD,OAAA,CAAA,uBAAA,GAAA,uBAAA","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/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["createVirtualElementFromClick.ts"],"names":[],"mappings":";;;;;;AAEA;;;AAGG;;AACH,SAAgB,6BAAhB,CAA8C,WAA9C,EAAqE;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;;AArBD,OAAA,CAAA,6BAAA,GAAA,6BAAA","sourcesContent":["import type { PopperVirtualElement } 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): PopperVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect(): ClientRect {\n return {\n left,\n top,\n right,\n bottom,\n\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iCAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,IAAA,OAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,6BAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,OAAA,CAAA,2BAAA;AAA2B;AAA3B,CAAA;AAA6B,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;AAAA,EAAA,UAAA,EAAA,IAAA;AAAA,EAAA,GAAA,EAAA,YAAA;AAAA,WAAA,OAAA,CAAA,gBAAA;AAAgB;AAAhB,CAAA;;AACtC,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './createVirtualElementFromClick';\nexport * from './createArrowStyles';\nexport * from './usePopper';\nexport * from './usePopperMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport * from './types';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.isIntersectingModifier = void 0;
|
7
|
+
|
8
|
+
const core_1 = /*#__PURE__*/require("@popperjs/core");
|
9
|
+
|
10
|
+
exports.isIntersectingModifier = {
|
11
|
+
name: 'is-intersecting-modifier',
|
12
|
+
enabled: true,
|
13
|
+
phase: 'main',
|
14
|
+
requires: ['preventOverflow'],
|
15
|
+
fn: ({
|
16
|
+
state,
|
17
|
+
name
|
18
|
+
}) => {
|
19
|
+
const popperRect = state.rects.popper;
|
20
|
+
const popperAltOverflow = core_1.detectOverflow(state, {
|
21
|
+
altBoundary: true
|
22
|
+
});
|
23
|
+
const isIntersectingTop = popperAltOverflow.top < popperRect.height && popperAltOverflow.top > 0;
|
24
|
+
const isIntersectingBottom = popperAltOverflow.bottom < popperRect.height && popperAltOverflow.bottom > 0;
|
25
|
+
const isIntersecting = isIntersectingTop || isIntersectingBottom;
|
26
|
+
state.modifiersData[name] = {
|
27
|
+
isIntersecting
|
28
|
+
};
|
29
|
+
state.attributes.popper = { ...state.attributes.popper,
|
30
|
+
'data-popper-is-intersecting': isIntersecting
|
31
|
+
};
|
32
|
+
}
|
33
|
+
};
|
34
|
+
//# sourceMappingURL=isIntersectingModifier.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["isIntersectingModifier.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,MAAA,gBAAA,OAAA,CAAA,gBAAA,CAAA;;AAEa,OAAA,CAAA,sBAAA,GAAiD;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,MAAA,CAAA,cAAA,CAAe,KAAf,EAAsB;AAAE,MAAA,WAAW,EAAE;AAAf,KAAtB,CAA1B;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,CAAjD","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-commonjs/types.d.ts
CHANGED
@@ -12,18 +12,25 @@ export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
|
12
12
|
export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
|
13
13
|
export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
|
14
14
|
export declare type PopperRefHandle = {
|
15
|
+
/**
|
16
|
+
* Updates the position of the popper imperatively.
|
17
|
+
* Useful when the position of the target changes from other factors than scrolling of window resize.
|
18
|
+
*/
|
15
19
|
updatePosition: () => void;
|
20
|
+
/**
|
21
|
+
* Sets the target and updates positioning imperatively.
|
22
|
+
* Useful for avoiding double renders with the target option.
|
23
|
+
*/
|
24
|
+
setTarget: (target: HTMLElement) => void;
|
16
25
|
};
|
17
26
|
export declare type PopperVirtualElement = PopperJs.VirtualElement;
|
18
|
-
export interface
|
27
|
+
export interface PopperOptions {
|
19
28
|
/** Alignment for the component. Only has an effect if used with the @see position option */
|
20
29
|
align?: Alignment;
|
21
30
|
/** The element which will define the boundaries of the popper position for the flip behavior. */
|
22
31
|
flipBoundary?: Boundary;
|
23
32
|
/** The element which will define the boundaries of the popper position for the overflow behavior. */
|
24
33
|
overflowBoundary?: Boundary;
|
25
|
-
/** An imperative handle to Popper methods. */
|
26
|
-
popperRef?: React.Ref<PopperRefHandle>;
|
27
34
|
/**
|
28
35
|
* Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
|
29
36
|
* and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
|
@@ -31,6 +38,11 @@ export interface PositioningProps {
|
|
31
38
|
* then provided value for 'align' will be ignored and 'center' will be used instead.
|
32
39
|
*/
|
33
40
|
position?: Position;
|
41
|
+
/**
|
42
|
+
* Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
|
43
|
+
* @default false
|
44
|
+
*/
|
45
|
+
positionFixed?: boolean;
|
34
46
|
/**
|
35
47
|
* Lets you displace a popper element from its reference element.
|
36
48
|
* This can be useful if you need to apply some margin between them or if you need to fine tune the
|
@@ -50,10 +62,6 @@ export interface PositioningProps {
|
|
50
62
|
* `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
|
51
63
|
*/
|
52
64
|
autoSize?: AutoSize;
|
53
|
-
/**
|
54
|
-
* Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
|
55
|
-
*/
|
56
|
-
target?: HTMLElement | PopperVirtualElement | null;
|
57
65
|
/**
|
58
66
|
* Modifies position and alignment to cover the target
|
59
67
|
*/
|
@@ -63,6 +71,19 @@ export interface PositioningProps {
|
|
63
71
|
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
64
72
|
*/
|
65
73
|
pinned?: boolean;
|
74
|
+
/**
|
75
|
+
* When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
|
76
|
+
* "all" enables this behavior for all axis.
|
77
|
+
*/
|
78
|
+
unstable_disableTether?: boolean | 'all';
|
79
|
+
}
|
80
|
+
export interface PositioningProps extends Omit<PopperOptions, 'positionFixed' | 'unstable_disableTether'> {
|
81
|
+
/** An imperative handle to Popper methods. */
|
82
|
+
popperRef?: React.Ref<PopperRefHandle>;
|
83
|
+
/**
|
84
|
+
* Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
|
85
|
+
*/
|
86
|
+
target?: HTMLElement | PopperVirtualElement | null;
|
66
87
|
}
|
67
88
|
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
89
|
export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
@@ -1,23 +1,11 @@
|
|
1
|
-
import * as PopperJs from '@popperjs/core';
|
2
1
|
import * as React from 'react';
|
3
2
|
import type { PositioningProps } from './types';
|
4
|
-
interface
|
3
|
+
interface UsePopperOptions extends PositioningProps {
|
5
4
|
/**
|
6
5
|
* If false, delays Popper's creation.
|
7
6
|
* @default true
|
8
7
|
*/
|
9
8
|
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
9
|
}
|
22
10
|
/**
|
23
11
|
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
@@ -27,7 +15,7 @@ interface PopperOptions extends PositioningProps {
|
|
27
15
|
* - contains a specific to React fix related to initial positioning when containers have components with managed focus
|
28
16
|
* to avoid focus jumps
|
29
17
|
*/
|
30
|
-
export declare function usePopper(options?:
|
18
|
+
export declare function usePopper(options?: UsePopperOptions): {
|
31
19
|
targetRef: React.MutableRefObject<any>;
|
32
20
|
containerRef: React.MutableRefObject<any>;
|
33
21
|
arrowRef: React.MutableRefObject<any>;
|
@@ -9,11 +9,13 @@ const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
|
9
9
|
|
10
10
|
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
11
11
|
|
12
|
-
const index_1 = /*#__PURE__*/require("./utils/index");
|
13
|
-
|
14
12
|
const PopperJs = /*#__PURE__*/require("@popperjs/core");
|
15
13
|
|
16
|
-
const React = /*#__PURE__*/require("react");
|
14
|
+
const React = /*#__PURE__*/require("react");
|
15
|
+
|
16
|
+
const isIntersectingModifier_1 = /*#__PURE__*/require("./isIntersectingModifier");
|
17
|
+
|
18
|
+
const index_1 = /*#__PURE__*/require("./utils/index"); //
|
17
19
|
// Dev utils to detect if nodes have "autoFocus" props.
|
18
20
|
//
|
19
21
|
|
@@ -50,27 +52,22 @@ function hasAutofocusFilter(node) {
|
|
50
52
|
|
51
53
|
function usePopperOptions(options, popperOriginalPositionRef) {
|
52
54
|
const {
|
55
|
+
align,
|
53
56
|
arrowPadding,
|
54
57
|
autoSize,
|
55
58
|
coverTarget,
|
56
59
|
flipBoundary,
|
57
60
|
offset,
|
58
|
-
onStateUpdate,
|
59
61
|
overflowBoundary,
|
62
|
+
pinned,
|
63
|
+
position,
|
64
|
+
positionFixed,
|
60
65
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
61
|
-
unstable_disableTether
|
62
|
-
pinned
|
66
|
+
unstable_disableTether
|
63
67
|
} = options;
|
64
68
|
const isRtl = react_shared_contexts_1.useFluent().dir === 'rtl';
|
65
|
-
const placement = index_1.getPlacement(
|
66
|
-
const strategy =
|
67
|
-
const handleStateUpdate = react_utilities_1.useEventCallback(({
|
68
|
-
state
|
69
|
-
}) => {
|
70
|
-
if (onStateUpdate) {
|
71
|
-
onStateUpdate(state);
|
72
|
-
}
|
73
|
-
});
|
69
|
+
const placement = index_1.getPlacement(align, position, isRtl);
|
70
|
+
const strategy = positionFixed ? 'fixed' : 'absolute';
|
74
71
|
const offsetModifier = React.useMemo(() => offset ? {
|
75
72
|
name: 'offset',
|
76
73
|
options: {
|
@@ -82,7 +79,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
|
|
82
79
|
|
83
80
|
const scrollParentElement = index_1.getScrollParent(container);
|
84
81
|
const hasScrollableElement = scrollParentElement ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body) : false;
|
85
|
-
const modifiers = [
|
82
|
+
const modifiers = [isIntersectingModifier_1.isIntersectingModifier,
|
86
83
|
/**
|
87
84
|
* We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
|
88
85
|
* with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
|
@@ -162,11 +159,6 @@ function usePopperOptions(options, popperOriginalPositionRef) {
|
|
162
159
|
altBoundary: true,
|
163
160
|
boundary: index_1.getBoundary(container, overflowBoundary)
|
164
161
|
}
|
165
|
-
}, {
|
166
|
-
name: 'onUpdate',
|
167
|
-
enabled: true,
|
168
|
-
phase: 'afterWrite',
|
169
|
-
fn: handleStateUpdate
|
170
162
|
}, {
|
171
163
|
// Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js
|
172
164
|
// popper-maxsize-modifier only calculates the max sizes.
|
@@ -262,14 +254,11 @@ function usePopperOptions(options, popperOriginalPositionRef) {
|
|
262
254
|
const popperOptions = {
|
263
255
|
modifiers,
|
264
256
|
placement,
|
265
|
-
strategy
|
266
|
-
onFirstUpdate: state => handleStateUpdate({
|
267
|
-
state
|
268
|
-
})
|
257
|
+
strategy
|
269
258
|
};
|
270
259
|
return popperOptions;
|
271
260
|
}, [arrowPadding, autoSize, coverTarget, flipBoundary, offsetModifier, overflowBoundary, placement, strategy, unstable_disableTether, pinned, // These can be skipped from deps as they will not ever change
|
272
|
-
|
261
|
+
popperOriginalPositionRef]);
|
273
262
|
}
|
274
263
|
/**
|
275
264
|
* Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
|
@@ -290,13 +279,11 @@ function usePopper(options = {}) {
|
|
290
279
|
const resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
|
291
280
|
const popperInstanceRef = React.useRef(null);
|
292
281
|
const handlePopperUpdate = react_utilities_1.useEventCallback(() => {
|
293
|
-
var _a;
|
282
|
+
var _a, _b;
|
294
283
|
|
295
284
|
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
296
285
|
popperInstanceRef.current = null;
|
297
|
-
const
|
298
|
-
target = targetRef.current
|
299
|
-
} = options;
|
286
|
+
const target = (_b = overrideTargetRef.current) !== null && _b !== void 0 ? _b : targetRef.current;
|
300
287
|
let popperInstance = null;
|
301
288
|
|
302
289
|
if (react_utilities_1.canUseDOM() && enabled) {
|
@@ -347,14 +334,36 @@ function usePopper(options = {}) {
|
|
347
334
|
|
348
335
|
const targetRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
349
336
|
const containerRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
350
|
-
const arrowRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
337
|
+
const arrowRef = index_1.useCallbackRef(null, handlePopperUpdate, true); // Stores external target from options.target or setTarget
|
338
|
+
|
339
|
+
const overrideTargetRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
|
351
340
|
React.useImperativeHandle(options.popperRef, () => ({
|
352
341
|
updatePosition: () => {
|
353
342
|
var _a;
|
354
343
|
|
355
344
|
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
|
345
|
+
},
|
346
|
+
setTarget: target => {
|
347
|
+
if (options.target && process.env.NODE_ENV !== 'production') {
|
348
|
+
const err = new Error(); // eslint-disable-next-line no-console
|
349
|
+
|
350
|
+
console.warn('Imperative setTarget should not be used at the same time as target option'); // eslint-disable-next-line no-console
|
351
|
+
|
352
|
+
console.warn(err.stack);
|
353
|
+
}
|
354
|
+
|
355
|
+
overrideTargetRef.current = target;
|
356
356
|
}
|
357
|
-
}),
|
357
|
+
}), // Missing deps:
|
358
|
+
// options.target - only used for a runtime warning
|
359
|
+
// targetRef - Stable between renders
|
360
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
361
|
+
[]);
|
362
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
363
|
+
if (options.target) {
|
364
|
+
overrideTargetRef.current = options.target;
|
365
|
+
}
|
366
|
+
}, [options.target, overrideTargetRef]);
|
358
367
|
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
359
368
|
handlePopperUpdate();
|
360
369
|
return () => {
|
@@ -363,15 +372,14 @@ function usePopper(options = {}) {
|
|
363
372
|
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
364
373
|
popperInstanceRef.current = null;
|
365
374
|
};
|
366
|
-
}, [handlePopperUpdate, options.enabled
|
375
|
+
}, [handlePopperUpdate, options.enabled]);
|
367
376
|
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
368
|
-
var _a;
|
377
|
+
var _a, _b;
|
369
378
|
|
370
379
|
if (!isFirstMount) {
|
371
|
-
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(
|
380
|
+
(_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions((_b = overrideTargetRef.current) !== null && _b !== void 0 ? _b : targetRef.current, containerRef.current, arrowRef.current));
|
372
381
|
}
|
373
382
|
}, // Missing deps:
|
374
|
-
// options.target - The useIsomorphicLayoutEffect before this will create a new popper instance if target changes
|
375
383
|
// isFirstMount - Should never change after mount
|
376
384
|
// arrowRef, containerRef, targetRef - Stable between renders
|
377
385
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|