Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Custom Component Files to master #40

Merged
merged 10 commits into from
Feb 17, 2021
Merged

feat: Custom Component Files to master #40

merged 10 commits into from
Feb 17, 2021

Conversation

arminbro
Copy link
Owner

@arminbro arminbro commented Feb 17, 2021

Custom component files

GRC comes with corresponding built-in files for a given component if you need them (i.e., withStyle, withTest, withStory, and withLazy).

What if you wanted to add custom files of your own?

For example, let's say you wanted to add an index.js file for each component, so you don't have to add the additional component name with each import (i.e., import Box from './components/Box' instead of import Box from './components/Box/Box').

Or maybe you need an additional style file for your component stories.

You can do so by editing your generate-react-cli.json config file like so.

{
  "usesTypeScript": false,
  "usesCssModule": false,
  "cssPreprocessor": "css",
  "testLibrary": "Testing Library",
  "component": {
    "default": {
      "path": "src/components",
      "withStyle": true,
      "withTest": true,
      "withStory": true,
      "withLazy": false,
      "withIndex": true,
      "withStoryStyle": true,
      "customTemplates": {
        "index": "templates/default/index.js",
        "storyStyle": "templates/default/TemplateName.stories.css"
      }
    }
  }
}
// templates/default/index.js

export { default } from './TemplateName';
/* templates/default/TemplateName.stories.css */

.TemplateName {}

In this case, we added a withIndex & withStoryStyle to the component.default. Note: You can add custom files to any of your custom component types.

You should also see that we added index and storyStyle to our customTemplates object. That's because custom files require custom templates. Otherwise, you will get an error when you generate a component.

Also, we used the TemplateName keyword for the storyStyle custom file. GRC will generate this corresponding file and replace TemplateName with the component name.

This PR should close #21, #22, #27, #34, #36, #37, #39

This feature will allow for adding custom component file types (e.g., withIndex, withwithStoryStyle,
etc.)

#21 #22 #27 #34 #36 #37 #39
When the TemplateName keyword is used in the template filename it will be replaced with the
component name.

BREAKING CHANGE: You will need to use the "TemplateName" keyword as your custom template filename if
you want the CLI to replace it with the component name.
@arminbro arminbro merged commit 8569f49 into master Feb 17, 2021
@arminbro arminbro deleted the 6.0.0 branch February 17, 2021 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment