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-return.js
134 lines (111 loc) · 2.47 KB
/
sc-return.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
import { html, svg, css } from 'lit';
import { theme } from './styles.js';
import ScElement from './ScElement.js';
class ScReturn extends ScElement {
static get properties() {
return {
width: {
type: Number,
},
height: {
type: Number,
},
value: {
type: Number,
},
};
}
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;
}
constructor() {
super();
this.width = 30;
this._active = false;
}
render() {
const size = this._size - 2;
return html`
<svg
class="${this._active ? 'active' : ''}"
style="
width: ${size}px;
height: ${size}px;
"
viewbox="-10 -8 120 120"
@mousedown="${this._onInput}"
@touchstart="${this._onInput}"
@mouseup="${this._toggleOff}"
@touchend="${this._toggleOff}"
@contextmenu="${this._preventContextMenu}"
>
<path
d="M 20,20
L 20,80
"
></path>
<polygon points="30,50 80,20 80,80"></polygon>
</svg>
`
}
_onInput(e) {
e.preventDefault();
e.stopPropagation();
this._active = true;
const changeEvent = new CustomEvent('input', {
bubbles: true,
composed: true,
detail: { value: this.value },
});
this.dispatchEvent(changeEvent);
this.requestUpdate();
}
_toggleOff(e) {
e.preventDefault();
e.stopPropagation();
this._active = false;
this.requestUpdate();
}
}
customElements.define('sc-return', ScReturn);
export default ScReturn;