CLI React prototypes
This package can be used for React projects.
Package name |
|
Repository link |
|
Latest version |
|
Changelog link |
Prototypes in the package
For more details, click the prototype name.
Example usage
To see how to set and use the @magnolia/cli-react-prototypes
, you can jumpstart a project based on the headless/react-demo/ce
template.
-
Jumpstart a new project based on the template.
npx @magnolia/cli jumpstart -t "headless/react-demo/ce"
The command downloads and creates a new project.
The
mgnl.config.js
file created:import CreatePagePlugin from "@magnolia/cli-create-page-plugin"; import CreateComponentPlugin from "@magnolia/cli-create-component-plugin"; ... export default { ... plugins: [ new CreatePagePlugin({ pagesSpaPath: './spa/react-minimal/src/pages', framework: '@magnolia/cli-react-prototypes@1', (1) prototype: 'basic' (2) }), new CreateComponentPlugin({ componentsSpaPath: './spa/react-minimal/src/components', framework: '@magnolia/cli-react-prototypes@1', (1) prototype: 'basic' (2) }), ... ], type: "js", lightModulesPath: "./magnolia/light-modules", lightModule: "react-minimal-lm", componentMappingFilePath: "./spa/react-minimal/src/magnolia.config.js" };
1 The framework prototypes package 2 The prototype available in the framework prototypes package chosen. -
Create a new page.
npm run mgnl -- create-page main
-
Files created:
-
/<project-path>/magnolia/light-modules/react-minimal-lm/dialogs/pages/main.yaml
Click to expand or collapse
label: Page Properties form: properties: title: label: Title $type: textField i18n: true
-
/<project-path>/magnolia/light-modules/react-minimal-lm/templates/pages/main.yaml
Click to expand or collapse
renderType: spa class: info.magnolia.rendering.spa.renderer.SpaRenderableDefinition title: main dialog: react-minimal-lm:pages/main baseUrl: http://localhost:3000 routeTemplate: '/{language}{{@path}}' # templateScript: /react-minimal-lm/webresources/build/index.html areas: main: title: Main Area extras: title: Extras Area
-
/<project-path>/spa/react-minimal/src/pages/main.js
Click to expand or collapse
import React from 'react'; import { EditableArea } from '@magnolia/react-editor'; const main = props => { const { main, extras, title } = props; return ( <div className="main"> <div>[Basic Page]</div> <h1>{title || props.metadata['@name']}</h1> <main> <div>[Main Area]</div> {main && <EditableArea className="Area" content={main} />} </main> <div> <div>[Secondary Area]</div> {extras && <EditableArea className="Area" content={extras} />} </div> </div> ) }; export default main;
-
-
The modified file with the
componentMapping
object:-
/<project-path>/spa/react-minimal/src/magnolia.config.js
Click to expand or collapse
import mainPage from './pages/main.js' const config = { 'componentMappings':{ ... "react-minimal-lm:pages/main": mainPage } }; export default config;
-
-
Create a new component and make it available in the
main
page created before.npm run mgnl -- create-component hero -a main
-
Files created:
-
/<project-path>/magnolia/light-modules/react-minimal-lm/dialogs/components/hero.yaml
Click to expand or collapse
label: hero form: properties: text: label: hero Text $type: textField i18n: true
-
/<project-path>/magnolia/light-modules/react-minimal-lm/templates/components/hero.yaml
Click to expand or collapse
title: hero dialog: react-minimal-lm:components/hero
-
/<project-path>/spa/react-minimal/src/components/hero.js
Click to expand or collapse
import React from 'react'; const hero = props => <h2>{props.text}</h2>; export default hero;
-
-
The modified
main
page file:-
/<project-path>/magnolia/light-modules/react-minimal-lm/templates/pages/main.yaml
Click to expand or collapse
... areas: main: title: Main Area availableComponents: hero: id: react-minimal-lm:components/hero ...
-
-
The modified file with the
componentMapping
object:-
/<project-path>/spa/react-minimal/src/magnolia.config.js
Click to expand or collapse
import heroComponent from './components/hero.js' ... const config = { 'componentMappings':{ ... "react-minimal-lm:components/hero": heroComponent } }; export default config;
-