import { html, LitElement, unsafeCSS } from "lit";
import { property, state } from "lit/decorators.js";
import globalStyle from "./f-tooltip-global.scss?inline";
import { FDiv } from "../f-div/f-div";
import { FText } from "../f-text/f-text";
import { FPopover } from "../f-popover/f-popover";
import { flowElement } from "./../../utils";
import { injectCss } from "@cldcvr/flow-core-config";
injectCss("f-tooltip", globalStyle);
export type FTooltipPlacement =
| "top"
| "top-start"
| "top-end"
| "right"
| "right-start"
| "right-end"
| "bottom"
| "bottom-start"
| "bottom-end"
| "left"
| "left-start"
| "left-end"
| "auto";
@flowElement("f-tooltip")
export class FTooltip extends LitElement {
/**
* css loaded from scss file
*/
static styles = [unsafeCSS(globalStyle), ...FDiv.styles, ...FText.styles, ...FPopover.styles];
/**
* local attribute for opem/close of tooltip
*/
@state()
open = false;
/**
* @attribute placement of `f-tooltip`
*/
@property({ type: String, reflect: true })
placement?: FTooltipPlacement = "auto";
/**
* @attribute close icon for tooltip
*/
@property({ type: Boolean, reflect: true })
closable?: boolean = false;
/**
* @attribute query selector of target
*/
target!: string | HTMLElement;
render() {
this.setAttribute("data-theme", "f-dark");
/**
* Final html to render
*/
if (this.open) {
return html`
${this.closable
? html` (this.open = false)}
>`
: ""}
`;
}
return html``;
}
}
/**
* Required for typescript
*/
declare global {
interface HTMLElementTagNameMap {
"f-tooltip": FTooltip;
}
}