Created
December 13, 2022 18:33
-
-
Save bobbyg603/976b998478194019d1d24ae250cb8004 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 src - url to use for the thumbnail image | |
*/ | |
@customElement('medium-card-thumbnail') | |
export class MediumCardThumbnailElement extends LitElement { | |
static override styles = css` | |
:host { | |
display: flex; | |
} | |
img { | |
height: var(--medium-thumbnail-height, 220px); | |
width: var(--medium-thumbnail-width, 330px); | |
border-top-left-radius: var(--medium-thumbnail-border-left-radius); | |
border-bottom-left-radius: var(--medium-thumbnail-border-left-radius); | |
border-top-right-radius: var(--medium-thumbnail-border-right-radius); | |
border-bottom-right-radius: var(--medium-thumbnail-border-right-radius); | |
object-fit: cover; | |
} | |
`; | |
@property() | |
src = ''; | |
override render() { | |
return html`<img src="${this.src}">`; | |
} | |
} | |
declare global { | |
interface HTMLElementTagNameMap { | |
'medium-card-thumbnail': MediumCardThumbnailElement; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment