@targetprocess/popover 12.20.1-alpha.4 → 12.20.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BodyDomNode.tsx +79 -76
- package/CHANGELOG.md +22 -22
- package/Popover.tsx +191 -188
- package/PopoverBody.tsx +40 -37
- package/PopoverContainer.tsx +325 -322
- package/PopoverPosition.ts +62 -59
- package/PositioningTarget.tsx +29 -26
- package/StatlessPopover.tsx +98 -101
- package/__tests__/BodyDomNode.tests.tsx +287 -284
- package/__tests__/Popover.tests.tsx +66 -63
- package/__tests__/PositioningTarget.tests.tsx +46 -43
- package/dist/BodyDomNode.d.ts +3 -0
- package/dist/Popover.d.ts +3 -0
- package/dist/PopoverBody.d.ts +3 -0
- package/dist/PopoverContainer.d.ts +3 -0
- package/dist/PositioningTarget.d.ts +3 -0
- package/dist/StatlessPopover.d.ts +4 -1
- package/dist/index.d.ts +3 -0
- package/dist/popover.es.js +22 -11
- package/dist/popover.js +22 -11
- package/dist/types.d.ts +3 -0
- package/index.ts +17 -14
- package/package.json +3 -3
- package/style/index.css +107 -104
- package/types.ts +40 -37
package/PopoverPosition.ts
CHANGED
|
@@ -1,59 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
/*********************************************************************
|
|
2
|
+
* © Copyright IBM Corp. 2024
|
|
3
|
+
*********************************************************************/
|
|
4
|
+
import {SpaceXS} from '@targetprocess/global-constants'
|
|
5
|
+
import {DefaultPopoverPositions} from './types'
|
|
6
|
+
|
|
7
|
+
export const PopoverPosition: DefaultPopoverPositions = {
|
|
8
|
+
bottomLeft: (hostRect, popoverRect, containerScroll) => ({
|
|
9
|
+
left: 0,
|
|
10
|
+
top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
|
|
11
|
+
}),
|
|
12
|
+
bottom: (hostRect, popoverRect, containerScroll) => ({
|
|
13
|
+
left: '50%',
|
|
14
|
+
marginLeft: -popoverRect.width / 2,
|
|
15
|
+
top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
|
|
16
|
+
}),
|
|
17
|
+
bottomRight: (hostRect, popoverRect, containerScroll) => ({
|
|
18
|
+
right: 0,
|
|
19
|
+
top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
|
|
20
|
+
}),
|
|
21
|
+
topLeft: (hostRect, popoverRect, containerScroll) => ({
|
|
22
|
+
left: 0,
|
|
23
|
+
bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
|
|
24
|
+
}),
|
|
25
|
+
top: (hostRect, popoverRect, containerScroll) => ({
|
|
26
|
+
left: '50%',
|
|
27
|
+
marginLeft: -popoverRect.width / 2,
|
|
28
|
+
bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
|
|
29
|
+
}),
|
|
30
|
+
topRight: (hostRect, popoverRect, containerScroll) => ({
|
|
31
|
+
right: 0,
|
|
32
|
+
bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
|
|
33
|
+
}),
|
|
34
|
+
leftTop: (hostRect, popoverRect, containerScroll) => ({
|
|
35
|
+
right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
|
|
36
|
+
top: 0
|
|
37
|
+
}),
|
|
38
|
+
left: (hostRect, popoverRect, containerScroll) => ({
|
|
39
|
+
right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
|
|
40
|
+
marginTop: -popoverRect.height / 2,
|
|
41
|
+
top: '50%'
|
|
42
|
+
}),
|
|
43
|
+
leftBottom: (hostRect, popoverRect, containerScroll) => ({
|
|
44
|
+
right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
|
|
45
|
+
marginTop: -popoverRect.height / 2,
|
|
46
|
+
bottom: 0
|
|
47
|
+
}),
|
|
48
|
+
rightTop: (hostRect, popoverRect, containerScroll) => ({
|
|
49
|
+
left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
|
|
50
|
+
top: 0
|
|
51
|
+
}),
|
|
52
|
+
right: (hostRect, popoverRect, containerScroll) => ({
|
|
53
|
+
left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
|
|
54
|
+
marginTop: -popoverRect.height / 2,
|
|
55
|
+
top: '50%'
|
|
56
|
+
}),
|
|
57
|
+
rightBottom: (hostRect, popoverRect, containerScroll) => ({
|
|
58
|
+
left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
|
|
59
|
+
marginTop: -popoverRect.height / 2,
|
|
60
|
+
bottom: 0
|
|
61
|
+
})
|
|
62
|
+
}
|
package/PositioningTarget.tsx
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
target: HTMLElement
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
/*********************************************************************
|
|
2
|
+
* © Copyright IBM Corp. 2024
|
|
3
|
+
*********************************************************************/
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import PropTypes from 'prop-types'
|
|
6
|
+
|
|
7
|
+
export class PositioningTarget extends React.Component<
|
|
8
|
+
{
|
|
9
|
+
children: (target: HTMLElement) => React.ReactNode
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
target: HTMLElement
|
|
13
|
+
}
|
|
14
|
+
> {
|
|
15
|
+
static propTypes = {
|
|
16
|
+
children: PropTypes.func.isRequired
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
state = {target: null}
|
|
20
|
+
targetRef = React.createRef<HTMLDivElement>()
|
|
21
|
+
|
|
22
|
+
componentDidMount() {
|
|
23
|
+
this.setState({target: this.targetRef.current})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
render() {
|
|
27
|
+
return <div ref={this.targetRef}>{this.props.children(this.state.target)}</div>
|
|
28
|
+
}
|
|
29
|
+
}
|
package/StatlessPopover.tsx
CHANGED
|
@@ -1,101 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{props.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
/*********************************************************************
|
|
2
|
+
* © Copyright IBM Corp. 2024
|
|
3
|
+
*********************************************************************/
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import ReactDOM from 'react-dom'
|
|
6
|
+
import {PopoverContainer} from './PopoverContainer'
|
|
7
|
+
import {PositioningTarget} from './PositioningTarget'
|
|
8
|
+
import {BodyDomNode} from './BodyDomNode'
|
|
9
|
+
import {GetPopoverPositionType} from './types'
|
|
10
|
+
|
|
11
|
+
export type StatelessPopoverProps = {
|
|
12
|
+
isOpen: boolean
|
|
13
|
+
getPopoverPosition: GetPopoverPositionType
|
|
14
|
+
getContainerElement?: () => HTMLElement
|
|
15
|
+
inline?: boolean
|
|
16
|
+
body?: React.ReactNode
|
|
17
|
+
zIndex: number
|
|
18
|
+
showTip?: boolean
|
|
19
|
+
className?: string
|
|
20
|
+
outerActionEvents?: string[]
|
|
21
|
+
onOuterAction?: (evt: Event) => void
|
|
22
|
+
onEscapeAction: (evt: Event) => void
|
|
23
|
+
trackScroll?: boolean
|
|
24
|
+
role?: 'tooltip' | 'dialog'
|
|
25
|
+
trapFocus?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
|
29
|
+
renderPortalContent({
|
|
30
|
+
props,
|
|
31
|
+
container,
|
|
32
|
+
positioningTarget
|
|
33
|
+
}: {
|
|
34
|
+
props: StatelessPopoverProps
|
|
35
|
+
container?: HTMLElement
|
|
36
|
+
positioningTarget: HTMLElement
|
|
37
|
+
}) {
|
|
38
|
+
const popoverContent = (
|
|
39
|
+
<PopoverContainer
|
|
40
|
+
key="popover-portal"
|
|
41
|
+
getPopoverPosition={this.props.getPopoverPosition}
|
|
42
|
+
relativeToParent={props.inline}
|
|
43
|
+
containerElement={this.getContainer()}
|
|
44
|
+
className={props.className}
|
|
45
|
+
positioningTarget={positioningTarget}
|
|
46
|
+
showTip={props.showTip}
|
|
47
|
+
zIndex={props.zIndex}
|
|
48
|
+
trackScroll={props.trackScroll}
|
|
49
|
+
role={this.props.role}
|
|
50
|
+
trapFocus={this.props.trapFocus}
|
|
51
|
+
onEscapeAction={this.props.onEscapeAction}
|
|
52
|
+
>
|
|
53
|
+
{props.body}
|
|
54
|
+
</PopoverContainer>
|
|
55
|
+
)
|
|
56
|
+
return ReactDOM.createPortal(popoverContent, container)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getContainer = () =>
|
|
60
|
+
(this.props.getContainerElement && this.props.getContainerElement()) || document.body
|
|
61
|
+
|
|
62
|
+
renderPortal(positioningTarget: HTMLElement) {
|
|
63
|
+
if (!this.props.isOpen) {
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
const containerElement = this.props.inline ? positioningTarget : this.getContainer()
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<BodyDomNode
|
|
70
|
+
onOuterAction={this.props.onOuterAction}
|
|
71
|
+
outerActionEvents={this.props.outerActionEvents}
|
|
72
|
+
positioningTarget={positioningTarget}
|
|
73
|
+
containerElement={containerElement}
|
|
74
|
+
>
|
|
75
|
+
{container =>
|
|
76
|
+
container
|
|
77
|
+
? this.renderPortalContent({props: this.props, container, positioningTarget})
|
|
78
|
+
: null
|
|
79
|
+
}
|
|
80
|
+
</BodyDomNode>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
render() {
|
|
85
|
+
return (
|
|
86
|
+
<PositioningTarget>
|
|
87
|
+
{positioningTarget =>
|
|
88
|
+
positioningTarget ? (
|
|
89
|
+
<React.Fragment>
|
|
90
|
+
{this.props.children}
|
|
91
|
+
{this.renderPortal(positioningTarget)}
|
|
92
|
+
</React.Fragment>
|
|
93
|
+
) : null
|
|
94
|
+
}
|
|
95
|
+
</PositioningTarget>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|