orcs-design-system 3.2.33 → 3.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,8 @@ import Box from "../Box";
|
|
|
5
5
|
import Grid from "../Grid";
|
|
6
6
|
import Flex from "../Flex";
|
|
7
7
|
import StyledLink from "../StyledLink";
|
|
8
|
-
import
|
|
8
|
+
import Spacer from "../Spacer";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
10
|
export default {
|
|
10
11
|
title: "Components/Popover",
|
|
11
12
|
decorators: [storyFn => /*#__PURE__*/_jsx(Box, {
|
|
@@ -111,31 +112,35 @@ export const textAlignment = () => /*#__PURE__*/_jsx(Popover, {
|
|
|
111
112
|
children: "Hover Me"
|
|
112
113
|
})
|
|
113
114
|
});
|
|
114
|
-
export const DisplayInlineBlock = () => /*#__PURE__*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
children: /*#__PURE__*/_jsx(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
115
|
+
export const DisplayInlineBlock = () => /*#__PURE__*/_jsx(Flex, {
|
|
116
|
+
flexDirection: "column",
|
|
117
|
+
children: /*#__PURE__*/_jsxs(Spacer, {
|
|
118
|
+
mt: "r",
|
|
119
|
+
children: [/*#__PURE__*/_jsx(Popover, {
|
|
120
|
+
text: "Description that explains child element",
|
|
121
|
+
inlineBlock: true,
|
|
122
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
123
|
+
children: "Inline Block Set"
|
|
124
|
+
})
|
|
125
|
+
}), /*#__PURE__*/_jsx(Popover, {
|
|
126
|
+
text: "Description that explains child element",
|
|
127
|
+
inlineBlock: true,
|
|
128
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
129
|
+
children: "Inline Block Set"
|
|
130
|
+
})
|
|
131
|
+
}), /*#__PURE__*/_jsx(Popover, {
|
|
132
|
+
text: "Because it is display: block, the triggering container is wider than the button",
|
|
133
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
134
|
+
children: "Not Inline"
|
|
135
|
+
})
|
|
136
|
+
}), /*#__PURE__*/_jsx(Popover, {
|
|
137
|
+
direction: "top",
|
|
138
|
+
text: "Description that explains child element",
|
|
139
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
140
|
+
children: "Not Inline"
|
|
141
|
+
})
|
|
142
|
+
})]
|
|
143
|
+
})
|
|
139
144
|
});
|
|
140
145
|
export const tooltipExample = () => /*#__PURE__*/_jsx(Popover, {
|
|
141
146
|
text: "This tooltip helps explain stuff",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { useFloating, autoUpdate, offset, flip, shift, useHover, useFocus, useDismiss, useRole, useInteractions, FloatingPortal, safePolygon, FloatingFocusManager } from "@floating-ui/react";
|
|
3
3
|
import themeGet from "@styled-system/theme-get";
|
|
4
4
|
import styled from "styled-components";
|
|
5
5
|
import Icon from "../Icon";
|
|
6
6
|
import { PropTypes } from "prop-types";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
7
|
+
import { getFloatingUiRootElement, getFloatingUiZIndex, isRenderedInReactSelectMenu } from "../../utils/floatingUiHelpers";
|
|
8
|
+
import { layout, space } from "styled-system";
|
|
9
9
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
10
|
const DIRECTIONS_MAP = {
|
|
11
11
|
topLeft: "top-start",
|
|
@@ -17,16 +17,20 @@ const DIRECTIONS_MAP = {
|
|
|
17
17
|
bottom: "bottom",
|
|
18
18
|
bottomRight: "bottom-end"
|
|
19
19
|
};
|
|
20
|
+
const Container = styled.div.withConfig({
|
|
21
|
+
displayName: "Popover__Container",
|
|
22
|
+
componentId: "sc-1bwoak-0"
|
|
23
|
+
})(["", " ", " display:", ";position:relative;"], space, layout, props => props.inlineBlock ? "inline-block !important" : "block !important");
|
|
20
24
|
const TooltipControl = styled.div.withConfig({
|
|
21
25
|
displayName: "Popover__TooltipControl",
|
|
22
|
-
componentId: "sc-1bwoak-
|
|
26
|
+
componentId: "sc-1bwoak-1"
|
|
23
27
|
})(["border:none;background:none;padding:0;cursor:help;font-size:1em;color:", ";transition:", ";&:hover,&:focus{outline:0;color:", ";}"], props => props.active ? themeGet("colors.primary")(props) : themeGet("colors.black")(props), themeGet("transition.transitionDefault"), themeGet("colors.primary"));
|
|
24
28
|
const StyledPopover = styled.div.withConfig({
|
|
25
29
|
displayName: "Popover__StyledPopover",
|
|
26
|
-
componentId: "sc-1bwoak-
|
|
30
|
+
componentId: "sc-1bwoak-2"
|
|
27
31
|
})(["font-size:", ";line-height:", ";font-weight:", ";text-align:", ";word-break:break-word;color:", ";outline:0;padding:", ";border-radius:", ";width:", ";background:", ";border:1px solid ", ";box-shadow:", ";user-select:", ";pointer-events:none;opacity:0;visibility:hidden;&.visible{opacity:1;pointer-events:auto;visibility:visible;}& a{font-size:", ";}&:before{content:\"\";z-index:2;height:0;width:0;border-style:solid;border-width:6px 6px 6px 0;border-color:transparent;border-right-color:", ";left:-6px;top:50%;margin-top:-6px;position:absolute;}&:after{content:\"\";z-index:1;position:absolute;border-color:transparent;border-right-color:", ";height:0;width:0;border-style:solid;border-width:6px 6px 6px 0;left:-7px;top:50%;margin-top:-6px;}&.top{&:before{left:50%;top:auto;margin-top:0;bottom:-9px;margin-left:-3px;transform:rotate(-90deg);}&:after{left:50%;top:auto;margin-top:0;bottom:-10px;margin-left:-3px;transform:rotate(-90deg);}}&.topRight,&.top-end{&:before{left:1px;top:auto;margin-top:0;bottom:-5px;margin-left:-6px;transform:rotate(-45deg);border-width:5px 10px 5px 0;}&:after{left:1px;top:auto;margin-top:0;bottom:-6px;margin-left:-7px;transform:rotate(-45deg);border-width:5px 10px 5px 0;}}&.bottomRight,&.bottom-end{&:before{left:1px;bottom:auto;margin-top:0;top:-5px;margin-left:-6px;transform:rotate(45deg);border-width:5px 10px 5px 0;}&:after{left:1px;bottom:auto;margin-top:0;top:-6px;margin-left:-7px;transform:rotate(45deg);border-width:5px 10px 5px 0;}}&.bottom{&:before{left:50%;top:-9px;margin-top:0;margin-left:-3px;transform:rotate(90deg);}&:after{left:50%;top:-10px;margin-top:0;margin-left:-3px;transform:rotate(90deg);}}&.bottomLeft,&.bottom-start{&:before{right:1px;left:auto;bottom:auto;margin-top:0;top:-5px;margin-right:-6px;transform:rotate(135deg);border-width:5px 10px 5px 0;}&:after{right:1px;left:auto;bottom:auto;margin-top:0;top:-6px;margin-right:-7px;transform:rotate(135deg);border-width:5px 10px 5px 0;}}&.left{&:before{left:auto;right:-6px;transform:rotate(180deg);}&:after{left:auto;right:-7px;transform:rotate(180deg);top:50%;margin-top:-6px;}}&.topLeft,&.top-start{&:before{right:1px;left:auto;top:auto;margin-top:0;bottom:-5px;margin-right:-6px;transform:rotate(225deg);border-width:5px 10px 5px 0;}&:after{right:1px;left:auto;top:auto;margin-top:0;bottom:-6px;margin-right:-7px;transform:rotate(225deg);border-width:5px 10px 5px 0;}}"], themeGet("fontSizes.0"), themeGet("fontSizes.1"), themeGet("fontWeights.1"), props => props.textAlign ? props.textAlign : "left", themeGet("colors.greyDarkest"), themeGet("space.3"), themeGet("radii.1"), props => props.width ? props.width : "200px", themeGet("colors.white"), themeGet("colors.greyLight"), themeGet("shadows.boxDefault"), props => props.enableSelectAll ? "all" : "auto", themeGet("fontSizes.0"), themeGet("colors.white"), themeGet("colors.greyMid"));
|
|
28
32
|
export default function Popover(_ref) {
|
|
29
|
-
var _children$
|
|
33
|
+
var _refs$floating, _children$props;
|
|
30
34
|
let {
|
|
31
35
|
children,
|
|
32
36
|
direction = "right",
|
|
@@ -36,6 +40,7 @@ export default function Popover(_ref) {
|
|
|
36
40
|
enableSelectAll,
|
|
37
41
|
variant,
|
|
38
42
|
ariaLabel,
|
|
43
|
+
inlineBlock,
|
|
39
44
|
...props
|
|
40
45
|
} = _ref;
|
|
41
46
|
const [visible, setVisible] = useState(false);
|
|
@@ -84,31 +89,6 @@ export default function Popover(_ref) {
|
|
|
84
89
|
}),
|
|
85
90
|
tabIndex: "0"
|
|
86
91
|
};
|
|
87
|
-
let triggerComponent = null;
|
|
88
|
-
if (variant === "tooltip") {
|
|
89
|
-
triggerComponent = /*#__PURE__*/_jsx(TooltipControl, {
|
|
90
|
-
...triggerProps,
|
|
91
|
-
active: visible,
|
|
92
|
-
tabIndex: "0",
|
|
93
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
|
94
|
-
transform: "grow-4",
|
|
95
|
-
icon: ["fas", "question-circle"],
|
|
96
|
-
fontSize: "2"
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
} else if ((children === null || children === void 0 || (_children$type = children.type) === null || _children$type === void 0 ? void 0 : _children$type.$$typeof) === Symbol.for("react.forward_ref")) {
|
|
100
|
-
triggerComponent = /*#__PURE__*/cloneElement(children, triggerProps);
|
|
101
|
-
} else {
|
|
102
|
-
var _children$props;
|
|
103
|
-
triggerComponent = /*#__PURE__*/_jsx("div", {
|
|
104
|
-
...triggerProps,
|
|
105
|
-
style: {
|
|
106
|
-
display: "inline-block"
|
|
107
|
-
},
|
|
108
|
-
"data-testid": "".concat((children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props["data-testid"]) || "popover", "-trigger"),
|
|
109
|
-
children: children
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
92
|
const directionClass = context.placement === DIRECTIONS_MAP[direction] ? direction : context.placement;
|
|
113
93
|
const Popover = /*#__PURE__*/_jsx(StyledPopover, {
|
|
114
94
|
textAlign: textAlign,
|
|
@@ -124,17 +104,31 @@ export default function Popover(_ref) {
|
|
|
124
104
|
ariaLabel: ariaLabel,
|
|
125
105
|
children: text
|
|
126
106
|
});
|
|
127
|
-
|
|
107
|
+
const containsLinks = (_refs$floating = refs.floating) === null || _refs$floating === void 0 || (_refs$floating = _refs$floating.current) === null || _refs$floating === void 0 ? void 0 : _refs$floating.querySelectorAll("a").length;
|
|
108
|
+
return /*#__PURE__*/_jsxs(Container, {
|
|
109
|
+
inlineBlock: inlineBlock,
|
|
110
|
+
"data-testid": "".concat((children === null || children === void 0 || (_children$props = children.props) === null || _children$props === void 0 ? void 0 : _children$props["data-testid"]) || "popover", "-trigger"),
|
|
128
111
|
...props,
|
|
112
|
+
...triggerProps,
|
|
129
113
|
"aria-describedby": context.floatingId,
|
|
130
|
-
children: [
|
|
114
|
+
children: [variant === "tooltip" && /*#__PURE__*/_jsx(TooltipControl, {
|
|
115
|
+
...triggerProps,
|
|
116
|
+
active: visible,
|
|
117
|
+
tabIndex: "0",
|
|
118
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
119
|
+
transform: "grow-4",
|
|
120
|
+
icon: ["fas", "question-circle"],
|
|
121
|
+
fontSize: "2"
|
|
122
|
+
})
|
|
123
|
+
}), text && (visible ? /*#__PURE__*/_jsx(FloatingPortal, {
|
|
131
124
|
root: getFloatingUiRootElement(context.refs.reference),
|
|
132
125
|
preserveTabOrder: true,
|
|
133
|
-
children: /*#__PURE__*/_jsx(FloatingFocusManager, {
|
|
126
|
+
children: containsLinks ? /*#__PURE__*/_jsx(FloatingFocusManager, {
|
|
134
127
|
context: context,
|
|
135
128
|
modal: false,
|
|
129
|
+
initialFocus: isRenderedInReactSelectMenu(context.refs.reference) && -1,
|
|
136
130
|
children: Popover
|
|
137
|
-
})
|
|
131
|
+
}) : Popover
|
|
138
132
|
}) : Popover
|
|
139
133
|
/*
|
|
140
134
|
* HACK: Fixing all the broken tests in teamform-app-ui is too time consuming
|
|
@@ -142,7 +136,7 @@ export default function Popover(_ref) {
|
|
|
142
136
|
* Rendering the markup even when closed but in a hidden state ensures that tests pass.
|
|
143
137
|
* Ideally, we would update all the tests in teamform-app-ui to open the Popover
|
|
144
138
|
* before assertion.
|
|
145
|
-
**/),
|
|
139
|
+
**/), children]
|
|
146
140
|
});
|
|
147
141
|
}
|
|
148
142
|
Popover.propTypes = {
|
|
@@ -6,6 +6,11 @@ const getFloatingUiZIndex = triggerRef => {
|
|
|
6
6
|
}
|
|
7
7
|
return 900;
|
|
8
8
|
};
|
|
9
|
+
const REACT_SELECT_MENU = "react-select-menu";
|
|
10
|
+
const isRenderedInReactSelectMenu = triggerRef => {
|
|
11
|
+
var _document$getElementB, _document$getElementB2;
|
|
12
|
+
return (_document$getElementB = document.getElementById(REACT_SELECT_MENU)) === null || _document$getElementB === void 0 || (_document$getElementB2 = _document$getElementB.contains) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.call(_document$getElementB, triggerRef.current);
|
|
13
|
+
};
|
|
9
14
|
const getFloatingUiRootElement = triggerRef => {
|
|
10
15
|
var _activeModalRef$conta2;
|
|
11
16
|
const activeModalRef = document.getElementById("modal-overlay");
|
|
@@ -13,6 +18,9 @@ const getFloatingUiRootElement = triggerRef => {
|
|
|
13
18
|
if (isRenderedInModal) {
|
|
14
19
|
return document.getElementById("modal");
|
|
15
20
|
}
|
|
21
|
+
if (isRenderedInReactSelectMenu(triggerRef)) {
|
|
22
|
+
return document.getElementById(REACT_SELECT_MENU).firstChild;
|
|
23
|
+
}
|
|
16
24
|
return undefined;
|
|
17
25
|
};
|
|
18
|
-
export { getFloatingUiZIndex, getFloatingUiRootElement };
|
|
26
|
+
export { getFloatingUiZIndex, getFloatingUiRootElement, isRenderedInReactSelectMenu };
|