@targetprocess/popover 12.23.1-alpha.2 → 12.23.1-alpha.4

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.
@@ -0,0 +1,36 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ export declare type BodyDomNodeProps = {
7
+ children: (node: HTMLElement) => React.ReactNode;
8
+ onOuterAction?: (event: Event) => void;
9
+ outerActionEvents?: string[];
10
+ positioningTarget: HTMLElement;
11
+ containerElement: HTMLElement;
12
+ };
13
+ export declare class BodyDomNode extends React.Component<BodyDomNodeProps, {
14
+ node: HTMLElement;
15
+ }> {
16
+ static propTypes: {
17
+ children: PropTypes.Validator<(...args: any[]) => any>;
18
+ onOuterAction: PropTypes.Requireable<(...args: any[]) => any>;
19
+ outerActionEvents: PropTypes.Requireable<string[]>;
20
+ positioningTarget: PropTypes.Requireable<HTMLElement>;
21
+ containerElement: PropTypes.Requireable<HTMLElement>;
22
+ };
23
+ static defaultProps: {
24
+ containerElement: HTMLElement;
25
+ };
26
+ state: {
27
+ node: any;
28
+ };
29
+ _onEvent: (event: any) => void;
30
+ _addDocumentEventListeners: () => void;
31
+ _removeDocumentEventListeners: (outerActionEvents?: string[]) => void;
32
+ componentDidMount(): void;
33
+ componentDidUpdate(prevProps: BodyDomNodeProps): void;
34
+ componentWillUnmount(): void;
35
+ render(): React.ReactNode;
36
+ }
@@ -0,0 +1,138 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { GetPopoverPositionType } from './types';
7
+ /**
8
+ * Popover is react component for displaying some toggleable content near
9
+ * other elements.
10
+ *
11
+ * By itself, `<Popover>` component is pass-through, i.e. it only renders
12
+ * its `children` without any other side effects. Its `body` prop accepts any
13
+ * react element, and when `isOpen` is set to `true`, it renders `body` in a
14
+ * portal and appends it to the element returned by `getContainerElement`
15
+ * (or to `document.body`, if it's not provided).
16
+ *
17
+ * By default, `body` doesn't add any additional styling. You can use
18
+ * `Popover.Body` component if you need a container with commonly styled
19
+ * box shadow and rounded corners.
20
+ *
21
+ * Popover accepts render props children, in which case it can use its
22
+ * own internal state to work in uncontrolled mode. In this mode, however,
23
+ * `isOpen` prop on `Popover` takes preceedence over internal state.
24
+ * Render prop function signature is
25
+ * `({isOpen: boolean, setOpened: (isOpen: boolean) => void}) => React.Element`;
26
+ * children can use `isOpen` to adjust their own view and call setOpened to open
27
+ * or close the popover:
28
+ * ```jsx
29
+ * <Popover body={<Popover.Body>hello world!</Popover.Body>}>
30
+ * {({isOpen, setOpened}) => (
31
+ * <button onClick={() => setOpened(!isOpen)}>
32
+ * Toggle popover
33
+ * </button>
34
+ * )}
35
+ * </Popover>
36
+ * ```
37
+ *
38
+ * Popover positioning can be configured using `getPopoverPosition` function.
39
+ * It also accepts any of the 12 positions as strings:
40
+ * `'bottomLeft', 'bottom', 'bottomRight', 'topLeft', 'top', 'topRight',
41
+ * 'leftTop', 'left', 'leftBottom', 'rightTop', 'right', 'rightBottom'`.
42
+ *
43
+ * `getPopoverPosition` accepts 3 arguments: trigger dimensions (x, y,
44
+ * wdith and height), body dimensions as DOMRect (x, y, width and height)
45
+ * and container element scroll offsets. It is expected to return any CSS
46
+ * style modifiers that will be then applied to the popover itself.
47
+ *
48
+ * For example, default `'bottom'` position is implemented as follows:
49
+ * ```js
50
+ * bottom: (hostRect, popoverRect, containerScroll) => ({
51
+ * left: '50%',
52
+ * marginLeft: -popoverRect.width / 2,
53
+ * top: hostRect.height + parseInt(SpaceXS) - containerScroll.top
54
+ * }),
55
+ * ```
56
+ *
57
+ * Default positioning functions are also avaliable from `Popover.Position`
58
+ * object, so you can reuse them in certain situations. For example, if you
59
+ * want to use `bottom` positioning but move it 5 pixels higher, you can do
60
+ * it like this:
61
+ * ```js
62
+ * const getPopoverPosition = (...args) => {
63
+ * const defaultBottomPosition = Popover.Position.bottom(...args);
64
+ * return {...defaultBottomPosition, top: defaultBottomPosition - 5}
65
+ * }
66
+ * ```
67
+ *
68
+ * You can also use `showTip` to display a triangle near popover.
69
+ * Triangle position is calculated automatically depending on relative popover
70
+ * position; it is always placed at the center of the trigger from the according side.
71
+ */
72
+ export declare type PopoverProps = {
73
+ closeOnOuterAction?: boolean;
74
+ isOpen?: boolean;
75
+ getPopoverPosition: GetPopoverPositionType;
76
+ onOuterAction?: (evt: Event) => void;
77
+ outerActionEvents?: string[];
78
+ getContainerElement?: () => HTMLElement;
79
+ inline?: boolean;
80
+ body?: React.ReactNode;
81
+ zIndex: number;
82
+ showTip?: boolean;
83
+ classNameTip?: string;
84
+ className?: string;
85
+ trackScroll?: boolean;
86
+ role?: 'tooltip' | 'dialog';
87
+ trapFocus?: boolean;
88
+ };
89
+ export declare type PopoverState = {
90
+ isOpen: boolean;
91
+ };
92
+ export declare class Popover extends React.Component<PopoverProps, PopoverState> {
93
+ static Body: React.FunctionComponent<import("./PopoverBody").PopoverBodyProps>;
94
+ static Position: import("./types").DefaultPopoverPositions;
95
+ static propTypes: {
96
+ /** Class name of toplevel popover container */
97
+ className: PropTypes.Requireable<string>;
98
+ /** Wether popover is opened or closed */
99
+ isOpen: PropTypes.Requireable<boolean>;
100
+ /** Element that will be mounted within the popover */
101
+ body: PropTypes.Requireable<PropTypes.ReactElementLike>;
102
+ /** Called when one of the `outerActionEvents` occurs */
103
+ onOuterAction: PropTypes.Requireable<(...args: any[]) => any>;
104
+ /** Must return DOM element to append popover to. */
105
+ getContainerElement: PropTypes.Requireable<(...args: any[]) => any>;
106
+ /** Wether to show the triangle. */
107
+ showTip: PropTypes.Requireable<boolean>;
108
+ /** Position string or positioning function. */
109
+ getPopoverPosition: PropTypes.Requireable<string | ((...args: any[]) => any)>;
110
+ /**
111
+ * Events that trigger `onOuterAction`.
112
+ */
113
+ outerActionEvents: PropTypes.Requireable<string[]>;
114
+ /** Whether uncontrolled (render props) popover should be closed on outer action */
115
+ closeOnOuterAction: PropTypes.Requireable<boolean>;
116
+ noPadding: PropTypes.Requireable<boolean>;
117
+ zIndex: PropTypes.Requireable<number>;
118
+ trackScroll: PropTypes.Requireable<boolean>;
119
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
120
+ role: PropTypes.Requireable<string>;
121
+ trapFocus: PropTypes.Requireable<boolean>;
122
+ };
123
+ static defaultProps: {
124
+ zIndex: number;
125
+ outerActionEvents: string[];
126
+ getPopoverPosition: string;
127
+ role: string;
128
+ trapFocus: boolean;
129
+ };
130
+ state: {
131
+ isOpen: boolean;
132
+ };
133
+ setOpened: (isOpen: boolean) => void;
134
+ onOuterAction: (event: Event) => void;
135
+ onEscapeAction: (event: Event) => void;
136
+ childrenRef?: HTMLElement;
137
+ render(): JSX.Element;
138
+ }
@@ -0,0 +1,11 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ export declare type PopoverBodyProps = {
6
+ children?: React.ReactNode;
7
+ className?: string;
8
+ classNameBody?: string;
9
+ noPadding?: boolean;
10
+ };
11
+ export declare const PopoverBody: React.FunctionComponent<PopoverBodyProps>;
@@ -0,0 +1,57 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { DimensionParams, GetPopoverPositionType, PositionParams } from './types';
7
+ declare type PopoverContainerProps = {
8
+ containerElement?: HTMLElement;
9
+ positioningTarget: HTMLElement;
10
+ className?: string;
11
+ relativeToParent?: boolean;
12
+ trackScroll?: boolean;
13
+ scrollThrottleIntervalMs?: number;
14
+ getPopoverPosition: GetPopoverPositionType;
15
+ showTip?: boolean;
16
+ classNameTip?: string;
17
+ zIndex: number;
18
+ role?: 'tooltip' | 'dialog';
19
+ trapFocus?: boolean;
20
+ onEscapeAction: (event: Event) => void;
21
+ };
22
+ declare type PopoverContainerState = {
23
+ adjusted: boolean;
24
+ positionX: number;
25
+ positionY: number;
26
+ hostRect?: PositionParams & DimensionParams;
27
+ popoverRect?: DimensionParams;
28
+ scroll?: PositionParams;
29
+ };
30
+ export declare class PopoverContainer extends React.Component<PopoverContainerProps, PopoverContainerState> {
31
+ static propTypes: {
32
+ positioningTarget: PropTypes.Requireable<object>;
33
+ containerElement: PropTypes.Requireable<object>;
34
+ className: PropTypes.Requireable<string>;
35
+ trackScroll: PropTypes.Requireable<boolean>;
36
+ role: PropTypes.Requireable<string>;
37
+ trapFocus: PropTypes.Requireable<boolean>;
38
+ onEscapeAction: PropTypes.Requireable<(...args: any[]) => any>;
39
+ };
40
+ static defaultProps: {
41
+ trackScroll: boolean;
42
+ };
43
+ mounted: boolean;
44
+ popoverContentRef: React.RefObject<HTMLDivElement>;
45
+ state: PopoverContainerState;
46
+ popoverContainerId: string;
47
+ adjustPosition(): void;
48
+ onResize: () => void;
49
+ onScroll: (...args: any[]) => void;
50
+ componentDidMount(): void;
51
+ componentDidUpdate(previousProps: any): void;
52
+ componentWillUnmount(): void;
53
+ getPopoverTipPosition: (popoverPosition: any, containerPosition: any) => "top" | "bottom" | "right" | "left";
54
+ handleKeyDown: (event: any) => void;
55
+ render(): JSX.Element;
56
+ }
57
+ export {};
@@ -0,0 +1,2 @@
1
+ import { DefaultPopoverPositions } from './types';
2
+ export declare const PopoverPosition: DefaultPopoverPositions;
@@ -0,0 +1,20 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ export declare class PositioningTarget extends React.Component<{
7
+ children: (target: HTMLElement) => React.ReactNode;
8
+ }, {
9
+ target: HTMLElement;
10
+ }> {
11
+ static propTypes: {
12
+ children: PropTypes.Validator<(...args: any[]) => any>;
13
+ };
14
+ state: {
15
+ target: any;
16
+ };
17
+ targetRef: React.RefObject<HTMLDivElement>;
18
+ componentDidMount(): void;
19
+ render(): JSX.Element;
20
+ }
@@ -0,0 +1,32 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import React from 'react';
5
+ import { GetPopoverPositionType } from './types';
6
+ export declare type StatelessPopoverProps = {
7
+ isOpen: boolean;
8
+ getPopoverPosition: GetPopoverPositionType;
9
+ getContainerElement?: () => HTMLElement;
10
+ inline?: boolean;
11
+ body?: React.ReactNode;
12
+ zIndex: number;
13
+ showTip?: boolean;
14
+ classNameTip?: string;
15
+ className?: string;
16
+ outerActionEvents?: string[];
17
+ onOuterAction?: (evt: Event) => void;
18
+ onEscapeAction: (evt: Event) => void;
19
+ trackScroll?: boolean;
20
+ role?: 'tooltip' | 'dialog';
21
+ trapFocus?: boolean;
22
+ };
23
+ export declare class StatelessPopover extends React.Component<StatelessPopoverProps> {
24
+ renderPortalContent({ props, container, positioningTarget }: {
25
+ props: StatelessPopoverProps;
26
+ container?: HTMLElement;
27
+ positioningTarget: HTMLElement;
28
+ }): React.ReactPortal;
29
+ getContainer: () => HTMLElement;
30
+ renderPortal(positioningTarget: HTMLElement): JSX.Element;
31
+ render(): JSX.Element;
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /*********************************************************************
2
+ * © Copyright IBM Corp. 2024
3
+ *********************************************************************/
4
+ import { Popover, PopoverProps } from './Popover';
5
+ import { PopoverBody, PopoverBodyProps } from './PopoverBody';
6
+ import { GetPopoverPositionType } from './types';
7
+ import { PopoverPosition } from './PopoverPosition';
8
+ export { Popover, PopoverBody, PopoverProps, PopoverBodyProps, GetPopoverPositionType, PopoverPosition };
9
+ export default Popover;