Skip to content

Instantly share code, notes, and snippets.

@bobbyg603
Created December 13, 2022 18:33
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 bobbyg603/976b998478194019d1d24ae250cb8004 to your computer and use it in GitHub Desktop.
Save bobbyg603/976b998478194019d1d24ae250cb8004 to your computer and use it in GitHub Desktop.
How to Build a Web Component
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