forked from NodeSecure/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpandable.js
More file actions
87 lines (76 loc) · 2.14 KB
/
expandable.js
File metadata and controls
87 lines (76 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Import Third-party Dependencies
import { LitElement, html, css } from "lit";
import { when } from "lit/directives/when.js";
// Import Internal Dependencies
import { currentLang } from "../../common/utils";
import "../icon/icon.js";
/**
* @typedef {Record<string, { home: { showMore: string, showLess: string } }>} I18nLanguage
*/
/**
* "Expandable" web component displaying a toggle button with an icon.
* @element expandable-span
* @prop {Function} onToggle - Function called during the interaction (default: () => void 0).
* @prop {boolean} isClosed - Specifies whether the associated content is hidden (true) or visible (false).
*/
export class Expandable extends LitElement {
static styles = css`
span.expandable {
display: flex;
align-items: center !important;
justify-content: center !important;
height: 35px;
font-size: 13px;
font-family: mononoki;
background: none;
color: #00B0FF;
text-shadow: 1px 1px 1px rgb(20 20 20 / 50%);
transition: all 0.2s linear;
margin-top: 5px;
}
span.expandable[data-value="opened"] {
color: #F44336 !important;
}
span.expandable:hover {
cursor: pointer;
}
span.expandable nsecure-icon {
margin-right: 4px;
margin-top: 1px;
}
`;
static properties = {
onToggle: { type: Function },
isClosed: { type: Boolean }
};
constructor() {
super();
this.isClosed = true;
/** @type {(instance: Expandable) => void} */
this.onToggle = () => void {};
}
render() {
const lang = currentLang();
const i18n =
/** @type I18nLanguage */
(window.i18n);
const translations = i18n[lang].home;
return html`
<span data-value=${this.isClosed ? "closed" : "opened"} @click=${this.#handleClick} class="expandable">
${when(this.isClosed,
() => html`<nsecure-icon name="plus"></nsecure-icon>
<p>${translations.showMore}</p>`,
() => html`<nsecure-icon name="minus"></nsecure-icon>
<p>${translations.showLess}</p>`
)}
</span>
`;
}
#handleClick() {
this.onToggle(this);
}
}
customElements.define("expandable-span", Expandable);
/**
* @typedef {import('./expandable.js').Expandable} ExpandableType
*/