1- import React , { HTMLAttributes , CSSProperties , FC } from 'react' ;
1+ import React , { HTMLAttributes , CSSProperties , FC , useRef } from 'react' ;
22import classnames from 'classnames' ;
33import {
44 AutoAlign ,
55 AutoAlignInjectedProps ,
66 RectangleAlignment ,
77} from './AutoAlign' ;
88
9+ /**
10+ *
11+ */
912export const PopoverHeader : React . FC = ( props ) => (
1013 < div className = 'slds-popover__header' > { props . children } </ div >
1114) ;
1215
16+ /**
17+ *
18+ */
1319export type PopoverBodyProps = React . HTMLAttributes < HTMLDivElement > ;
1420
1521export const PopoverBody : React . FC < PopoverBodyProps > = ( props ) => (
@@ -18,6 +24,9 @@ export const PopoverBody: React.FC<PopoverBodyProps> = (props) => (
1824 </ div >
1925) ;
2026
27+ /**
28+ *
29+ */
2130export type PopoverPosition =
2231 | 'top'
2332 | 'top-left'
@@ -42,62 +51,62 @@ export type PopoverProps = {
4251 bodyStyle ?: CSSProperties ;
4352} & HTMLAttributes < HTMLDivElement > ;
4453
45- class PopoverInner extends React . Component <
46- PopoverProps & AutoAlignInjectedProps
47- > {
48- node : HTMLDivElement | null = null ;
49-
50- render ( ) {
51- const {
52- children,
53- alignment,
54- hidden,
55- theme,
56- tooltip,
57- style,
58- bodyStyle,
59- ...props
60- } = this . props ;
61- const nubbinPosition = alignment . join ( '-' ) ;
62- const [ firstAlign , secondAlign ] = alignment ;
63- const popoverClassNames = classnames (
64- 'slds-popover' ,
65- {
66- 'slds-hide' : hidden ,
67- 'slds-popover_tooltip ' : tooltip ,
68- } ,
69- `slds-nubbin_ ${ nubbinPosition } ` ,
70- `slds-m- ${ firstAlign } _small ` ,
71- theme ? `slds-theme_ ${ theme } ` : undefined
72- ) ;
73- const rootStyle : typeof style = {
74- ... style ,
75- position : 'absolute' ,
76- [ firstAlign ] : 0 ,
77- ... ( secondAlign ? { [ secondAlign ] : 0 } : { } ) ,
78- ...( tooltip ? { width : 'max-content' } : { } ) ,
79- transform :
80- secondAlign === undefined
81- ? firstAlign === 'top' || firstAlign === 'bottom'
82- ? 'translateX(-50%) '
83- : firstAlign === 'left' || firstAlign === 'right '
84- ? 'translateY(-50%) '
85- : undefined
86- : undefined ,
87- } ;
88- return (
89- < div
90- ref = { ( node : HTMLDivElement | null ) => ( this . node = node ) }
91- className = { popoverClassNames }
92- role = { tooltip ? 'tooltip' : 'dialog' }
93- style = { rootStyle }
94- { ... props }
95- >
96- < PopoverBody style = { bodyStyle } > { children } </ PopoverBody >
97- </ div >
98- ) ;
99- }
100- }
54+ /**
55+ *
56+ */
57+ export const PopoverInner : FC < PopoverProps & AutoAlignInjectedProps > = (
58+ props
59+ ) => {
60+ const {
61+ children,
62+ alignment,
63+ hidden,
64+ theme,
65+ tooltip,
66+ style,
67+ bodyStyle,
68+ ...rprops
69+ } = props ;
70+ const elRef = useRef < HTMLDivElement | null > ( null ) ;
71+ const nubbinPosition = alignment . join ( '-' ) ;
72+ const [ firstAlign , secondAlign ] = alignment ;
73+ const popoverClassNames = classnames (
74+ 'slds-popover' ,
75+ {
76+ 'slds-hide ' : hidden ,
77+ 'slds-popover_tooltip' : tooltip ,
78+ } ,
79+ `slds-nubbin_ ${ nubbinPosition } ` ,
80+ `slds-m- ${ firstAlign } _small` ,
81+ theme ? `slds-theme_ ${ theme } ` : undefined
82+ ) ;
83+ const rootStyle : typeof style = {
84+ ... style ,
85+ position : 'absolute' ,
86+ [ firstAlign ] : 0 ,
87+ ...( secondAlign ? { [ secondAlign ] : 0 } : { } ) ,
88+ ... ( tooltip ? { width : 'max-content' } : { } ) ,
89+ transform :
90+ secondAlign === undefined
91+ ? firstAlign === 'top' || firstAlign === 'bottom '
92+ ? 'translateX(-50%) '
93+ : firstAlign === 'left' || firstAlign === 'right '
94+ ? 'translateY(-50%)'
95+ : undefined
96+ : undefined ,
97+ } ;
98+ return (
99+ < div
100+ ref = { elRef }
101+ className = { popoverClassNames }
102+ role = { tooltip ? 'tooltip' : 'dialog' }
103+ style = { rootStyle }
104+ { ... rprops }
105+ >
106+ < PopoverBody style = { bodyStyle } > { children } </ PopoverBody >
107+ </ div >
108+ ) ;
109+ } ;
101110
102111/**
103112 *
0 commit comments