UNPKG

@vime/core

Version:

Customizable, extensible, accessible and framework agnostic media player.

209 lines (208 loc) 5.68 kB
import { Component, Element, h, Prop } from '@stencil/core'; import { isString } from '../../../utils/unit'; import { withComponentRegistry } from '../../core/player/withComponentRegistry'; import { withPlayerContext } from '../../core/player/withPlayerContext'; let tooltipIdCount = 0; /** * A small pop-up box that appears when a user moves their mouse over an element. Their main purpose * is to provide a description about the function of that element. * * ## Visual * * <img * src="https://raw.githubusercontent.com/vime-js/vime/master/packages/core/src/components/ui/tooltip/tooltip.png" * alt="Vime tooltip component" * /> * * @slot - Used to pass in the contents of the tooltip. */ export class Tooltip { constructor() { // Avoid tooltips flashing when player initializing. this.hasLoaded = false; /** * Whether the tooltip is displayed or not. */ this.hidden = false; /** * Whether the tooltip is visible or not. */ this.active = false; /** * Determines if the tooltip appears on top/bottom of it's parent. */ this.position = 'top'; /** @internal */ this.isTouch = false; /** @internal */ this.isMobile = false; withComponentRegistry(this); withPlayerContext(this, ['isTouch', 'isMobile']); } componentDidLoad() { this.hasLoaded = true; } getId() { // eslint-disable-next-line prefer-destructuring const id = this.host.id; if (isString(id) && id.length > 0) return id; tooltipIdCount += 1; return `vm-tooltip-${tooltipIdCount}`; } render() { return (h("div", { id: this.getId(), role: "tooltip", "aria-hidden": !this.active || this.isTouch || this.isMobile ? 'true' : 'false', class: { tooltip: true, hidden: !this.hasLoaded || this.hidden, onTop: this.position === 'top', onBottom: this.position === 'bottom', growLeft: this.direction === 'left', growRight: this.direction === 'right', } }, h("slot", null))); } static get is() { return "vm-tooltip"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["tooltip.css"] }; } static get styleUrls() { return { "$": ["tooltip.css"] }; } static get properties() { return { "hidden": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Whether the tooltip is displayed or not." }, "attribute": "hidden", "reflect": false, "defaultValue": "false" }, "active": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Whether the tooltip is visible or not." }, "attribute": "active", "reflect": false, "defaultValue": "false" }, "position": { "type": "string", "mutable": false, "complexType": { "original": "TooltipPosition", "resolved": "\"bottom\" | \"top\"", "references": { "TooltipPosition": { "location": "import", "path": "./types" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "Determines if the tooltip appears on top/bottom of it's parent." }, "attribute": "position", "reflect": false, "defaultValue": "'top'" }, "direction": { "type": "string", "mutable": false, "complexType": { "original": "TooltipDirection", "resolved": "\"left\" | \"right\" | undefined", "references": { "TooltipDirection": { "location": "import", "path": "./types" } } }, "required": false, "optional": true, "docs": { "tags": [], "text": "Determines if the tooltip should grow according to its contents to the left/right. By default\ncontent grows outwards from the center." }, "attribute": "direction", "reflect": false }, "isTouch": { "type": "boolean", "mutable": false, "complexType": { "original": "PlayerProps['isTouch']", "resolved": "boolean", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": false, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "is-touch", "reflect": false, "defaultValue": "false" }, "isMobile": { "type": "boolean", "mutable": false, "complexType": { "original": "PlayerProps['isMobile']", "resolved": "boolean", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": false, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "is-mobile", "reflect": false, "defaultValue": "false" } }; } static get elementRef() { return "host"; } }