2023-10-16 13:28:41 -04:00
|
|
|
/* Adapted from https://github.com/argyleink/gui-challenges/blob/main/tooltips/tool-tip.css */
|
|
|
|
|
|
|
|
.tooltip {
|
2024-04-19 10:50:58 -04:00
|
|
|
/* Used to power spacing and layout for RTL languages */
|
|
|
|
--isRTL: -1;
|
|
|
|
|
2023-10-16 13:28:41 -04:00
|
|
|
/* internal CSS vars */
|
|
|
|
--_delay: 200ms;
|
2024-04-19 10:50:58 -04:00
|
|
|
--_triangle-width: 8px;
|
|
|
|
--_triangle-height: 12px;
|
|
|
|
--_p-inline: calc(50% + calc(var(--isRTL) * var(--_triangle-width) / 2));
|
2023-10-16 13:28:41 -04:00
|
|
|
--_p-block: 4px;
|
|
|
|
--_bg: var(--chalkboard-10);
|
2024-04-19 10:50:58 -04:00
|
|
|
--_shadow-alpha: 5%;
|
|
|
|
--_theme-alpha: 0.15;
|
|
|
|
--_theme-outline: drop-shadow(
|
|
|
|
0 1px 0
|
|
|
|
oklch(
|
|
|
|
var(--primary-lightness) var(--primary-chroma) var(--primary-hue) /
|
|
|
|
var(--_theme-alpha)
|
|
|
|
)
|
2023-10-16 13:28:41 -04:00
|
|
|
)
|
2024-04-19 10:50:58 -04:00
|
|
|
drop-shadow(
|
|
|
|
0 -1px 0 oklch(var(--primary-lightness) var(--primary-chroma)
|
|
|
|
var(--primary-hue) / var(--_theme-alpha))
|
2023-10-16 13:28:41 -04:00
|
|
|
)
|
2024-04-19 10:50:58 -04:00
|
|
|
drop-shadow(
|
|
|
|
1px 0 0
|
|
|
|
oklch(
|
|
|
|
var(--primary-lightness) var(--primary-chroma) var(--primary-hue) /
|
|
|
|
var(--_theme-alpha)
|
|
|
|
)
|
2023-10-16 13:28:41 -04:00
|
|
|
)
|
2024-04-19 10:50:58 -04:00
|
|
|
drop-shadow(
|
|
|
|
-1px 0 0 oklch(var(--primary-lightness) var(--primary-chroma)
|
|
|
|
var(--primary-hue) / var(--_theme-alpha))
|
|
|
|
);
|
2023-10-16 13:28:41 -04:00
|
|
|
|
|
|
|
pointer-events: none;
|
|
|
|
user-select: none;
|
|
|
|
|
|
|
|
/* The parts that will be transitioned */
|
|
|
|
opacity: 0;
|
|
|
|
transform: translate(var(--_x, 0), var(--_y, 0));
|
|
|
|
transition: transform 0.15s ease-out, opacity 0.11s ease-out;
|
|
|
|
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
inline-size: max-content;
|
|
|
|
max-inline-size: 25ch;
|
|
|
|
text-align: start;
|
|
|
|
font-family: var(--mono-font-family);
|
|
|
|
text-transform: none;
|
|
|
|
font-size: 0.9rem;
|
|
|
|
font-weight: normal;
|
|
|
|
line-height: initial;
|
|
|
|
letter-spacing: 0;
|
|
|
|
padding: var(--_p-block) var(--_p-inline);
|
|
|
|
margin: 0;
|
|
|
|
border-radius: 3px;
|
|
|
|
background: var(--_bg);
|
|
|
|
@apply text-chalkboard-110;
|
|
|
|
will-change: filter;
|
|
|
|
filter: drop-shadow(0 1px 3px hsl(0 0% 0% / var(--_shadow-alpha)))
|
2024-04-19 10:50:58 -04:00
|
|
|
drop-shadow(0 4px 8px hsl(0 0% 0% / var(--_shadow-alpha)))
|
|
|
|
var(--_theme-outline);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
:global(.dark) .tooltip {
|
|
|
|
--_bg: var(--chalkboard-110);
|
2024-04-19 10:50:58 -04:00
|
|
|
--_theme-alpha: 40%;
|
2023-10-16 13:28:41 -04:00
|
|
|
@apply text-chalkboard-10;
|
2024-04-19 10:50:58 -04:00
|
|
|
filter: var(--_theme-outline);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip:dir(rtl) {
|
|
|
|
--isRTL: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* :has and :is are pretty fresh CSS pseudo-selectors, may not see full support */
|
|
|
|
:has(> .tooltip) {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2024-04-15 12:04:17 -04:00
|
|
|
:is(:hover, :active) > .tooltip {
|
2023-10-16 13:28:41 -04:00
|
|
|
opacity: 1;
|
|
|
|
transition-delay: var(--_delay);
|
|
|
|
}
|
|
|
|
|
2024-04-15 12:04:17 -04:00
|
|
|
:is(:focus-visible) > .tooltip.withFocus {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.tooltip:focus-visible {
|
2023-10-16 13:28:41 -04:00
|
|
|
--_delay: 0 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prepend some prose for screen readers only */
|
|
|
|
.tooltip::before {
|
|
|
|
content: '; Has tooltip: ';
|
|
|
|
clip: rect(1px, 1px, 1px, 1px);
|
|
|
|
clip-path: inset(50%);
|
|
|
|
height: 1px;
|
|
|
|
width: 1px;
|
|
|
|
margin: -1px;
|
|
|
|
overflow: hidden;
|
|
|
|
padding: 0;
|
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
/* Sometimes there's no visible label,
|
|
|
|
* so we'll use the tooltip as the label
|
|
|
|
*/
|
|
|
|
.tooltip:only-child::before {
|
|
|
|
content: 'Tooltip:';
|
|
|
|
}
|
|
|
|
|
|
|
|
.caret {
|
|
|
|
width: 8px;
|
|
|
|
height: var(--_triangle-height);
|
2023-10-16 13:28:41 -04:00
|
|
|
position: absolute;
|
|
|
|
z-index: -1;
|
2024-04-19 10:50:58 -04:00
|
|
|
transform-origin: center center;
|
|
|
|
color: var(--_bg);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.top,
|
|
|
|
.bottom {
|
2023-10-16 13:28:41 -04:00
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.tooltip.top {
|
2023-10-16 13:28:41 -04:00
|
|
|
inset-inline-start: 50%;
|
2024-04-19 10:50:58 -04:00
|
|
|
inset-block-end: calc(100% + var(--_p-block) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
--_x: calc(50% * var(--isRTL));
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.top .caret {
|
|
|
|
inset-block-start: calc(100% - 1px);
|
|
|
|
inset-inline-start: 50%;
|
|
|
|
transform: translateX(-50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip.top-right {
|
|
|
|
inset-inline-end: var(--_p-inline);
|
|
|
|
inset-block-end: calc(100% + var(--_p-block) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
/* The corner caret SVG is bottom-right oriented by default */
|
|
|
|
.top-right .caret {
|
|
|
|
inset-block-start: calc(100% - 1px);
|
|
|
|
inset-inline-end: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip.right {
|
|
|
|
inset-inline-start: calc(100% + var(--_p-inline) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
inset-block-end: 50%;
|
|
|
|
--_y: 50%;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.right .caret {
|
|
|
|
inset-inline-end: calc(100% - 1px);
|
|
|
|
inset-block-start: 50%;
|
|
|
|
transform: translateY(-50%) rotate(90deg);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.tooltip.bottom-right {
|
|
|
|
inset-inline-end: var(--_p-inline);
|
|
|
|
inset-block-start: calc(100% + var(--_p-block) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.bottom-right .caret {
|
|
|
|
inset-block-end: calc(100% - 1px);
|
|
|
|
inset-inline-end: 0;
|
|
|
|
transform: rotate(180deg) scaleX(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip.bottom {
|
2023-10-16 13:28:41 -04:00
|
|
|
--_x: calc(50% * var(--isRTL));
|
2024-04-19 10:50:58 -04:00
|
|
|
inset-inline-start: 50%;
|
|
|
|
inset-block-start: calc(100% + var(--_p-block) + var(--_triangle-height));
|
|
|
|
}
|
|
|
|
|
|
|
|
.bottom .caret {
|
|
|
|
inset-block-end: calc(100% - 1px);
|
|
|
|
inset-inline-start: 50%;
|
|
|
|
transform: translateX(-50%) scaleY(-1);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.tooltip.bottom-left {
|
|
|
|
inset-inline-start: var(--_p-inline);
|
|
|
|
inset-block-start: calc(100% + var(--_p-block) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.bottom-left .caret {
|
|
|
|
inset-block-end: calc(100% - 1px);
|
|
|
|
inset-inline-start: 0;
|
|
|
|
transform: rotate(180deg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip.left {
|
|
|
|
inset-inline-end: calc(100% + var(--_p-inline) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
inset-block-end: 50%;
|
|
|
|
--_y: 50%;
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.left .caret {
|
|
|
|
inset-inline-start: calc(100% - 1px);
|
|
|
|
inset-block-start: 50%;
|
|
|
|
transform: translateY(-50%) rotate(-90deg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tooltip.top-left {
|
|
|
|
inset-inline-start: var(--_p-inline);
|
|
|
|
inset-block-end: calc(100% + var(--_p-block) + var(--_triangle-height));
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
2024-04-19 10:50:58 -04:00
|
|
|
.top-left .caret {
|
|
|
|
inset-block-start: calc(100% - 1px);
|
|
|
|
inset-inline-start: 0;
|
|
|
|
transform: rotate(-90deg);
|
2023-10-16 13:28:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@media (prefers-reduced-motion: no-preference) {
|
|
|
|
/* TOP || BLOCK-START */
|
2024-04-19 10:50:58 -04:00
|
|
|
:has(> :is(.tooltip.top, .tooltip.top-left, .tooltip.top-right)):not(
|
|
|
|
:hover,
|
|
|
|
:active
|
|
|
|
)
|
|
|
|
.tooltip {
|
2023-10-16 13:28:41 -04:00
|
|
|
--_y: 3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RIGHT || INLINE-END */
|
2024-04-19 10:50:58 -04:00
|
|
|
:has(> :is(.tooltip.right)):not(:hover, :active) .tooltip {
|
2023-10-16 13:28:41 -04:00
|
|
|
--_x: calc(var(--isRTL) * -3px * -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BOTTOM || BLOCK-END */
|
2024-04-19 10:50:58 -04:00
|
|
|
:has(
|
|
|
|
> :is(
|
|
|
|
.tooltip.bottom,
|
|
|
|
.tooltip.tooltip.bottom-left,
|
|
|
|
.tooltip.bottom-right
|
|
|
|
)
|
|
|
|
):not(:hover, :active)
|
2023-10-16 13:28:41 -04:00
|
|
|
.tooltip {
|
|
|
|
--_y: -3px;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BOTTOM || BLOCK-END */
|
2024-04-19 10:50:58 -04:00
|
|
|
:has(> :is(.tooltip.left)):not(:hover, :active) .tooltip {
|
2023-10-16 13:28:41 -04:00
|
|
|
--_x: calc(var(--isRTL) * 3px * -1);
|
|
|
|
}
|
|
|
|
}
|