Created
March 12, 2024 02:39
-
-
Save powerlanguage/04c02b07c44d22f838ecc335edf133b0 to your computer and use it in GitHub Desktop.
VSCode Snippet for scaffolding webcomponents
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
Show hidden characters
{ | |
// 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