Skip to content

Instantly share code, notes, and snippets.

@Westbrook
Created May 8, 2023 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Westbrook/fca1faa0f2dad202903c4c1f5f7c6222 to your computer and use it in GitHub Desktop.
Save Westbrook/fca1faa0f2dad202903c4c1f5f7c6222 to your computer and use it in GitHub Desktop.
import { LitComponent } from "./LitComponent.js";
export const TAG_NAME = "hz-lit-component";
if (!customElements.get(TAG_NAME)) {
customElements.define(TAG_NAME, LitComponent);
}
declare global {
interface HTMLElementTagNameMap {
[TAG_NAME]: LitComponent;
}
}
<!DOCTYPE html>
<head>
<script type="module" src="./hz-lit-component.js"></script>
</head>
<body>
<button id="remove">Remove</button>
<hz-lit-component></hz-lit-component>
<script>
document.remove.addEventListener('click', ({target}) => target.nextElementSibling.remove());
</script>
</body>
import { css } from "lit";
export const style = css`
:host {
border: 1px solid black;
display: block;
width: 100%;
padding: 10px;
}
`;
import { html, LitElement } from "lit";
import { style } from "./LitComponent.css.js";
import type { TemplateResult } from "lit";
export class LitComponent extends LitElement {
public static readonly styles = style;
public render(): TemplateResult {
return html` <p>This is a simple component using LitCompoent</p> `;
}
}
{
"dependencies": {
"lit": "^2.0.0",
"@lit/reactive-element": "^1.0.0",
"lit-element": "^3.0.0",
"lit-html": "^2.0.0"
}
}
{
"files": {
"LitComponent.ts": {
"position": 0
},
"index.html": {
"position": 1
},
"package.json": {
"position": 2,
"hidden": true
},
"LitComponent.css.ts": {
"position": 3
},
"hz-lit-component.ts": {
"position": 4
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment