@lemonadejs/switch 1.4.0 → 5.2.0
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/index.d.ts +15 -1
- package/dist/index.js +51 -11
- package/dist/style.css +47 -15
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ declare namespace Switch {
|
|
|
12
12
|
text?: string;
|
|
13
13
|
/** Value will hold the current switch internal state value */
|
|
14
14
|
value?: boolean;
|
|
15
|
+
/** Checked state */
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
/** Color **/
|
|
18
|
+
color?: 'green' | 'orange' | 'red' | 'purple';
|
|
15
19
|
/** Identification name */
|
|
16
20
|
name?: string;
|
|
17
21
|
/** Determines whether the switch can be toggled or not */
|
|
@@ -19,14 +23,24 @@ declare namespace Switch {
|
|
|
19
23
|
/** Text position. Default undefined */
|
|
20
24
|
position?: 'right' | undefined;
|
|
21
25
|
/** Onchange event */
|
|
22
|
-
onchange: (value: string) => void;
|
|
26
|
+
onchange: (instance: object, value: string) => void;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
interface Instance {
|
|
30
|
+
/** The 'Text' serves as the label displayed on the switch side, indicating the information associated with the switch */
|
|
31
|
+
text?: string;
|
|
26
32
|
/** Value will hold the current switch internal state value */
|
|
27
33
|
value?: boolean;
|
|
34
|
+
/** Checked state */
|
|
35
|
+
checked?: boolean;
|
|
36
|
+
/** Color **/
|
|
37
|
+
color?: 'green' | 'orange' | 'red' | 'purple';
|
|
38
|
+
/** Identification name */
|
|
39
|
+
name?: string;
|
|
28
40
|
/** Determines whether the switch can be toggled or not */
|
|
29
41
|
disabled?: boolean;
|
|
42
|
+
/** Text position. Default undefined */
|
|
43
|
+
position?: 'right' | undefined;
|
|
30
44
|
}
|
|
31
45
|
}
|
|
32
46
|
|
package/dist/index.js
CHANGED
|
@@ -8,25 +8,65 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
8
8
|
global.Switch = factory();
|
|
9
9
|
}(this, (function () {
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
class CustomEvents extends Event {
|
|
12
|
+
constructor(type, props, options) {
|
|
13
|
+
super(type, {
|
|
14
|
+
bubbles: true,
|
|
15
|
+
composed: true,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (props) {
|
|
20
|
+
for (const key in props) {
|
|
21
|
+
// Avoid assigning if property already exists anywhere on `this`
|
|
22
|
+
if (! (key in this)) {
|
|
23
|
+
this[key] = props[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Dispatcher
|
|
31
|
+
const Dispatch = function(method, type, options) {
|
|
32
|
+
// Try calling the method directly if provided
|
|
33
|
+
if (typeof method === 'function') {
|
|
34
|
+
let a = Object.values(options);
|
|
35
|
+
return method(...a);
|
|
36
|
+
} else if (this.tagName) {
|
|
37
|
+
this.dispatchEvent(new CustomEvents(type, options));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const Switch = function (children, { onchange, onload }) {
|
|
12
42
|
let self = this;
|
|
13
43
|
|
|
14
|
-
|
|
44
|
+
// Event
|
|
45
|
+
let change = self.onchange;
|
|
46
|
+
self.onchange = null;
|
|
15
47
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
48
|
+
const state = () => {
|
|
49
|
+
let s = self.el.firstChild.checked;
|
|
50
|
+
if (s !== self.checked) {
|
|
51
|
+
self.checked = s;
|
|
19
52
|
}
|
|
20
53
|
}
|
|
21
54
|
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
self
|
|
55
|
+
onchange((prop, a, b, c, d) => {
|
|
56
|
+
if (a !== b) {
|
|
57
|
+
Dispatch.call(self, change, 'change', {
|
|
58
|
+
instance: self,
|
|
59
|
+
value: self.value,
|
|
60
|
+
});
|
|
25
61
|
}
|
|
26
|
-
}
|
|
27
62
|
|
|
28
|
-
|
|
29
|
-
|
|
63
|
+
state();
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
onload(state);
|
|
67
|
+
|
|
68
|
+
return render => render`<label class="lm-switch" position="{{self.position}}" data-color="{{self.color}}">
|
|
69
|
+
<input type="checkbox" name="{{self.name}}" disabled="{{self.disabled}}" checked="{{self.checked}}" :bind="self.value" /> <span>{{self.text}}</span>
|
|
30
70
|
</label>`
|
|
31
71
|
}
|
|
32
72
|
|
package/dist/style.css
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--lm-switch-front-color: 0,0,0;
|
|
3
|
+
--lm-switch-primary-color: 255,255,255;
|
|
4
|
+
--lm-switch-main-color: var(--lm-main-color, #1565C0);
|
|
5
|
+
--lm-switch-main-color-alpha: var(--lm-main-color-alpha, #1565C088);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.lm-switch[data-color="green"] {
|
|
9
|
+
--lm-switch-main-color: #2E7D32;
|
|
10
|
+
--lm-switch-main-color-alpha: #2E7D3288;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.lm-switch[data-color="orange"] {
|
|
14
|
+
--lm-switch-main-color: #EF6C00;
|
|
15
|
+
--lm-switch-main-color-alpha: #EF6C0088;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.lm-switch[data-color="red"] {
|
|
19
|
+
--lm-switch-main-color: #C62828;
|
|
20
|
+
--lm-switch-main-color-alpha: #C6282888;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.lm-switch[data-color="purple"] {
|
|
24
|
+
--lm-switch-main-color: #6A1B9A;
|
|
25
|
+
--lm-switch-main-color-alpha: #6A1B9A88;
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
.lm-switch {
|
|
2
29
|
position: relative;
|
|
3
30
|
display: inline-flex;
|
|
4
31
|
z-index: 0;
|
|
5
32
|
align-items: center;
|
|
6
|
-
min-
|
|
7
|
-
min-
|
|
33
|
+
min-width: 36px;
|
|
34
|
+
min-height: 20px;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
user-select: none;
|
|
8
37
|
}
|
|
9
38
|
|
|
10
39
|
.lm-switch:before {
|
|
@@ -14,8 +43,6 @@
|
|
|
14
43
|
|
|
15
44
|
.lm-switch > input {
|
|
16
45
|
appearance: none;
|
|
17
|
-
-moz-appearance: none;
|
|
18
|
-
-webkit-appearance: none;
|
|
19
46
|
position: absolute;
|
|
20
47
|
left: 0;
|
|
21
48
|
margin: 0;
|
|
@@ -54,7 +81,7 @@
|
|
|
54
81
|
border-radius: 7px;
|
|
55
82
|
width: 36px;
|
|
56
83
|
height: 14px;
|
|
57
|
-
background-color: rgba(var(--lm-switch-front-color
|
|
84
|
+
background-color: rgba(var(--lm-switch-front-color), 0.38);
|
|
58
85
|
transition: background-color 0.2s, opacity 0.2s;
|
|
59
86
|
}
|
|
60
87
|
|
|
@@ -65,14 +92,14 @@
|
|
|
65
92
|
border-radius: 50%;
|
|
66
93
|
width: 20px;
|
|
67
94
|
height: 20px;
|
|
68
|
-
background-color: rgb(var(
|
|
95
|
+
background-color: rgb(var(--lm-switch-primary-color));
|
|
69
96
|
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
|
|
70
97
|
transition: background-color 0.2s, transform 0.2s;
|
|
71
98
|
}
|
|
72
99
|
|
|
73
100
|
.lm-switch > input:checked {
|
|
74
101
|
left: 11px;
|
|
75
|
-
background-color: var(--lm-main-color
|
|
102
|
+
background-color: var(--lm-switch-main-color);
|
|
76
103
|
}
|
|
77
104
|
|
|
78
105
|
.lm-switch > input:not(:checked) {
|
|
@@ -81,11 +108,11 @@
|
|
|
81
108
|
}
|
|
82
109
|
|
|
83
110
|
.lm-switch > input:checked + span::before {
|
|
84
|
-
background-color: var(--lm-main-color-alpha
|
|
111
|
+
background-color: var(--lm-switch-main-color-alpha);
|
|
85
112
|
}
|
|
86
113
|
|
|
87
114
|
.lm-switch > input:checked + span::after {
|
|
88
|
-
background-color: var(--lm-main-color
|
|
115
|
+
background-color: var(--lm-switch-main-color);
|
|
89
116
|
transform: translateX(16px);
|
|
90
117
|
}
|
|
91
118
|
|
|
@@ -109,11 +136,11 @@
|
|
|
109
136
|
}
|
|
110
137
|
|
|
111
138
|
.lm-switch > input:active + span::before {
|
|
112
|
-
background-color: var(--lm-main-color-alpha
|
|
139
|
+
background-color: var(--lm-switch-main-color-alpha);
|
|
113
140
|
}
|
|
114
141
|
|
|
115
142
|
.lm-switch > input:checked:active + span::before {
|
|
116
|
-
background-color: rgba(var(--lm-front-color
|
|
143
|
+
background-color: rgba(var(--lm-switch-front-color), 0.38);
|
|
117
144
|
}
|
|
118
145
|
|
|
119
146
|
.lm-switch > input:disabled {
|
|
@@ -121,17 +148,17 @@
|
|
|
121
148
|
}
|
|
122
149
|
|
|
123
150
|
.lm-switch > input:disabled + span {
|
|
124
|
-
color: rgb(var(--lm-front-color
|
|
151
|
+
color: rgb(var(--lm-switch-front-color));
|
|
125
152
|
opacity: 0.50;
|
|
126
153
|
cursor: default;
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
.lm-switch > input:disabled + span::before {
|
|
130
|
-
background-color: rgba(var(--lm-front-color
|
|
157
|
+
background-color: rgba(var(--lm-switch-front-color), 0.38);
|
|
131
158
|
}
|
|
132
159
|
|
|
133
160
|
.lm-switch > input:checked:disabled + span::before {
|
|
134
|
-
background-color: var(--lm-main-color-alpha
|
|
161
|
+
background-color: var(--lm-switch-main-color-alpha);
|
|
135
162
|
}
|
|
136
163
|
|
|
137
164
|
.lm-switch[position="right"] > span {
|
|
@@ -140,7 +167,12 @@
|
|
|
140
167
|
|
|
141
168
|
.lm-switch[position="right"] > input {
|
|
142
169
|
left: initial;
|
|
143
|
-
right:
|
|
170
|
+
right: 11px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.lm-switch[position="right"] > input:checked {
|
|
174
|
+
left: initial;
|
|
175
|
+
right: -5px;
|
|
144
176
|
}
|
|
145
177
|
|
|
146
178
|
.lm-switch[position="right"] > span::before {
|