-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
90 lines (87 loc) · 3.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Candid is an unopinionated, frameworkless JavaScript library for building web applications.">
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="black">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<link rel="icon" type="image/svg+xml" href="candid-logo.svg" />
<title>Candid</title>
<style>
*:not(:defined) {
display: inline-block;
height: 10vh;
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
</style>
<script>
if (navigator.vendor.match(/apple/i)) {
const script = document.createElement('script');
script.src = "https://cdn.jsdelivr.net/npm/@ungap/custom-elements";
document.head.appendChild(script);
}
</script>
</head>
<body>
<!-- best practice: use a web component as root for the content in order to reduce FOUC -->
<!-- also: don't use slots to prevent FOUC -->
<hello-world><span slot="udc">User defined content!</span></hello-world>
<my-title></my-title>
<my-counter></my-counter>
<my-counter></my-counter>
<no-template></no-template>
<div is="ext-div">Loading...</div>
<!-- it is possible to have web components without content -->
<!-- however, it will have a (shadow) root and a __ctx -->
<web-component name="no-template"></web-component>
<!-- web components can have sub-web-components (don't do that) -->
<web-component name="hello-world" mode="open" props="{ say: 'hi!' }">
<template>
<script>
this.onMount = () => console.log('[hello-world] onMount');
this.onUpdate = (name, oldValue, newValue) => console.log(`[hello-world] onUpdate(name: ${name}, oldValue: ${oldValue}, newValue: ${newValue})`);
this.onSlotChange = (e) => console.log('[hello-world] onSlotChange', e);
</script>
<!-- it is possible to load css using a web import but the recommended way is to use style's @import -->
<web-import src="hello-world.css.html"></web-import>
<h1>Hi <human-being></human-being>!</h1>
<h2>
<em>
<slot name="udc"></slot>
</em>
</h2>
<web-component name="human-being">
<template>
<script>console.log('y\'all!');</script>
<web-import src="human-being.html"></web-import>
</template>
</web-component>
</template>
</web-component>
<web-component name="ext-div" extends="div">
<template>
<script>
this.root.innerHTML = `Hello from ${this.element.tagName}!`
</script>
</template>
</web-component>
<web-import
src="https://raw.githubusercontent.com/danieldietrich/--candid-web-import-2/main/components/my-title.html">
</web-import>
<web-import src="my-counter.html"></web-import>
<no-web-import></no-web-import>
<web-component name="no-web-import">
<template>
<style>
@import 'test.css';
</style>
<script src="./test.js"></script>
<h1>Hello Daniel!</h1>
</template>
</web-component>
<!-- the template content is processed before connecting it to the live DOM -->
<script type="module" src="./src/index.ts"></script>
</body>
</html>