Skip to content

Instantly share code, notes, and snippets.

@powerlanguage
Created March 12, 2024 02:39
Show Gist options
  • Save powerlanguage/04c02b07c44d22f838ecc335edf133b0 to your computer and use it in GitHub Desktop.
Save powerlanguage/04c02b07c44d22f838ecc335edf133b0 to your computer and use it in GitHub Desktop.
VSCode Snippet for scaffolding webcomponents
{
// Filename transformations: https://gist.github.com/natemoo-re/94cfba2bfb17cbeec0680c05309ea9ee
"Scaffold web component": {
"scope": "javascript,typescript",
"prefix": "wc",
"body": [
"const template = document.createElement('template');",
"template.innerHTML = $BLOCK_COMMENT_START HTML $BLOCK_COMMENT_END `<style></style><div></div>`",
"",
"export class ${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/capitalize}${2:/capitalize}/g} extends HTMLElement {",
" constructor() {",
" super();",
" this.attachShadow({mode: 'open'});",
" }",
"",
" connectedCallback(){",
" this.shadowRoot!.appendChild(template.content.cloneNode(true))",
" this.render();",
" }",
" render(){",
" }",
"}",
"",
"customElements.define('${TM_FILENAME_BASE}', ${TM_FILENAME_BASE/(\\w+)?[-_\\s]+(\\w+)/${1:/capitalize}${2:/capitalize}/g});"
],
"description": "Scaffold vanilla webcomponent"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment