@targetprocess/popover 12.20.1-alpha.2 → 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.
@@ -1,59 +1,62 @@
1
- import {SpaceXS} from '@targetprocess/global-constants'
2
- import {DefaultPopoverPositions} from './types'
3
-
4
- export const PopoverPosition: DefaultPopoverPositions = {
5
- bottomLeft: (hostRect, popoverRect, containerScroll) => ({
6
- left: 0,
7
- top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
8
- }),
9
- bottom: (hostRect, popoverRect, containerScroll) => ({
10
- left: '50%',
11
- marginLeft: -popoverRect.width / 2,
12
- top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
13
- }),
14
- bottomRight: (hostRect, popoverRect, containerScroll) => ({
15
- right: 0,
16
- top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
17
- }),
18
- topLeft: (hostRect, popoverRect, containerScroll) => ({
19
- left: 0,
20
- bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
21
- }),
22
- top: (hostRect, popoverRect, containerScroll) => ({
23
- left: '50%',
24
- marginLeft: -popoverRect.width / 2,
25
- bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
26
- }),
27
- topRight: (hostRect, popoverRect, containerScroll) => ({
28
- right: 0,
29
- bottom: hostRect.height + parseInt(SpaceXS) + containerScroll.top
30
- }),
31
- leftTop: (hostRect, popoverRect, containerScroll) => ({
32
- right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
33
- top: 0
34
- }),
35
- left: (hostRect, popoverRect, containerScroll) => ({
36
- right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
37
- marginTop: -popoverRect.height / 2,
38
- top: '50%'
39
- }),
40
- leftBottom: (hostRect, popoverRect, containerScroll) => ({
41
- right: hostRect.width + parseInt(SpaceXS) - containerScroll.left,
42
- marginTop: -popoverRect.height / 2,
43
- bottom: 0
44
- }),
45
- rightTop: (hostRect, popoverRect, containerScroll) => ({
46
- left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
47
- top: 0
48
- }),
49
- right: (hostRect, popoverRect, containerScroll) => ({
50
- left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
51
- marginTop: -popoverRect.height / 2,
52
- top: '50%'
53
- }),
54
- rightBottom: (hostRect, popoverRect, containerScroll) => ({
55
- left: hostRect.width + parseInt(SpaceXS) + containerScroll.left,
56
- marginTop: -popoverRect.height / 2,
57
- bottom: 0
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
+ }
@@ -1,26 +1,29 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
-
4
- export class PositioningTarget extends React.Component<
5
- {
6
- children: (target: HTMLElement) => React.ReactNode
7
- },
8
- {
9
- target: HTMLElement
10
- }
11
- > {
12
- static propTypes = {
13
- children: PropTypes.func.isRequired
14
- }
15
-
16
- state = {target: null}
17
- targetRef = React.createRef<HTMLDivElement>()
18
-
19
- componentDidMount() {
20
- this.setState({target: this.targetRef.current})
21
- }
22
-
23
- render() {
24
- return <div ref={this.targetRef}>{this.props.children(this.state.target)}</div>
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
+ }
@@ -1,101 +1,98 @@
1
- import React from 'react'
2
- import ReactDOM from 'react-dom'
3
- import {PopoverContainer} from './PopoverContainer'
4
- import {PositioningTarget} from './PositioningTarget'
5
- import {BodyDomNode} from './BodyDomNode'
6
- import {GetPopoverPositionType} from './types'
7
-
8
- export type StatelessPopoverProps = {
9
- isOpen: boolean
10
- getPopoverPosition: GetPopoverPositionType
11
- getContainerElement?: () => HTMLElement
12
- inline?: boolean
13
- body?: React.ReactNode
14
- zIndex: number
15
- showTip?: boolean
16
- className?: string
17
- outerActionEvents?: string[]
18
- onOuterAction?: (evt: Event) => void
19
- onEscapeAction: (evt: Event) => void
20
- trackScroll?: boolean
21
- role?: 'tooltip' | 'dialog'
22
- trapFocus?: boolean
23
- }
24
-
25
- export class StatelessPopover extends React.Component<StatelessPopoverProps> {
26
- renderPortalContent({
27
- props,
28
- container,
29
- positioningTarget
30
- }: {
31
- props: StatelessPopoverProps
32
- container?: HTMLElement
33
- positioningTarget: HTMLElement
34
- }) {
35
- const popoverContent = (
36
- <PopoverContainer
37
- key="popover-portal"
38
- getPopoverPosition={this.props.getPopoverPosition}
39
- relativeToParent={props.inline}
40
- containerElement={this.getContainer()}
41
- className={props.className}
42
- positioningTarget={positioningTarget}
43
- showTip={props.showTip}
44
- zIndex={props.zIndex}
45
- trackScroll={props.trackScroll}
46
- role={this.props.role}
47
- trapFocus={this.props.trapFocus}
48
- onEscapeAction={this.props.onEscapeAction}
49
- >
50
- {props.body}
51
- </PopoverContainer>
52
- )
53
-
54
- if (!props.inline) {
55
- return ReactDOM.createPortal(popoverContent, container)
56
- }
57
-
58
- return popoverContent
59
- }
60
-
61
- getContainer = () =>
62
- (this.props.getContainerElement && this.props.getContainerElement()) || document.body
63
-
64
- renderPortal(positioningTarget: HTMLElement) {
65
- if (!this.props.isOpen) {
66
- return null
67
- }
68
-
69
- return this.props.inline ? (
70
- this.renderPortalContent({props: this.props, positioningTarget})
71
- ) : (
72
- <BodyDomNode
73
- onOuterAction={this.props.onOuterAction}
74
- outerActionEvents={this.props.outerActionEvents}
75
- positioningTarget={positioningTarget}
76
- containerElement={this.getContainer()}
77
- >
78
- {container =>
79
- container
80
- ? this.renderPortalContent({props: this.props, container, positioningTarget})
81
- : null
82
- }
83
- </BodyDomNode>
84
- )
85
- }
86
-
87
- render() {
88
- return (
89
- <PositioningTarget>
90
- {positioningTarget =>
91
- positioningTarget ? (
92
- <React.Fragment>
93
- {this.props.children}
94
- {this.renderPortal(positioningTarget)}
95
- </React.Fragment>
96
- ) : null
97
- }
98
- </PositioningTarget>
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
+ }