@teambit/react 0.0.568 → 0.0.569
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/compositions-app.tsx +31 -0
- package/highlighter-widget.tsx +19 -0
- package/mount.tsx +17 -0
- package/package-tar/teambit-react-0.0.569.tgz +0 -0
- package/package.json +44 -59
- package/react.composition.tsx +7 -0
- package/react.ui.runtime.tsx +35 -0
- package/templates/react-app/files/app-root.ts +10 -0
- package/templates/react-app/files/app.ts +30 -0
- package/templates/react-app/files/aspect.ts +10 -0
- package/templates/react-app/files/compositions.ts +11 -0
- package/templates/react-app/files/doc.ts +29 -0
- package/templates/react-app/files/index.ts +10 -0
- package/templates/react-app/files/main.runtime.ts +22 -0
- package/templates/react-app/index.ts +47 -0
- package/templates/react-component/files/component.ts +25 -0
- package/templates/react-component/files/composition.ts +16 -0
- package/templates/react-component/files/docs.ts +32 -0
- package/templates/react-component/files/test.ts +19 -0
- package/templates/react-component/index.ts +40 -0
- package/templates/react-component-js/files/component.ts +18 -0
- package/templates/react-component-js/files/composition.ts +16 -0
- package/templates/react-component-js/files/docs.ts +32 -0
- package/templates/react-component-js/files/test.ts +21 -0
- package/templates/react-component-js/index.ts +38 -0
- package/templates/react-context/files/composition.ts +27 -0
- package/templates/react-context/files/context-provider.ts +27 -0
- package/templates/react-context/files/context.ts +21 -0
- package/templates/react-context/files/docs.ts +51 -0
- package/templates/react-context/files/test.ts +18 -0
- package/templates/react-context/index.ts +32 -0
- package/templates/react-env/files/aspect.ts +10 -0
- package/templates/react-env/files/doc.ts +163 -0
- package/templates/react-env/files/index.ts +10 -0
- package/templates/react-env/files/jest.config.ts +21 -0
- package/templates/react-env/files/main.runtime.ts +84 -0
- package/templates/react-env/files/preview.runtime.ts +27 -0
- package/templates/react-env/files/typescript.config.ts +21 -0
- package/templates/react-env/files/webpack.config.ts +48 -0
- package/templates/react-env/index.ts +51 -0
- package/templates/react-hook/files/component.ts +16 -0
- package/templates/react-hook/files/composition.ts +23 -0
- package/templates/react-hook/files/docs.ts +33 -0
- package/templates/react-hook/files/test.ts +20 -0
- package/templates/react-hook/index.ts +21 -0
- package/templates/react-workspace/index.ts +27 -0
- package/templates/react-workspace-app/index.ts +20 -0
- package/templates/react-workspace-deprecated/index.ts +28 -0
- package/templates/react-workspace-lib/index.ts +21 -0
- package/templates/workspace-common/files/eslint-config.ts +6 -0
- package/templates/workspace-common/files/git-ignore.ts +113 -0
- package/templates/workspace-common/files/prettier-config.ts +5 -0
- package/templates/workspace-common/files/readme-file.ts +36 -0
- package/templates/workspace-common/files/ts-config.ts +7 -0
- package/templates/workspace-common/files/types/asset.ts +28 -0
- package/templates/workspace-common/files/types/style.ts +43 -0
- package/templates/workspace-common/files/workspace-config.ts +58 -0
- package/templates/workspace-common/generate-files.ts +51 -0
- package/templates/workspace-common/index.ts +1 -0
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
- package/typescript/asset.d.ts +29 -0
- package/typescript/style.d.ts +42 -0
- package/webpack/postcss.config.ts +21 -0
- package/webpack/webpack.config.base.prod.ts +123 -0
- package/webpack/webpack.config.base.ts +365 -0
- package/webpack/webpack.config.component.dev.ts +99 -0
- package/webpack/webpack.config.component.prod.ts +39 -0
- package/webpack/webpack.config.env.dev.ts +21 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Composer } from '@teambit/base-ui.utils.composer';
|
|
3
|
+
import { StandaloneNotFoundPage } from '@teambit/design.ui.pages.standalone-not-found-page';
|
|
4
|
+
import { RenderingContext } from '@teambit/preview';
|
|
5
|
+
import { ErrorFallback } from '@teambit/react.ui.error-fallback';
|
|
6
|
+
import { LoaderFallback } from '@teambit/react.ui.loader-fallback';
|
|
7
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
8
|
+
import { ReactAspect } from './react.aspect';
|
|
9
|
+
|
|
10
|
+
// hide scrollbars so they won't be visible in the preview at the component card (and it's ok not to show them in the compositions page)
|
|
11
|
+
const hideScrollbars = 'body::-webkit-scrollbar {display: none;}';
|
|
12
|
+
|
|
13
|
+
export function CompositionsApp({
|
|
14
|
+
Composition,
|
|
15
|
+
previewContext,
|
|
16
|
+
}: {
|
|
17
|
+
Composition?: React.ComponentType;
|
|
18
|
+
previewContext: RenderingContext;
|
|
19
|
+
}) {
|
|
20
|
+
const reactContext = previewContext.get(ReactAspect.id);
|
|
21
|
+
const providers = reactContext?.providers || [];
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ErrorBoundary FallbackComponent={ErrorFallback} resetKeys={[Composition]}>
|
|
25
|
+
<Composer components={providers}>
|
|
26
|
+
<style>{hideScrollbars}</style>
|
|
27
|
+
<LoaderFallback Target={Composition} DefaultComponent={StandaloneNotFoundPage} />
|
|
28
|
+
</Composer>
|
|
29
|
+
</ErrorBoundary>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OptionButton } from '@teambit/design.ui.input.option-button';
|
|
3
|
+
import { Tooltip } from '@teambit/design.ui.tooltip';
|
|
4
|
+
import { usePreviewQueryParams } from '@teambit/compositions.ui.hooks.use-composition';
|
|
5
|
+
|
|
6
|
+
const PARAM_NAME = 'highlighter';
|
|
7
|
+
|
|
8
|
+
export function HighlighterWidget() {
|
|
9
|
+
const [active, setActive] = usePreviewQueryParams(PARAM_NAME);
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Tooltip content="Component Highlighter (beta)">
|
|
13
|
+
{/* tooltip requires child with ref */}
|
|
14
|
+
<span>
|
|
15
|
+
<OptionButton icon="highlighter-toggle" onClick={() => setActive(!active)} active={active} />
|
|
16
|
+
</span>
|
|
17
|
+
</Tooltip>
|
|
18
|
+
);
|
|
19
|
+
}
|
package/mount.tsx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { RenderingContext } from '@teambit/preview';
|
|
4
|
+
|
|
5
|
+
import { CompositionsApp } from './compositions-app';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* this mounts compositions into the DOM in the component preview.
|
|
9
|
+
* this function can be overridden through ReactAspect.overrideCompositionsMounter() API
|
|
10
|
+
* to apply custom logic for component DOM mounting.
|
|
11
|
+
*/
|
|
12
|
+
export default (Composition: React.ComponentType, previewContext: RenderingContext) => {
|
|
13
|
+
ReactDOM.render(
|
|
14
|
+
<CompositionsApp Composition={Composition} previewContext={previewContext} />,
|
|
15
|
+
document.getElementById('root')
|
|
16
|
+
);
|
|
17
|
+
};
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.569",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/react/react",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.react",
|
|
8
8
|
"name": "react",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.569"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"react-error-boundary": "^3.0.0",
|
|
@@ -79,47 +79,47 @@
|
|
|
79
79
|
"@teambit/react.instructions.react.adding-compositions": "0.0.6",
|
|
80
80
|
"@teambit/react.instructions.react.adding-tests": "0.0.6",
|
|
81
81
|
"@teambit/design.ui.pages.standalone-not-found-page": "0.0.354",
|
|
82
|
-
"@teambit/preview": "0.0.
|
|
83
|
-
"@teambit/react.ui.error-fallback": "0.0.
|
|
84
|
-
"@teambit/react.ui.loader-fallback": "0.0.
|
|
85
|
-
"@teambit/compositions.ui.hooks.use-composition": "0.0.
|
|
82
|
+
"@teambit/preview": "0.0.569",
|
|
83
|
+
"@teambit/react.ui.error-fallback": "0.0.96",
|
|
84
|
+
"@teambit/react.ui.loader-fallback": "0.0.74",
|
|
85
|
+
"@teambit/compositions.ui.hooks.use-composition": "0.0.149",
|
|
86
86
|
"@teambit/design.ui.input.option-button": "0.0.26",
|
|
87
87
|
"@teambit/design.ui.tooltip": "0.0.352",
|
|
88
|
-
"@teambit/application": "0.0.
|
|
89
|
-
"@teambit/bundler": "0.0.
|
|
90
|
-
"@teambit/builder": "0.0.
|
|
91
|
-
"@teambit/isolator": "0.0.
|
|
92
|
-
"@teambit/toolbox.network.get-port": "0.0.
|
|
93
|
-
"@teambit/compiler": "0.0.
|
|
94
|
-
"@teambit/component.modules.component-url": "0.0.
|
|
95
|
-
"@teambit/component": "0.0.
|
|
96
|
-
"@teambit/envs": "0.0.
|
|
97
|
-
"@teambit/eslint": "0.0.
|
|
98
|
-
"@teambit/formatter": "0.0.
|
|
99
|
-
"@teambit/jest": "0.0.
|
|
100
|
-
"@teambit/linter": "0.0.
|
|
101
|
-
"@teambit/pkg": "0.0.
|
|
102
|
-
"@teambit/prettier": "0.0.
|
|
103
|
-
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.
|
|
104
|
-
"@teambit/schema": "0.0.
|
|
105
|
-
"@teambit/tester": "0.0.
|
|
106
|
-
"@teambit/typescript": "0.0.
|
|
107
|
-
"@teambit/webpack": "0.0.
|
|
108
|
-
"@teambit/workspace": "0.0.
|
|
109
|
-
"@teambit/cli": "0.0.
|
|
110
|
-
"@teambit/dependency-resolver": "0.0.
|
|
111
|
-
"@teambit/generator": "0.0.
|
|
112
|
-
"@teambit/graphql": "0.0.
|
|
113
|
-
"@teambit/react.ui.highlighter-provider": "0.0.
|
|
114
|
-
"@teambit/compositions": "0.0.
|
|
115
|
-
"@teambit/ui": "0.0.
|
|
116
|
-
"@teambit/react.eslint-config-bit-react": "0.0.
|
|
117
|
-
"@teambit/mdx.modules.mdx-loader": "0.0.
|
|
118
|
-
"@teambit/react.babel.bit-react-transformer": "0.0.
|
|
119
|
-
"@teambit/webpack.modules.generate-style-loaders": "0.0.
|
|
120
|
-
"@teambit/webpack.modules.style-regexps": "0.0.
|
|
121
|
-
"@teambit/component-id": "0.0.
|
|
122
|
-
"@teambit/config": "0.0.
|
|
88
|
+
"@teambit/application": "0.0.211",
|
|
89
|
+
"@teambit/bundler": "0.0.569",
|
|
90
|
+
"@teambit/builder": "0.0.569",
|
|
91
|
+
"@teambit/isolator": "0.0.569",
|
|
92
|
+
"@teambit/toolbox.network.get-port": "0.0.99",
|
|
93
|
+
"@teambit/compiler": "0.0.569",
|
|
94
|
+
"@teambit/component.modules.component-url": "0.0.106",
|
|
95
|
+
"@teambit/component": "0.0.569",
|
|
96
|
+
"@teambit/envs": "0.0.569",
|
|
97
|
+
"@teambit/eslint": "0.0.569",
|
|
98
|
+
"@teambit/formatter": "0.0.120",
|
|
99
|
+
"@teambit/jest": "0.0.569",
|
|
100
|
+
"@teambit/linter": "0.0.569",
|
|
101
|
+
"@teambit/pkg": "0.0.569",
|
|
102
|
+
"@teambit/prettier": "0.0.120",
|
|
103
|
+
"@teambit/react.ui.highlighter.component-metadata.bit-component-meta": "0.0.6",
|
|
104
|
+
"@teambit/schema": "0.0.569",
|
|
105
|
+
"@teambit/tester": "0.0.569",
|
|
106
|
+
"@teambit/typescript": "0.0.569",
|
|
107
|
+
"@teambit/webpack": "0.0.569",
|
|
108
|
+
"@teambit/workspace": "0.0.569",
|
|
109
|
+
"@teambit/cli": "0.0.395",
|
|
110
|
+
"@teambit/dependency-resolver": "0.0.569",
|
|
111
|
+
"@teambit/generator": "0.0.569",
|
|
112
|
+
"@teambit/graphql": "0.0.569",
|
|
113
|
+
"@teambit/react.ui.highlighter-provider": "0.0.160",
|
|
114
|
+
"@teambit/compositions": "0.0.569",
|
|
115
|
+
"@teambit/ui": "0.0.569",
|
|
116
|
+
"@teambit/react.eslint-config-bit-react": "0.0.473",
|
|
117
|
+
"@teambit/mdx.modules.mdx-loader": "0.0.473",
|
|
118
|
+
"@teambit/react.babel.bit-react-transformer": "0.0.480",
|
|
119
|
+
"@teambit/webpack.modules.generate-style-loaders": "0.0.89",
|
|
120
|
+
"@teambit/webpack.modules.style-regexps": "0.0.118",
|
|
121
|
+
"@teambit/component-id": "0.0.385",
|
|
122
|
+
"@teambit/config": "0.0.407"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
125
|
"@types/react": "^17.0.8",
|
|
@@ -134,10 +134,10 @@
|
|
|
134
134
|
"@types/mocha": "5.2.7",
|
|
135
135
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
136
136
|
"@types/jest": "^26.0.0",
|
|
137
|
-
"@teambit/react.aspect-docs.react": "0.0.
|
|
137
|
+
"@teambit/react.aspect-docs.react": "0.0.115"
|
|
138
138
|
},
|
|
139
139
|
"peerDependencies": {
|
|
140
|
-
"@teambit/legacy": "1.0.
|
|
140
|
+
"@teambit/legacy": "1.0.181",
|
|
141
141
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
142
142
|
"react": "^16.8.0 || ^17.0.0"
|
|
143
143
|
},
|
|
@@ -199,27 +199,12 @@
|
|
|
199
199
|
"@types/jest": "^26.0.0"
|
|
200
200
|
},
|
|
201
201
|
"peerDependencies": {
|
|
202
|
-
"@teambit/legacy": "1.0.
|
|
202
|
+
"@teambit/legacy": "1.0.181",
|
|
203
203
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
204
204
|
"react": "^16.8.0 || ^17.0.0"
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
},
|
|
208
|
-
"files": [
|
|
209
|
-
"dist",
|
|
210
|
-
"!dist/tsconfig.tsbuildinfo",
|
|
211
|
-
"**/*.md",
|
|
212
|
-
"**/*.mdx",
|
|
213
|
-
"**/*.js",
|
|
214
|
-
"**/*.json",
|
|
215
|
-
"**/*.sass",
|
|
216
|
-
"**/*.scss",
|
|
217
|
-
"**/*.less",
|
|
218
|
-
"**/*.css",
|
|
219
|
-
"**/*.css",
|
|
220
|
-
"**/*.jpeg",
|
|
221
|
-
"**/*.gif"
|
|
222
|
-
],
|
|
223
208
|
"private": false,
|
|
224
209
|
"engines": {
|
|
225
210
|
"node": ">=12.22.0"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CompositionsAspect, CompositionsUI } from '@teambit/compositions';
|
|
3
|
+
import { UIRuntime } from '@teambit/ui';
|
|
4
|
+
import { TesterAspect, TesterUI } from '@teambit/tester';
|
|
5
|
+
import { AddingTests } from '@teambit/react.instructions.react.adding-tests';
|
|
6
|
+
import { AddingCompositions } from '@teambit/react.instructions.react.adding-compositions';
|
|
7
|
+
import { ReactAspect } from './react.aspect';
|
|
8
|
+
import { HighlighterWidget } from './highlighter-widget';
|
|
9
|
+
|
|
10
|
+
export class ReactUI {
|
|
11
|
+
static runtime = UIRuntime;
|
|
12
|
+
static slots = [];
|
|
13
|
+
static dependencies = [CompositionsAspect, TesterAspect];
|
|
14
|
+
|
|
15
|
+
static async provider([compositionsUI, testerUi]: [CompositionsUI, TesterUI]) {
|
|
16
|
+
const reactUI = new ReactUI();
|
|
17
|
+
testerUi.registerEmptyState(() => {
|
|
18
|
+
return <AddingTests />;
|
|
19
|
+
});
|
|
20
|
+
compositionsUI.registerEmptyState(() => {
|
|
21
|
+
return <AddingCompositions />;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
compositionsUI.registerMenuWidget({
|
|
25
|
+
location: 'start',
|
|
26
|
+
content: <HighlighterWidget />,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return reactUI;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ReactAspect.addRuntime(ReactUI);
|
|
34
|
+
|
|
35
|
+
export default ReactUI;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function appRootFile({ namePascalCase: Name }: ComponentContext) {
|
|
4
|
+
return `import React from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import { ${Name}App } from './app';
|
|
7
|
+
|
|
8
|
+
ReactDOM.render(<${Name}App />, document.getElementById('root'));
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function appFile({ namePascalCase: Name }: ComponentContext) {
|
|
4
|
+
return `import React from 'react';
|
|
5
|
+
import { BrowserRouter, Switch, Route } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
export function ${Name}App() {
|
|
8
|
+
return (
|
|
9
|
+
<BrowserRouter>
|
|
10
|
+
|
|
11
|
+
{/* header component */}
|
|
12
|
+
|
|
13
|
+
<Switch>
|
|
14
|
+
<Route path="/">
|
|
15
|
+
{/* home page component */}
|
|
16
|
+
</Route>
|
|
17
|
+
|
|
18
|
+
<Route path="/about">
|
|
19
|
+
{/* about page component */}
|
|
20
|
+
</Route>
|
|
21
|
+
|
|
22
|
+
</Switch>
|
|
23
|
+
|
|
24
|
+
{/* footer component */}
|
|
25
|
+
|
|
26
|
+
</BrowserRouter>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function aspectFile({ name, namePascalCase: Name }: ComponentContext) {
|
|
4
|
+
return `import { Aspect } from '@teambit/harmony';
|
|
5
|
+
|
|
6
|
+
export const ${Name}Aspect = Aspect.create({
|
|
7
|
+
id: 'YourOrgName.YourScopeName/namespace?/${name}'
|
|
8
|
+
});
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentContext } from '@teambit/generator';
|
|
2
|
+
|
|
3
|
+
export function compositionsFile({ namePascalCase: Name }: ComponentContext) {
|
|
4
|
+
return `import React from 'react';
|
|
5
|
+
import { ${Name}App } from './app';
|
|
6
|
+
|
|
7
|
+
export const ${Name}Basic = () => {
|
|
8
|
+
return <${Name}App></${Name}App>;
|
|
9
|
+
};
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
@@ -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
|
+
};
|