-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
282 lines (216 loc) · 7.1 KB
/
index.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<!DOCTYPE html>
<html>
<head>
<title>Examples of SelectMenu</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/material-components-web@latest/dist/material-components-web.css">
<link rel="stylesheet" type="text/css" href="dist/dropdawn-1.0.0.css">
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<main>
<header class="mdc-toolbar">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<span class="mdc-toolbar__title">Select Dropdown Examples</span>
</section>
</div>
</header>
<div class="mdc-layout-grid">
<div class="mdc-layout-grid__inner">
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>dropdawn</h2>
<div class="mdc-form-field" id="dropdawn"></div>
</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>With API</h2>
<div class="mdc-form-field" id="withApi"></div>
<p>
Without using redux, you can connect this component to an API with a handy
callback function. The function is called on each input in the search bar,
and should return a Promise that resolves to a list of options.
</p>
<p>
The Promise doesn't have to resolve (for instance if not enough letters are typed in),
and you can use throttling/debouncing to minimize the amount of API-calls.
</p>
<code>
function apiCall(value) {<br>
return new Promise(function(resolve, reject) {<br>
...<br>
});<br>
}<br>
<br>
<dropdawn ... apiCall={apiCall}/>
</code>
</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>Create new</h2>
<div class="mdc-form-field" id="createNew"></div>
<p>
When provided with a function to create new items on the list,
a plus-button will appear next to the search bar. When clicking
this button, the function will run.
</p>
<p>
A second argument to the function is a callback. This can be incoked
with the new options, who then gets selected. You could then, for
instance bring up a dialog and call the callback when the form in dialog
is filled out.
</p>
</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>With link</h2>
<div class="mdc-form-field" id="withLink"></div>
<p>
When an employee is selected in this dropdown box, a link shows up in the helper text below.
This link takes you to the employees detail page.
</p>
<p>
This is done by specifying the attributes <em>viewLink</em> and <em>viewLinkText</em>. If
viewLinkText is not specified, the content is used instead. <em>viewLink</em> is a function
that recieves the option as an argument, and returns the href as a string:
</p>
<code>
<dropdawn<br> ...<br> viewLink={function(option) { return '/employee/' + option.value}}<br> viewLinkText="See employee details" />
</code>
</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>Disabled</h2>
<div class="mdc-form-field" id="disabled"></div>
<p>
</p>
<code>
<dropdawn ... disabled={true} />
</code>
</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-6">
<h2>Readonly</h2>
<div class="mdc-form-field" id="readonly"></div>
<p>
</p>
<code>
<dropdawn ... readonly={true} />
</code>
</div>
</div>
</div>
</main>
<!--<script type="text/javascript" src="https://unpkg.com/material-components-web@latest/dist/material-components-web.js"></script>-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
<script type="text/javascript" src="dist/dropdawn-1.0.0.js"></script>
<script type="text/javascript">
var opts = [{
value: 0,
// Used on screen
displayName: 'Lars-Erik Bruce',
// Used in list
content: 'Lars-Erik Bruce'
},{
value: 1,
displayName: 'Inge Syvertsen',
content: 'Inge Syvertsen'
},{
value: 2,
displayName: 'Harry Nystad',
content: 'Harry Nystad'
},{
value: 3,
displayName: 'En ansatt med et veldig langt navn, han kommer kanskje fra et eksotisk land',
content: 'En ansatt med et veldig langt navn, han kommer kanskje fra et eksotisk land'
},{
value: 4,
displayName: 'Jens Jensen',
content: 'Jens Jensen'
},{
value: 5,
displayName: 'Hans Hansen',
content: 'Hans Hansen',
},{
value: 6,
displayName: 'Ole Olesen',
content: 'Ole Olesen'
},{
value: 7,
displayName: 'Lars Larsen',
content: 'Lars Larsen'
},{
value: 8,
displayName: 'Ida Olasdottir',
content: 'Ida Olasdottir'
},{
value: 9,
displayName: 'Some Random Dude',
content: 'Some Random Dude'
}];
function apiCall(value) {
if(value.length < 3) return new Promise(function(resolve, reject) {
/*setTimeout(function() {
resolve([]);
});*/
});
return new Promise(function(resolve, reject) {
setTimeout(function() {
let a = opts.slice(0, opts.length).reverse();
resolve(a);
}, 500)
});
}
ReactDOM.render(React.createElement(TLXSelect, {
label: 'Velg ansatt',
options: opts,
hideLabelWhenSelected: true,
hideSearch: false,
removeSelectedText: 'Ingen',
name: 'travelreport.employee' }), document.getElementById('dropdawn'));
ReactDOM.render(React.createElement(TLXSelect, {
apiCall: apiCall,
label: 'Velg ansatt',
name: 'travelreport.employee',
removeSelectedText: 'Fjern valg',
className: "random" }), document.getElementById('withApi'));
ReactDOM.render(React.createElement(TLXSelect, {
options: opts,
label: 'Velg ansatt',
name: 'travelreport.employee',
createNew: function createNew(cb) {
setTimeout(function() {
cb({content: 'Something new', value: parseInt(Math.random() * 1000)})
}, 1000)
},
removeSelectedText: 'Fjern valg',
className: "random" }), document.getElementById('createNew'));
ReactDOM.render(React.createElement(TLXSelect, {
options: opts,
label: 'Velg ansatt',
name: 'travelreport.employee',
removeSelectedText: 'Fjern valg',
viewLink: function(option) { return '/employee/' + option.value},
viewLinkText: 'See employee details',
className: "random" }), document.getElementById('withLink'));
ReactDOM.render(React.createElement(TLXSelect, {
options: opts,
label: 'Velg ansatt',
name: 'travelreport.employee',
disabled: true,
viewLinkText: 'See employee details',
className: "random" }), document.getElementById('disabled'));
ReactDOM.render(React.createElement(TLXSelect, {
options: opts,
label: 'Velg ansatt',
name: 'travelreport.employee',
selected: {
value: 3434,
displayName: 'Jeg finnes ikke blant alternativene engang'
},
readonly: true,
removeSelectedText: 'Fjern valg',
className: "random" }), document.getElementById('readonly'));
</script>
</body>
</html>