Skip to content

Commit

Permalink
fix(player): include tooltip left/right default theme styles
Browse files Browse the repository at this point in the history
closes #1059
  • Loading branch information
mihar-22 committed Dec 20, 2023
1 parent fcb938f commit 80ad732
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/vidstack/player/styles/default/tooltips.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@
--exit-transform: translateY(-12px) scale(0.8);
}

/* Left */
:where(.vds-tooltip-content[data-placement~='left']) {
--enter-transform: translateX(0) scale(1);
--exit-transform: translateX(12px) scale(0.8);
}

/* Right */
:where(.vds-tooltip-content[data-placement~='right']) {
--enter-transform: translateX(0) scale(1);
--exit-transform: translateX(-12px) scale(0.8);
}

@keyframes vds-tooltip-enter {
from {
opacity: 0;
Expand Down
9 changes: 5 additions & 4 deletions packages/vidstack/src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,18 @@ export function autoPlacement(
setStyle(el, 'visibility', !trigger ? 'hidden' : null);
if (!trigger) return;

const negateY = (y: string) => (placement.includes('top') ? `calc(-1 * ${y})` : y);
const negateX = (x: string) => (placement.includes('left') ? `calc(-1 * ${x})` : x),
negateY = (y: string) => (placement.includes('top') ? `calc(-1 * ${y})` : y);

return autoUpdate(trigger, el, () => {
computePosition(trigger, el, { placement: floatingPlacement, ...options }).then(({ x, y }) => {
Object.assign(el.style, {
top: `calc(${y + 'px'} + ${negateY(
yOffset ? yOffset + 'px' : `var(--${offsetVarName}-y-offset, 0px)`,
)})`,
left: `calc(${x + 'px'} + ${
xOffset ? xOffset + 'px' : `var(--${offsetVarName}-x-offset, 0px)`
})`,
left: `calc(${x + 'px'} + ${negateX(
xOffset ? xOffset + 'px' : `var(--${offsetVarName}-x-offset, 0px)`,
)})`,
});
});
});
Expand Down

0 comments on commit 80ad732

Please sign in to comment.