@entur/tooltip 4.0.0-beta.0 → 4.0.0
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.
- package/dist/Popover.d.ts +3 -1
- package/dist/Tooltip.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/styles.css +160 -163
- package/dist/tooltip.cjs.development.js +104 -127
- package/dist/tooltip.cjs.development.js.map +1 -1
- package/dist/tooltip.cjs.production.min.js +1 -1
- package/dist/tooltip.cjs.production.min.js.map +1 -1
- package/dist/tooltip.esm.js +105 -128
- package/dist/tooltip.esm.js.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/package.json +7 -9
package/dist/Popover.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Placement } from '
|
|
2
|
+
import { Placement } from './utils';
|
|
3
3
|
import './Popover.scss';
|
|
4
4
|
export type PopoverProps = {
|
|
5
5
|
/** Innholdet i Popover */
|
|
@@ -27,5 +27,7 @@ export declare const PopoverCloseButton: React.FC<PopoverCloseButtonProps>;
|
|
|
27
27
|
export type PopoverContentProps = {
|
|
28
28
|
/**Innholdet til Popover */
|
|
29
29
|
children: React.ReactNode;
|
|
30
|
+
className?: string;
|
|
31
|
+
style?: React.CSSProperties;
|
|
30
32
|
};
|
|
31
33
|
export declare const PopoverContent: React.ForwardRefExoticComponent<PopoverContentProps & React.RefAttributes<HTMLDivElement>>;
|
package/dist/Tooltip.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Placement } from './utils';
|
|
2
3
|
import './Tooltip.scss';
|
|
3
4
|
type Modifier = {
|
|
4
5
|
name: string;
|
|
@@ -9,7 +10,6 @@ type Modifier = {
|
|
|
9
10
|
data?: Record<string, unknown>;
|
|
10
11
|
[key: string]: any;
|
|
11
12
|
};
|
|
12
|
-
export type Placement = 'top' | 'top-left' | 'top-start' | 'top-right' | 'top-end' | 'left' | 'right' | 'bottom-left' | 'bottom-start' | 'bottom' | 'bottom-right' | 'bottom-end';
|
|
13
13
|
/** @deprecated use variant="negative" instead */
|
|
14
14
|
declare const error = "error";
|
|
15
15
|
export type TooltipProps = {
|
package/dist/index.d.ts
CHANGED
package/dist/styles.css
CHANGED
|
@@ -1,92 +1,5 @@
|
|
|
1
1
|
/* DO NOT CHANGE!*/
|
|
2
2
|
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
3
|
-
/* DO NOT CHANGE!*/
|
|
4
|
-
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
5
|
-
.eds-floating-button {
|
|
6
|
-
align-items: center;
|
|
7
|
-
-webkit-appearance: none;
|
|
8
|
-
-moz-appearance: none;
|
|
9
|
-
appearance: none;
|
|
10
|
-
background: var(--components-button-floating-standard-default);
|
|
11
|
-
border: 0;
|
|
12
|
-
border-radius: 1.5rem;
|
|
13
|
-
box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.25);
|
|
14
|
-
color: var(--components-button-floating-standard-text);
|
|
15
|
-
cursor: pointer;
|
|
16
|
-
display: flex;
|
|
17
|
-
font-family: inherit;
|
|
18
|
-
font-size: 0.875rem;
|
|
19
|
-
font-weight: 500;
|
|
20
|
-
justify-content: center;
|
|
21
|
-
min-height: 3rem;
|
|
22
|
-
margin: 0;
|
|
23
|
-
min-width: 3rem;
|
|
24
|
-
padding: 0 1rem;
|
|
25
|
-
position: relative;
|
|
26
|
-
z-index: 10;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.eds-floating-button--extended {
|
|
30
|
-
padding: 0 0.9375rem;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.eds-floating-button:hover {
|
|
34
|
-
background-color: var(--components-button-floating-standard-hover);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.eds-floating-button:active {
|
|
38
|
-
background-color: var(--components-button-floating-standard-active);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.eds-floating-button:focus {
|
|
42
|
-
outline: 2px solid #181c56;
|
|
43
|
-
outline-color: var(--basecolors-stroke-focus-standard);
|
|
44
|
-
outline-offset: 0.125rem;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.eds-contrast .eds-floating-button:focus {
|
|
48
|
-
outline-color: var(--basecolors-stroke-focus-contrast);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.eds-contrast .eds-floating-button {
|
|
52
|
-
background: var(--components-button-floating-contrast-default);
|
|
53
|
-
color: var(--components-button-floating-contrast-text);
|
|
54
|
-
box-shadow: 0 0.0625rem 0.1875rem rgb(57, 61, 121);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.eds-contrast .eds-floating-button:hover {
|
|
58
|
-
background-color: var(--components-button-floating-contrast-hover);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.eds-contrast .eds-floating-button:active {
|
|
62
|
-
background-color: var(--components-button-floating-contrast-active);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.eds-floating-button--small {
|
|
66
|
-
border-radius: 1rem;
|
|
67
|
-
height: 2rem;
|
|
68
|
-
padding: 0 0.5rem;
|
|
69
|
-
min-width: 2rem;
|
|
70
|
-
min-height: 2rem;
|
|
71
|
-
flex: 0 1 auto;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.eds-floating-button--small.eds-floating-button--extended {
|
|
75
|
-
padding: 0 0.6875rem;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.eds-floating-button--extended > * {
|
|
79
|
-
margin: 0 0.5em;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.eds-floating-button--extended > *:first-child {
|
|
83
|
-
margin-left: 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.eds-floating-button--extended > *:last-child {
|
|
87
|
-
margin-right: 0;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
3
|
/* DO NOT CHANGE!*/
|
|
91
4
|
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
92
5
|
a.eds-button {
|
|
@@ -333,6 +246,104 @@ a.eds-button--size-large {
|
|
|
333
246
|
border-color: transparent;
|
|
334
247
|
}
|
|
335
248
|
|
|
249
|
+
/* DO NOT CHANGE!*/
|
|
250
|
+
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
251
|
+
.eds-button-group .eds-button {
|
|
252
|
+
margin-right: 0.75rem;
|
|
253
|
+
margin-bottom: 0.75rem;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.eds-button-group .eds-button:only-child {
|
|
257
|
+
margin: 0;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* DO NOT CHANGE!*/
|
|
261
|
+
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
262
|
+
.eds-floating-button {
|
|
263
|
+
align-items: center;
|
|
264
|
+
-webkit-appearance: none;
|
|
265
|
+
-moz-appearance: none;
|
|
266
|
+
appearance: none;
|
|
267
|
+
background: var(--components-button-floating-standard-default);
|
|
268
|
+
border: 0;
|
|
269
|
+
border-radius: 1.5rem;
|
|
270
|
+
box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.25);
|
|
271
|
+
color: var(--components-button-floating-standard-text);
|
|
272
|
+
cursor: pointer;
|
|
273
|
+
display: flex;
|
|
274
|
+
font-family: inherit;
|
|
275
|
+
font-size: 0.875rem;
|
|
276
|
+
font-weight: 500;
|
|
277
|
+
justify-content: center;
|
|
278
|
+
min-height: 3rem;
|
|
279
|
+
margin: 0;
|
|
280
|
+
min-width: 3rem;
|
|
281
|
+
padding: 0 1rem;
|
|
282
|
+
position: relative;
|
|
283
|
+
z-index: 10;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.eds-floating-button--extended {
|
|
287
|
+
padding: 0 0.9375rem;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.eds-floating-button:hover {
|
|
291
|
+
background-color: var(--components-button-floating-standard-hover);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.eds-floating-button:active {
|
|
295
|
+
background-color: var(--components-button-floating-standard-active);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
.eds-floating-button:focus {
|
|
299
|
+
outline: 2px solid #181c56;
|
|
300
|
+
outline-color: var(--basecolors-stroke-focus-standard);
|
|
301
|
+
outline-offset: 0.125rem;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.eds-contrast .eds-floating-button:focus {
|
|
305
|
+
outline-color: var(--basecolors-stroke-focus-contrast);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.eds-contrast .eds-floating-button {
|
|
309
|
+
background: var(--components-button-floating-contrast-default);
|
|
310
|
+
color: var(--components-button-floating-contrast-text);
|
|
311
|
+
box-shadow: 0 0.0625rem 0.1875rem rgb(57, 61, 121);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.eds-contrast .eds-floating-button:hover {
|
|
315
|
+
background-color: var(--components-button-floating-contrast-hover);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.eds-contrast .eds-floating-button:active {
|
|
319
|
+
background-color: var(--components-button-floating-contrast-active);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.eds-floating-button--small {
|
|
323
|
+
border-radius: 1rem;
|
|
324
|
+
height: 2rem;
|
|
325
|
+
padding: 0 0.5rem;
|
|
326
|
+
min-width: 2rem;
|
|
327
|
+
min-height: 2rem;
|
|
328
|
+
flex: 0 1 auto;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.eds-floating-button--small.eds-floating-button--extended {
|
|
332
|
+
padding: 0 0.6875rem;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.eds-floating-button--extended > * {
|
|
336
|
+
margin: 0 0.5em;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.eds-floating-button--extended > *:first-child {
|
|
340
|
+
margin-left: 0;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.eds-floating-button--extended > *:last-child {
|
|
344
|
+
margin-right: 0;
|
|
345
|
+
}
|
|
346
|
+
|
|
336
347
|
/* DO NOT CHANGE!*/
|
|
337
348
|
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
338
349
|
.eds-square-button {
|
|
@@ -532,13 +543,70 @@ a.eds-button--size-large {
|
|
|
532
543
|
|
|
533
544
|
/* DO NOT CHANGE!*/
|
|
534
545
|
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
535
|
-
.eds-
|
|
536
|
-
|
|
537
|
-
|
|
546
|
+
.eds-icon-button {
|
|
547
|
+
border: 0.125rem solid transparent;
|
|
548
|
+
border-radius: 0.25rem;
|
|
549
|
+
background: none;
|
|
550
|
+
color: var(--components-button-iconbutton-standard-text);
|
|
551
|
+
cursor: pointer;
|
|
552
|
+
display: flex;
|
|
553
|
+
justify-content: center;
|
|
554
|
+
align-items: center;
|
|
555
|
+
font-size: 1rem;
|
|
556
|
+
padding: 0.5rem;
|
|
538
557
|
}
|
|
539
558
|
|
|
540
|
-
.eds-
|
|
541
|
-
|
|
559
|
+
.eds-contrast .eds-icon-button {
|
|
560
|
+
color: var(--components-button-iconbutton-contrast-text);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
.eds-contrast .eds-icon-button > .eds-loading-dots .eds-loading-dots__dot {
|
|
564
|
+
background-color: var(--components-button-iconbutton-contrast-icon);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.eds-icon-button--size-small {
|
|
568
|
+
height: 1.5rem;
|
|
569
|
+
width: 1.5rem;
|
|
570
|
+
padding: 0;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
.eds-icon-button:hover {
|
|
574
|
+
background-color: var(--components-button-iconbutton-standard-hover);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
.eds-contrast .eds-icon-button:hover {
|
|
578
|
+
background-color: var(--components-button-iconbutton-contrast-hover);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
.eds-icon-button:active {
|
|
582
|
+
background: var(--components-button-iconbutton-standard-active);
|
|
583
|
+
color: var(--components-button-iconbutton-standard-text-active);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.eds-contrast .eds-icon-button:active {
|
|
587
|
+
background: var(--components-button-iconbutton-contrast-active);
|
|
588
|
+
color: var(--components-button-iconbutton-contrast-text-active);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
.eds-icon-button:focus {
|
|
592
|
+
outline: 2px solid #181c56;
|
|
593
|
+
outline-color: var(--basecolors-stroke-focus-standard);
|
|
594
|
+
outline-offset: 0.125rem;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
.eds-contrast .eds-icon-button:focus {
|
|
598
|
+
outline-color: var(--basecolors-stroke-focus-contrast);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
.eds-icon-button--disabled {
|
|
602
|
+
opacity: 0.5;
|
|
603
|
+
pointer-events: none;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
.eds-icon-button--disabled__wrapper {
|
|
607
|
+
cursor: not-allowed;
|
|
608
|
+
width: -moz-fit-content;
|
|
609
|
+
width: fit-content;
|
|
542
610
|
}
|
|
543
611
|
|
|
544
612
|
/* DO NOT CHANGE!*/
|
|
@@ -923,74 +991,6 @@ a.eds-button--size-large {
|
|
|
923
991
|
--eds-button: 1;
|
|
924
992
|
}
|
|
925
993
|
|
|
926
|
-
/* DO NOT CHANGE!*/
|
|
927
|
-
/* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
|
|
928
|
-
.eds-icon-button {
|
|
929
|
-
border: 0.125rem solid transparent;
|
|
930
|
-
border-radius: 0.25rem;
|
|
931
|
-
background: none;
|
|
932
|
-
color: var(--components-button-iconbutton-standard-text);
|
|
933
|
-
cursor: pointer;
|
|
934
|
-
display: flex;
|
|
935
|
-
justify-content: center;
|
|
936
|
-
align-items: center;
|
|
937
|
-
font-size: 1rem;
|
|
938
|
-
padding: 0.5rem;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
.eds-contrast .eds-icon-button {
|
|
942
|
-
color: var(--components-button-iconbutton-contrast-text);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
.eds-contrast .eds-icon-button > .eds-loading-dots .eds-loading-dots__dot {
|
|
946
|
-
background-color: var(--components-button-iconbutton-contrast-icon);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
.eds-icon-button--size-small {
|
|
950
|
-
height: 1.5rem;
|
|
951
|
-
width: 1.5rem;
|
|
952
|
-
padding: 0;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
.eds-icon-button:hover {
|
|
956
|
-
background-color: var(--components-button-iconbutton-standard-hover);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
.eds-contrast .eds-icon-button:hover {
|
|
960
|
-
background-color: var(--components-button-iconbutton-contrast-hover);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
.eds-icon-button:active {
|
|
964
|
-
background: var(--components-button-iconbutton-standard-active);
|
|
965
|
-
color: var(--components-button-iconbutton-standard-text-active);
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
.eds-contrast .eds-icon-button:active {
|
|
969
|
-
background: var(--components-button-iconbutton-contrast-active);
|
|
970
|
-
color: var(--components-button-iconbutton-contrast-text-active);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
.eds-icon-button:focus {
|
|
974
|
-
outline: 2px solid #181c56;
|
|
975
|
-
outline-color: var(--basecolors-stroke-focus-standard);
|
|
976
|
-
outline-offset: 0.125rem;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
.eds-contrast .eds-icon-button:focus {
|
|
980
|
-
outline-color: var(--basecolors-stroke-focus-contrast);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
.eds-icon-button--disabled {
|
|
984
|
-
opacity: 0.5;
|
|
985
|
-
pointer-events: none;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
.eds-icon-button--disabled__wrapper {
|
|
989
|
-
cursor: not-allowed;
|
|
990
|
-
width: -moz-fit-content;
|
|
991
|
-
width: fit-content;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
994
|
.eds-tooltip-wrapper {
|
|
995
995
|
display: inline-block;
|
|
996
996
|
position: relative;
|
|
@@ -1094,9 +1094,6 @@ a.eds-button--size-large {
|
|
|
1094
1094
|
background: var(--components-tooltip-popover-contrast-fill);
|
|
1095
1095
|
box-shadow: 0 0.0625rem 0.1875rem rgb(57, 61, 121);
|
|
1096
1096
|
}
|
|
1097
|
-
.eds-popover--hidden {
|
|
1098
|
-
display: none;
|
|
1099
|
-
}
|
|
1100
1097
|
.eds-popover:focus {
|
|
1101
1098
|
outline: 2px solid #181c56;
|
|
1102
1099
|
outline-color: var(--basecolors-stroke-focus-standard);
|
|
@@ -9,7 +9,6 @@ var reactDom = require('@floating-ui/react-dom');
|
|
|
9
9
|
var icons = require('@entur/icons');
|
|
10
10
|
var button = require('@entur/button');
|
|
11
11
|
var tokens = require('@entur/tokens');
|
|
12
|
-
var reactPopper = require('react-popper');
|
|
13
12
|
var layout = require('@entur/layout');
|
|
14
13
|
|
|
15
14
|
function _extends() {
|
|
@@ -39,6 +38,21 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
39
38
|
return target;
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
function standardisePlacement(placement) {
|
|
42
|
+
switch (placement) {
|
|
43
|
+
case 'top-left':
|
|
44
|
+
return 'top-start';
|
|
45
|
+
case 'top-right':
|
|
46
|
+
return 'top-end';
|
|
47
|
+
case 'bottom-left':
|
|
48
|
+
return 'bottom-start';
|
|
49
|
+
case 'bottom-right':
|
|
50
|
+
return 'bottom-end';
|
|
51
|
+
default:
|
|
52
|
+
return placement;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
var _excluded$1 = ["placement", "content", "children", "className", "isOpen", "disableHoverListener", "disableFocusListener", "disableKeyboardListener", "disableClickListner", "showCloseButton", "variant", "style"];
|
|
43
57
|
/** @deprecated use variant="negative" instead */
|
|
44
58
|
var error = 'error';
|
|
@@ -68,8 +82,8 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
68
82
|
setShowTooltip = _useState[1];
|
|
69
83
|
var tooltipArrowRef = React.useRef(null);
|
|
70
84
|
var tooltipId = utils.useRandomId('eds-tooltip');
|
|
71
|
-
var hoverOpenTimer;
|
|
72
|
-
var hoverCloseTimer;
|
|
85
|
+
var hoverOpenTimer = React.useRef();
|
|
86
|
+
var hoverCloseTimer = React.useRef();
|
|
73
87
|
// calculations for floating-UI tooltip position
|
|
74
88
|
var _useFloating = reactDom.useFloating({
|
|
75
89
|
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
@@ -91,26 +105,23 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
91
105
|
middlewareData = _useFloating.middlewareData,
|
|
92
106
|
actualPlacement = _useFloating.placement;
|
|
93
107
|
var onMouseEnter = function onMouseEnter() {
|
|
94
|
-
clearTimeout(hoverCloseTimer);
|
|
95
|
-
hoverOpenTimer = setTimeout(function () {
|
|
108
|
+
clearTimeout(hoverCloseTimer.current);
|
|
109
|
+
hoverOpenTimer.current = setTimeout(function () {
|
|
96
110
|
setShowTooltip(true);
|
|
97
111
|
}, 150);
|
|
98
112
|
};
|
|
99
113
|
var onMouseLeave = function onMouseLeave() {
|
|
100
|
-
clearTimeout(hoverOpenTimer);
|
|
101
|
-
hoverCloseTimer = setTimeout(function () {
|
|
114
|
+
clearTimeout(hoverOpenTimer.current);
|
|
115
|
+
hoverCloseTimer.current = setTimeout(function () {
|
|
102
116
|
setShowTooltip(false);
|
|
103
117
|
}, 300);
|
|
104
118
|
};
|
|
105
119
|
React.useEffect(function () {
|
|
106
120
|
return function () {
|
|
107
|
-
clearTimeout(hoverOpenTimer);
|
|
108
|
-
clearTimeout(hoverCloseTimer);
|
|
121
|
+
clearTimeout(hoverOpenTimer.current);
|
|
122
|
+
clearTimeout(hoverCloseTimer.current);
|
|
109
123
|
};
|
|
110
124
|
}, []);
|
|
111
|
-
React.useEffect(function () {
|
|
112
|
-
console.log(actualPlacement);
|
|
113
|
-
}, [actualPlacement]);
|
|
114
125
|
var referenceListenerProps = _extends({
|
|
115
126
|
'aria-describedby': showTooltip ? tooltipId : undefined
|
|
116
127
|
}, !disableFocusListener && {
|
|
@@ -170,38 +181,8 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
170
181
|
}
|
|
171
182
|
})));
|
|
172
183
|
};
|
|
173
|
-
function standardisePlacement(placement) {
|
|
174
|
-
switch (placement) {
|
|
175
|
-
case 'top-left':
|
|
176
|
-
return 'top-start';
|
|
177
|
-
case 'top-right':
|
|
178
|
-
return 'top-end';
|
|
179
|
-
case 'bottom-left':
|
|
180
|
-
return 'bottom-start';
|
|
181
|
-
case 'bottom-right':
|
|
182
|
-
return 'bottom-end';
|
|
183
|
-
default:
|
|
184
|
-
return placement;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
184
|
|
|
188
185
|
var _excluded = ["children"];
|
|
189
|
-
var PopoverContext = /*#__PURE__*/React.createContext(undefined);
|
|
190
|
-
var usePopoverContext = function usePopoverContext() {
|
|
191
|
-
var context = React.useContext(PopoverContext);
|
|
192
|
-
if (context == null) {
|
|
193
|
-
throw Error('usePopoverContext must be used within <Popover/>');
|
|
194
|
-
}
|
|
195
|
-
return context;
|
|
196
|
-
};
|
|
197
|
-
var useCustomState = function useCustomState(state, setState) {
|
|
198
|
-
var _React$useState = React.useState(false),
|
|
199
|
-
internalState = _React$useState[0],
|
|
200
|
-
setInternalState = _React$useState[1];
|
|
201
|
-
var controlled = state !== undefined && setState !== undefined;
|
|
202
|
-
if (controlled) return [state, setState, controlled];
|
|
203
|
-
return [internalState, setInternalState, controlled];
|
|
204
|
-
};
|
|
205
186
|
var Popover = function Popover(_ref) {
|
|
206
187
|
var children = _ref.children,
|
|
207
188
|
_ref$placement = _ref.placement,
|
|
@@ -212,86 +193,69 @@ var Popover = function Popover(_ref) {
|
|
|
212
193
|
showPopover = _useCustomState[0],
|
|
213
194
|
setShowPopover = _useCustomState[1],
|
|
214
195
|
controlled = _useCustomState[2];
|
|
215
|
-
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
offset:
|
|
225
|
-
}
|
|
226
|
-
}]
|
|
227
|
-
placement: placement
|
|
196
|
+
// calculations for floating-UI popover position
|
|
197
|
+
var _useFloating = reactDom.useFloating({
|
|
198
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
199
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
200
|
+
},
|
|
201
|
+
placement: standardisePlacement(placement),
|
|
202
|
+
middleware: [reactDom.offset(tokens.space.extraSmall), reactDom.flip(), reactDom.shift({
|
|
203
|
+
padding: tokens.space.extraSmall,
|
|
204
|
+
limiter: reactDom.limitShift({
|
|
205
|
+
offset: 8
|
|
206
|
+
})
|
|
207
|
+
})]
|
|
228
208
|
}),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
React.useEffect(function () {
|
|
233
|
-
if (forceUpdate) {
|
|
234
|
-
forceUpdate();
|
|
235
|
-
}
|
|
236
|
-
}, [showPopover, forceUpdate]);
|
|
237
|
-
var triggerProps = React.useCallback(function () {
|
|
238
|
-
var buttonProps = {
|
|
239
|
-
'aria-haspopup': 'dialog',
|
|
240
|
-
'aria-expanded': showPopover,
|
|
241
|
-
ref: triggerElement,
|
|
242
|
-
type: 'button'
|
|
243
|
-
};
|
|
244
|
-
var buttonOnClick = {
|
|
245
|
-
onClick: function onClick(e) {
|
|
246
|
-
e.preventDefault();
|
|
247
|
-
setShowPopover(function (prev) {
|
|
248
|
-
return !prev;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
return controlled ? buttonProps : _extends({}, buttonProps, buttonOnClick);
|
|
253
|
-
}, [triggerElement, showPopover, setShowPopover, controlled]);
|
|
254
|
-
utils.useOnClickOutside([contentElement, triggerElement], function () {
|
|
209
|
+
refs = _useFloating.refs,
|
|
210
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
211
|
+
utils.useOnClickOutside([refs.floating, refs.reference], function () {
|
|
255
212
|
return setShowPopover(false);
|
|
256
213
|
});
|
|
214
|
+
var popoverTriggerProps = _extends({
|
|
215
|
+
'aria-haspopup': 'dialog',
|
|
216
|
+
'aria-expanded': showPopover,
|
|
217
|
+
ref: refs.setReference,
|
|
218
|
+
type: 'button'
|
|
219
|
+
}, !controlled && {
|
|
220
|
+
onClick: function onClick() {
|
|
221
|
+
return setShowPopover(function (prev) {
|
|
222
|
+
return !prev;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
var popoverContentProps = {
|
|
227
|
+
role: 'dialog',
|
|
228
|
+
'aria-modal': false,
|
|
229
|
+
'aria-hidden': !showPopover,
|
|
230
|
+
ref: refs.setFloating,
|
|
231
|
+
style: _extends({}, !showPopover && {
|
|
232
|
+
display: 'none'
|
|
233
|
+
}),
|
|
234
|
+
onKeyDown: function onKeyDown(event) {
|
|
235
|
+
if (event.key === 'Escape') setShowPopover(false);
|
|
236
|
+
},
|
|
237
|
+
onBlur: function onBlur(event) {
|
|
238
|
+
var elementReceivingFocus = event.relatedTarget;
|
|
239
|
+
// The check for 'tabindex=-1' is a special case for focus handling in Docz
|
|
240
|
+
if (!elementReceivingFocus || elementReceivingFocus.getAttribute('tabindex') === '-1') return;
|
|
241
|
+
var focusedElementIsPopover = elementContainsElement(refs.floating.current, elementReceivingFocus);
|
|
242
|
+
var focusedElementIsTrigger = elementContainsElement(refs.reference.current, elementReceivingFocus);
|
|
243
|
+
var popoverShouldClose = !focusedElementIsPopover && !focusedElementIsTrigger;
|
|
244
|
+
if (showPopover && popoverShouldClose) setShowPopover(false);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
257
247
|
var closeButtonProps = {
|
|
258
|
-
onClick: function onClick(
|
|
259
|
-
|
|
260
|
-
setShowPopover(false);
|
|
248
|
+
onClick: function onClick() {
|
|
249
|
+
return setShowPopover(false);
|
|
261
250
|
},
|
|
262
251
|
type: 'button'
|
|
263
252
|
};
|
|
264
|
-
var popoverContentProps = React.useCallback(function () {
|
|
265
|
-
var contentProps = {
|
|
266
|
-
role: 'dialog',
|
|
267
|
-
'aria-modal': 'false',
|
|
268
|
-
ref: contentElement,
|
|
269
|
-
onKeyDown: function onKeyDown(event) {
|
|
270
|
-
if (event.key === 'Escape') {
|
|
271
|
-
showPopover && setShowPopover(false);
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
onBlur: function onBlur(event) {
|
|
275
|
-
var elementReceivingFocus = event.relatedTarget;
|
|
276
|
-
// The check for 'tabindex=-1' is a special case for focus handling in Docz
|
|
277
|
-
if (!elementReceivingFocus || elementReceivingFocus.getAttribute('tabindex') === '-1') return;
|
|
278
|
-
var focusElementIsPopover = elementContainsElement(contentElement.current, elementReceivingFocus);
|
|
279
|
-
var focusElementIsTrigger = elementContainsElement(triggerElement.current, elementReceivingFocus);
|
|
280
|
-
var isValidBlur = !focusElementIsPopover && !focusElementIsTrigger;
|
|
281
|
-
if (showPopover && isValidBlur) setShowPopover(false);
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
return contentProps;
|
|
285
|
-
}, [contentElement, showPopover, setShowPopover]);
|
|
286
253
|
var contextValue = {
|
|
287
254
|
showPopover: showPopover,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
styles: styles,
|
|
291
|
-
attributes: attributes,
|
|
255
|
+
floatingStyles: floatingStyles,
|
|
256
|
+
popoverTriggerProps: popoverTriggerProps,
|
|
292
257
|
popoverContentProps: popoverContentProps,
|
|
293
|
-
closeButtonProps: closeButtonProps
|
|
294
|
-
triggerProps: triggerProps
|
|
258
|
+
closeButtonProps: closeButtonProps
|
|
295
259
|
};
|
|
296
260
|
return React.createElement(PopoverContext.Provider, {
|
|
297
261
|
value: contextValue
|
|
@@ -300,9 +264,9 @@ var Popover = function Popover(_ref) {
|
|
|
300
264
|
var PopoverTrigger = function PopoverTrigger(_ref2) {
|
|
301
265
|
var children = _ref2.children;
|
|
302
266
|
var _usePopoverContext = usePopoverContext(),
|
|
303
|
-
|
|
267
|
+
popoverTriggerProps = _usePopoverContext.popoverTriggerProps;
|
|
304
268
|
var child = React.Children.only(children);
|
|
305
|
-
return React.cloneElement(child,
|
|
269
|
+
return React.cloneElement(child, popoverTriggerProps);
|
|
306
270
|
};
|
|
307
271
|
var PopoverCloseButton = function PopoverCloseButton(_ref3) {
|
|
308
272
|
var children = _ref3.children,
|
|
@@ -312,23 +276,36 @@ var PopoverCloseButton = function PopoverCloseButton(_ref3) {
|
|
|
312
276
|
return React.cloneElement(children, _extends({}, closeButtonProps, rest));
|
|
313
277
|
};
|
|
314
278
|
var PopoverContent = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
|
|
315
|
-
var children = _ref4.children
|
|
279
|
+
var children = _ref4.children,
|
|
280
|
+
className = _ref4.className,
|
|
281
|
+
style = _ref4.style;
|
|
316
282
|
var _usePopoverContext3 = usePopoverContext(),
|
|
317
|
-
|
|
318
|
-
attributes = _usePopoverContext3.attributes,
|
|
319
|
-
styles = _usePopoverContext3.styles,
|
|
283
|
+
floatingStyles = _usePopoverContext3.floatingStyles,
|
|
320
284
|
popoverContentProps = _usePopoverContext3.popoverContentProps;
|
|
321
|
-
var props = popoverContentProps({
|
|
322
|
-
ref: ref
|
|
323
|
-
});
|
|
324
285
|
return React.createElement(layout.Contrast, _extends({
|
|
325
|
-
className: classNames('eds-popover'
|
|
326
|
-
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
286
|
+
className: classNames(className, 'eds-popover')
|
|
287
|
+
}, popoverContentProps, {
|
|
288
|
+
style: _extends({}, floatingStyles, popoverContentProps.style, style),
|
|
289
|
+
// @ts-expect-error correct type for floating cannot be set via useFloating
|
|
290
|
+
ref: utils.mergeRefs(popoverContentProps.ref, ref)
|
|
291
|
+
}), children);
|
|
331
292
|
});
|
|
293
|
+
var PopoverContext = /*#__PURE__*/React.createContext(undefined);
|
|
294
|
+
var usePopoverContext = function usePopoverContext() {
|
|
295
|
+
var context = React.useContext(PopoverContext);
|
|
296
|
+
if (context == null) {
|
|
297
|
+
throw Error('usePopoverContext must be used within <Popover/>');
|
|
298
|
+
}
|
|
299
|
+
return context;
|
|
300
|
+
};
|
|
301
|
+
var useCustomState = function useCustomState(state, setState) {
|
|
302
|
+
var _React$useState = React.useState(false),
|
|
303
|
+
internalState = _React$useState[0],
|
|
304
|
+
setInternalState = _React$useState[1];
|
|
305
|
+
var controlled = state !== undefined && setState !== undefined;
|
|
306
|
+
if (controlled) return [state, setState, controlled];
|
|
307
|
+
return [internalState, setInternalState, controlled];
|
|
308
|
+
};
|
|
332
309
|
function elementContainsElement(parent, child) {
|
|
333
310
|
if (!parent) return false;
|
|
334
311
|
return parent === child || parent.contains(child);
|