Skip to content

Commit c188deb

Browse files
committed
fix: add PropsWithChildren to functional template feat: BREAKING: non styled-component styles are scss modules now
1 parent 7a00374 commit c188deb

File tree

9 files changed

+412
-358
lines changed

9 files changed

+412
-358
lines changed

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# changelog
22

3-
## work in progress
3+
## 0.0.4
44

55
- feat: make variable path name parts formatting configurable
6+
- fix: add `PropsWithChildren` to functional template
7+
- feat: BREAKING: non styled-component styles are scss modules now
68

79
## 0.0.3
810

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@a9g/plop-generator-react-atomic-component",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "plop generator react atomic component",
55
"main": "dist/index.js",
66
"types": "dist/types/index.d.ts",
@@ -32,7 +32,7 @@
3232
"devDependencies": {
3333
"@typescript-eslint/eslint-plugin": "^5.6.0",
3434
"@typescript-eslint/parser": "^5.6.0",
35-
"eslint": "^8.4.1",
35+
"eslint": "^8.8.0",
3636
"eslint-config-prettier": "^8.3.0",
3737
"husky": "^7.0.4",
3838
"lint-staged": "^12.1.2",
@@ -45,7 +45,7 @@
4545
"*.{ts,tsx,css,md,json,js}": "prettier --write"
4646
},
4747
"dependencies": {
48-
"node-plop": "^0.30.0"
48+
"node-plop": "^0.31.0"
4949
},
5050
"volta": {
5151
"node": "16.13.1",

plopfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const defaultConfig = {
88
withStyleInterfaceImportPath: "/framework/ui",
99
tests: true,
1010
stories: true,
11-
styledComponents: true,
11+
styledComponents: false,
1212
useNative: false,
1313
useMacro: false,
1414
typeFormatter: "pascaleCase",

src/atomicComponent.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ const atomicComponent = (
5151
let styledComponentsType = "styled-components";
5252
let baseComponent = "div";
5353
let testId = "data-testid";
54-
let withClassNameClassName = `className={${
55-
IS_FUNCTIONAL ? "" : "this."
56-
}props.className} `;
54+
55+
let classNames = [];
56+
classNames.push(`${IS_FUNCTIONAL ? "" : "this."}props.className`);
57+
58+
if (!WITH_STYLED_COMPONENTS) {
59+
classNames.push("styles.root");
60+
}
61+
62+
let withClassNameClassName = `className={[${classNames}].join()} `;
63+
64+
if (WITH_STYLED_COMPONENTS) {
65+
withClassNameClassName = `className={${classNames}} `;
66+
}
67+
5768
let withClassNameProps = "interface Props extends PropsWithClassName";
5869
let withClassNameImport = `import {PropsWithClassName} from '${fullConfig.withClassnameInterfaceImportPath}'`;
5970

@@ -105,9 +116,11 @@ const atomicComponent = (
105116
let templateBaseComponent = "Root";
106117

107118
if (!WITH_STYLED_COMPONENTS) {
108-
styleImport = "";
119+
styleImport = `import * as styles from './${formattedFileName}.module.scss'`;
120+
109121
templateBaseComponent = "div";
110122
if (IS_NATIVE) {
123+
styleImport = "";
111124
templateBaseComponent = "Text";
112125
}
113126
}
@@ -219,6 +232,9 @@ const atomicComponent = (
219232
});
220233
}
221234
let stylesTemplateFile = CURRENT_DIR + "/templates/styles.hbs";
235+
if (WITH_STYLED_COMPONENTS) {
236+
stylesTemplateFile = CURRENT_DIR + "/templates/stylesStyledComponents.hbs";
237+
}
222238

223239
if (fullConfig.templateStyles !== undefined) {
224240
if (fs.existsSync(fullConfig.templateStyles)) {
@@ -230,7 +246,9 @@ const atomicComponent = (
230246
type: "add",
231247
path:
232248
fullConfig.basePath +
233-
`/${formattedType}/${formattedDirName}/${formattedFileName}.styles.ts`,
249+
`/${formattedType}/${formattedDirName}/${formattedFileName}.${
250+
WITH_STYLED_COMPONENTS ? "styles.ts" : "module.scss"
251+
}`,
234252
templateFile: stylesTemplateFile,
235253
data,
236254
});

src/templates/component_class_based.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
{{> withClassNameImport }};
22
import { Component } from 'react';
33

4-
{{#if styledComponents}}
54
{{> styleImport }};
65

7-
{{/if}}
86
interface State {}
97

108
{{ withClassNameProps }} {}

src/templates/component_functional.hbs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{{> withClassNameImport }};
22
import React, { PropsWithChildren } from 'react';
33

4-
{{#if styledComponents}}
54
{{> styleImport }};
65

7-
{{/if}}
86
{{ withClassNameProps }} {}
97

10-
const {{ pascalCase name }}: React.FC<Props> = (props: PropsWithChildren<Props>): React.ReactElement => {
8+
const {{ pascalCase name }}: React.FC<PropsWithChildren<Props>> = (props: PropsWithChildren<Props>): React.ReactElement => {
119
return (
1210
<{{ templateBaseComponent }} {{> withClassNameClassName }} {{> testId }}={"{{kebabCase name }}-root"}>
1311
{{ name }}

src/templates/styles.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import styled from '{{ styledComponentsType }}';
1+
.root {
22

3-
export const Root = styled.{{ baseComponent }}``;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import styled from '{{ styledComponentsType }}';
2+
3+
export const Root = styled.{{ baseComponent }}``;

0 commit comments

Comments
 (0)