Skip to content

Instantly share code, notes, and snippets.

@wellserrano
Last active March 30, 2023 19:30
Show Gist options
  • Save wellserrano/b0ee5c5e9ae96c6dc683a7701007599b to your computer and use it in GitHub Desktop.
Save wellserrano/b0ee5c5e9ae96c6dc683a7701007599b to your computer and use it in GitHub Desktop.
FC boilerplate
{
"Typescript React Function Component": {
"prefix": "fc",
"body": [
"import * as React from 'react'",
"import { cva, VariantProps } from 'class-variance-authority'",
"//import { cn } from '../../lib/utils/cn'",
"",
"const ${TM_FILENAME_BASE/([^.]+)/${1:/downcase}/g}Variants = cva(",
"`$1`,",
"{",
" variants: {",
" variant: {",
" opt1: 'test1',",
" opt2: 'test2',",
" },",
" },",
" defaultVariants: {",
" variant: 'opt1'",
" }",
" }",
")",
"",
"interface ${TM_FILENAME_BASE}Props",
"extends VariantProps<typeof ${TM_FILENAME_BASE/([^.]+)/${1:/downcase}/g}Variants> {",
" $2",
"}",
"",
"const $TM_FILENAME_BASE = React.forwardRef<${TM_FILENAME_BASE}Props>(",
"({$2}, ref) => {",
" return (",
" <div>$TM_FILENAME_BASE</div>",
" )",
"})",
"",
"${TM_FILENAME_BASE}.displayName = '${TM_FILENAME_BASE}'",
"",
"export {$TM_FILENAME_BASE}"
],
"description": "Typescript React Function Component"
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment