@lemonadejs/switch 5.0.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 -19
- package/dist/style.css +11 -14
- 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,33 +8,65 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
8
8
|
global.Switch = factory();
|
|
9
9
|
}(this, (function () {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
class CustomEvents extends Event {
|
|
12
|
+
constructor(type, props, options) {
|
|
13
|
+
super(type, {
|
|
14
|
+
bubbles: true,
|
|
15
|
+
composed: true,
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} else {
|
|
23
|
-
// Version 5
|
|
24
|
-
if (a !== b && typeof(onchange) === 'function') {
|
|
25
|
-
onchange.call(self, self, self.value);
|
|
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
|
+
}
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
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
|
+
}
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
const Switch = function (children, { onchange, onload }) {
|
|
42
|
+
let self = this;
|
|
43
|
+
|
|
44
|
+
// Event
|
|
45
|
+
let change = self.onchange;
|
|
46
|
+
self.onchange = null;
|
|
47
|
+
|
|
48
|
+
const state = () => {
|
|
49
|
+
let s = self.el.firstChild.checked;
|
|
50
|
+
if (s !== self.checked) {
|
|
51
|
+
self.checked = s;
|
|
33
52
|
}
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
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>
|
|
38
70
|
</label>`
|
|
39
71
|
}
|
|
40
72
|
|
package/dist/style.css
CHANGED
|
@@ -6,23 +6,23 @@
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
.lm-switch[data-color="green"] {
|
|
9
|
-
--lm-switch-main-color:
|
|
10
|
-
--lm-switch-main-color-alpha:
|
|
9
|
+
--lm-switch-main-color: #2E7D32;
|
|
10
|
+
--lm-switch-main-color-alpha: #2E7D3288;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
.lm-switch[data-color="orange"] {
|
|
14
|
-
--lm-switch-main-color:
|
|
15
|
-
--lm-switch-main-color-alpha:
|
|
14
|
+
--lm-switch-main-color: #EF6C00;
|
|
15
|
+
--lm-switch-main-color-alpha: #EF6C0088;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
.lm-switch[data-color="red"] {
|
|
19
|
-
--lm-switch-main-color:
|
|
20
|
-
--lm-switch-main-color-alpha:
|
|
19
|
+
--lm-switch-main-color: #C62828;
|
|
20
|
+
--lm-switch-main-color-alpha: #C6282888;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
.lm-switch[data-color="purple"] {
|
|
24
|
-
--lm-switch-main-color:
|
|
25
|
-
--lm-switch-main-color-alpha:
|
|
24
|
+
--lm-switch-main-color: #6A1B9A;
|
|
25
|
+
--lm-switch-main-color-alpha: #6A1B9A88;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
.lm-switch {
|
|
@@ -31,10 +31,9 @@
|
|
|
31
31
|
z-index: 0;
|
|
32
32
|
align-items: center;
|
|
33
33
|
min-width: 36px;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
display: inline-flex;
|
|
34
|
+
min-height: 20px;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
user-select: none;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
.lm-switch:before {
|
|
@@ -44,8 +43,6 @@ label.lm-switch {
|
|
|
44
43
|
|
|
45
44
|
.lm-switch > input {
|
|
46
45
|
appearance: none;
|
|
47
|
-
-moz-appearance: none;
|
|
48
|
-
-webkit-appearance: none;
|
|
49
46
|
position: absolute;
|
|
50
47
|
left: 0;
|
|
51
48
|
margin: 0;
|