File tree Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Expand file tree Collapse file tree 3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,7 @@ import { Accordion } from 'webcoreui/react'
207
207
- [ Input] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Input )
208
208
- [ Menu] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Menu )
209
209
- [ Modal] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Modal )
210
+ - [ Popover] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Popover )
210
211
- [ Progress] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Progress )
211
212
- [ Radio] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Radio )
212
213
- [ Rating] ( https://github.com/Frontendland/webcoreui/tree/main/src/components/Rating )
Original file line number Diff line number Diff line change
1
+ export const debounce = ( fn : any , waitFor = 100 ) => {
2
+ let timeout : ReturnType < typeof setTimeout > | null
3
+
4
+ const clear = ( ) => {
5
+ if ( timeout !== null ) {
6
+ clearTimeout ( timeout )
7
+ timeout = null
8
+ }
9
+ }
10
+
11
+ const debouncedFn = ( ...args : any [ ] ) => {
12
+ clear ( )
13
+
14
+ timeout = setTimeout ( ( ) => {
15
+ fn ( ...args )
16
+ } , waitFor )
17
+ }
18
+
19
+ debouncedFn . cancel = ( ) => {
20
+ clear ( )
21
+ }
22
+
23
+ return debouncedFn
24
+ }
Original file line number Diff line number Diff line change 1
1
import { closeModal } from './modal'
2
+ import { debounce } from './debounce'
2
3
3
4
type PopoverPosition = 'top'
4
5
| 'top-start'
@@ -161,15 +162,33 @@ export const popover = ({
161
162
} , 300 )
162
163
}
163
164
165
+ const removeOnResize = debounce ( ( ) => {
166
+ popoverDOM . dataset . show = ''
167
+
168
+ setTimeout ( ( ) => {
169
+ if ( ! popoverDOM . dataset . show ) {
170
+ popoverDOM . removeAttribute ( 'data-show' )
171
+ }
172
+ } , 300 )
173
+ } )
174
+
175
+ const observer = new ResizeObserver ( ( ) => {
176
+ if ( popoverDOM . dataset . show ) {
177
+ removeOnResize ( )
178
+ }
179
+ } )
180
+
164
181
triggerDOM . addEventListener ( 'click' , handleOpen )
182
+ observer . observe ( document . body )
165
183
166
184
if ( closeOnBlur ) {
167
185
document . addEventListener ( 'click' , handleClose )
168
186
}
169
187
170
188
return {
171
189
remove ( ) {
172
- triggerDOM . removeEventListener ( 'click' , handleOpen )
190
+ triggerDOM . removeEventListener ( 'click' , handleOpen ) ;
191
+ observer . disconnect ( )
173
192
174
193
if ( closeOnBlur ) {
175
194
document . removeEventListener ( 'click' , handleClose )
You can’t perform that action at this time.
0 commit comments