@teambit/react 0.0.554 → 0.0.558
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mount.d.ts +5 -0
- package/dist/react-app-options.d.ts +25 -0
- package/dist/react.env.d.ts +87 -1
- package/dist/react.main.runtime.d.ts +89 -1
- package/package.json +51 -43
- package/tsconfig.json +1 -2
- package/compositions-app.tsx +0 -31
- package/eslint/eslintrc.js +0 -12
- package/highlighter-widget.tsx +0 -19
- package/index.ts +0 -9
- package/jest/css-transform.js +0 -12
- package/jest/file-transform.js +0 -38
- package/jest/jest.config.js +0 -30
- package/jest/setupTests.js +0 -7
- package/jest/transformer.js +0 -41
- package/mount.tsx +0 -17
- package/package-tar/teambit-react-0.0.554.tgz +0 -0
- package/prettier/prettier.config.js +0 -5
- package/react-app-options.ts +0 -45
- package/react.app-type.ts +0 -19
- package/react.application.ts +0 -96
- package/react.aspect.ts +0 -5
- package/react.composition.tsx +0 -7
- package/react.docs.mdx +0 -8
- package/react.env.ts +0 -363
- package/react.graphql.ts +0 -52
- package/react.main.runtime.ts +0 -437
- package/react.preview.runtime.ts +0 -44
- package/react.templates.ts +0 -29
- package/react.ui.runtime.tsx +0 -35
- package/templates/react-app/files/app-root.ts +0 -10
- package/templates/react-app/files/app.ts +0 -30
- package/templates/react-app/files/aspect.ts +0 -10
- package/templates/react-app/files/compositions.ts +0 -11
- package/templates/react-app/files/doc.ts +0 -29
- package/templates/react-app/files/index.ts +0 -10
- package/templates/react-app/files/main.runtime.ts +0 -22
- package/templates/react-app/index.ts +0 -47
- package/templates/react-component/files/component.ts +0 -25
- package/templates/react-component/files/composition.ts +0 -16
- package/templates/react-component/files/docs.ts +0 -32
- package/templates/react-component/files/test.ts +0 -19
- package/templates/react-component/index.ts +0 -40
- package/templates/react-component-js/files/component.ts +0 -18
- package/templates/react-component-js/files/composition.ts +0 -16
- package/templates/react-component-js/files/docs.ts +0 -32
- package/templates/react-component-js/files/test.ts +0 -21
- package/templates/react-component-js/index.ts +0 -38
- package/templates/react-context/files/composition.ts +0 -27
- package/templates/react-context/files/context-provider.ts +0 -27
- package/templates/react-context/files/context.ts +0 -21
- package/templates/react-context/files/docs.ts +0 -51
- package/templates/react-context/files/test.ts +0 -18
- package/templates/react-context/index.ts +0 -32
- package/templates/react-env/files/aspect.ts +0 -10
- package/templates/react-env/files/doc.ts +0 -163
- package/templates/react-env/files/index.ts +0 -10
- package/templates/react-env/files/jest.config.ts +0 -21
- package/templates/react-env/files/main.runtime.ts +0 -84
- package/templates/react-env/files/preview.runtime.ts +0 -27
- package/templates/react-env/files/typescript.config.ts +0 -21
- package/templates/react-env/files/webpack.config.ts +0 -48
- package/templates/react-env/index.ts +0 -51
- package/templates/react-hook/files/component.ts +0 -16
- package/templates/react-hook/files/composition.ts +0 -23
- package/templates/react-hook/files/docs.ts +0 -33
- package/templates/react-hook/files/test.ts +0 -20
- package/templates/react-hook/index.ts +0 -21
- package/templates/react-workspace/index.ts +0 -27
- package/templates/react-workspace-app/index.ts +0 -20
- package/templates/react-workspace-deprecated/index.ts +0 -28
- package/templates/react-workspace-lib/index.ts +0 -21
- package/templates/workspace-common/files/eslint-config.ts +0 -6
- package/templates/workspace-common/files/git-ignore.ts +0 -113
- package/templates/workspace-common/files/prettier-config.ts +0 -5
- package/templates/workspace-common/files/readme-file.ts +0 -36
- package/templates/workspace-common/files/ts-config.ts +0 -7
- package/templates/workspace-common/files/types/asset.ts +0 -28
- package/templates/workspace-common/files/types/style.ts +0 -43
- package/templates/workspace-common/files/workspace-config.ts +0 -58
- package/templates/workspace-common/generate-files.ts +0 -51
- package/templates/workspace-common/index.ts +0 -1
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/typescript/asset.d.ts +0 -29
- package/typescript/style.d.ts +0 -42
- package/typescript/tsconfig.build.json +0 -22
- package/typescript/tsconfig.json +0 -18
- package/webpack/format-webpack-messages.js +0 -102
- package/webpack/launch-editor-endpoint.js +0 -8
- package/webpack/postcss.config.ts +0 -21
- package/webpack/react-hot-dev-client.js +0 -274
- package/webpack/refresh.js +0 -16
- package/webpack/webpack.config.base.prod.ts +0 -123
- package/webpack/webpack.config.base.ts +0 -365
- package/webpack/webpack.config.component.dev.ts +0 -104
- package/webpack/webpack.config.component.prod.ts +0 -39
- package/webpack/webpack.config.env.dev.ts +0 -21
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ComponentContext, ComponentTemplate } from '@teambit/generator';
|
|
2
|
-
import { indexFile } from './files/index';
|
|
3
|
-
import { docFile } from './files/doc';
|
|
4
|
-
import { mainRuntimeFile } from './files/main.runtime';
|
|
5
|
-
import { compositionsFile } from './files/compositions';
|
|
6
|
-
import { aspectFile } from './files/aspect';
|
|
7
|
-
import { appFile } from './files/app';
|
|
8
|
-
import { appRootFile } from './files/app-root';
|
|
9
|
-
|
|
10
|
-
export const reactAppTemplate: ComponentTemplate = {
|
|
11
|
-
name: 'react-app',
|
|
12
|
-
hidden: true,
|
|
13
|
-
description: 'Creates a React app',
|
|
14
|
-
generateFiles: (context: ComponentContext) => {
|
|
15
|
-
return [
|
|
16
|
-
{
|
|
17
|
-
relativePath: 'index.ts',
|
|
18
|
-
content: indexFile(context),
|
|
19
|
-
isMain: true,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
relativePath: `${context.name}.docs.mdx`,
|
|
23
|
-
content: docFile(context),
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
relativePath: `${context.name}.main.runtime.ts`,
|
|
27
|
-
content: mainRuntimeFile(context),
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
relativePath: `${context.name}.compositions.tsx`,
|
|
31
|
-
content: compositionsFile(context),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
relativePath: `${context.name}.aspect.ts`,
|
|
35
|
-
content: aspectFile(context),
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
relativePath: `app.tsx`,
|
|
39
|
-
content: appFile(context),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
relativePath: `${context.name}.app-root.tsx`,
|
|
43
|
-
content: appRootFile(context),
|
|
44
|
-
},
|
|
45
|
-
];
|
|
46
|
-
},
|
|
47
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const componentFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
return {
|
|
6
|
-
relativePath: `${name}.tsx`,
|
|
7
|
-
content: `import React from 'react';
|
|
8
|
-
|
|
9
|
-
export type ${Name}Props = {
|
|
10
|
-
/**
|
|
11
|
-
* a text to be rendered in the component.
|
|
12
|
-
*/
|
|
13
|
-
text: string
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function ${Name}({ text }: ${Name}Props) {
|
|
17
|
-
return (
|
|
18
|
-
<div>
|
|
19
|
-
{text}
|
|
20
|
-
</div>
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
`,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const compositionFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.composition.tsx`,
|
|
8
|
-
content: `import React from 'react';
|
|
9
|
-
import { ${Name} } from './${name}';
|
|
10
|
-
|
|
11
|
-
export const Basic${Name} = () => (
|
|
12
|
-
<${Name} text="hello from ${Name}" />
|
|
13
|
-
);
|
|
14
|
-
`,
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const docsFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.docs.mdx`,
|
|
8
|
-
content: `---
|
|
9
|
-
description: 'A ${Name} component.'
|
|
10
|
-
labels: ['label1', 'label2', 'label3']
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
import { ${Name} } from './${name}';
|
|
14
|
-
|
|
15
|
-
## React Component for rendering text
|
|
16
|
-
|
|
17
|
-
A basic div that renders some text
|
|
18
|
-
|
|
19
|
-
### Component usage
|
|
20
|
-
\`\`\`js
|
|
21
|
-
<${Name} text="hello from ${Name}" />
|
|
22
|
-
\`\`\`
|
|
23
|
-
|
|
24
|
-
### Using props to customize the text
|
|
25
|
-
|
|
26
|
-
Modify the text to see it change live:
|
|
27
|
-
\`\`\`js live
|
|
28
|
-
<${Name} text="hello from ${Name}" />
|
|
29
|
-
\`\`\`
|
|
30
|
-
`,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const testFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.spec.tsx`,
|
|
8
|
-
content: `import React from 'react';
|
|
9
|
-
import { render } from '@testing-library/react';
|
|
10
|
-
import { Basic${Name} } from './${name}.composition';
|
|
11
|
-
|
|
12
|
-
it('should render with the correct text', () => {
|
|
13
|
-
const { getByText } = render(<Basic${Name} />);
|
|
14
|
-
const rendered = getByText('hello from ${Name}');
|
|
15
|
-
expect(rendered).toBeTruthy();
|
|
16
|
-
});
|
|
17
|
-
`,
|
|
18
|
-
};
|
|
19
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ComponentTemplate, ComponentContext } from '@teambit/generator';
|
|
2
|
-
import { componentFile } from './files/component';
|
|
3
|
-
import { compositionFile } from './files/composition';
|
|
4
|
-
import { docsFile } from './files/docs';
|
|
5
|
-
import { testFile } from './files/test';
|
|
6
|
-
|
|
7
|
-
export const reactComponent: ComponentTemplate = {
|
|
8
|
-
name: 'react',
|
|
9
|
-
description: 'a basic react component',
|
|
10
|
-
|
|
11
|
-
generateFiles: (context: ComponentContext) => {
|
|
12
|
-
const { name, namePascalCase: Name } = context;
|
|
13
|
-
const indexFile = {
|
|
14
|
-
relativePath: 'index.ts',
|
|
15
|
-
content: `export { ${Name} } from './${name}';
|
|
16
|
-
export type { ${Name}Props } from './${name}';
|
|
17
|
-
`,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return [indexFile, componentFile(context), compositionFile(context), docsFile(context), testFile(context)];
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const deprecatedReactComponent: ComponentTemplate = {
|
|
25
|
-
name: 'react-component',
|
|
26
|
-
description: 'a basic react component',
|
|
27
|
-
hidden: true,
|
|
28
|
-
|
|
29
|
-
generateFiles: (context: ComponentContext) => {
|
|
30
|
-
const { name, namePascalCase: Name } = context;
|
|
31
|
-
const indexFile = {
|
|
32
|
-
relativePath: 'index.ts',
|
|
33
|
-
content: `export { ${Name} } from './${name}';
|
|
34
|
-
export type { ${Name}Props } from './${name}';
|
|
35
|
-
`,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return [indexFile, componentFile(context), compositionFile(context), docsFile(context), testFile(context)];
|
|
39
|
-
},
|
|
40
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const componentFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
return {
|
|
6
|
-
relativePath: `${name}.jsx`,
|
|
7
|
-
content: `import React from 'react';
|
|
8
|
-
|
|
9
|
-
export function ${Name}({ text }) {
|
|
10
|
-
return (
|
|
11
|
-
<div>
|
|
12
|
-
{text}
|
|
13
|
-
</div>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
`,
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const compositionFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.composition.jsx`,
|
|
8
|
-
content: `import React from 'react';
|
|
9
|
-
import { ${Name} } from './${name}';
|
|
10
|
-
|
|
11
|
-
export const Basic${Name} = () => (
|
|
12
|
-
<${Name} text="hello from ${Name}" />
|
|
13
|
-
);
|
|
14
|
-
`,
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const docsFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.docs.mdx`,
|
|
8
|
-
content: `---
|
|
9
|
-
description: 'A ${Name} component.'
|
|
10
|
-
labels: ['label1', 'label2', 'label3']
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
import { ${Name} } from './${name}';
|
|
14
|
-
|
|
15
|
-
## React Component for rendering text
|
|
16
|
-
|
|
17
|
-
A basic div that renders some text
|
|
18
|
-
|
|
19
|
-
### Component usage
|
|
20
|
-
\`\`\`js
|
|
21
|
-
<${Name} text="hello from ${Name}" />
|
|
22
|
-
\`\`\`
|
|
23
|
-
|
|
24
|
-
### Using props to customize the text
|
|
25
|
-
|
|
26
|
-
Modify the text to see it change live:
|
|
27
|
-
\`\`\`js live
|
|
28
|
-
<${Name} text="hello from ${Name}" />
|
|
29
|
-
\`\`\`
|
|
30
|
-
`,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const testFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}.spec.jsx`,
|
|
8
|
-
content: `import React from 'react';
|
|
9
|
-
import { render } from '@testing-library/react';
|
|
10
|
-
import { Basic${Name} } from './${name}.composition';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
it('should render with the correct text', () => {
|
|
14
|
-
const { getByText } = render(<Basic${Name} />);
|
|
15
|
-
const rendered = getByText('hello from ${Name}');
|
|
16
|
-
expect(rendered).toBeTruthy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
`,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ComponentTemplate, ComponentContext } from '@teambit/generator';
|
|
2
|
-
import { componentFile } from './files/component';
|
|
3
|
-
import { compositionFile } from './files/composition';
|
|
4
|
-
import { docsFile } from './files/docs';
|
|
5
|
-
import { testFile } from './files/test';
|
|
6
|
-
|
|
7
|
-
export const reactComponentJS: ComponentTemplate = {
|
|
8
|
-
name: 'react-js',
|
|
9
|
-
description: 'a basic react component in js',
|
|
10
|
-
|
|
11
|
-
generateFiles: (context: ComponentContext) => {
|
|
12
|
-
const { name, namePascalCase: Name } = context;
|
|
13
|
-
const indexFile = {
|
|
14
|
-
relativePath: 'index.js',
|
|
15
|
-
content: `export { ${Name} } from './${name}';
|
|
16
|
-
`,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return [indexFile, componentFile(context), compositionFile(context), docsFile(context), testFile(context)];
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const deprecatedReactComponentJS: ComponentTemplate = {
|
|
24
|
-
name: 'react-component-js',
|
|
25
|
-
description: 'a basic react component in js',
|
|
26
|
-
hidden: true,
|
|
27
|
-
|
|
28
|
-
generateFiles: (context: ComponentContext) => {
|
|
29
|
-
const { name, namePascalCase: Name } = context;
|
|
30
|
-
const indexFile = {
|
|
31
|
-
relativePath: 'index.js',
|
|
32
|
-
content: `export { ${Name} } from './${name}';
|
|
33
|
-
`,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return [indexFile, componentFile(context), compositionFile(context), docsFile(context), testFile(context)];
|
|
37
|
-
},
|
|
38
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const compositionFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}-context.composition.tsx`,
|
|
8
|
-
content: `import React, { useContext } from 'react';
|
|
9
|
-
import { ${Name}Provider } from './${name}-context-provider';
|
|
10
|
-
import { ${Name}Context } from './${name}-context';
|
|
11
|
-
|
|
12
|
-
export function MockComponent() {
|
|
13
|
-
const theme = useContext(${Name}Context);
|
|
14
|
-
|
|
15
|
-
return <div style={{ color: theme.color }}>this should be {theme.color}</div>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const BasicThemeUsage = () => {
|
|
19
|
-
return (
|
|
20
|
-
<${Name}Provider color="blue">
|
|
21
|
-
<MockComponent />
|
|
22
|
-
</${Name}Provider>
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
`,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const contextProviderFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
return {
|
|
6
|
-
relativePath: `${name}-context-provider.tsx`,
|
|
7
|
-
content: `import React, { ReactNode } from 'react';
|
|
8
|
-
import { ${Name}Context } from './${name}-context';
|
|
9
|
-
|
|
10
|
-
export type ${Name}ProviderProps = {
|
|
11
|
-
/**
|
|
12
|
-
* primary color of theme.
|
|
13
|
-
*/
|
|
14
|
-
color?: string,
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* children to be rendered within this theme.
|
|
18
|
-
*/
|
|
19
|
-
children: ReactNode
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export function ${Name}Provider({ color, children }: ${Name}ProviderProps) {
|
|
23
|
-
return <${Name}Context.Provider value={{ color }}>{children}</${Name}Context.Provider>
|
|
24
|
-
}
|
|
25
|
-
`,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const contextFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
return {
|
|
6
|
-
relativePath: `${name}-context.tsx`,
|
|
7
|
-
content: `import { createContext } from 'react';
|
|
8
|
-
|
|
9
|
-
export type ${Name}ContextType = {
|
|
10
|
-
/**
|
|
11
|
-
* primary color of theme.
|
|
12
|
-
*/
|
|
13
|
-
color?: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const ${Name}Context = createContext<${Name}ContextType>({
|
|
17
|
-
color: 'aqua'
|
|
18
|
-
});
|
|
19
|
-
`,
|
|
20
|
-
};
|
|
21
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const docsFile = (context: ComponentContext) => {
|
|
4
|
-
const { name, namePascalCase: Name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}-context.docs.mdx`,
|
|
8
|
-
content: `---
|
|
9
|
-
description: ${Name} context.
|
|
10
|
-
labels: ['context']
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
import { ${Name}Context } from './${name}-context';
|
|
14
|
-
import { ${Name}Provider } from './${name}-context-provider';
|
|
15
|
-
import { MockComponent } from './${name}-context.composition';
|
|
16
|
-
|
|
17
|
-
## React Theme Context
|
|
18
|
-
|
|
19
|
-
This is a simple [React Context](https://reactjs.org/docs/context.html) shared as a Bit component.
|
|
20
|
-
Use this component to apply a theme as a context to set on it's children.
|
|
21
|
-
|
|
22
|
-
### Component usage
|
|
23
|
-
|
|
24
|
-
\`\`\`tsx
|
|
25
|
-
() => {
|
|
26
|
-
import React, { useContext } from 'react';
|
|
27
|
-
import { ThemeProvider } from './theme-context-provider';
|
|
28
|
-
import { ThemeContext } from './theme-context';
|
|
29
|
-
|
|
30
|
-
<${Name}Provider color="blue">
|
|
31
|
-
// My lovely children now get a theme!
|
|
32
|
-
<MockComponent />
|
|
33
|
-
</${Name}Provider>;
|
|
34
|
-
\`\`\`
|
|
35
|
-
|
|
36
|
-
### Using props to customize the theme
|
|
37
|
-
|
|
38
|
-
Change the color to see the text change:
|
|
39
|
-
|
|
40
|
-
\`\`\`tsx live
|
|
41
|
-
() => {
|
|
42
|
-
return (
|
|
43
|
-
<${Name}Provider color="red">
|
|
44
|
-
<MockComponent />
|
|
45
|
-
</${Name}Provider>
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
\`\`\`
|
|
49
|
-
`,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export const testFile = (context: ComponentContext) => {
|
|
4
|
-
const { name } = context;
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
relativePath: `${name}-context.spec.tsx`,
|
|
8
|
-
content: `import { BasicThemeUsage } from './${name}-context.composition';
|
|
9
|
-
import { render } from '@testing-library/react';
|
|
10
|
-
|
|
11
|
-
it('should render the button in the color blue', () => {
|
|
12
|
-
const { getByText } = render(<BasicThemeUsage />);
|
|
13
|
-
const rendered = getByText('this should be blue');
|
|
14
|
-
expect(rendered).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
`,
|
|
17
|
-
};
|
|
18
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ComponentTemplate, ComponentContext } from '@teambit/generator';
|
|
2
|
-
import { contextFile } from './files/context';
|
|
3
|
-
import { contextProviderFile } from './files/context-provider';
|
|
4
|
-
import { compositionFile } from './files/composition';
|
|
5
|
-
import { docsFile } from './files/docs';
|
|
6
|
-
import { testFile } from './files/test';
|
|
7
|
-
|
|
8
|
-
export const reactContext: ComponentTemplate = {
|
|
9
|
-
name: 'react-context',
|
|
10
|
-
description: 'a react context component',
|
|
11
|
-
|
|
12
|
-
generateFiles: (context: ComponentContext) => {
|
|
13
|
-
const { name, namePascalCase: Name } = context;
|
|
14
|
-
const indexFile = {
|
|
15
|
-
relativePath: 'index.ts',
|
|
16
|
-
content: `export { ${Name}Context } from './${name}-context';
|
|
17
|
-
export type { ${Name}ContextType } from './${name}-context';
|
|
18
|
-
export { ${Name}Provider } from './${name}-context-provider';
|
|
19
|
-
export type { ${Name}ProviderProps } from './${name}-context-provider';
|
|
20
|
-
`,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return [
|
|
24
|
-
indexFile,
|
|
25
|
-
contextFile(context),
|
|
26
|
-
contextProviderFile(context),
|
|
27
|
-
compositionFile(context),
|
|
28
|
-
docsFile(context),
|
|
29
|
-
testFile(context),
|
|
30
|
-
];
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export function aspectFile({ namePascalCase: Name, componentId }: ComponentContext) {
|
|
4
|
-
return `import { Aspect } from '@teambit/harmony';
|
|
5
|
-
|
|
6
|
-
export const ${Name}Aspect = Aspect.create({
|
|
7
|
-
id: '${componentId}',
|
|
8
|
-
});
|
|
9
|
-
`;
|
|
10
|
-
}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export function docFile({ name, componentId }: ComponentContext) {
|
|
4
|
-
return `---
|
|
5
|
-
description: 'A standard React component development environment'
|
|
6
|
-
labels: ['react', 'typescript', 'env', 'extension']
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
A customized version which extends the default React component development environment created by teambit. This environment can be applied to all your components or a set of components under the variants of your \`workspace.json\` file. That means they will use your custom environment instead of the default environment. Environment components are just like any other Bit components in that they can be exported and then shared and used in various projects which makes it easier to create standards when working with many teams.
|
|
12
|
-
|
|
13
|
-
### Usage instructions
|
|
14
|
-
|
|
15
|
-
Under the **variant** section of your \`workspace.json\` file choose which components you want to have the custom environment set. You can find the id of the extension in the \`${name}.aspect.ts\` file.
|
|
16
|
-
|
|
17
|
-
\`\`\`json
|
|
18
|
-
{
|
|
19
|
-
"teambit.workspace/variants": {
|
|
20
|
-
"{ui/**}, {pages/**}": {
|
|
21
|
-
"${componentId}": {}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
\`\`\`
|
|
26
|
-
|
|
27
|
-
## Runtime Configurations
|
|
28
|
-
|
|
29
|
-
Extend the \`main.runtime\` file when you want to add custom configurations at runtime.
|
|
30
|
-
|
|
31
|
-
### Compilation
|
|
32
|
-
|
|
33
|
-
By default, Component compilation is done with the TypeScript compiler. Target format is \`ES2015\` which
|
|
34
|
-
supports execution from both NodeJS and browser runtimes for server-side rendering. You can modify the \`tsconfig.json\` file to add your own compiler options which will then be merged with the default configs set by teambit.
|
|
35
|
-
|
|
36
|
-
Example:
|
|
37
|
-
|
|
38
|
-
\`\`\`json
|
|
39
|
-
{
|
|
40
|
-
"compilerOptions": {
|
|
41
|
-
"target": "es2017",
|
|
42
|
-
"module": "es2015",
|
|
43
|
-
"moduleResolution": "node",
|
|
44
|
-
"lib": ["es2017", "dom"],
|
|
45
|
-
"experimentalDecorators": true,
|
|
46
|
-
"esModuleInterop": true,
|
|
47
|
-
"outDir": "dist",
|
|
48
|
-
"sourceMap": true,
|
|
49
|
-
"emitDecoratorMetadata": true,
|
|
50
|
-
"allowJs": true,
|
|
51
|
-
"baseUrl": ".",
|
|
52
|
-
"jsx": "react"
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
\`\`\`
|
|
56
|
-
|
|
57
|
-
### Testing
|
|
58
|
-
|
|
59
|
-
Component testing is done through [Jest](https://jestjs.io/) with the default \`teambit.react/react\` environment. You can modify the \`jestconfig.js\` file to add your own configurations which will then be merged with the default configs set by teambit.
|
|
60
|
-
|
|
61
|
-
Example:
|
|
62
|
-
|
|
63
|
-
To Override the Jest config to ignore transpiling from specific folders add this to the \`jestconfig.js\` file:
|
|
64
|
-
|
|
65
|
-
\`\`\`js
|
|
66
|
-
const reactJestConfig = require('@teambit/react/jest/jest.config');
|
|
67
|
-
module.exports = {
|
|
68
|
-
...reactJestConfig,
|
|
69
|
-
transformIgnorePatterns: ['/node_modules/(?!(prop-types|@teambit))']
|
|
70
|
-
};
|
|
71
|
-
\`\`\`
|
|
72
|
-
|
|
73
|
-
### Webpack
|
|
74
|
-
|
|
75
|
-
Bit uses webpack 5 to bundle components. You can modify the \`webpack.config.js\` file to add your own configurations which will then be merged with the default configs set by teambit.
|
|
76
|
-
|
|
77
|
-
Example:
|
|
78
|
-
|
|
79
|
-
\`\`\`ts
|
|
80
|
-
module.exports = {
|
|
81
|
-
module: {
|
|
82
|
-
// add your custom rules here
|
|
83
|
-
rules: []
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
\`\`\`
|
|
87
|
-
|
|
88
|
-
### ESLint
|
|
89
|
-
|
|
90
|
-
Bit uses ESLint to lint your components. You can add your own rules in the \`${name}.main.runtime\` file.
|
|
91
|
-
|
|
92
|
-
Example:
|
|
93
|
-
|
|
94
|
-
\`\`\`ts
|
|
95
|
-
react.useEslint({
|
|
96
|
-
transformers: [
|
|
97
|
-
(config) => {
|
|
98
|
-
config.setRule('no-console', ['error']);
|
|
99
|
-
// add more rules here
|
|
100
|
-
return config;
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
}),
|
|
104
|
-
\`\`\`
|
|
105
|
-
|
|
106
|
-
To use ESLint:
|
|
107
|
-
|
|
108
|
-
\`\`\`bash
|
|
109
|
-
bit lint
|
|
110
|
-
bit lint --fix
|
|
111
|
-
\`\`\`
|
|
112
|
-
|
|
113
|
-
### Formatting
|
|
114
|
-
|
|
115
|
-
Bit uses Prettier to format your components. You can add your own rules in the \`${name}.main.runtime\` file.
|
|
116
|
-
|
|
117
|
-
Example:
|
|
118
|
-
|
|
119
|
-
\`\`\`ts
|
|
120
|
-
react.usePrettier({
|
|
121
|
-
transformers: [
|
|
122
|
-
(config) => {
|
|
123
|
-
config.setKey('tabWidth', 2);
|
|
124
|
-
// add more rules here
|
|
125
|
-
return config;
|
|
126
|
-
}
|
|
127
|
-
]
|
|
128
|
-
}),
|
|
129
|
-
\`\`\`
|
|
130
|
-
|
|
131
|
-
To use Prettier:
|
|
132
|
-
|
|
133
|
-
\`\`\`bash
|
|
134
|
-
bit format --check
|
|
135
|
-
bit format
|
|
136
|
-
\`\`\`
|
|
137
|
-
|
|
138
|
-
### Dependencies
|
|
139
|
-
|
|
140
|
-
Override the default dependencies in the \`${name}.main.runtime\` file to include react types of a different version for example.
|
|
141
|
-
|
|
142
|
-
\`\`\`ts
|
|
143
|
-
react.overrideDependencies({
|
|
144
|
-
devDependencies: {
|
|
145
|
-
'@types/react': '17.0.3'
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
\`\`\`
|
|
149
|
-
|
|
150
|
-
## Preview Configurations
|
|
151
|
-
|
|
152
|
-
Extend the \`${name}.preview.runtime\` file when you want to add your own customizations only for previewing in the Bit UI.
|
|
153
|
-
|
|
154
|
-
### Adding a Theme
|
|
155
|
-
|
|
156
|
-
A custom theme has been added to the env which wraps all the composition files with the required theme so they can be developed with the correct themeing rather than the browsers default. This is added only in the preview runtime and not in the main runtime meaning it is only applied to compositions and not when consuming components. Adding a theme when consuming should be done at App level as you component may be consumed in various apps and have different themes applied depending on where it is consumed.
|
|
157
|
-
|
|
158
|
-
Example:
|
|
159
|
-
|
|
160
|
-
\`\`\`ts
|
|
161
|
-
react.registerProvider([ThemeCompositions]);
|
|
162
|
-
`;
|
|
163
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ComponentContext } from '@teambit/generator';
|
|
2
|
-
|
|
3
|
-
export function indexFile({ namePascalCase: Name, name }: ComponentContext) {
|
|
4
|
-
return `import { ${Name}Aspect } from './${name}.aspect';
|
|
5
|
-
|
|
6
|
-
export type { ${Name}Main } from './${name}.main.runtime';
|
|
7
|
-
export default ${Name}Aspect;
|
|
8
|
-
export { ${Name}Aspect };
|
|
9
|
-
`;
|
|
10
|
-
}
|