Code Monkey home page Code Monkey logo

vs-code-create-react-folder-component's Introduction

Create React Folder Component

A simple wizard that speeds up creating new React folder components.

It supports both JavaScript and TypeScript.

The templates used when creating the component files are completely configurable through settings.

Features

This extension provides two commands, accessible in the explorer context menu and in the command palette.

Command palette: Command palette commands

Explorer context menu: Context menu commands

When activated it will prompt you to give your component a name: Name component

The extension will then create a folder and files for a new component with your given name: Component structure

With styles: Component structure with style

The default contents of those files will be (without style): Component content Index content

Requirements

No extra requirements ๐ŸŽ‰.

Extension Settings

Template Language

By default the extension will ask you each time which language you want to use for your component but you can change that behaviour with this setting.

Available options:

  • JavaScript
  • TypeScript
  • Ask

Default: Ask

Template content settings

All the following settings control the contents of the templates that will be used when creating your components.

The following variables are exposed in your templates.

Variable Description
$COMPONENT_NAME The name you entered for the component.
$COMPONENT_CAMELCASE_NAME Same as $COMPONENT_NAME but with a lower case leading letter.
$STYLE_COMPONENT_NAME A transformed css-style name of the component name.
$STYLE_COMPONENT_FILENAME The filename of the style file. It's a result of the styleFileNameTemplate setting of the current language.

JavaScript Component file Template

Template for your component file in JavaScript.

Default:

[
  "import React from 'react'",
  "import PropTypes from 'prop-types'",
  "",
  "$COMPONENT_NAME.propTypes = {",
  "}",
  "",
  "export default function $COMPONENT_NAME({}) {",
  "}"
]

JavaScript styled Component file Template

Template used for creating the styled Component file in JavaScript.

Default:

[
  "import React from 'react'",
  "import PropTypes from 'prop-types'",
  "import './$STYLE_COMPONENT_FILENAME'",
  "",
  "$COMPONENT_NAME.propTypes = {",
  "}",
  "",
  "export default function $COMPONENT_NAME({}) {",
  "}"
]

JavaScript index file Template

Template used for creating the index file in JavaScript.

Default:

["export { default } from './$COMPONENT_NAME'"]

JavaScript style file Template

Template used for creating the style file in JavaScript.

Default:

[".$STYLE_COMPONENT_NAME {}"]

JavaScript style file name template

File name for style file in JavaScript.

Default: "$STYLE_COMPONENT_NAME.scss"

TypeScript Component file Template

Template used for creating the Component file in TypeScript.

Default:

[
  "import React from 'react'",
  "",
  "interface $COMPONENT_NAMEProps {",
  "}",
  "",
  "export default function $COMPONENT_NAME({}: $COMPONENT_NAMEProps) {",
  "}"
]

TypeScript styled Component file Template

Template used for creating the styled Component file in TypeScript.

Default:

[
  "import React from 'react'",
  "import './$STYLE_COMPONENT_FILENAME'",
  "",
  "interface $COMPONENT_NAMEProps {",
  "}",
  "",
  "export default function $COMPONENT_NAME({}: $COMPONENT_NAMEProps) {",
  "}"
]

TypeScript index file Template

Template used for creating the index file in TypeScript.

Default:

["export { default } from './$COMPONENT_NAME'"]

TypeScript style file Template

Template used for creating the style file in TypeScript.

Default:

[".$STYLE_COMPONENT_NAME {}"]

TypeScript style file name template

File name for style file in TypeScript.

Default: "$STYLE_COMPONENT_NAME.scss"

Custom files

There is also support for custom files through the customFiles setting. This has no defaults, but here is an example:

[
  {
    "filename": "$COMPONENT_NAME.hooks.ts",
    "outputForLanguage": "TypeScript", // the file will be created for both JS and TS if left 'undefined'
    "contents": [
      "import classNames from 'classnames'",
      "",
      "import styles from './$STYLE_COMPONENT_NAME.scss'",
      "",
      "export function useComponentStyles() {",
      "  const $COMPONENT_CAMELCASE_NAMEStyles = classNames({",
      "    [styles['$COMPONENT_CAMELCASE_NAME']]: true",
      "  })",
      "",
      "  return {",
      "    $COMPONENT_CAMELCASE_NAMEStyles",
      "  }",
      "}"
    ]
  }
]

Known Issues

There's no known issues ๐Ÿž.

If you find something, please report it at https://github.com/HektorW/vs-code-create-react-folder-component.

Release Notes

See CHANGELOG.md

vs-code-create-react-folder-component's People

Contributors

dependabot[bot] avatar hektorw avatar mrtamagotchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vs-code-create-react-folder-component's Issues

Setting for default component folder

A setting for the default component folder so that it would be possible to skip the step of choosing where to create the component each time.

  • Ask Works as it does now
  • /foo/components/ Component folder will be created without further questions

Change to a completely dynamic templating system

A system where it's possible to create an unspecified amount of template variations and completely configurable how many and which files they create.

A suggestion of the templating structure:

{
  "createfoldercomponent.alwaysPresentFiles": {
    "index.ts": [
      "export { default } from './$COMPONENT_NAME'"
    ]
  },

  "createfoldercomponent.templates": {
    "React TypeScript Component": {
      "files": {
        "$COMPONENT_NAME.tsx": [
          "import React from 'react'",
          "",
          "interface $COMPONENT_NAMEProps {",
          "}",
          "",
          "export default function $COMPONENT_NAME({}: $COMPONENT_NAMEProps) {",
          "}"
        ]
      }
    },

    "React TypeScript Component with stories": {
      "extends": "React TypeScript Component",
      "files": {
        "$COMPONENT_NAME.stories.tsx": [
          "import React from 'react'"
          "import $COMPONENT_NAME from './$COMPONENT_NAME'",
          "",
          "export function main() {"
          "  return <$COMPONENT_NAME />"
          "}"
        ]
      }
    }
  }
}

File naming problem

Hello!
First of all, thank you for a great plugin. I use it daily and it has really enhanced my workflow.

At the moment I'm experiencing a minor issue when it comes to the automatic file naming. When creating the component Error404Page the associated style-file gets the name (and pre-populated classname) error404-page. Maybe it's a good idea to split not only before capital letters but also before the first digit of a number?

This is really an edge case, and not sure it splitting it like this would mess up some other naming convention, but since you usually don't have numbers in component names I assume it's safe.

If this is interesting I could try to submit a PR.

Anyways, thanks and keep up the good work! ๐Ÿฅณ

Failed to create folder

Error: ENOENT: no such file or directory, mkdir '...\ClientTsNode\client\components...\ClientTsNode\client\components\SomeModule'

Seems to be some error with path joining.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.