Skip to content

Instantly share code, notes, and snippets.

@SeedyROM
Last active January 11, 2019 13:44
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 SeedyROM/a26c14ef803d6685fa2cf6dbede3b7b4 to your computer and use it in GitHub Desktop.
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.
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