@teambit/react 0.0.566 → 0.0.570

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.
Files changed (75) hide show
  1. package/compositions-app.tsx +31 -0
  2. package/dist/react.env.d.ts +0 -2
  3. package/dist/react.env.js +1 -38
  4. package/dist/react.env.js.map +1 -1
  5. package/dist/webpack/webpack.config.component.dev.d.ts +1 -1
  6. package/dist/webpack/webpack.config.component.dev.js +9 -13
  7. package/dist/webpack/webpack.config.component.dev.js.map +1 -1
  8. package/highlighter-widget.tsx +19 -0
  9. package/mount.tsx +17 -0
  10. package/package-tar/teambit-react-0.0.570.tgz +0 -0
  11. package/package.json +46 -61
  12. package/react.composition.tsx +7 -0
  13. package/react.ui.runtime.tsx +35 -0
  14. package/templates/react-app/files/app-root.ts +10 -0
  15. package/templates/react-app/files/app.ts +30 -0
  16. package/templates/react-app/files/aspect.ts +10 -0
  17. package/templates/react-app/files/compositions.ts +11 -0
  18. package/templates/react-app/files/doc.ts +29 -0
  19. package/templates/react-app/files/index.ts +10 -0
  20. package/templates/react-app/files/main.runtime.ts +22 -0
  21. package/templates/react-app/index.ts +47 -0
  22. package/templates/react-component/files/component.ts +25 -0
  23. package/templates/react-component/files/composition.ts +16 -0
  24. package/templates/react-component/files/docs.ts +32 -0
  25. package/templates/react-component/files/test.ts +19 -0
  26. package/templates/react-component/index.ts +40 -0
  27. package/templates/react-component-js/files/component.ts +18 -0
  28. package/templates/react-component-js/files/composition.ts +16 -0
  29. package/templates/react-component-js/files/docs.ts +32 -0
  30. package/templates/react-component-js/files/test.ts +21 -0
  31. package/templates/react-component-js/index.ts +38 -0
  32. package/templates/react-context/files/composition.ts +27 -0
  33. package/templates/react-context/files/context-provider.ts +27 -0
  34. package/templates/react-context/files/context.ts +21 -0
  35. package/templates/react-context/files/docs.ts +51 -0
  36. package/templates/react-context/files/test.ts +18 -0
  37. package/templates/react-context/index.ts +32 -0
  38. package/templates/react-env/files/aspect.ts +10 -0
  39. package/templates/react-env/files/doc.ts +163 -0
  40. package/templates/react-env/files/index.ts +10 -0
  41. package/templates/react-env/files/jest.config.ts +21 -0
  42. package/templates/react-env/files/main.runtime.ts +84 -0
  43. package/templates/react-env/files/preview.runtime.ts +27 -0
  44. package/templates/react-env/files/typescript.config.ts +21 -0
  45. package/templates/react-env/files/webpack.config.ts +48 -0
  46. package/templates/react-env/index.ts +51 -0
  47. package/templates/react-hook/files/component.ts +16 -0
  48. package/templates/react-hook/files/composition.ts +23 -0
  49. package/templates/react-hook/files/docs.ts +33 -0
  50. package/templates/react-hook/files/test.ts +20 -0
  51. package/templates/react-hook/index.ts +21 -0
  52. package/templates/react-workspace/index.ts +27 -0
  53. package/templates/react-workspace-app/index.ts +20 -0
  54. package/templates/react-workspace-deprecated/index.ts +28 -0
  55. package/templates/react-workspace-lib/index.ts +21 -0
  56. package/templates/workspace-common/files/eslint-config.ts +6 -0
  57. package/templates/workspace-common/files/git-ignore.ts +113 -0
  58. package/templates/workspace-common/files/prettier-config.ts +5 -0
  59. package/templates/workspace-common/files/readme-file.ts +36 -0
  60. package/templates/workspace-common/files/ts-config.ts +7 -0
  61. package/templates/workspace-common/files/types/asset.ts +28 -0
  62. package/templates/workspace-common/files/types/style.ts +43 -0
  63. package/templates/workspace-common/files/workspace-config.ts +58 -0
  64. package/templates/workspace-common/generate-files.ts +51 -0
  65. package/templates/workspace-common/index.ts +1 -0
  66. package/types/asset.d.ts +29 -0
  67. package/types/style.d.ts +42 -0
  68. package/typescript/asset.d.ts +29 -0
  69. package/typescript/style.d.ts +42 -0
  70. package/webpack/postcss.config.ts +21 -0
  71. package/webpack/webpack.config.base.prod.ts +123 -0
  72. package/webpack/webpack.config.base.ts +365 -0
  73. package/webpack/webpack.config.component.dev.ts +99 -0
  74. package/webpack/webpack.config.component.prod.ts +39 -0
  75. package/webpack/webpack.config.env.dev.ts +21 -0
@@ -0,0 +1,29 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function docFile({ name }: ComponentContext) {
4
+ return `---
5
+ description: Application.
6
+ labels: ['env', 'app']
7
+ ---
8
+
9
+ ## Application component
10
+
11
+ - The app file contains components from react router dom so you can add here all routes for your app and include all your page components.
12
+ - The main runtime file contains what is needed to build your application as a React app.
13
+ - The app root file renders your app to the DOM.
14
+ - The compositions file renders your app so it can be seen in the compositions tab.
15
+ - The aspect file contains the id of the aspect. You will need to modify this with your own org name, scope name and namespace if any, and then add it to your \`workspace.json\` file at root level like:
16
+
17
+ \`\`\`json
18
+ "org-name.scope-name/namespace/name": {},
19
+ \`\`\`
20
+
21
+ ### Run the application
22
+
23
+ You can run your application on a separate port to see it outside of the Bit workspace
24
+
25
+ \`\`\`bash
26
+ bit run ${name}
27
+ \`\`\`
28
+ `;
29
+ }
@@ -0,0 +1,10 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function indexFile({ name, namePascalCase: 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
+ }
@@ -0,0 +1,22 @@
1
+ import { ComponentContext } from '@teambit/generator';
2
+
3
+ export function mainRuntimeFile({ name, namePascalCase: Name }: ComponentContext) {
4
+ return `import { MainRuntime } from '@teambit/cli';
5
+ import { ReactAspect, ReactMain } from '@teambit/react';
6
+ import { ${Name}Aspect } from './${name}.aspect';
7
+
8
+ export class ${Name}Main {
9
+ static slots = [];
10
+ static dependencies = [ReactAspect];
11
+ static runtime = MainRuntime;
12
+ static async provider([react]: [ReactMain]) {
13
+ react.registerReactApp({
14
+ name: '${name}',
15
+ entry: ['dist/${name}.app-root']
16
+ });
17
+ return new ${Name}Main();
18
+ }
19
+ }
20
+ ${Name}Aspect.addRuntime(${Name}Main);
21
+ `;
22
+ }
@@ -0,0 +1,47 @@
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
+ };
@@ -0,0 +1,25 @@
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
+ };
@@ -0,0 +1,16 @@
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
+ };
@@ -0,0 +1,32 @@
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
+ };
@@ -0,0 +1,19 @@
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
+ };
@@ -0,0 +1,40 @@
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
+ };
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,16 @@
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
+ };
@@ -0,0 +1,32 @@
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
+ };
@@ -0,0 +1,21 @@
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
+ };
@@ -0,0 +1,38 @@
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
+ };
@@ -0,0 +1,27 @@
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
+ };
@@ -0,0 +1,27 @@
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
+ };
@@ -0,0 +1,21 @@
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
+ };
@@ -0,0 +1,51 @@
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
+ };
@@ -0,0 +1,18 @@
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
+ };
@@ -0,0 +1,32 @@
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
+ };
@@ -0,0 +1,10 @@
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
+ }