@fluid-topics/ft-wc-utils 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ import { Constructor } from "./generic-types";
2
+ import { FtLitElement } from "./FtLitElement";
3
+ export type FtLitElementWithConditionalVisibilityInterface = {
4
+ forceVisible: boolean;
5
+ isVisible: boolean;
6
+ isElementWithConditionalVisibility: boolean;
7
+ };
8
+ type FtLitElementWithConditionalVisibilityType<T extends Constructor<FtLitElement>> = T & Constructor<FtLitElementWithConditionalVisibilityInterface>;
9
+ export declare function withConditionalVisibility<T extends Constructor<FtLitElement>>(Class: T): FtLitElementWithConditionalVisibilityType<T>;
10
+ export {};
@@ -0,0 +1,48 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { property, state } from "lit/decorators.js";
8
+ export function withConditionalVisibility(Class) {
9
+ class FtLitElementWithConditionalVisibilityClass extends Class {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.forceVisible = false;
13
+ this.isVisible = true;
14
+ this.isElementWithConditionalVisibility = true;
15
+ }
16
+ calculateStyles(condition, styleString) {
17
+ if (condition) {
18
+ const style = document.createElement("style");
19
+ style.classList.add("conditional-visibility-style");
20
+ style.innerHTML = styleString;
21
+ this.shadowRoot.append(style);
22
+ }
23
+ }
24
+ hideIfNecessary() {
25
+ const isHidden = !(this.forceVisible || this.isVisible);
26
+ this.calculateStyles(isHidden, ":host { display: none !important; }");
27
+ }
28
+ highlightIfForceVisible() {
29
+ this.calculateStyles(this.forceVisible, ":host { box-shadow: 0px 0px 0px 8px rgba(227,119,59,0.4) inset; }");
30
+ }
31
+ update(props) {
32
+ super.update(props);
33
+ this.updateComplete.then(() => {
34
+ this.shadowRoot.querySelectorAll(".conditional-visibility-style")
35
+ .forEach((element) => element.remove());
36
+ this.hideIfNecessary();
37
+ this.highlightIfForceVisible();
38
+ });
39
+ }
40
+ }
41
+ __decorate([
42
+ property({ type: Boolean, attribute: false })
43
+ ], FtLitElementWithConditionalVisibilityClass.prototype, "forceVisible", void 0);
44
+ __decorate([
45
+ state()
46
+ ], FtLitElementWithConditionalVisibilityClass.prototype, "isVisible", void 0);
47
+ return FtLitElementWithConditionalVisibilityClass;
48
+ }