-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
147 lines (109 loc) · 3.92 KB
/
main.ts
File metadata and controls
147 lines (109 loc) · 3.92 KB
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
import type { NgElement, WithProperties } from '@angular/elements'
import { CheckboxComponent, DropdownComponent, InputtextComponent, MultiselectComponent, RadiobuttonComponent, SliderComponent } from 'provenance-widgets'
import './style.css'
/**
* Sliders
*/
// Single slider
const sliderOpts = { floor: 0, ceil: 250, showTicks: true, tickStep: 25 }
const slider = document.createElement("web-provenance-slider") as NgElement & WithProperties<SliderComponent>
slider.id = 'wp-slider'
slider.value = 25
slider.options = sliderOpts
slider.provenance = undefined
// Listening to events
slider.addEventListener('provenanceChange', console.log)
slider.addEventListener('selectedChange', console.log)
document.querySelector("label[for='wp-slider']")?.insertAdjacentElement("afterend", slider)
// Range slider
const rangeSlider = document.createElement("web-provenance-slider") as NgElement & WithProperties<SliderComponent>
rangeSlider.id = 'wp-range-slider'
rangeSlider.value = 25
rangeSlider.highValue = 75
rangeSlider.options = sliderOpts
document.querySelector("label[for='wp-range-slider']")?.insertAdjacentElement("afterend", rangeSlider)
/**
* Text Input
*/
const inputtext = document.createElement("web-provenance-inputtext") as NgElement & WithProperties<InputtextComponent>
document.querySelector("label[for='wp-inputtext']")?.insertAdjacentElement("afterend", inputtext)
/**
* Selection-type widgets
*/
const cities = [
{
name: 'New York',
code: 'New York',
inputId: 'NY'
},
{
name: 'Rome',
code: 'Rome',
inputId: 'RM'
},
{
name: 'London',
code: 'London',
inputId: 'LDN'
},
{
name: 'Istanbul',
code: 'Istanbul',
inputId: 'IST'
},
{
name: 'Paris',
code: 'Paris',
inputId: 'PRS'
}
];
// Multiselect
const multiselect = document.createElement("web-provenance-multiselect") as NgElement & WithProperties<MultiselectComponent>
multiselect.id = 'wp-multiselect'
multiselect.options = cities
multiselect.optionLabel = 'name'
multiselect.dataKey = 'code'
multiselect.selected = cities.slice(0, 2);
multiselect.addEventListener("selectedChange", (event: any) => {
// Mandatory to update the selected property
multiselect.selected = event.detail
})
// Dropdown
document.querySelector("label[for='wp-multiselect']")?.insertAdjacentElement("afterend", multiselect)
const dropdown = document.createElement("web-provenance-dropdown") as NgElement & WithProperties<DropdownComponent>
dropdown.id = 'wp-dropdown'
dropdown.options = cities
dropdown.optionLabel = 'name'
dropdown.dataKey = 'code'
dropdown.selected = undefined
dropdown.addEventListener("selectedChange", (event: any) => {
// Mandatory to update the selected property
dropdown.selected = event.detail
})
document.querySelector("label[for='wp-dropdown']")?.insertAdjacentElement("afterend", dropdown)
// Checkbox
const checkbox = document.createElement("web-provenance-checkbox") as NgElement & WithProperties<CheckboxComponent>
checkbox.id = 'wp-checkbox'
checkbox.data = cities
checkbox.name="undefined"
checkbox.label = 'name'
checkbox.value = 'code'
checkbox.selected = cities.slice(0, 2).map(c => c.code);
checkbox.addEventListener("selectedChange", (event: any) => {
// Mandatory to update the selected property
checkbox.selected = event.detail
})
document.querySelector("label[for='wp-checkbox']")?.insertAdjacentElement("afterend", checkbox)
// Radiobutton
const radiobutton = document.createElement("web-provenance-radiobutton") as NgElement & WithProperties<RadiobuttonComponent>
radiobutton.id = 'wp-radiobutton'
radiobutton.data = cities
checkbox.name="r-interaction"
radiobutton.label = 'name'
radiobutton.value = 'code'
radiobutton.selected = cities[0].code;
radiobutton.addEventListener("selectedChange", (event: any) => {
// Mandatory to update the selected property
radiobutton.selected = event.detail
})
document.querySelector("label[for='wp-radiobutton']")?.insertAdjacentElement("afterend", radiobutton)