forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
402 lines (381 loc) · 15.6 KB
/
Copy pathindex.html
File metadata and controls
402 lines (381 loc) · 15.6 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset='UTF-8'>
<title>solid-ui UI.tabs examples page</title>
<script type="text/javascript" src="../../lib/webpack-bundle.js"></script>
<script id="data-tabWidget-with-collection" type="text/turtle">
@prefix : <#> .
:subject1
:predicate1 ( :item1A :item1B ) .
</script>
<script id="data-tabWidget-with-unsorted-triples" type="text/turtle">
@prefix : <#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:subject2
:predicate2 :item2A, :item2B .
:item2A
rdfs:label "Tab 1" .
:item2B
rdfs:label "Tab 2" .
</script>
<script>
function showData (widgetName) {
const viewDataElement = document.querySelector(`#viewData-${widgetName}`)
if (!viewDataElement) return
viewDataElement.innerHTML = document.querySelector(`#data-${widgetName}`).innerText
.replace(/ /g, '')
.replace(/</g, '<')
.replace(/>/g, '>')
}
function showSource (widgetName) {
document.querySelector(`#viewSource-${widgetName}`).innerHTML = document.querySelector(`#script-${widgetName}`).innerText
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''')
}
function loadData (dataTag) {
UI.rdf.parse(dataTag.innerText, UI.store, location.origin, 'text/turtle', error => {
if (error) console.error(error)
})
}
Array.from(document.querySelectorAll('script[type="text/turtle"]')).forEach(dataTag => loadData(dataTag))
window.addEventListener('DOMContentLoaded', () => {
Array.from(document.querySelectorAll('article')).forEach(title => {
const section = title.id
showData(section)
showSource(section)
})
})
</script>
</head>
<body>
<h1>The Tabs module</h1>
<p>
On this page you'll find some examples from the Tabs module.
</p>
<article id="tabWidget-with-collection">
<h2>
<a href="#tabWidget-with-collection">
<code>tabWidget</code>: Populating content using an RDF collection
</a>
</h2>
<p>
In this first example we'll see how you can generate a tabs widget using triples that are formatted as a
collection
in RDF. See <a href="https://solid.github.io/solid-ui/Documentation/api/modules/_tabs_.html#tabwidget">API
documentation</a>
for more info about how to use the tabWidget.
</p>
<script id="script-tabWidget-with-collection">
window.addEventListener('DOMContentLoaded', () => {
const subject = UI.rdf.namedNode(location.origin + '#subject1')
const predicate = UI.rdf.namedNode(location.origin + '#predicate1')
const tabs = UI.tabs.tabWidget({
subject,
predicate,
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject.uri}`
}
})
document.querySelector('#demo-tabWidget-with-collection').appendChild(tabs)
})
</script>
<p>
The triples belows shows the minimum data you need to start using the tabWidget in combination with
<code>UI.store</code>.
</p>
<pre id="viewData-tabWidget-with-collection"></pre>
<p>
Note that you would probably use <code>UI.rdf.namedNode</code> directly from rdflib.js. (E.g. instead of
<code>UI.rdf.namedNode</code> you would probably make use of namedNode with
<code>import { namedNode } from 'rdflib'</code>.
</p>
<pre id="viewSource-tabWidget-with-collection"></pre>
<div id="demo-tabWidget-with-collection"></div>
</article>
<article id="tabWidget-with-unsorted-triples">
<h2>
<a href="#tabWidget-with-unsorted-triples">
<code>tabWidget</code>: Populating content using unsorted triples
</a>
</h2>
<p>
In this second example we'll use an unsorted set of triples instead of a collection.
</p>
<script id="script-tabWidget-with-unsorted-triples">
window.addEventListener('DOMContentLoaded', () => {
const subject = UI.rdf.namedNode(location.origin + '#subject2')
const predicate = UI.rdf.namedNode(location.origin + '#predicate2')
const tabs = UI.tabs.tabWidget({
subject,
predicate,
ordered: false,
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${UI.utils.label(subject)}`
}
})
document.querySelector('#demo-tabWidget-with-unsorted-triples').appendChild(tabs)
})
</script>
<p>
This is the data we will be working with. Note that we've also added labels to the items to help the widget know
how to label the tabs.
</p>
<pre id="viewData-tabWidget-with-unsorted-triples"></pre>
<p>
Note that we've set option ordered to false in this example.
</p>
<pre id="viewSource-tabWidget-with-unsorted-triples"></pre>
<div id="demo-tabWidget-with-unsorted-triples"></div>
</article>
<article id="tabWidget-with-items">
<h2>
<a href="#tabWidget-with-unsorted-triples">
<code>tabWidget</code>: Populating content using option <code>items</code>
</a>
</h2>
<p>
Finally we can set the items manually by using option <code>items</code>.
</p>
<script id="script-tabWidget-with-items">
window.addEventListener('DOMContentLoaded', () => {
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
const tabs = UI.tabs.tabWidget({
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
})
document.querySelector('#demo-tabWidget-with-items').appendChild(tabs)
})
</script>
<p>
We do not need to use options <code>subject</code> and <code>predicate</code> when using <code>items</code>.
</p>
<pre id="viewSource-tabWidget-with-items"></pre>
<p>
For the remaining examples we'll use option <code>items</code> to populate our tabs.
</p>
<div id="demo-tabWidget-with-items"></div>
</article>
<article id="tabWidget-option-backgroundColor">
<h2>
<a href="#tabWidget-option-backgroundColor">
<code>tabWidget</code>: Option <code>backgroundColor</code>
</a>
</h2>
<p>
Using option <code>backgroundColor</code> we can set a specific color (in hex value) to our tabs. It will
consider how light a color is when figuring out which color to set to the text. It will also distinguish
between selected and not selected tabs by coloring the selected tab a bit darker.
</p>
<script id="script-tabWidget-option-backgroundColor">
window.addEventListener('DOMContentLoaded', () => {
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
document.querySelector('#demo-tabWidget-option-backgroundColor').appendChild(UI.tabs.tabWidget({
backgroundColor: '#ff0000', // hex color for red
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
document.querySelector('#demo-tabWidget-option-backgroundColor').appendChild(UI.tabs.tabWidget({
backgroundColor: '#ffff00', // hex color for yellow
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
})
</script>
<pre id="viewSource-tabWidget-option-backgroundColor"></pre>
<div id="demo-tabWidget-option-backgroundColor"></div>
</article>
<article id="tabWidget-option-onClose">
<h2>
<a href="#tabWidget-option-onClose"><code>tabWidget</code>: Option <code>onClose</code></a>
</h2>
<p>
Using option <code>backgroundColor</code> we can set a specific color (in hex value) to our tabs. It will
consider how light a color is when figuring out which color to set to the text.
</p>
<script id="script-tabWidget-option-onClose">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-onClose')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
onClose: () => {
const showTabsButton = document.createElement('button')
showTabsButton.innerText = 'Show Tabs'
showTabsButton.onclick = () => {
demo.innerHTML = ''
createTabsWithOnClose()
}
demo.innerHTML = ''
demo.appendChild(showTabsButton)
},
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
})
</script>
<pre id="viewSource-tabWidget-option-onClose"></pre>
<div id="demo-tabWidget-option-onClose"></div>
</article>
<article id="tabWidget-option-orientation">
<h2>
<a href="#tabWidget-option-orientation"><code>tabWidget</code>: Option <code>orientation</code></a>
</h2>
<p>
Using option <code>orientation</code> we can set how the tabs and body should be positioned.
</p>
<script id="script-tabWidget-option-orientation">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-orientation')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
orientation: '1', // tabs shown to the left of body
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
orientation: '2', // tabs shown below body
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
orientation: '3', // tabs shown to the right of body
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
}
}))
})
</script>
<pre id="viewSource-tabWidget-option-orientation"></pre>
<div id="demo-tabWidget-option-orientation"></div>
</article>
<article id="tabWidget-option-renderTab">
<h2>
<a href="#tabWidget-option-renderTab"><code>tabWidget</code>: Option <code>renderTab</code></a>
</h2>
<p>
<code>renderTab</code> allows us to override the default behavior for how tabs are rendered, e.g.
which text should be shown for each tab.
</p>
<script id="script-tabWidget-option-renderTab">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-renderTab')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
},
renderTab: (tabDiv, subject) => {
tabDiv.innerText = `Go to ${subject.uri}`
}
}))
})
</script>
<pre id="viewSource-tabWidget-option-renderTab"></pre>
<div id="demo-tabWidget-option-renderTab"></div>
</article>
<article id="tabWidget-option-renderTabSettings">
<h2>
<a href="#tabWidget-option-renderTabSettings"><code>tabWidget</code>: Option <code>renderTabSettings</code></a>
</h2>
<p>
<code>renderTabSettings</code> functions much like <code>renderMain</code>, expect that it is triggered by
holding ALT key (Option key on Mac) and clicking on a tab.
</p>
<script id="script-tabWidget-option-renderTabSettings">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-renderTabSettings')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
},
renderTabSettings: (bodyMain, subject) => {
bodyMain.innerText = `Settings for ${subject.uri}`
}
}))
})
</script>
<pre id="viewSource-tabWidget-option-renderTabSettings"></pre>
<p>Remember to hold ALT while click on a tab to show settings for the given tab.</p>
<div id="demo-tabWidget-option-renderTabSettings"></div>
</article>
<article id="tabWidget-option-selectedTab">
<h2>
<a href="#tabWidget-option-selectedTab"><code>tabWidget</code>: Option <code>selectedTab</code></a>
</h2>
<p>
<code>selectedTab</code> allows you to set which tab should be opened by when the widget is initially
rendered. It must be used in junction with <code>renderTab</code> since it relies on <code>dataset.name</code>
being set.
</p>
<script id="script-tabWidget-option-selectedTab">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-selectedTab')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
},
renderTab: (tabDiv, subject) => {
tabDiv.dataset.name = subject.uri
tabDiv.innerText = UI.utils.label(subject)
},
selectedTab: item2.uri
}))
})
</script>
<pre id="viewSource-tabWidget-option-selectedTab"></pre>
<div id="demo-tabWidget-option-selectedTab"></div>
</article>
<article id="tabWidget-option-startEmpty">
<h2>
<a href="#tabWidget-option-startEmpty"><code>tabWidget</code>: Option <code>startEmpty</code></a>
</h2>
<p>
<code>startEmpty</code> makes it so that a the body of a tab isn't shown when initially rendered.
</p>
<script id="script-tabWidget-option-startEmpty">
window.addEventListener('DOMContentLoaded', function createTabsWithOnClose () {
const demo = document.querySelector('#demo-tabWidget-option-startEmpty')
const item1 = UI.rdf.namedNode(location.origin + '#item3A')
const item2 = UI.rdf.namedNode(location.origin + '#item3B')
demo.appendChild(UI.tabs.tabWidget({
items: [item1, item2],
renderMain: (bodyMain, subject) => {
bodyMain.innerText = `Content of ${subject}`
},
startEmpty: true
}))
})
</script>
<pre id="viewSource-tabWidget-option-startEmpty"></pre>
<div id="demo-tabWidget-option-startEmpty"></div>
</article>
</body>
</html>