feat: styled-components support - #90
Conversation
arminbro
left a comment
There was a problem hiding this comment.
Hi @doubleedesign,
Thanks for taking the time and contributing to GRC. Your PR looks excellent!
You could have used custom-component-templates to have styled components in your project.
In your GRC config file, you could do something like this:
{
"usesTypeScript": true,
"usesCssModule": false,
"cssPreprocessor": "css",
"testLibrary": "Testing Library",
"component": {
"default": {
"customTemplates": {
"component": ".grc/templates/styled-component/TemplateName.tsx",
"style": ".grc/templates/styled-component/TemplateName.styled.ts"
},
"path": "src/components",
"withStyle": true,
"withTest": true,
"withStory": false,
"withLazy": false
}
},
"usesStyledComponents": false
}Then, in your project, you could have created the costume styled template:
// .grc/templates/styled-component/TemplateName.styled.ts
import styled from 'styled-components';
export const TemplateNameWrapper = styled.div`
`;And this is what your custom component template would look like:
// .grc/templates/styled-component/TemplateName.tsx
import React, { FC } from "react";
import { TemplateNameWrapper } from "./TemplateName.styled";
interface TemplateNameProps {}
const TemplateName: FC<TemplateNameProps> = () => (
<TemplateNameWrapper data-testid="TemplateName">
TemplateName Component
</TemplateNameWrapper>
);
export default TemplateName;But your PR is still helpful and keeps the GRC config file clean. So I'm going to approve and merge your PR.
Thanks Again.
|
🎉 This PR is included in version 8.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Thanks for the quick response, feedback and merge @arminbro! I started using the custom templates like you've described, but then thought "Gee wouldn't it be good if it could do this out of the box?" and saw that issue had been raised...an afternoon well-spent making it happen! 🥳 |
Adds an option to use styled-components instead of CSS modules.
During setup:
During component creation:
withStylesetting to determine whether to generate a styled component in this instancewithStyleis true:divin the template is replaced by aComponentNameWrapper, andComponentName.styled.{js,ts}file is created, definingComponentNameWrapperas adiv.Could close #48.