Skip to content

Commit 6d484c3

Browse files
authored
Merge pull request #1 from rafauke/fix/change-default-templates
Fix/change default templates
2 parents 5c2d92d + ed89a4a commit 6d484c3

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

src/atomicComponent.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ const atomicComponent = (
4949

5050
let styledComponentsType = "styled-components";
5151
let baseComponent = "div";
52+
let testId = "data-testid";
5253
let withClassNameClassName = `className={${
5354
IS_FUNCTIONAL ? "" : "this."
5455
}props.className} `;
5556
let withClassNameProps = "interface Props extends PropsWithClassName";
56-
let withClassNameImport = `import {PropsWithClassName} from "${fullConfig.withClassnameInterfaceImportPath}";\n`;
57+
let withClassNameImport = `import {PropsWithClassName} from '${fullConfig.withClassnameInterfaceImportPath}'`;
5758

5859
if (fullConfig.useMacro) {
5960
styledComponentsType = "styled-components/macro";
@@ -62,14 +63,15 @@ const atomicComponent = (
6263
if (IS_NATIVE) {
6364
styledComponentsType = "styled-components/native";
6465
baseComponent = "Text";
66+
testId = "testID";
6567
withClassNameClassName = `style={${
6668
IS_FUNCTIONAL ? "" : "this."
6769
}props.style} `;
6870
withClassNameProps = "interface Props extends PropsWithNativeStyle";
69-
withClassNameImport = `import {PropsWithNativeStyle} from "${fullConfig.withStyleInterfaceImportPath}";\n`;
71+
withClassNameImport = `import {PropsWithNativeStyle} from '${fullConfig.withStyleInterfaceImportPath}'`;
7072
}
7173

72-
let styleImport = `\nimport {Root} from './{{pascalCase name}}.styles';`;
74+
let styleImport = `import {Root} from './{{pascalCase name}}.styles'`;
7375
let templateBaseComponent = "Root";
7476

7577
if (!WITH_STYLED_COMPONENTS) {
@@ -81,12 +83,16 @@ const atomicComponent = (
8183
}
8284

8385
data = {
84-
templateBaseComponent,
85-
withClassNameProps,
86-
withClassNameClassName,
86+
styledComponents: fullConfig.styledComponents,
8787
baseComponent,
8888
styledComponentsType,
89+
templateBaseComponent,
90+
withClassNameClassName,
91+
withClassNameProps,
92+
testId,
8993
};
94+
95+
plop.setPartial("testId", testId);
9096
plop.setPartial("styleImport", styleImport);
9197
plop.setPartial("withClassNameImport", withClassNameImport);
9298
plop.setPartial("withClassNameClassName", withClassNameClassName);

src/templates/component_class_based.hbs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import {Component} from 'react';{{> styleImport }}
2-
{{> withClassNameImport }}
1+
{{> withClassNameImport }};
2+
import { Component } from 'react';
33

4-
interface State {
5-
}
4+
{{#if styledComponents}}
5+
{{> styleImport }};
66

7-
{{ withClassNameProps }} {
8-
}
7+
{{/if}}
8+
interface State {}
9+
10+
{{ withClassNameProps }} {}
911

1012
export class {{pascalCase name }} extends Component<Props, State> {
1113
constructor(props: Props) {
@@ -16,7 +18,7 @@ export class {{pascalCase name }} extends Component<Props, State> {
1618

1719
render() {
1820
return (
19-
<{{ templateBaseComponent }} {{> withClassNameClassName }}data-testid={"{{kebabCase name }}-root"}>
21+
<{{ templateBaseComponent }} {{> withClassNameClassName }} {{> testId }}={"{{kebabCase name }}-root"}>
2022
{{ name }}
2123
</{{ templateBaseComponent }}>
2224
);
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import React, { PropsWithChildren } from 'react';{{> styleImport }}
2-
{{> withClassNameImport }}
1+
{{> withClassNameImport }};
2+
import React, { PropsWithChildren } from 'react';
33

4-
{{ withClassNameProps }} {
5-
}
4+
{{#if styledComponents}}
5+
{{> styleImport }};
6+
7+
{{/if}}
8+
{{ withClassNameProps }} {}
69

7-
const {{pascalCase name }} : React.FC<Props> = (props: PropsWithChildren<Props>): React.ReactElement => {
10+
const {{ pascalCase name }}: React.FC<Props> = (props: PropsWithChildren<Props>): React.ReactElement => {
811
return (
9-
<{{ templateBaseComponent }} {{> withClassNameClassName }}data-testid={"{{kebabCase name }}-root"}>
12+
<{{ templateBaseComponent }} {{> withClassNameClassName }} {{> testId }}={"{{kebabCase name }}-root"}>
1013
{{ name }}
1114
</{{ templateBaseComponent }}>
1215
);
1316
}
1417

15-
export { {{pascalCase name }} }
18+
export { {{ pascalCase name }} }

src/templates/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import {{{pascalCase name }}} from './{{pascalCase name }}';
1+
import { {{pascalCase name}} } from './{{pascalCase name}}';
22

33
export default {{pascalCase name }};

src/templates/story.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{{ componentImport }}
1+
import { {{ pascalCase name }} } from './{{ pascalCase name }}';
22

33
const StorybookSettings = {
44
title: 'Design System/{{ type }}s/{{ name }}'
55
};
66

77
export default StorybookSettings;
88

9-
export const Basic{{pascalCase name }} = () => <{{pascalCase name }} />;
9+
export const Basic{{ pascalCase name }} = () => <{{ pascalCase name }} />;

src/templates/styles.hbs

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

3-
export const Root = styled.{{ baseComponent }}`
4-
`;
3+
export const Root = styled.{{ baseComponent }}``;

0 commit comments

Comments
 (0)