/
_tooltip.scss
697 lines (576 loc) · 17.5 KB
/
_tooltip.scss
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//
@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/layout';
@import '../../globals/scss/tooltip';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../../globals/scss/css--reset';
// TODO: deprecate legacy tooltip mixins
// Tooltip Icon
// Icon CSS only tooltip
/// @access private
/// @deprecated
/// @group tooltip
@mixin tooltip--icon {
@include reset;
position: relative;
display: inline-flex;
align-items: center;
overflow: visible;
cursor: pointer;
// Tooltip - renders as a combo of ::before and ::after elements
&::before,
&::after {
@include type-style('body-short-01');
position: absolute;
display: flex;
align-items: center;
opacity: 0;
transition: opacity $duration--fast-01 motion(standard, productive);
pointer-events: none;
}
&::before {
right: 0;
left: 0;
width: 0;
height: 0;
margin: 0 auto;
margin-top: 1px;
margin-left: 50%;
border-color: transparent transparent $inverse-02 transparent;
border-style: solid;
border-width: 0 rem(4px) rem(5px) rem(4px);
content: '';
}
&::after {
@include box-shadow;
min-width: rem(24px);
max-width: rem(208px);
height: rem(24px);
margin-left: 50%;
padding: 0 1rem;
color: $inverse-01;
font-weight: 400;
white-space: nowrap;
background-color: $inverse-02;
border-radius: rem(2px);
transform: translateX(-50%);
content: attr(aria-label);
pointer-events: none;
}
&:hover,
&:focus {
&::before,
&::after {
opacity: 1;
}
}
}
// Tooltip Icon caret - top position
/// @param {String} $position ['bottom'] - The position, from: `top`, `bottom`
/// @param {String} $align ['center'] - The alignment, from: `start`, `center`, `end`
/// @access private
/// @deprecated
/// @group tooltip
@mixin tooltip--icon-placement($position: 'bottom', $align: 'center') {
$translate-x: if($align == 'center', -50%, 0);
$translate-y-caret: if($position == 'top', calc(-100% - 9px), 10px);
$translate-y-body: if(
$position == 'top',
calc(-100% - 12px),
calc(100% + 10px)
);
$rotate-caret: if($position == 'top', 180deg, 0);
&::before {
transform: translate($translate-x, $translate-y-caret) rotate($rotate-caret);
@if ($position == 'top') {
top: 1px;
} @else {
bottom: 0;
}
@if ($align == 'start') {
margin-left: 4px;
} @else if ($align == 'end') {
right: 0;
left: auto;
margin-right: 4px;
}
}
&::after {
transform: translate($translate-x, $translate-y-body);
@if ($position == 'top') {
top: 0;
} @else {
bottom: 0;
}
@if ($align != 'center') {
margin-left: 0;
}
@if ($align == 'end') {
right: 0;
}
}
}
// legacy definition tooltip mixin
/// @access private
/// @deprecated
/// @group tooltip
@mixin tooltip--definition--legacy {
.#{$prefix}--tooltip--definition {
@include reset;
position: relative;
.#{$prefix}--tooltip__trigger {
@include type-style('label-01');
position: relative;
display: inline-flex;
color: $text-01;
border-bottom: 1px dotted $interactive-01;
&:hover {
cursor: pointer;
+ .#{$prefix}--tooltip--definition__top,
+ .#{$prefix}--tooltip--definition__bottom {
display: block;
}
}
&:focus {
@include focus-outline('border');
+ .#{$prefix}--tooltip--definition__top,
+ .#{$prefix}--tooltip--definition__bottom {
display: block;
}
}
}
}
.#{$prefix}--tooltip--definition__bottom,
.#{$prefix}--tooltip--definition__top {
@include box-shadow;
position: absolute;
z-index: 1;
display: none;
width: rem(208px);
margin-top: $carbon--spacing-04;
padding: $carbon--spacing-03 $carbon--spacing-05;
background: $inverse-02;
border-radius: rem(2px);
cursor: pointer;
pointer-events: none;
p {
@include type-style('body-short-01');
color: $inverse-01;
}
.#{$prefix}--tooltip__caret {
position: absolute;
right: 0;
left: 0;
width: 0.6rem;
height: 0.6rem;
margin-left: $carbon--spacing-05;
background: $inverse-02;
}
}
// Tooltip Definition caret - bottom position
.#{$prefix}--tooltip--definition__bottom .#{$prefix}--tooltip__caret {
top: -0.2rem;
transform: rotate(-135deg);
}
// Tooltip Definition caret - top position
.#{$prefix}--tooltip--definition__top {
margin-top: rem(-32px);
transform: translateY(-100%);
.#{$prefix}--tooltip__caret {
bottom: -0.2rem;
transform: rotate(45deg);
}
}
.#{$prefix}--tooltip--definition__align-end {
right: 0;
}
.#{$prefix}--tooltip--definition__align-center {
margin-left: 50%;
transform: translateX(-50%);
}
.#{$prefix}--tooltip--definition__top.#{$prefix}--tooltip--definition__align-center {
margin-left: 50%;
transform: translate(-50%, -100%);
}
.#{$prefix}--tooltip--definition__align-center .#{$prefix}--tooltip__caret {
left: auto;
// Adjust by the half of the diagonal of the caret, which sizes 0.6rem
margin-right: calc(50% - 6px);
margin-left: auto;
}
.#{$prefix}--tooltip--definition__align-end .#{$prefix}--tooltip__caret {
left: auto;
margin-right: rem(16px);
margin-left: auto;
}
}
// legacy icon tooltip mixin
/// @access private
/// @deprecated
/// @group tooltip
@mixin tooltip--icon--legacy {
// Icon CSS only tooltip
.#{$prefix}--tooltip--icon {
display: inline-flex;
align-items: center;
}
.#{$prefix}--tooltip--icon__top,
.#{$prefix}--tooltip--icon__bottom {
@include tooltip--icon;
&:hover,
&:focus {
svg {
fill: $icon-02;
}
}
&:focus {
outline: 1px solid transparent;
svg {
@include focus-outline('border');
}
}
}
// Tooltip Icon caret - top position
.#{$prefix}--tooltip--icon__top {
@include tooltip--icon-placement('top');
}
// Tooltip Icon caret - bottom position
.#{$prefix}--tooltip--icon__bottom {
@include tooltip--icon-placement('bottom');
}
// Tooltip Icon caret - top position, left alignment
.#{$prefix}--tooltip--icon__top.#{$prefix}--tooltip--icon__align-start {
@include tooltip--icon-placement('top', 'start');
}
// Tooltip Icon caret - top position, right alignment
.#{$prefix}--tooltip--icon__top.#{$prefix}--tooltip--icon__align-end {
@include tooltip--icon-placement('top', 'end');
}
// Tooltip Icon caret - bottom position, left alignment
.#{$prefix}--tooltip--icon__bottom.#{$prefix}--tooltip--icon__align-start {
@include tooltip--icon-placement('bottom', 'start');
}
// Tooltip Icon caret - bottom position, right alignment
.#{$prefix}--tooltip--icon__bottom.#{$prefix}--tooltip--icon__align-end {
@include tooltip--icon-placement('bottom', 'end');
}
// Tooltip position - icon only
.#{$prefix}--tooltip--icon .#{$prefix}--tooltip__trigger svg {
margin-left: 0;
}
}
/// Tooltip styles
/// @access private
/// @group tooltip
@mixin tooltip {
// Caret's original size was 13.75px square
$caret-size: rem(6.875px);
.#{$prefix}--tooltip__label {
@include type-style('label-01');
display: inline-flex;
align-items: center;
color: $text-02;
&:focus {
@include focus-outline('border');
}
}
.#{$prefix}--tooltip__trigger svg {
fill: $icon-02;
// Windows, Firefox HCM Fix
@media screen and (-ms-high-contrast: active),
screen and (prefers-contrast) {
// `ButtonText` is a CSS2 system color to help improve colors in HCM
fill: ButtonText;
}
}
.#{$prefix}--tooltip__trigger:not(.#{$prefix}--btn--icon-only) {
@include button-reset($width: false);
display: inline-flex;
align-items: center;
font-size: 1rem;
cursor: pointer;
&:focus {
@include focus-outline('border');
fill: $hover-primary;
}
}
.#{$prefix}--tooltip__label .#{$prefix}--tooltip__trigger {
// Override `margin: 0` from button-reset mixin
margin-left: $carbon--spacing-03;
}
.#{$prefix}--tooltip__label--bold {
font-weight: 600;
}
.#{$prefix}--tooltip {
@include reset;
position: absolute;
z-index: z('floating');
display: none;
min-width: rem(208px);
max-width: rem(288px);
margin-top: $carbon--spacing-02;
padding: $carbon--spacing-05;
color: $inverse-01;
word-wrap: break-word;
border-radius: rem(2px);
// Windows, Firefox HCM Fix
@media screen and (-ms-high-contrast: active),
screen and (prefers-contrast) {
// `ButtonText` is a CSS2 system color to help improve colors in HCM
border: 1px solid transparent;
}
// @todo this can be deprecated in v11 since focus should always be on the content container not the tooltip
&:focus {
outline: 0;
box-shadow: inset 0 0 0 1px $inverse-02, inset 0 0 0 2px $ui-background;
}
p {
@include type-style('body-short-01');
}
button {
padding-right: $carbon--spacing-07;
}
.#{$prefix}--btn:focus {
border-color: $inverse-focus-ui;
outline-color: $inverse-02;
}
.#{$prefix}--link {
color: $inverse-link;
font-size: rem(14px);
&:focus {
outline: 1px solid $inverse-focus-ui;
outline-offset: 2px;
}
&:active,
&:active:visited,
&:active:visited:hover {
color: $inverse-01;
}
&:visited {
color: $inverse-link;
}
}
.#{$prefix}--tooltip__content {
background-color: $inverse-02;
box-shadow: 0 0 0 $spacing-05 $inverse-02,
0 2px 6px $spacing-05 rgba(0, 0, 0, 0.2);
}
// Tooltips need to be click focusable but not sequentially focusable so the user can click within
// the tooltip and not have it close. Because the element is not actionable it does not need
// to have a visible focus indicator (OK'd by IBMa)
.#{$prefix}--tooltip__content[tabindex='-1']:focus {
outline: none;
}
.#{$prefix}--tooltip__caret {
position: absolute;
top: calc(#{$caret-size * (-1)} + 1px);
right: 0;
left: 0;
width: 0;
height: 0;
margin: 0 auto;
border-right: $caret-size solid transparent;
border-bottom: $caret-size solid $inverse-02;
border-left: $caret-size solid transparent;
content: '';
}
&.#{$prefix}--tooltip--top.#{$prefix}--tooltip--align-start,
&.#{$prefix}--tooltip--bottom.#{$prefix}--tooltip--align-start {
.#{$prefix}--tooltip__content {
transform: translate(calc(50% - 6px), 0);
}
}
&.#{$prefix}--tooltip--top.#{$prefix}--tooltip--align-end,
&.#{$prefix}--tooltip--bottom.#{$prefix}--tooltip--align-end {
.#{$prefix}--tooltip__content {
transform: translate(calc(6px - 50%), 0);
}
}
&.#{$prefix}--tooltip--left.#{$prefix}--tooltip--align-start {
.#{$prefix}--tooltip__content {
transform: translate(0, calc(9px + 50% - #{$spacing-03}));
}
}
&.#{$prefix}--tooltip--right.#{$prefix}--tooltip--align-start {
.#{$prefix}--tooltip__content {
transform: translate(0, calc(-3px + 50% - #{$spacing-03}));
}
}
&.#{$prefix}--tooltip--left.#{$prefix}--tooltip--align-end {
.#{$prefix}--tooltip__content {
transform: translate(0, calc(9px - 50% + #{$spacing-03}));
}
}
&.#{$prefix}--tooltip--right.#{$prefix}--tooltip--align-end {
.#{$prefix}--tooltip__content {
transform: translate(0, calc(-3px - 50% + #{$spacing-03}));
}
}
.#{$prefix}--tooltip__footer {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 1rem;
}
&[data-floating-menu-direction='left'] {
.#{$prefix}--tooltip__caret {
top: 50%;
// left position has an additional space between caret and tooltip
right: calc(#{$caret-size * (-1)} + 1px);
left: auto;
transform: rotate(90deg) translate(50%, -50%);
}
}
&[data-floating-menu-direction='top'] {
.#{$prefix}--tooltip__caret {
top: auto;
bottom: calc(#{$caret-size * (-1)} + 1px);
transform: rotate(180deg);
}
}
&[data-floating-menu-direction='right'] {
.#{$prefix}--tooltip__caret {
top: 50%;
right: auto;
left: calc(#{$caret-size * (-1)} + 1px);
transform: rotate(270deg) translate(50%, -50%);
}
}
}
.#{$prefix}--tooltip__heading {
@include carbon--type-style('productive-heading-01');
margin-bottom: $spacing-03;
}
.#{$prefix}--tooltip--shown {
display: block;
}
// Tooltip Definition
/* begin legacy definition tooltip TODO: deprecate */
@include tooltip--definition--legacy;
/* end legacy definition tooltip */
.#{$prefix}--tooltip--definition.#{$prefix}--tooltip--a11y {
// Wrapping element set to inline since the tooltip isn't contained within the trigger (affects center and end alignments)
// Also allows for Definition Tooltip to be used within a paragraph of text as defined in the usage guidelines
display: inline-flex;
}
// default buttons in Safari are adding a small margin, affecting tooltip placement
.#{$prefix}--tooltip--definition button.#{$prefix}--tooltip--a11y {
margin: 0;
}
// Definition CSS only tooltip
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip__trigger--definition {
@include type-style('label-01');
border-bottom: rem(1px) dotted $text-02;
transition: border-color $duration--fast-02;
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip__trigger--definition:hover,
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip__trigger--definition:focus {
border-bottom-color: $interactive-04;
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip__trigger--definition.#{$prefix}--tooltip--top {
@include tooltip--trigger('definition', 'top');
@include tooltip--placement('definition', 'top', 'start');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('definition', 'top', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('definition', 'top', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('definition', 'top', 'end');
}
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip__trigger--definition.#{$prefix}--tooltip--bottom {
@include tooltip--trigger('definition', 'bottom');
@include tooltip--placement('definition', 'bottom', 'start');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('definition', 'bottom', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('definition', 'bottom', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('definition', 'bottom', 'end');
}
}
// Tooltip Icon
/* begin tooltip icon (TODO: deprecate) */
@include tooltip--icon--legacy;
/* end legacy tooltip icon */
// Icon CSS only tooltip
.#{$prefix}--tooltip__trigger {
&:hover,
&:focus {
svg {
fill: $icon-02;
// Windows, Firefox HCM Fix
@media screen and (-ms-high-contrast: active),
screen and (prefers-contrast) {
// `ButtonText` is a CSS2 system color to help improve colors in HCM
fill: ButtonText;
}
}
}
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip--top {
@include tooltip--trigger('icon', 'top');
@include tooltip--placement('icon', 'top', 'center');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('icon', 'top', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('icon', 'top', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('icon', 'top', 'end');
}
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip--right {
@include tooltip--trigger('icon', 'right');
@include tooltip--placement('icon', 'right', 'center');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('icon', 'right', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('icon', 'right', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('icon', 'right', 'end');
}
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip--bottom {
@include tooltip--trigger('icon', 'bottom');
@include tooltip--placement('icon', 'bottom', 'center');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('icon', 'bottom', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('icon', 'bottom', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('icon', 'bottom', 'end');
}
}
.#{$prefix}--tooltip__trigger.#{$prefix}--tooltip--left {
@include tooltip--trigger('icon', 'left');
@include tooltip--placement('icon', 'left', 'center');
&.#{$prefix}--tooltip--align-start {
@include tooltip--placement('icon', 'left', 'start');
}
&.#{$prefix}--tooltip--align-center {
@include tooltip--placement('icon', 'left', 'center');
}
&.#{$prefix}--tooltip--align-end {
@include tooltip--placement('icon', 'left', 'end');
}
}
}
@include exports('tooltip') {
@include tooltip;
}