-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter-app.js
More file actions
116 lines (106 loc) · 2.52 KB
/
counter-app.js
File metadata and controls
116 lines (106 loc) · 2.52 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright 2025 Charlie
* @license Apache-2.0, see LICENSE for full text.
*/
import { LitElement, html, css } from "lit";
import { DDDSuper } from "@haxtheweb/d-d-d/d-d-d.js";
import { I18NMixin } from "@haxtheweb/i18n-manager/lib/I18NMixin.js";
/**
* `counter-app`
*
* @demo index.html
* @element counter-app
*/
export class CounterApp extends DDDSuper(I18NMixin(LitElement)) {
static get tag() {
return "counter-app";
}
constructor() {
super();
this.count = 16;
this.title = "";
this.t = this.t || {};
this.t = {
...this.t,
title: "Title",
};
this.registerLocalization({
context: this,
localesPath:
new URL("./locales/counter-app.ar.json", import.meta.url).href +
"/../",
locales: ["ar", "es", "hi", "zh"],
});
}
// Lit reactive properties
static get properties() {
return {
...super.properties,
count: { type: Number, reflect : true },
};
}
// Lit scoped styles
static get styles() {
return [super.styles,
css`
:host {
display: block;
color: var(--ddd-theme-primary);
background-color: var(--ddd-theme-accent);
font-family: var(--ddd-font-navigation);
}
:host([count="21"]) {
color: var(--ddd-theme-default-athertonViolet);
}
:host([count="18"]) {
color: var(--ddd-theme-default-pughBlue);
}
:host([count="10"]) {
color: var(--ddd-theme-default-pughBlue);
}
:host([count="25"]) {
color: var(--ddd-theme-default-pughBlue);
}
.wrapper {
margin: var(--ddd-spacing-2);
padding: var(--ddd-spacing-4);
}
.counter {
font-size: var(--counter-app-label-font-size, var(--ddd-font-size-xxl));
}
`];
}
// Lit render the HTML
render() {
return html`
<confetti-container id="confetti"></confetti-container>
<div class="wrapper">
<div class="counter">${this.count}</div>
<div class="buttons">
<button @click ="${this.decrease}">-1</button>
<button @click="${this.increase}">+1</button>
</div>
</div>`;
}
increase() {
if(this.count < 25) {
this.count++;
}
}
decrease() {
if(this.count > 10) {
this.count--;
}
}
reset() {
this.count = 16;
}
/**
* haxProperties integration via file reference
*/
static get haxProperties() {
return new URL(`./lib/${this.tag}.haxProperties.json`, import.meta.url)
.href;
}
}
globalThis.customElements.define(CounterApp.tag, CounterApp);