Last active
January 11, 2019 13:44
-
-
Save SeedyROM/a26c14ef803d6685fa2cf6dbede3b7b4 to your computer and use it in GitHub Desktop.
A simple helper to create functional Vue components with CSS modules and Typescript.
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 { componentFactory } from 'vue-tsx-support'; | |
import { VNode } from 'vue'; | |
type Styles = string | Array<string>; | |
interface WrapperProps { | |
as?: string; | |
} | |
export default ( | |
styles: Styles, | |
tag: string = 'div', | |
) => componentFactory.create<object & WrapperProps, {}>({ | |
functional: true, | |
render(h, context): VNode { | |
const { props, children, data } = context; | |
const elementName = tag || props.as; | |
return h(elementName, { attrs: data.attrs, props, class: styles }, children); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment