@@ -30,8 +30,7 @@ const FlyoutBody = styled.div(
30
30
${ getFontStyle ( { size : 'medium' } ) }
31
31
z-index : 100 ;
32
32
position : absolute;
33
- width : fit-conent;
34
- box-shadow : 0 2px 6px 0 rgba (75 , 78 , 82 , 0.2 );
33
+ box-shadow : 0 2qpx 6px 0 rgba (75 , 78 , 82 , 0.2 );
35
34
border : 1px solid ${ theme . ui4 } ;
36
35
overflow : visible;
37
36
& [data-popper-reference-hidden = 'true' ] {
@@ -95,20 +94,33 @@ const FlyoutContent = styled.div<FlyoutContentProps>(
95
94
FlyoutContent . displayName = 'FlyoutContent' ;
96
95
97
96
const FlyoutInt : React . FC < FlyoutProps & WithClickOutsideFCProps > = props => {
98
- const [ controlled ] = useState < boolean > ( props . open !== undefined ) ;
99
- const [ visible , setVisible ] = useState < boolean > ( Boolean ( props . open ) ) ;
97
+ const {
98
+ position,
99
+ defaultPosition,
100
+ offset,
101
+ open,
102
+ outsideClickEvent,
103
+ onChange,
104
+ children,
105
+ content,
106
+ theme,
107
+ ...restProps
108
+ } = props ;
109
+
110
+ const [ controlled ] = useState < boolean > ( open !== undefined ) ;
111
+ const [ visible , setVisible ] = useState < boolean > ( Boolean ( open ) ) ;
100
112
const [ referenceElement , setReferenceElement ] = useState < HTMLDivElement | undefined > ( ) ;
101
113
const [ popperElement , setPopperElement ] = useState < HTMLDivElement | undefined > ( ) ;
102
114
const [ arrowElement , setArrowElement ] = useState < HTMLDivElement | undefined > ( ) ;
103
115
104
116
const popperModifiers : Array < Modifier < unknown > > = [
105
117
{ name : 'hide' } ,
106
- { name : 'flip' , enabled : ! props . position } ,
118
+ { name : 'flip' , enabled : ! position } ,
107
119
{ name : 'arrow' , options : { element : arrowElement } } ,
108
- { name : 'offset' , options : { offset : [ 0 , props . offset || 4 + flyout . arrowSize / 2 ] } } ,
120
+ { name : 'offset' , options : { offset : [ 0 , offset || 4 + flyout . arrowSize / 2 ] } } ,
109
121
] ;
110
122
111
- if ( ! props . position ) {
123
+ if ( ! position ) {
112
124
popperModifiers . push ( {
113
125
name : 'preventOverflow' ,
114
126
options : {
@@ -118,35 +130,35 @@ const FlyoutInt: React.FC<FlyoutProps & WithClickOutsideFCProps> = props => {
118
130
}
119
131
120
132
const { styles, attributes } = usePopper ( referenceElement , popperElement , {
121
- placement : mapFlyoutPositionToPopperPlacement ( props . position || props . defaultPosition ) ,
133
+ placement : mapFlyoutPositionToPopperPlacement ( position || defaultPosition ) ,
122
134
modifiers : popperModifiers ,
123
135
} ) ;
124
136
125
- useEffect ( ( ) => setVisible ( Boolean ( props . open ) ) , [ props . open ] ) ;
126
- useEffect ( ( ) => changeVisibility ( false ) , [ props . outsideClickEvent ] ) ;
137
+ useEffect ( ( ) => setVisible ( Boolean ( open ) ) , [ open ] ) ;
138
+ useEffect ( ( ) => changeVisibility ( false ) , [ outsideClickEvent ] ) ;
127
139
128
140
const onClick = ( ) => changeVisibility ( ! visible ) ;
129
141
130
142
const changeVisibility = ( nextVisibility : boolean ) => {
131
143
if ( controlled || nextVisibility === visible ) {
132
144
return ;
133
145
}
134
- typeof props . onChange === 'function' && props . onChange ( { open : nextVisibility } ) ;
146
+ typeof onChange === 'function' && onChange ( { open : nextVisibility } ) ;
135
147
setVisible ( nextVisibility ) ;
136
148
} ;
137
149
138
150
return (
139
151
< FlyoutContainer >
140
152
< FlyoutTarget onClick = { onClick } ref = { setReferenceElement } >
141
- { props . children }
153
+ { children }
142
154
</ FlyoutTarget >
143
- { visible && props . content && (
144
- < FlyoutBody ref = { setPopperElement } style = { styles . popper } { ...attributes . popper } >
155
+ { visible && content && (
156
+ < FlyoutBody ref = { setPopperElement } style = { styles . popper } { ...attributes . popper } { ... restProps } >
145
157
{ /* Normally a styled component gets the theme from context. But some other component
146
158
may pass a customized theme as a prop. See example at Tooltip component */ }
147
- < FlyoutContent theme = { props . theme } > { props . content } </ FlyoutContent >
159
+ < FlyoutContent theme = { theme } > { content } </ FlyoutContent >
148
160
< FlyoutArrow
149
- theme = { props . theme }
161
+ theme = { theme }
150
162
ref = { setArrowElement }
151
163
style = { calculateArrowStyleOverrides ( attributes . popper , styles . arrow ) }
152
164
/>
@@ -155,6 +167,7 @@ const FlyoutInt: React.FC<FlyoutProps & WithClickOutsideFCProps> = props => {
155
167
</ FlyoutContainer >
156
168
) ;
157
169
} ;
170
+
158
171
FlyoutInt . displayName = 'FlyoutInt' ;
159
172
160
173
export const Flyout = withClickOutsideFC < FlyoutProps > ( FlyoutInt ) ;
0 commit comments