mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(react): use popover and anchor position API (#178)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { contains, getDocument, getDocumentOrShadowRoot, safePolygon } from '@videojs/utils/dom';
|
||||
|
||||
type Placement = 'top' | 'bottom' | 'left' | 'right';
|
||||
type Placement = 'top' | 'top-start' | 'top-end';
|
||||
|
||||
export class PopoverElement extends HTMLElement {
|
||||
static get observedAttributes(): string[] {
|
||||
@@ -18,9 +18,14 @@ export class PopoverElement extends HTMLElement {
|
||||
this.style.setProperty('position-anchor', `--${newValue}`);
|
||||
}
|
||||
|
||||
this.style.setProperty('top', `calc(anchor(${this.side}) - ${this.sideOffset}px)`);
|
||||
const [side, alignment] = this.side.split('-');
|
||||
this.style.setProperty('top', `calc(anchor(${side}) - ${this.sideOffset}px)`);
|
||||
this.style.setProperty('translate', `0 -100%`);
|
||||
this.style.setProperty('justify-self', 'anchor-center');
|
||||
this.style.setProperty('justify-self', alignment === 'start'
|
||||
? 'anchor-start'
|
||||
: alignment === 'end'
|
||||
? 'anchor-end'
|
||||
: 'anchor-center');
|
||||
}
|
||||
|
||||
connectedCallback(): void {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
getInBoundsAdjustments,
|
||||
} from '@videojs/utils/dom';
|
||||
|
||||
type Placement = 'top' | 'bottom' | 'left' | 'right';
|
||||
type Placement = 'top' | 'top-start' | 'top-end';
|
||||
|
||||
export class TooltipElement extends HTMLElement {
|
||||
static get observedAttributes(): string[] {
|
||||
@@ -30,14 +30,18 @@ export class TooltipElement extends HTMLElement {
|
||||
if (name === 'id') {
|
||||
this.style.setProperty('position-anchor', `--${newValue}`);
|
||||
}
|
||||
|
||||
this.style.setProperty('top', `calc(anchor(${this.side}) - ${this.sideOffset}px)`);
|
||||
const [side, alignment] = this.side.split('-');
|
||||
this.style.setProperty('top', `calc(anchor(${side}) - ${this.sideOffset}px)`);
|
||||
|
||||
if (this.trackCursorAxis) {
|
||||
this.style.setProperty('translate', `-50% -100%`);
|
||||
} else {
|
||||
this.style.setProperty('translate', `0 -100%`);
|
||||
this.style.setProperty('justify-self', 'anchor-center');
|
||||
this.style.setProperty('justify-self', alignment === 'start'
|
||||
? 'anchor-start'
|
||||
: alignment === 'end'
|
||||
? 'anchor-end'
|
||||
: 'anchor-center');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,10 @@ import type { Constructor, CustomElement } from '@open-wc/context-protocol';
|
||||
|
||||
import { ConsumerMixin } from '@open-wc/context-protocol';
|
||||
|
||||
/* @TODO We need to make sure portal logic is non-brittle longer term (CJP) */
|
||||
export function getTemplateHTML() {
|
||||
return /* html */ `
|
||||
<slot name="media"></slot>
|
||||
<slot></slot>
|
||||
<div id="@default_portal_id" style={ position: absolute; zIndex: 10; }>
|
||||
<slot name="portal"></slot>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user