-
Notifications
You must be signed in to change notification settings - Fork 0
/
picker-element.js
101 lines (92 loc) · 2.71 KB
/
picker-element.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
import { LitElement, html, css } from 'lit-element';
class PickerElement extends LitElement {
static get properties() {
return {
legend: { type: String },
name: { type: String },
options: { type: Array },
value: { type: String },
size: { type: Number },
}
}
static get styles() {
return [
css`
:host {
display: block;
}
.center {
width: fit-content;
margin: auto;
}
.legend {
font-size: 1.25rem;
margin-bottom: 0.75rem;
}
.label {
font-size: 1rem;
}
`
];
}
constructor() {
super();
this.value = '';
this.size = 3;
}
render() {
return html`
<link rel="stylesheet" href="./salesforce-lightning-design-system.min.css">
<style>
.icon-size {
height: ${this.size}rem;
width: ${this.size}rem;
}
</style>
<fieldset class="slds-form-element">
<legend class="slds-form-element__legend slds-form-element__label legend center">
${this.legend}
</legend>
<div class="slds-form-element__control wrapper center">
${this.options ? this.options.map((opt) => (html`
<div class="slds-visual-picker slds-visual-picker_large">
<input
type="radio"
id="opt-${opt.value}"
value="${opt.value}"
.name="${this.name}"
@click="${this._onSelect}"
opt-input />
<label for="opt-${opt.value}">
<span class="slds-visual-picker__figure slds-visual-picker__icon slds-align_absolute-center">
<span class="slds-is-selected">
<span class="slds-icon_container">
<img class="slds-icon icon-size" alt="" src="${opt.image}"/>
</span>
</span>
<span class="slds-is-not-selected">
<span class="slds-icon_container">
<img class="slds-icon icon-size " alt="" src="${opt.image}"/>
</span>
</span>
</span>
<span class="slds-visual-picker__body">
<span class="slds-text-title label">${opt.label}</span>
</span>
</label>
</div>
`)) : null}
</div>
</fieldset>
`;
}
_onSelect(e) {
this.value = e.currentTarget.value;
this.dispatchEvent(new CustomEvent('picker-value-changed', {
detail: {
value: e.currentTarget.value,
},
}));
}
}
window.customElements.define('picker-element', PickerElement);