| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608 |
40x
12x
12x
12x
11x
11x
11x
11x
11x
11x
38x
38x
38x
38x
38x
38x
38x
2x
2x
19x
19x
19x
12x
12x
12x
12x
14x
14x
1x
13x
13x
13x
4x
4x
4x
4x
16x
16x
16x
16x
16x
16x
5x
5x
5x
5x
5x
5x
106x
106x
106x
106x
106x
171x
106x
106x
63x
63x
63x
63x
63x
33x
33x
33x
33x
33x
33x
7x
7x
7x
7x
7x
3x
3x
3x
3x
3x
3x
106x
106x
106x
171x
2x
1x
1x
1x
89x
89x
89x
| import React from 'react';
import PropTypes from 'prop-types';
import { EventOverlay } from '@collab-ui/react';
import { omit } from 'lodash';
/**
* @category communication
* @component popover
* @variations collab-ui-react
*/
class Popover extends React.Component {
state = {
isOpen: false,
isHovering: false
};
componentDidMount() {
this.props.startOpen &&
this.delayedShow();
}
componentWillUnmount() {
this.hideTimerId && clearTimeout(this.hideTimerId);
this.showTimerId && clearTimeout(this.showTimerId);
}
delayedHide = e => {
const { delay, hideDelay, onClose } = this.props;
const { isHovering } = this.state;
if ( isHovering ) return;
Iif (this.showTimerId) {
clearTimeout(this.showTimerId);
this.showTimerId = null;
}
const popoverHideTime = hideDelay
? hideDelay
: delay;
this.hideTimerId = setTimeout(() => {
this.hideTimerId = null;
this.setState(
{ isOpen: false, isHovering: false },
onClose && onClose(e)
);
}, popoverHideTime);
e && e.stopPropagation();
};
delayedShow = e => {
const { delay, showDelay } = this.props;
Iif (this.hideTimerId) {
clearTimeout(this.hideTimerId);
this.hideTimerId = null;
}
const popoverShowTime = showDelay
? showDelay
: delay;
this.showTimerId = setTimeout(() => {
this.showTimerId = null;
this.setState(
{ isOpen: true, isHovering: true }
);
}, popoverShowTime);
e && e.stopPropagation();
};
handleClose = e => {
const { onClose } = this.props;
this.setState(
{ isOpen: false },
onClose && onClose(e)
);
};
handleMouseEnter = e => {
const { children } = this.props;
children.props.onMouseEnter && children.props.onMouseEnter(e);
return !this.showTimerId && !this.state.isOpen && this.delayedShow(e);
};
delayCheckHover = e => {
const { hoverDelay } = this.props;
e.persist();
this.setState(
{ isHovering: false },
() => setTimeout(() => this.delayedHide(e), hoverDelay)
);
}
handleMouseLeave = e => {
const { children } = this.props;
if (this.hasFocus) {
return false;
}
Iif (this.showTimerId) {
clearTimeout(this.showTimerId);
this.showTimerId = null;
}
children.props.onMouseLeave && children.props.onMouseLeave(e);
return !this.hideTimerId && this.state.isOpen && this.delayCheckHover(e);
};
handleBlur = e => {
const { children } = this.props;
this.hasFocus = false;
children.props.onBlur && children.props.onBlur(e);
this.handleMouseLeave(e);
};
handleClick = e => {
const { children, doesAnchorToggle } = this.props;
const { isOpen } = this.state;
this.hasFocus = true;
children.props.onClick && children.props.onClick(e);
Eif(!this.showTimerId) {
return !isOpen
? this.delayedShow(e)
: doesAnchorToggle && this.handleBlur(e);
}
}
handleFocus = e => {
const { children } = this.props;
const { isOpen } = this.state;
this.hasFocus = true;
children.props.onFocus && children.props.onFocus(e);
Eif(!this.showTimerId) {
return !isOpen
? this.delayedShow(e)
: this.handleBlur(e);
}
};
render() {
const { isOpen } = this.state;
const {
children,
className,
content,
overflowType,
popoverTrigger,
showArrow,
...props
} = this.props;
const otherProps = omit({...props}, [
'delay',
'doesAnchorToggle',
'hideDelay',
'hoverDelay',
'onClose',
'showDelay',
'startOpen',
]);
const getTriggers = () => {
const triggerProps = {};
triggerProps.ref = ele => (this.anchorRef = ele);
triggerProps.key = 'child-1';
switch (popoverTrigger) {
case 'MouseEnter':
triggerProps.onMouseEnter = this.handleMouseEnter;
triggerProps.onMouseLeave = this.handleMouseLeave;
triggerProps.onFocus = this.handleFocus;
triggerProps.onBlur = this.handleBlur;
break;
case 'Click':
triggerProps.onClick = this.handleClick;
triggerProps.onBlur = null;
triggerProps.onFocus = null;
triggerProps.onMouseEnter = null;
triggerProps.onMouseLeave = null;
break;
case 'Focus':
triggerProps.onFocus = this.handleFocus;
triggerProps.onBlur = this.handleBlur;
triggerProps.onMouseEnter = null;
triggerProps.onMouseLeave = null;
break;
case 'None':
triggerProps.onClick = null;
triggerProps.onFocus = null;
triggerProps.onBlur = null;
triggerProps.onMouseEnter = null;
triggerProps.onMouseLeave = null;
break;
}
return triggerProps;
};
const anchorWithTriggers =
children && React.cloneElement(children, getTriggers());
return (
<span>
{anchorWithTriggers}
<EventOverlay
anchorNode={this.anchorRef}
className={className}
close={this.handleClose}
isOpen={isOpen}
ref={ref => this.overlay = ref}
showArrow={showArrow}
style={
{ overflow: overflowType }
}
{...popoverTrigger === 'MouseEnter' && {
onMouseEnter: () => {
this.setState({isHovering: true, isOpen: true});
},
onMouseLeave: e => {
e.persist();
this.setState(
{isHovering: false}
, () => this.delayedHide(e)
);
}}
}
{...otherProps}
>
{content}
</EventOverlay>
</span>
);
}
}
Popover.propTypes = {
/** @prop Children node that should be the popover trigger(this should be a stateful component) */
children: PropTypes.element.isRequired,
/** @prop Optional CSS class names which goes over popover container | '' */
className: PropTypes.string,
/** @prop The content that goes into the popover */
content: PropTypes.oneOfType([PropTypes.element, PropTypes.node]).isRequired,
/** @prop The delay for popover on hover, click, focus (hide/show) | 0 */
delay: PropTypes.number,
/** @prop Boolean for whether the Anchor Toggles the Popover | true */
doesAnchorToggle: PropTypes.bool,
/** @prop The hide delay for popover on hover, click, focus | 0 */
hideDelay: PropTypes.number,
/** @prop The hover delay for checking whether we are still hovering before closing | 500 */
hoverDelay: PropTypes.number,
/** @prop Callback function that will execute on close | null */
onClose: PropTypes.func,
/** @prop Optional prop that controls overflow css style of EventOverlay | 'auto' */
overflowType: PropTypes.string,
/** @prop Event that will trigger popover appearance | 'MouseEnter' */
popoverTrigger: PropTypes.oneOf(['MouseEnter', 'Click', 'Focus', 'None']),
/** @prop Boolean for whether the Arrow should show | true */
showArrow: PropTypes.bool,
/** @prop The show delay for popover on hover, click, focus | 0 */
showDelay: PropTypes.number,
/** @prop Should Popover start open | false */
startOpen: PropTypes.bool,
};
Popover.defaultProps = {
className: '',
delay: 0,
doesAnchorToggle: true,
hideDelay: 0,
hoverDelay: 500,
onClose: null,
overflowType: 'auto',
popoverTrigger: 'MouseEnter',
showArrow: true,
showDelay: 0,
startOpen: false,
};
Popover.displayName = 'Popover';
export default Popover;
/**
* @component popover
* @section default
* @react
import {
Button,
Icon,
List,
ListItem,
ListItemSection,
Popover,
} from '@collab-ui/react';
export default function ContentDefault() {
const content = (
<List>
<ListItem>
<ListItemSection position="left">
<Icon name="edit_20" />
</ListItemSection>
<ListItemSection position="center">
Edit space settings
</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="favorite_20" />
</ListItemSection>
<ListItemSection position="center">Add to favorites</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="alert_20" />
</ListItemSection>
<ListItemSection position="center">Notifications</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="accessories_20" />
</ListItemSection>
<ListItemSection position="center">
Add Integrations & Bots
</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="stored-info_20" />
</ListItemSection>
<ListItemSection position="center">View space policy</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="archive_20" />
</ListItemSection>
<ListItemSection position="center">Archive space</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="cancel_20" />
</ListItemSection>
<ListItemSection position="center">
Remove space from team
</ListItemSection>
</ListItem>
<ListItem>
<ListItemSection position="left">
<Icon name="exit-room_20" />
</ListItemSection>
<ListItemSection position="center">Leave space</ListItemSection>
</ListItem>
</List>
);
const contentFocus = (
<span key="1" style={{ padding: '10px'}}>Focus</span>
);
return (
<div className="row">
<div className="docs-example docs-example--spacing">
<Popover
content={content}
popoverTrigger={'Click'}
>
<Button children="Click" ariaLabel="Click" />
</Popover>
</div>
<div className="docs-example docs-example--spacing">
<Popover
content={content}
popoverTrigger={'MouseEnter'}
>
<Button children="MouseEnter" ariaLabel="MouseEnter" />
</Popover>
</div>
<div className="docs-example docs-example--spacing">
<Popover
content={contentFocus}
popoverTrigger={'Focus'}
>
<Button children="Focus" ariaLabel="Focus" />
</Popover>
</div>
</div>
);
}
**/
/**
* @component popover
* @section delay
* @react
import {
Button,
Popover,
} from '@collab-ui/react';
export default function PopOverDelay() {
const contentDelay = (
<span key="1" style={{ padding: '10px'}}>Delayed</span>
);
return (
<div className="docs-example docs-example--spacing">
<Popover
content={contentDelay}
delay={500}
>
<Button children='Hover with Delay' ariaLabel='Hover with Delay' />
</Popover>
</div>
);
}
**/
/**
* @component popover
* @section direction
* @react
import {
Button,
Popover
} from '@collab-ui/react';
export default function PopOverDirection() {
const content = (
<span key="1" style={{ padding: '10px'}}>right-center</span>
);
return (
<div className="docs-example docs-example--spacing">
<Popover
content={content}
direction={'right-center'}
>
<Button children='Direction' ariaLabel='Direction' />
</Popover>
</div>
);
}
**/
/**
* @component popover
* @section arrow
* @react
import {
Button,
Popover
} from '@collab-ui/react';
export default function PopoverArrow() {
const contentArrow = (
<span key="1" style={{ padding: '10px'}}>Arrow</span>
);
return (
<div className="docs-example docs-example--spacing">
<Popover
content={contentArrow}
direction={'right-center'}
showArrow={true}
>
<Button children='showArrow' ariaLabel='showArrow' />
</Popover>
</div>
);
}
**/
/**
* @component popover
* @section offset
* @react
import {
Button,
Popover
} from '@collab-ui/react';
export default function PopoverOffset() {
const contentOffset = (
<span key="1" style={{ padding: '10px'}}>Offset</span>
);
return (
<div className="docs-example docs-example--spacing">
<Popover
content={contentOffset}
direction={'top-center'}
targetOffset={{ vertical: 20 }}
>
<Button children='offset' ariaLabel='offset' />
</Popover>
</div>
);
}
**/
/**
* @component popover
* @section contained
* @react
import {
Button,
Popover
} from '@collab-ui/react';
export default function PopoverContained() {
const tall = (
<span key="1" style={{ height: '3000px' }}>Popover(height: 3000px)</span>
);
return (
<Popover
isContained
content={tall}
direction={'bottom-center'}
popoverTrigger={'Click'}
>
<Button children='Tall' ariaLabel='Tall' />
</Popover>
);
}
**/
/**
* @component popover
* @section overflow
* @react
import {
Button,
Popover
} from '@collab-ui/react';
export default function PopoverOverflow() {
const tall = (
<span key="1" style={{ height: '3000px' }}>Popover(height: 3000px)</span>
);
return (
<div
className="docs-example docs-example--spacing"
style={{
border: '2px solid #666666',
width: '100%',
height: '500px',
overflow: 'scroll',
padding: '125px'
}}
>
<Popover
isContained={true}
checkOverflow
content={tall}
direction={'bottom-center'}
popoverTrigger={'Click'}
>
<Button children='Tall' ariaLabel='Tall' />
</Popover>
</div>
);
}
**/
|