wj-elements 0.0.11 → 0.0.13
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.
- package/dist/localize-20081fd1.js +55 -0
- package/dist/router-links-26e4a166.js +204 -0
- package/dist/style.css +2243 -2
- package/dist/wj-animation.js +35 -23
- package/dist/wj-aside.js +22 -16
- package/dist/wj-avatar.js +49 -30
- package/dist/wj-badge.js +22 -18
- package/dist/wj-breadcrumb.js +102 -50
- package/dist/wj-breadcrumbs.js +36 -19
- package/dist/wj-button-group.js +36 -22
- package/dist/wj-button.js +104 -39
- package/dist/wj-card-content.js +18 -14
- package/dist/wj-card-controls.js +18 -14
- package/dist/wj-card-header.js +20 -14
- package/dist/wj-card-subtitle.js +19 -15
- package/dist/wj-card-title.js +18 -14
- package/dist/wj-card.js +20 -14
- package/dist/wj-carousel-item.js +22 -16
- package/dist/wj-carousel.js +169 -92
- package/dist/wj-checkbox.js +46 -24
- package/dist/wj-chip.js +39 -21
- package/dist/wj-col.js +31 -17
- package/dist/wj-color-picker.js +877 -509
- package/dist/wj-container.js +20 -16
- package/dist/wj-copy-button.js +112 -64
- package/dist/wj-dialog.js +68 -42
- package/dist/wj-divider.js +20 -14
- package/dist/wj-dropdown.js +29 -17
- package/dist/wj-element.js +415 -241
- package/dist/wj-fetchAndParseCSS.js +49 -32
- package/dist/wj-file-upload-item.js +64 -38
- package/dist/wj-file-upload.js +237 -137
- package/dist/wj-footer.js +18 -14
- package/dist/wj-form.js +18 -14
- package/dist/wj-format-digital.js +40 -25
- package/dist/wj-grid.js +20 -16
- package/dist/wj-header.js +22 -16
- package/dist/wj-icon-picker.js +122 -68
- package/dist/wj-icon.js +144 -64
- package/dist/wj-img-comparer.js +72 -41
- package/dist/wj-img.js +31 -19
- package/dist/wj-infinite-scroll.js +90 -52
- package/dist/wj-input-file.js +50 -27
- package/dist/wj-input.js +169 -70
- package/dist/wj-item.js +34 -17
- package/dist/wj-label.js +21 -19
- package/dist/wj-list.js +20 -15
- package/dist/wj-main.js +18 -14
- package/dist/wj-masonry.js +140 -83
- package/dist/wj-master.js +492 -350
- package/dist/wj-menu-button.js +19 -15
- package/dist/wj-menu-item.js +150 -64
- package/dist/wj-menu-label.js +21 -17
- package/dist/wj-menu.js +24 -18
- package/dist/wj-popup.js +1140 -712
- package/dist/wj-progress-bar.js +100 -40
- package/dist/wj-radio-group.js +38 -25
- package/dist/wj-radio.js +46 -22
- package/dist/wj-rate.js +121 -71
- package/dist/wj-relative-time.js +48 -24
- package/dist/wj-route.js +11 -8
- package/dist/wj-router-link.js +22 -17
- package/dist/wj-router-outlet.js +135 -71
- package/dist/wj-routerx.js +1124 -641
- package/dist/wj-row.js +21 -19
- package/dist/wj-slider.js +97 -55
- package/dist/wj-split-view.js +81 -43
- package/dist/wj-store.js +195 -110
- package/dist/wj-textarea.js +86 -37
- package/dist/wj-thumbnail.js +19 -15
- package/dist/wj-toast.js +87 -34
- package/dist/wj-toggle.js +42 -24
- package/dist/wj-toolbar-action.js +27 -16
- package/dist/wj-toolbar.js +26 -19
- package/dist/wj-tooltip.js +40 -24
- package/dist/wj-visually-hidden.js +18 -14
- package/package.json +1 -1
- package/dist/localize-762a9f0f.js +0 -43
- package/dist/router-links-e0087f84.js +0 -146
package/dist/wj-progress-bar.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement from "./wj-element.js";
|
|
5
8
|
import "./wj-store.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class f extends j {
|
|
9
|
+
const styles = "/*\n[ WJ Progress bar ]\n*/\n:host(.wj-color-primary) #bar {\n --wj-progress-bar-color: var(--wj-color-primary);\n}\n\n:host(.wj-color-complete) #bar {\n --wj-progress-bar-color: var(--wj-color-complete);\n}\n\n:host(.wj-color-success) #bar {\n --wj-progress-bar-color: var(--wj-color-success);\n}\n\n:host(.wj-color-warning) #bar {\n --wj-progress-bar-color: var(--wj-color-warning);\n}\n\n:host(.wj-color-danger) #bar {\n --wj-progress-bar-color: var(--wj-color-danger);\n}\n\n:host(.wj-color-dark) #bar {\n --wj-progress-bar-color: var(--wj-color-contrast-0);\n}\n\n:host(.wj-color-light) #bar {\n --wj-progress-bar-color: var(--wj-color-contrast-11);\n}\n\n:host {\n --wj-progress-bar-color: var(--wj-color-contrast-6);\n --wj-progress-bar-text-size: .75rem;\n --wj-progress-bar-text-color: var(--wj-color);\n}\n:host .progress {\n position: relative;\n display: flex;\n align-items: center;\n}\n:host .slot-wrapper {\n display: flex;\n position: absolute;\n top: 0;\n align-items: center;\n width: 100%;\n height: 100%;\n justify-content: center;\n}\n:host #bar {\n stroke: var(--wj-progress-bar-color);\n}\n:host text {\n transform: rotate(90deg);\n transform-origin: center;\n text-anchor: middle;\n dominant-baseline: middle;\n font-size: var(--wj-progress-bar-text-size);\n fill: var(--wj-progress-bar-text-color);\n}\n\n:host(.wj-color) #bar {\n stroke: var(--wj-progress-bar-color);\n}\n\n::slotted([slot=start]) {\n margin-inline: 0 1rem;\n}\n\n::slotted([slot=end]) {\n margin-inline: 1rem 0;\n}";
|
|
10
|
+
class ProgressBar extends WJElement {
|
|
9
11
|
constructor() {
|
|
10
12
|
super();
|
|
11
|
-
|
|
12
|
-
this.timerInterval = null
|
|
13
|
+
__publicField(this, "className", "ProgressBar");
|
|
14
|
+
this.timerInterval = null;
|
|
15
|
+
this.timeLimit = 60;
|
|
13
16
|
}
|
|
14
|
-
set radius(
|
|
15
|
-
this.setAttribute("radius",
|
|
17
|
+
set radius(value) {
|
|
18
|
+
this.setAttribute("radius", value);
|
|
16
19
|
}
|
|
17
20
|
get radius() {
|
|
18
21
|
return +this.getAttribute("radius") || 70;
|
|
@@ -20,8 +23,8 @@ class f extends j {
|
|
|
20
23
|
get diameter() {
|
|
21
24
|
return this.radius * 2 + this.stroke;
|
|
22
25
|
}
|
|
23
|
-
set stroke(
|
|
24
|
-
this.setAttribute("stroke",
|
|
26
|
+
set stroke(value) {
|
|
27
|
+
this.setAttribute("stroke", value);
|
|
25
28
|
}
|
|
26
29
|
get stroke() {
|
|
27
30
|
return +this.getAttribute("stroke") || 6;
|
|
@@ -30,7 +33,7 @@ class f extends j {
|
|
|
30
33
|
return this.getAttribute("linecap") || "square";
|
|
31
34
|
}
|
|
32
35
|
static get cssStyleSheet() {
|
|
33
|
-
return
|
|
36
|
+
return styles;
|
|
34
37
|
}
|
|
35
38
|
static get observedAttributes() {
|
|
36
39
|
return ["progress"];
|
|
@@ -38,37 +41,94 @@ class f extends j {
|
|
|
38
41
|
setupAttributes() {
|
|
39
42
|
this.isShadowRoot = "open";
|
|
40
43
|
}
|
|
41
|
-
draw(
|
|
42
|
-
let
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
draw(context, store, params) {
|
|
45
|
+
let xy = this.radius + this.stroke / 2;
|
|
46
|
+
let fragment = document.createDocumentFragment();
|
|
47
|
+
if (params.color)
|
|
48
|
+
this.classList.add("wj-color-" + params.color, "wj-color");
|
|
49
|
+
let element = document.createElement("div");
|
|
50
|
+
element.classList.add("progress");
|
|
51
|
+
let slot = document.createElement("slot");
|
|
52
|
+
let slotWrapper = document.createElement("div");
|
|
53
|
+
slotWrapper.classList.add("slot-wrapper");
|
|
54
|
+
let slotStart = document.createElement("slot");
|
|
55
|
+
slotStart.setAttribute("name", "start");
|
|
56
|
+
let slotEnd = document.createElement("slot");
|
|
57
|
+
slotEnd.setAttribute("name", "end");
|
|
58
|
+
let svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
59
|
+
let background;
|
|
60
|
+
let bar;
|
|
53
61
|
if ((this == null ? void 0 : this.type) === "circle") {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
svg.setAttribute("width", this.diameter);
|
|
63
|
+
svg.setAttribute("height", this.diameter);
|
|
64
|
+
svg.setAttribute("viewBox", `0 0 ${this.diameter} ${this.diameter}`);
|
|
65
|
+
svg.setAttribute("style", "transform: rotate(-90deg)");
|
|
66
|
+
background = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
67
|
+
background.setAttribute("r", this.radius);
|
|
68
|
+
background.setAttribute("cx", xy);
|
|
69
|
+
background.setAttribute("cy", xy);
|
|
70
|
+
background.setAttribute("fill", "transparent");
|
|
71
|
+
bar = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
72
|
+
bar.setAttribute("r", this.radius);
|
|
73
|
+
bar.setAttribute("cx", xy);
|
|
74
|
+
bar.setAttribute("cy", xy);
|
|
75
|
+
bar.setAttribute("fill", "transparent");
|
|
76
|
+
bar.setAttribute("stroke-dasharray", "0");
|
|
77
|
+
bar.setAttribute("stroke-dashoffset", "0");
|
|
78
|
+
let text = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
79
|
+
text.setAttribute("x", "50%");
|
|
80
|
+
text.setAttribute("y", "50%");
|
|
81
|
+
text.innerHTML = this.progress + "%";
|
|
82
|
+
svg.appendChild(text);
|
|
83
|
+
} else {
|
|
84
|
+
svg.setAttribute("width", "100%");
|
|
85
|
+
svg.setAttribute("height", this.stroke);
|
|
86
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
87
|
+
background = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
88
|
+
background.setAttribute("x1", 0);
|
|
89
|
+
background.setAttribute("y1", this.stroke / 2);
|
|
90
|
+
background.setAttribute("x2", "100%");
|
|
91
|
+
background.setAttribute("y2", this.stroke / 2);
|
|
92
|
+
bar = document.createElementNS("http://www.w3.org/2000/svg", "line");
|
|
93
|
+
bar.setAttribute("x1", 0);
|
|
94
|
+
bar.setAttribute("y1", this.stroke / 2);
|
|
95
|
+
bar.setAttribute("x2", this.progress + "%");
|
|
96
|
+
bar.setAttribute("y2", this.stroke / 2);
|
|
97
|
+
}
|
|
98
|
+
background.setAttribute("stroke", "#e0e0e0");
|
|
99
|
+
background.setAttribute("stroke-linecap", this.linecap);
|
|
100
|
+
background.setAttribute("stroke-width", this.stroke + "px");
|
|
101
|
+
bar.setAttribute("stroke-linecap", this.linecap);
|
|
102
|
+
bar.setAttribute("stroke-width", this.stroke + "px");
|
|
103
|
+
bar.setAttribute("id", "bar");
|
|
104
|
+
svg.appendChild(background);
|
|
105
|
+
svg.appendChild(bar);
|
|
106
|
+
slotWrapper.appendChild(slot);
|
|
107
|
+
element.appendChild(slotStart);
|
|
108
|
+
element.appendChild(slotWrapper);
|
|
109
|
+
element.appendChild(svg);
|
|
110
|
+
element.appendChild(slotEnd);
|
|
111
|
+
fragment.appendChild(element);
|
|
112
|
+
this.background = background;
|
|
113
|
+
this.bar = bar;
|
|
114
|
+
return fragment;
|
|
60
115
|
}
|
|
61
|
-
afterDraw(
|
|
62
|
-
this.type === "circle"
|
|
116
|
+
afterDraw(context, store, params) {
|
|
117
|
+
if (this.type === "circle") {
|
|
118
|
+
this.background.setAttribute("stroke-dasharray", this.getCircleDashoffset(100) + "px");
|
|
119
|
+
this.background.setAttribute("stroke-dashoffset", "0px");
|
|
120
|
+
this.bar.setAttribute("stroke-dasharray", this.getCircleDasharray(this.radius) + "px");
|
|
121
|
+
this.bar.setAttribute("stroke-dashoffset", this.getCircleDashoffset(params.progress, this.radius) + "px");
|
|
122
|
+
}
|
|
63
123
|
}
|
|
64
|
-
getCircleDasharray(
|
|
65
|
-
return 2 * Math.PI *
|
|
124
|
+
getCircleDasharray(radius = 70) {
|
|
125
|
+
return 2 * Math.PI * radius;
|
|
66
126
|
}
|
|
67
|
-
getCircleDashoffset(
|
|
68
|
-
return this.getCircleDasharray(
|
|
127
|
+
getCircleDashoffset(progress = 0, radius) {
|
|
128
|
+
return this.getCircleDasharray(radius) * ((100 - progress) / 100);
|
|
69
129
|
}
|
|
70
130
|
}
|
|
71
|
-
customElements.get("wj-progress-bar") || window.customElements.define("wj-progress-bar",
|
|
131
|
+
customElements.get("wj-progress-bar") || window.customElements.define("wj-progress-bar", ProgressBar);
|
|
72
132
|
export {
|
|
73
|
-
|
|
133
|
+
ProgressBar
|
|
74
134
|
};
|
package/dist/wj-radio-group.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement from "./wj-element.js";
|
|
8
|
+
import { Radio } from "./wj-radio.js";
|
|
6
9
|
import "./wj-store.js";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
class m extends u {
|
|
10
|
+
const styles = "/*\n[ WJ Radio Group ]\n*/\n.wj-inline {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n gap: 0.5rem;\n}";
|
|
11
|
+
class RadioGroup extends WJElement {
|
|
10
12
|
constructor() {
|
|
11
13
|
super();
|
|
12
|
-
|
|
14
|
+
__publicField(this, "className", "RadioGroup");
|
|
13
15
|
}
|
|
14
16
|
static get cssStyleSheet() {
|
|
15
|
-
return
|
|
17
|
+
return styles;
|
|
16
18
|
}
|
|
17
19
|
static get observedAttributes() {
|
|
18
20
|
return [];
|
|
@@ -20,33 +22,44 @@ class m extends u {
|
|
|
20
22
|
setupAttributes() {
|
|
21
23
|
this.isShadowRoot = "open";
|
|
22
24
|
}
|
|
23
|
-
draw(
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
draw(context, store, params) {
|
|
26
|
+
let fragment = document.createDocumentFragment();
|
|
27
|
+
let native = document.createElement("div");
|
|
28
|
+
native.classList.add("native-radio-group", this.hasAttribute("inline") ? "wj-inline" : "ddd");
|
|
29
|
+
let slot = document.createElement("slot");
|
|
30
|
+
native.appendChild(slot);
|
|
31
|
+
fragment.appendChild(native);
|
|
32
|
+
return fragment;
|
|
28
33
|
}
|
|
29
34
|
afterDraw() {
|
|
30
|
-
|
|
31
|
-
this.
|
|
35
|
+
if (this.value) {
|
|
36
|
+
this.setRadioToChekced(this.getRadioByValue(this.value));
|
|
37
|
+
}
|
|
38
|
+
this.addEventListener("wj:radio:input", (e) => {
|
|
39
|
+
this.removeCheck();
|
|
40
|
+
this.setRadioToChekced(e.detail.context);
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
|
-
getRadioByValue(
|
|
35
|
-
return this.getAllElements().filter((
|
|
43
|
+
getRadioByValue(value) {
|
|
44
|
+
return this.getAllElements().filter((el) => el instanceof Radio && el.value === value)[0];
|
|
36
45
|
}
|
|
37
46
|
removeCheck() {
|
|
38
|
-
this.getAllElements().forEach((
|
|
39
|
-
|
|
47
|
+
this.getAllElements().forEach((el) => {
|
|
48
|
+
if (el instanceof Radio)
|
|
49
|
+
el.checked = false;
|
|
40
50
|
});
|
|
41
51
|
}
|
|
42
|
-
setRadioToChekced(
|
|
43
|
-
|
|
52
|
+
setRadioToChekced(radio) {
|
|
53
|
+
if (radio instanceof Radio) {
|
|
54
|
+
this.setAttribute("value", radio.value);
|
|
55
|
+
radio.checked = true;
|
|
56
|
+
}
|
|
44
57
|
}
|
|
45
58
|
getAllElements() {
|
|
46
59
|
return Array.from(this.childNodes);
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
|
-
customElements.get("wj-radio-group") || window.customElements.define("wj-radio-group",
|
|
62
|
+
customElements.get("wj-radio-group") || window.customElements.define("wj-radio-group", RadioGroup);
|
|
50
63
|
export {
|
|
51
|
-
|
|
64
|
+
RadioGroup
|
|
52
65
|
};
|
package/dist/wj-radio.js
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement, { event } from "./wj-element.js";
|
|
5
8
|
import "./wj-store.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class h extends s {
|
|
9
|
+
const styles = '/*\n[ WJ Radio ]\n*/\n:host {\n --wj-radio-margin-top: 0;\n --wj-radio-margin-bottom: .5rem;\n --wj-radio-margin-inline: 0;\n display: block;\n margin-top: var(--wj-radio-margin-top);\n margin-bottom: var(--wj-radio-margin-bottom);\n margin-inline: var(--wj-radio-margin-inline);\n line-height: 100%;\n padding-left: 0;\n}\n:host label {\n display: inline-flex;\n cursor: pointer;\n position: relative;\n padding-left: 1.5rem;\n min-width: 16px;\n min-height: 16px;\n margin-bottom: 0;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -moz-user-select: none; /* Old versions of Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera and Firefox */\n align-items: center;\n}\n:host label:before {\n content: "";\n position: absolute;\n width: 16px;\n height: 16px;\n left: 0;\n -webkit-box-sizing: inherit;\n box-sizing: border-box;\n background-color: var(--wj-color-contrast-1);\n border: 1px solid var(--wj-color-contrast-4);\n}\n\n.native-radio input[type=radio] + label:before {\n border-radius: var(--wj-border-radius-circle);\n transition: border 0.3s 0s cubic-bezier(0.455, 0.03, 0.215, 1.33);\n}\n.native-radio input[type=radio]:checked + label:before {\n border-color: var(--wj-color-contrast-6);\n border-width: 5px;\n}\n.native-radio input[type=radio]:focus + label {\n color: var(--wj-color);\n}\n.native-radio input[type=radio]:focus + label:before {\n outline: none !important;\n box-shadow: 0 0 0 0 #78c8fe;\n}\n.native-radio input[type=radio] {\n opacity: 0;\n position: absolute;\n top: 3px;\n width: 16px;\n height: 16px;\n}\n.native-radio input[type=radio][disabled] + label {\n cursor: not-allowed !important;\n color: var(--wj-color-contrast-9);\n opacity: 0.5;\n}\n.native-radio input[type=radio][disabled] + label:before {\n cursor: not-allowed !important;\n}\n\n.success input[type=radio]:checked + label:before {\n border-color: var(--wj-color-success);\n}\n.primary input[type=radio]:checked + label:before {\n border-color: var(--wj-color-primary);\n}\n.complete input[type=radio]:checked + label:before {\n border-color: var(--wj-color-complete);\n}\n.warning input[type=radio]:checked + label:before {\n border-color: var(--wj-color-warning);\n}\n.danger input[type=radio]:checked + label:before {\n border-color: var(--wj-color-danger);\n}\n.neutral input[type=radio]:checked + label:before {\n border-color: var(--wj-color-info);\n}';
|
|
10
|
+
class Radio extends WJElement {
|
|
9
11
|
constructor() {
|
|
10
12
|
super();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
__publicField(this, "className", "Radio");
|
|
14
|
+
__publicField(this, "inputEvent", (e) => {
|
|
13
15
|
this.checked = e.target.checked;
|
|
14
16
|
});
|
|
15
|
-
this._checked =
|
|
17
|
+
this._checked = false;
|
|
16
18
|
}
|
|
17
|
-
set checked(
|
|
18
|
-
this._checked =
|
|
19
|
+
set checked(value) {
|
|
20
|
+
this._checked = value;
|
|
21
|
+
if (value)
|
|
22
|
+
this.setAttribute("checked", "");
|
|
23
|
+
else
|
|
24
|
+
this.removeAttribute("checked");
|
|
19
25
|
}
|
|
20
26
|
get checked() {
|
|
21
27
|
return this._checked;
|
|
22
28
|
}
|
|
23
29
|
static get cssStyleSheet() {
|
|
24
|
-
return
|
|
30
|
+
return styles;
|
|
25
31
|
}
|
|
26
32
|
static get observedAttributes() {
|
|
27
33
|
return ["checked"];
|
|
@@ -29,20 +35,38 @@ class h extends s {
|
|
|
29
35
|
setupAttributes() {
|
|
30
36
|
this.isShadowRoot = "open";
|
|
31
37
|
}
|
|
32
|
-
draw(
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
draw(context, store, params) {
|
|
39
|
+
let fragment = document.createDocumentFragment();
|
|
40
|
+
let native = document.createElement("div");
|
|
41
|
+
native.classList.add("native-radio");
|
|
42
|
+
if (this.color)
|
|
43
|
+
native.classList.add(this.color);
|
|
44
|
+
this.input = document.createElement("input");
|
|
45
|
+
this.input.type = "radio";
|
|
46
|
+
this.input.id = "radio";
|
|
47
|
+
this.input.name = this.name + "-radio";
|
|
48
|
+
this.input.checked = this.hasAttribute("checked");
|
|
49
|
+
this.input.disabled = this.hasAttribute("disabled");
|
|
50
|
+
this.input.indeterminate = this.hasAttribute("indeterminate");
|
|
51
|
+
let label = document.createElement("label");
|
|
52
|
+
label.htmlFor = "radio";
|
|
53
|
+
label.innerHTML = "<slot></slot>";
|
|
54
|
+
native.appendChild(this.input);
|
|
55
|
+
native.appendChild(label);
|
|
56
|
+
fragment.appendChild(native);
|
|
57
|
+
return fragment;
|
|
37
58
|
}
|
|
38
59
|
afterDraw() {
|
|
39
|
-
this.hasAttribute("disabled")
|
|
60
|
+
if (!this.hasAttribute("disabled")) {
|
|
61
|
+
event.addListener(this, "click", "wj:radio:change");
|
|
62
|
+
event.addListener(this, "click", "wj:radio:input");
|
|
63
|
+
}
|
|
40
64
|
}
|
|
41
65
|
disconnectedCallback() {
|
|
42
|
-
|
|
66
|
+
event.removeElement(this);
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
|
-
customElements.get("wj-radio") || window.customElements.define("wj-radio",
|
|
69
|
+
customElements.get("wj-radio") || window.customElements.define("wj-radio", Radio);
|
|
46
70
|
export {
|
|
47
|
-
|
|
71
|
+
Radio
|
|
48
72
|
};
|
package/dist/wj-rate.js
CHANGED
|
@@ -1,127 +1,177 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement from "./wj-element.js";
|
|
5
8
|
import "./wj-store.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
class m extends d {
|
|
9
|
+
const styles = "/*\n[ WJ Rate ]\n*/\n:host {\n display: flex;\n}\n\n.native-rate {\n position: relative;\n display: flex;\n gap: var(--wj-rate-gap, 0.25rem);\n}\n\n.wj-rate-icon {\n position: relative;\n cursor: pointer;\n}\n\n.selected {\n color: var(--wj-color-danger);\n}\n\n:host(:not([readonly])) .wj-rate-icon:hover {\n transform: scale(1.2);\n}\n\n.half wj-icon:first-child {\n color: white;\n}\n\n.half wj-icon:last-child {\n color: currentColor;\n position: absolute;\n top: 0;\n left: 0;\n}\n\n:host([disabled]) .native-rate {\n pointer-events: none;\n opacity: 0.5;\n}";
|
|
10
|
+
class Rate extends WJElement {
|
|
9
11
|
constructor() {
|
|
10
12
|
super();
|
|
11
|
-
|
|
13
|
+
__publicField(this, "className", "Rate");
|
|
12
14
|
/*
|
|
13
15
|
* Events - Mouse
|
|
14
16
|
*/
|
|
15
|
-
|
|
16
|
-
e.preventDefault()
|
|
17
|
+
__publicField(this, "onMouseEnter", (e) => {
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
this.hoverValue = this.getValueFromXPosition(e.clientX);
|
|
20
|
+
this.changeRate();
|
|
17
21
|
});
|
|
18
|
-
|
|
19
|
-
e.preventDefault()
|
|
22
|
+
__publicField(this, "onMouseLeave", (e) => {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
this.hoverValue = 0;
|
|
25
|
+
this.changeRate();
|
|
20
26
|
});
|
|
21
|
-
|
|
27
|
+
__publicField(this, "onMouseMove", (e) => {
|
|
22
28
|
e.preventDefault();
|
|
23
|
-
let
|
|
24
|
-
|
|
29
|
+
let newValue = this.getValueFromXPosition(e.clientX);
|
|
30
|
+
if (newValue != this.hoverValue) {
|
|
31
|
+
this.hoverValue = newValue;
|
|
32
|
+
this.changeRate();
|
|
33
|
+
}
|
|
25
34
|
});
|
|
26
35
|
/*
|
|
27
36
|
* Events - Touch
|
|
28
37
|
*/
|
|
29
|
-
|
|
30
|
-
e.preventDefault()
|
|
38
|
+
__publicField(this, "onTouchStart", (e) => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
|
|
41
|
+
this.changeRate();
|
|
31
42
|
});
|
|
32
|
-
|
|
33
|
-
e.preventDefault()
|
|
43
|
+
__publicField(this, "onTouchEnd", (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
this.hoverValue = 0;
|
|
46
|
+
this.changeRate();
|
|
34
47
|
});
|
|
35
|
-
|
|
36
|
-
e.preventDefault()
|
|
48
|
+
__publicField(this, "onTouchMove", (e) => {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
this.hoverValue = this.getValueFromXPosition(e.touches[0].clientX);
|
|
51
|
+
this.changeRate();
|
|
37
52
|
});
|
|
38
|
-
|
|
39
|
-
e.preventDefault()
|
|
53
|
+
__publicField(this, "onClick", (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
this.value = +this.hoverValue;
|
|
40
56
|
});
|
|
41
57
|
}
|
|
42
|
-
set precision(
|
|
43
|
-
this.setAttribute("precision",
|
|
58
|
+
set precision(value) {
|
|
59
|
+
this.setAttribute("precision", value);
|
|
44
60
|
}
|
|
45
61
|
get precision() {
|
|
46
62
|
return this.hasAttribute("precision") ? +this.getAttribute("precision") : 1;
|
|
47
63
|
}
|
|
48
|
-
set max(
|
|
49
|
-
this.setAttribute("max",
|
|
64
|
+
set max(value) {
|
|
65
|
+
this.setAttribute("max", value);
|
|
50
66
|
}
|
|
51
67
|
get max() {
|
|
52
68
|
return this.hasAttribute("icons") ? this.icons.length : +this.getAttribute("max");
|
|
53
69
|
}
|
|
54
|
-
set icons(
|
|
55
|
-
return
|
|
70
|
+
set icons(value) {
|
|
71
|
+
return value;
|
|
56
72
|
}
|
|
57
73
|
get icons() {
|
|
58
74
|
return this.hasAttribute("icons") ? JSON.parse(this.getAttribute("icons").replace(/'/g, '"')) : ["star-filled"];
|
|
59
75
|
}
|
|
60
|
-
set value(
|
|
61
|
-
this.setAttribute("value",
|
|
76
|
+
set value(value) {
|
|
77
|
+
this.setAttribute("value", value);
|
|
62
78
|
}
|
|
63
79
|
get value() {
|
|
64
80
|
return this.hasAttribute("value") ? +this.getAttribute("value") : 0;
|
|
65
81
|
}
|
|
66
82
|
static get cssStyleSheet() {
|
|
67
|
-
return
|
|
83
|
+
return styles;
|
|
68
84
|
}
|
|
69
85
|
static get observedAttributes() {
|
|
70
86
|
return ["is-hover"];
|
|
71
87
|
}
|
|
72
|
-
attributeChangedCallback(
|
|
88
|
+
attributeChangedCallback(name, old, newName) {
|
|
73
89
|
}
|
|
74
90
|
setupAttributes() {
|
|
75
91
|
this.isShadowRoot = "open";
|
|
76
92
|
}
|
|
77
|
-
draw(
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
draw(context, store, params) {
|
|
94
|
+
let fragment = document.createDocumentFragment();
|
|
95
|
+
let native = document.createElement("div");
|
|
96
|
+
native.setAttribute("part", "native");
|
|
97
|
+
native.classList.add("native-rate");
|
|
98
|
+
this.native = native;
|
|
99
|
+
if (this.hasAttribute("icons")) {
|
|
100
|
+
let icons = this.icons;
|
|
101
|
+
for (let i = 0; i < icons.length; i++) {
|
|
102
|
+
native.appendChild(this.createIcons(i));
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
for (let i = 0; i < this.max; i++) {
|
|
106
|
+
native.appendChild(this.createIcons(i));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.changeRate();
|
|
110
|
+
fragment.appendChild(native);
|
|
111
|
+
return fragment;
|
|
87
112
|
}
|
|
88
113
|
afterDraw() {
|
|
89
|
-
this.hasAttribute("disabled") || this.hasAttribute("readonly")
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
if (this.hasAttribute("disabled") || this.hasAttribute("readonly")) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.addEventListener("mouseenter", this.onMouseEnter);
|
|
118
|
+
this.addEventListener("mouseleave", this.onMouseLeave);
|
|
119
|
+
this.addEventListener("mousemove", this.onMouseMove);
|
|
120
|
+
this.addEventListener("touchstart", this.onTouchStart);
|
|
121
|
+
this.addEventListener("touchend", this.onTouchEnd);
|
|
122
|
+
this.addEventListener("touchmove", this.onTouchMove);
|
|
123
|
+
this.addEventListener("click", this.onClick);
|
|
124
|
+
}
|
|
125
|
+
createIcons(i) {
|
|
126
|
+
let div = document.createElement("div");
|
|
127
|
+
div.classList.add("wj-rate-icon");
|
|
128
|
+
let icon = this.getIcons(i);
|
|
129
|
+
div.appendChild(icon);
|
|
130
|
+
if (this.value > i && this.value < i + 1) {
|
|
131
|
+
let clone = icon.cloneNode(true);
|
|
132
|
+
div.appendChild(clone);
|
|
98
133
|
}
|
|
99
|
-
return
|
|
134
|
+
return div;
|
|
100
135
|
}
|
|
101
136
|
changeRate() {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
137
|
+
const icons = this.native.children;
|
|
138
|
+
const rateValue = this.value !== this.hoverValue && this.hoverValue !== 0 && this.hoverValue !== void 0 ? this.hoverValue : this.value;
|
|
139
|
+
for (let i = 0; i < icons.length; i++) {
|
|
140
|
+
icons[i].classList.remove("selected", "hovered");
|
|
141
|
+
if (icons[i].children.length > 1) {
|
|
142
|
+
icons[i].classList.remove("half");
|
|
143
|
+
icons[i].querySelector("wj-icon:first-child").removeAttribute("style");
|
|
144
|
+
icons[i].querySelector("wj-icon:last-child").remove();
|
|
109
145
|
}
|
|
146
|
+
if (i < rateValue) {
|
|
147
|
+
icons[i].classList.add("selected");
|
|
148
|
+
}
|
|
149
|
+
if (rateValue > i && rateValue < i + 1 && icons[i].children.length === 1) {
|
|
150
|
+
let clone = icons[i].querySelector("wj-icon").cloneNode(true);
|
|
151
|
+
icons[i].appendChild(clone);
|
|
152
|
+
let percent = (rateValue - i) * 100;
|
|
153
|
+
icons[i].classList.add("half");
|
|
154
|
+
icons[i].querySelector("wj-icon:first-child").style.clipPath = `inset(0 0 0 ${percent}%)`;
|
|
155
|
+
icons[i].querySelector("wj-icon:last-child").style.clipPath = `inset(0 ${percent}% 0 0)`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
110
158
|
}
|
|
111
|
-
getIcons(
|
|
112
|
-
let
|
|
113
|
-
|
|
159
|
+
getIcons(index) {
|
|
160
|
+
let icon = document.createElement("wj-icon");
|
|
161
|
+
icon.setAttribute("name", this.max ? this.icons[0] : this.icons[index]);
|
|
162
|
+
return icon;
|
|
114
163
|
}
|
|
115
|
-
getValueFromXPosition(
|
|
116
|
-
const { left
|
|
117
|
-
|
|
164
|
+
getValueFromXPosition(coordinate) {
|
|
165
|
+
const { left, right, width } = this.native.getBoundingClientRect();
|
|
166
|
+
const value = this.roundToPrecision((coordinate - left) / width * this.max, this.precision);
|
|
167
|
+
return Math.min(Math.max(value, 0), this.max);
|
|
118
168
|
}
|
|
119
|
-
roundToPrecision(
|
|
120
|
-
const
|
|
121
|
-
return Math.ceil(
|
|
169
|
+
roundToPrecision(numberToRound, precision = 0.5) {
|
|
170
|
+
const multiplier = 1 / precision;
|
|
171
|
+
return Math.ceil(numberToRound * multiplier) / multiplier;
|
|
122
172
|
}
|
|
123
173
|
}
|
|
124
|
-
customElements.get("wj-rate") || window.customElements.define("wj-rate",
|
|
174
|
+
customElements.get("wj-rate") || window.customElements.define("wj-rate", Rate);
|
|
125
175
|
export {
|
|
126
|
-
|
|
176
|
+
Rate
|
|
127
177
|
};
|