Skip to content

Commit 0fbd7b7

Browse files
committed
added js test app
1 parent 90ce063 commit 0fbd7b7

File tree

10 files changed

+560
-2
lines changed

10 files changed

+560
-2
lines changed

js-component-tests/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

js-component-tests/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + Lit</title>
8+
<link rel="stylesheet" href="./src/index.css" />
9+
<script type="module" src="/src/my-element.js"></script>
10+
</head>
11+
<body>
12+
<my-element>
13+
<h1>Vite + Lit</h1>
14+
</my-element>
15+
</body>
16+
</html>

js-component-tests/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "js-component-tests",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"lit": "^3.1.2",
13+
"lit-functions": "../lit-functions-v1.0.0.tgz"
14+
},
15+
"devDependencies": {
16+
"vite": "^5.2.0"
17+
}
18+
}

js-component-tests/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading

js-component-tests/src/assets/lit.svg

Lines changed: 1 addition & 0 deletions
Loading

js-component-tests/src/index.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
:root {
2+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3+
line-height: 1.5;
4+
font-weight: 400;
5+
6+
color-scheme: light dark;
7+
color: rgba(255, 255, 255, 0.87);
8+
background-color: #242424;
9+
10+
font-synthesis: none;
11+
text-rendering: optimizeLegibility;
12+
-webkit-font-smoothing: antialiased;
13+
-moz-osx-font-smoothing: grayscale;
14+
}
15+
16+
body {
17+
margin: 0;
18+
display: flex;
19+
place-items: center;
20+
min-width: 320px;
21+
min-height: 100vh;
22+
}
23+
24+
@media (prefers-color-scheme: light) {
25+
:root {
26+
color: #213547;
27+
background-color: #ffffff;
28+
}
29+
}

js-component-tests/src/my-element.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { html, css } from "lit";
2+
import litLogo from './assets/lit.svg'
3+
import viteLogo from '/vite.svg'
4+
import component from "lit-functions";
5+
6+
const style = css`
7+
:host {
8+
max-width: 1280px;
9+
margin: 0 auto;
10+
padding: 2rem;
11+
text-align: center;
12+
}
13+
14+
.logo {
15+
height: 6em;
16+
padding: 1.5em;
17+
will-change: filter;
18+
transition: filter 300ms;
19+
}
20+
.logo:hover {
21+
filter: drop-shadow(0 0 2em #646cffaa);
22+
}
23+
.logo.lit:hover {
24+
filter: drop-shadow(0 0 2em #325cffaa);
25+
}
26+
27+
.card {
28+
padding: 2em;
29+
}
30+
31+
.read-the-docs {
32+
color: #888;
33+
}
34+
35+
a {
36+
font-weight: 500;
37+
color: #646cff;
38+
text-decoration: inherit;
39+
}
40+
a:hover {
41+
color: #535bf2;
42+
}
43+
44+
::slotted(h1) {
45+
font-size: 3.2em;
46+
line-height: 1.1;
47+
}
48+
49+
button {
50+
border-radius: 8px;
51+
border: 1px solid transparent;
52+
padding: 0.6em 1.2em;
53+
font-size: 1em;
54+
font-weight: 500;
55+
font-family: inherit;
56+
background-color: #1a1a1a;
57+
cursor: pointer;
58+
transition: border-color 0.25s;
59+
}
60+
button:hover {
61+
border-color: #646cff;
62+
}
63+
button:focus,
64+
button:focus-visible {
65+
outline: 4px auto -webkit-focus-ring-color;
66+
}
67+
68+
@media (prefers-color-scheme: light) {
69+
a:hover {
70+
color: #747bff;
71+
}
72+
button {
73+
background-color: #f9f9f9;
74+
}
75+
}
76+
`
77+
78+
/**
79+
*
80+
* @param {import('lit-functions').Props} param0
81+
* @returns
82+
*/
83+
function myElement({useProp, onMount, updated}) {
84+
const [count, setCount] = useProp('count', {type: Number}, 0);
85+
const [refreshCounter, refresh] = useProp('refreshCounter', {type: Number}, 2);
86+
const [docs, _] = useProp('docs', {type: String}, 'This is some test docs');
87+
88+
onMount(() => {
89+
console.log('onMount');
90+
refresh(refreshCounter + 1)
91+
});
92+
93+
updated(
94+
/**
95+
*
96+
* @param {import('lit').PropertyDeclaration} changedProperties
97+
*/
98+
(changedProperties) => {
99+
console.log('changed', changedProperties);
100+
});
101+
102+
return html`
103+
<div>
104+
<a href="https://vitejs.dev" target="_blank">
105+
<img src=${viteLogo} class="logo" alt="Vite logo" />
106+
</a>
107+
<a href="https://lit.dev" target="_blank">
108+
<img src=${litLogo} class="logo lit" alt="Lit logo" />
109+
</a>
110+
</div>
111+
<slot></slot>
112+
<div class="card">
113+
<button part="button" @click="${() => setCount(count + 1)}">
114+
count is ${count}
115+
</button>
116+
</div>
117+
<p class="read-the-docs">${refreshCounter}</p>
118+
<p class="read-the-docs">${docs}</p>
119+
`
120+
}
121+
122+
component(myElement, [style]);

0 commit comments

Comments
 (0)