-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
188 lines (172 loc) Β· 8.5 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
<!DOCTYPE html>
<html lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>custom-element Declarative Custom Element implementation demo</title>
<link rel="icon" href="demo/wc-square.svg" />
<script type="importmap">
{
"imports": {
"@epa-wg/custom-element/": "./",
"@epa-wg/custom-element-dist/": "./"
}
}
</script>
<script type="module" src="./http-request.js"></script>
<script type="module" src="./location-element.js"></script>
<script type="module" src="./custom-element.js"></script>
<style>
@import "demo/demo.css";
</style>
</head>
<body xmlns:xhtml="http://www.w3.org/1999/xhtml">
<nav>
<h3><code>custom-element</code> demo</h3>
<div><a href="https://github.com/EPA-WG/custom-element"
><img src="https://cdnjs.cloudflare.com/ajax/libs/octicons/8.5.0/svg/mark-github.svg" alt="icon">GIT</a>
| <a href="https://github.com/EPA-WG/custom-element/blob/main/README.md">README</a>
| <a href="https://stackblitz.com/github/EPA-WG/custom-element?file=index.html">Sandbox</a>
| <a href="https://chrome.google.com/webstore/detail/epa-wgcustom-element/hiofgpmmkdembdogjpagmbbbmefefhbl"
>Chrome devtools plugin</a>
| <custom-element src="@epa-wg/custom-element/demo/npm-versions.html#npm-version-to-url"
slice="selected" package-name="@epa-wg/custom-element">
<i slot="label">version:</i>
</custom-element>
</div>
<p>
This <em>Declarative Custom Element</em> allows to define<br/>
custom HTML tag with template filled from slots, attributes, dataset. </p>
<p>The template is fully loaded with variables, conditions, loops, etc. <br/>
The data query is powered by XPath. </p>
<p>Try in <a href="https://stackblitz.com/github/EPA-WG/custom-element?file=index.html" >Sandbox</a> </p>
<section>
<h4>Features demo</h4>
<a href="./demo/local-storage.html" >local-storage </a> |
<a href="./demo/http-request.html" >http-request </a> |
<a href="./demo/location-element.html" >location-element </a> |
<a href="./demo/set-url.html" >set-url </a> |
<a href="./demo/external-template.html" >external template </a> |
<a href="./demo/module-url.html" >importmap </a> <br/>
<a href="./demo/hex-grid.html" >hex grid lib </a> |
<a href="./demo/scoped-css.html" >scoped CSS </a> |
<a href="./demo/parameters.html" >attributes </a> |
<a href="./demo/data-slices.html" >data slices/events </a> |
<a href="./demo/form.html" >Form validation </a> |
<a href="./demo/dom-merge.html" >DOM merge on dynamic update </a><br/>
<a href="./demo/npm-versions-demo.html">npm version </a>
</section>
</nav>
<html-demo-element legend="1. simple payload"
description="payload is ignored as in DCE definition there is no default slot">
<template>
<custom-element tag="dce-link" hidden>
<a href="#">link π</a>
</custom-element>
<dce-link><i>π</i></dce-link>
</template>
</html-demo-element>
<html-demo-element legend="2. payload with slot definition and slot value"
description="slots are filled as in template+shadow root">
<template>
<custom-element tag="dce-1-slot" hidden>
πβ€οΈ<slot name="slot1"> π₯¦</slot>
</custom-element>
<dce-1-slot><i slot="slot1">π₯</i></dce-1-slot>
</template>
</html-demo-element>
<html-demo-element legend="2a. payload with slot definition and slot value"
description="unlike in TEMPLATE, same slot can be used multiple times and within attribute ">
<template>
<custom-element tag="dce-2-slots" hidden>
<slot name="slot2"> π</slot> and again:
<slot name="slot2"> π</slot>
<xhtml:input placeholder="πβ€οΈ{//*[@slot='slot2']}"/>
</custom-element>
<dce-2-slots><i slot="slot2">π₯</i></dce-2-slots>
<dce-2-slots></dce-2-slots>
</template>
</html-demo-element>
<html-demo-element legend="2b. named default slot"
description="slot without `name` attribute or with blank value `name=''` use whole payload">
<template>
<custom-element tag="dce-3-slot" hidden>
#1
<slot name=""> π</slot>
and
<slot> π</slot>
</custom-element>
<dce-3-slot><i slot="">π₯</i></dce-3-slot>
</template>
</html-demo-element>
<html-demo-element legend="2c. named default slot"
description="slot without `name` attribute or with blank value `name=''` use whole payload">
<template>
<custom-element tag="dce-4-slot" hidden>
#2
<slot name=""> π</slot>
and
<slot> π</slot>
</custom-element>
<dce-4-slot>π₯</dce-4-slot>
</template>
</html-demo-element>
<html-demo-element legend="2d. default slot"
description="slot without `name` attribute use whole payload">
<template>
<custom-element tag="greet-element" hidden>
<slot> Hello </slot> World!
</custom-element>
<greet-element></greet-element>
<greet-element>π</greet-element>
</template>
</html-demo-element>
<html-demo-element legend="3. πͺ DCE template "
description="Complex case with slots, attributes, dataset, conditional render">
<template>
<custom-element tag="pokemon-tile" hidden id="shared-template">
<template>
<h3> {title} </h3> <!-- title is an attribute in instance
mapped into /*/attributes/title -->
<if test="//smile"> <!-- data-smile DCE instance attribute,
mapped into /*/dataset/smile
used in condition -->
<!-- data-smile DCE instance attribute, used as HTML -->
<div>Smile as: {//smile}</div> <!-- /datadom/dataset/smile -->
</if>
<!-- image would not be visible in sandbox, see live demo -->
<img src="https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/{pokemon-id}.svg"
alt="{title} image"/>
<!-- image-src and title are DCE instance attributes,
mapped into /*/attributes/
used within output attribute via curly brackets -->
<!-- `slot name=xxx` replaced with elements with `slot=xxx` attribute -->
<p><slot name="description"><i>description is not available</i></slot></p>
<for-each select="//*[@pokemon-id]">
<!-- loop over payload elements with `pokemon-id` attribute,
i.e LI elements -->
<button>
<img height="32"
src="https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/{@pokemon-id}.svg"
alt="{text()}"/>
<br/>
{text()} <!-- text from LI element in loop -->
</button>
</for-each>
</template>
</custom-element>
<pokemon-tile title="bulbasaur" data-smile="πΌ" pokemon-id="1" >
<p slot="description">Bulbasaur is a cute PokΓ©mon born with a large seed firmly affixed to its back;
the seed grows in size as the PokΓ©mon does.</p>
<ul>
<li pokemon-id="2">ivysaur</li>
<li pokemon-id="3">venusaur</li>
</ul>
</pokemon-tile>
<pokemon-tile title="ninetales" pokemon-id="38" >
<li pokemon-id="37">vulpix</li>
</pokemon-tile>
</template>
</html-demo-element>
<script type="module" src="https://unpkg.com/[email protected]/html-demo-element.js"></script>
</body>
</html>