This repository has been archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc-loop.js
150 lines (127 loc) · 2.87 KB
/
sc-loop.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { html, svg, css } from 'lit';
import { theme } from './styles.js';
import ScElement from './ScElement.js';
class ScLoop extends ScElement {
static get properties() {
return {
width: {
type: Number,
},
height: {
type: Number,
},
active: {
type: Boolean,
reflect: true,
},
value: {
type: Boolean,
},
};
}
static get styles() {
return css`
:host {
vertical-align: top;
display: inline-block;
box-sizing: border-box;
font-size: 0 !important;
cursor: pointer;
}
svg {
margin-right: 5px;
box-sizing: border-box;
border-radius: 2px;
border: 1px solid ${theme['--color-primary-2']};
background-color: ${theme['--color-primary-2']};
fill: #ffffff;
stroke: #ffffff;
}
svg.active {
background-color: ${theme['--color-primary-0']};
fill: ${theme['--color-secondary-4']};
stroke: ${theme['--color-secondary-4']};
}
path {
stroke-width: 10;
fill-opacity: 0;
}
`;
}
set width(value) {
this._size = value;
this.requestUpdate();
}
get width() {
return this._size;
}
set height(value) {
this._size = value;
this.requestUpdate();
}
get height() {
return this._size;
}
// alias active for consistency and genericity with other components
get value() {
return this.active;
}
set value(active) {
this.active = active;
}
constructor() {
super();
this.width = 30;
this.active = false;
}
render() {
const size = this._size - 2;
return html`
<div>
<svg
class="${this.active ? 'active' : ''}"
style="
width: ${size}px;
height: ${size}px;
"
viewbox="-10 -8 120 120"
@mousedown="${this._onChange}"
@touchstart="${this._onChange}"
@contextmenu="${this._preventContextMenu}"
>
<path
d="M 30,20
L 70,20
C 75,20 80,25 80,30
L 80,70
C 80,75 75,80 70,80
L 60,80
M 40,80
L 30,80
C 25,80 20,75 20,70
L 20,30
C 20,25 25,20 30,20
"
></path>
<polygon points="45,80 60,65 60,95"></polygon>
</svg>
</div>
`
}
_onChange(e) {
e.preventDefault();
e.stopPropagation();
this.active = !this.active;
const changeEvent = new CustomEvent('change', {
bubbles: true,
composed: true,
detail: { value: this.active },
});
this.dispatchEvent(changeEvent);
this.requestUpdate();
}
}
if (customElements.get('sc-loop') === undefined) {
customElements.define('sc-loop', ScLoop);
}
export default ScLoop;