Skip to content

Commit 76cf574

Browse files
committed
feat: TemplateElement handler
add vite-vanilla and lit case
1 parent 6327b01 commit 76cf574

32 files changed

+886
-43
lines changed

apps/vite-lit/.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?

apps/vite-lit/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 + TS</title>
8+
<link rel="stylesheet" href="./src/index.css" />
9+
<script type="module" src="/src/my-element.ts"></script>
10+
</head>
11+
<body>
12+
<my-element>
13+
<h1>Vite + Lit</h1>
14+
</my-element>
15+
</body>
16+
</html>

apps/vite-lit/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "vite-lit",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"main": "dist/my-element.es.js",
7+
"exports": {
8+
".": "./dist/my-element.es.js"
9+
},
10+
"types": "types/my-element.d.ts",
11+
"files": [
12+
"dist",
13+
"types"
14+
],
15+
"scripts": {
16+
"dev": "vite",
17+
"build": "tsc && vite build",
18+
"prepare": "tw-patch"
19+
},
20+
"dependencies": {
21+
"lit": "^2.6.1"
22+
},
23+
"devDependencies": {
24+
"typescript": "^4.9.3",
25+
"vite": "^4.2.0",
26+
"autoprefixer": "^10.4.14",
27+
"postcss": "^8.4.21",
28+
"tailwindcss": "^3.3.1",
29+
"tailwindcss-patch": "workspace:*",
30+
"unplugin-tailwindcss-mangle": "workspace:*"
31+
}
32+
}

apps/vite-lit/postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {}
5+
}
6+
}

apps/vite-lit/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading

apps/vite-lit/src/assets/lit.svg

Lines changed: 1 addition & 0 deletions
Loading

apps/vite-lit/src/index.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;
4+
5+
:root {
6+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
7+
line-height: 1.5;
8+
font-weight: 400;
9+
10+
color-scheme: light dark;
11+
color: rgba(255, 255, 255, 0.87);
12+
background-color: #242424;
13+
14+
font-synthesis: none;
15+
text-rendering: optimizeLegibility;
16+
-webkit-font-smoothing: antialiased;
17+
-moz-osx-font-smoothing: grayscale;
18+
-webkit-text-size-adjust: 100%;
19+
}
20+
21+
a {
22+
font-weight: 500;
23+
color: #646cff;
24+
text-decoration: inherit;
25+
}
26+
a:hover {
27+
color: #535bf2;
28+
}
29+
30+
body {
31+
margin: 0;
32+
display: flex;
33+
place-items: center;
34+
min-width: 320px;
35+
min-height: 100vh;
36+
}
37+
38+
@media (prefers-color-scheme: light) {
39+
:root {
40+
color: #213547;
41+
background-color: #ffffff;
42+
}
43+
}

apps/vite-lit/src/my-element.ts

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import { LitElement, css, html } from 'lit'
2+
import { customElement, property } from 'lit/decorators.js'
3+
import litLogo from './assets/lit.svg'
4+
5+
/**
6+
* An example element.
7+
*
8+
* @slot - This element has a slot
9+
* @csspart button - The button
10+
*/
11+
@customElement('my-element')
12+
export class MyElement extends LitElement {
13+
/**
14+
* Copy for the read the docs hint.
15+
*/
16+
@property()
17+
docsHint = 'Click on the Vite and Lit logos to learn more'
18+
19+
/**
20+
* The number of times the button has been clicked.
21+
*/
22+
@property({ type: Number })
23+
count = 0
24+
25+
render() {
26+
return html`
27+
<main class="flex min-h-screen flex-col items-center justify-between p-24">
28+
<div class="z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex">
29+
<p
30+
class="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30"
31+
>
32+
Get started by editing&nbsp;
33+
<code class="font-mono font-bold">pages/index.tsx</code>
34+
</p>
35+
<div
36+
class="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none"
37+
>
38+
<a
39+
class="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
40+
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
41+
target="_blank"
42+
rel="noopener noreferrer"
43+
>
44+
By
45+
<img src="${litLogo}" alt="Vercel Logo" class="dark:invert" priority />
46+
</a>
47+
</div>
48+
</div>
49+
50+
<div
51+
class="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700/10 after:dark:from-sky-900 after:dark:via-[#0141ff]/40 before:lg:h-[360px]"
52+
>
53+
<img class="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert" src="${'/vite.svg'}" alt="Next.js Logo" priority />
54+
</div>
55+
56+
<div class="mb-32 grid text-center lg:mb-0 lg:grid-cols-4 lg:text-left">
57+
<a
58+
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
59+
class="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
60+
target="_blank"
61+
rel="noopener noreferrer"
62+
>
63+
<h2 class="mb-3 text-2xl font-semibold">Docs <span class="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">-&gt;</span></h2>
64+
<p class="m-0 max-w-[30ch] text-sm opacity-50">Find in-depth information about Next.js features and API.</p>
65+
</a>
66+
67+
<a
68+
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
69+
class="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
70+
target="_blank"
71+
rel="noopener noreferrer"
72+
>
73+
<h2 class="mb-3 text-2xl font-semibold">Learn <span class="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">-&gt;</span></h2>
74+
<p class="m-0 max-w-[30ch] text-sm opacity-50">Learn about Next.js in an interactive course with&nbsp;quizzes!</p>
75+
</a>
76+
77+
<a
78+
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
79+
class="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
80+
target="_blank"
81+
rel="noopener noreferrer"
82+
>
83+
<h2 class="mb-3 text-2xl font-semibold">
84+
Templates <span class="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">-&gt;</span>
85+
</h2>
86+
<p class="m-0 max-w-[30ch] text-sm opacity-50">Discover and deploy boilerplate example Next.js&nbsp;projects.</p>
87+
</a>
88+
89+
<a
90+
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template-tw&utm_campaign=create-next-app"
91+
class="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
92+
target="_blank"
93+
rel="noopener noreferrer"
94+
>
95+
<h2 class="mb-3 text-2xl font-semibold">Deploy <span class="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">-&gt;</span></h2>
96+
<p class="m-0 max-w-[30ch] text-sm opacity-50">Instantly deploy your Next.js site to a shareable URL with Vercel.</p>
97+
</a>
98+
</div>
99+
</main>
100+
`
101+
}
102+
103+
private _onClick() {
104+
this.count++
105+
}
106+
107+
static styles = css`
108+
:host {
109+
max-width: 1280px;
110+
margin: 0 auto;
111+
padding: 2rem;
112+
text-align: center;
113+
}
114+
115+
.logo {
116+
height: 6em;
117+
padding: 1.5em;
118+
will-change: filter;
119+
transition: filter 300ms;
120+
}
121+
.logo:hover {
122+
filter: drop-shadow(0 0 2em #646cffaa);
123+
}
124+
.logo.lit:hover {
125+
filter: drop-shadow(0 0 2em #325cffaa);
126+
}
127+
128+
.card {
129+
padding: 2em;
130+
}
131+
132+
.read-the-docs {
133+
color: #888;
134+
}
135+
136+
h1 {
137+
font-size: 3.2em;
138+
line-height: 1.1;
139+
}
140+
141+
a {
142+
font-weight: 500;
143+
color: #646cff;
144+
text-decoration: inherit;
145+
}
146+
a:hover {
147+
color: #535bf2;
148+
}
149+
150+
button {
151+
border-radius: 8px;
152+
border: 1px solid transparent;
153+
padding: 0.6em 1.2em;
154+
font-size: 1em;
155+
font-weight: 500;
156+
font-family: inherit;
157+
background-color: #1a1a1a;
158+
cursor: pointer;
159+
transition: border-color 0.25s;
160+
}
161+
button:hover {
162+
border-color: #646cff;
163+
}
164+
button:focus,
165+
button:focus-visible {
166+
outline: 4px auto -webkit-focus-ring-color;
167+
}
168+
169+
@media (prefers-color-scheme: light) {
170+
a:hover {
171+
color: #747bff;
172+
}
173+
button {
174+
background-color: #f9f9f9;
175+
}
176+
}
177+
`
178+
}
179+
180+
declare global {
181+
interface HTMLElementTagNameMap {
182+
'my-element': MyElement
183+
}
184+
}

apps/vite-lit/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

apps/vite-lit/tailwind.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('tailwindcss').Config} */
2+
export default {
3+
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
4+
theme: {
5+
extend: {}
6+
},
7+
plugins: []
8+
}

0 commit comments

Comments
 (0)