Created
December 13, 2022 18:37
-
-
Save bobbyg603/a5b20f14729f845ee01420ffeba760cb to your computer and use it in GitHub Desktop.
How to Build a Web Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LitElement, html, css } from 'lit'; | |
import { customElement, property } from 'lit/decorators.js'; | |
/** | |
* Medium card header sub-component | |
* @property header - larger header | |
* @property subheader - smaller header | |
*/ | |
@customElement('medium-card-header') | |
export class MediumCardHeaderElement extends LitElement { | |
static override styles = css` | |
:host { | |
flex-grow: 1; | |
color: var(--medium-header-color); | |
} | |
h2, h3 { | |
margin: 0; | |
} | |
`; | |
@property() | |
header = ''; | |
@property() | |
subheader = ''; | |
override render() { | |
return html` | |
<h2>${this.header}</h2> | |
<h3>${this.subheader}</h3> | |
`; | |
} | |
} | |
declare global { | |
interface HTMLElementTagNameMap { | |
'medium-card-header': MediumCardHeaderElement; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment