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-starter/ce template.
- 
Jumpstart a new project based on the template. npx @magnolia/cli@latest jumpstart -t "headless/react-starter/ce"The command downloads and creates a new project. The mgnl.config.jsfile created:import CreatePagePlugin from "@magnolia/cli-create-page-plugin"; import CreateComponentPlugin from "@magnolia/cli-create-component-plugin"; ... export default { ... plugins: [ new CreatePagePlugin({ pagesSpaPath: './spa/src/templates/pages', framework: '@magnolia/cli-react-prototypes', (1) prototype: 'mhd', (2) templateData: { port: '8181' } }), new CreateComponentPlugin({ componentsSpaPath: './spa/src/templates/components', framework: '@magnolia/cli-react-prototypes', (1) prototype: 'mhd' (2) }), ... ], type: "jsx", lightModulesPath: "./light-modules", lightModule: "spa-lm", componentMappingFilePath: "./spa/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 mainWindows users using PowerShell must enclose the two consecutive hyphens ( --) in quotes:npm run mgnl "--" ...
- 
Files created: - 
/<project-path>/light-modules/spa-lm/dialogs/pages/main.yamlClick to expand or collapse label: Page Properties form: properties: title: label: Title $type: textField i18n: true
- 
/<project-path>/light-modules/spa-lm/templates/pages/main.yamlClick to expand or collapse renderType: spa class: info.magnolia.rendering.spa.renderer.SpaRenderableDefinition title: main dialog: spa-lm:pages/main baseUrl: http://localhost:8181 routeTemplate: '/{language}{{@path}}' areas: main: title: Main Area extras: title: Extras Area
- 
/<project-path>/spa/src/templates/pages/main.jsxClick to expand or collapse import PropTypes from 'prop-types'; import { EditableArea } from '@magnolia/react-editor'; const main = ({ main, extras, title, metadata }) => { return ( <div className='main'> <div>[Basic Page]</div> <h1>{title || 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> ); }; main.propTypes = { main: PropTypes.object, extras: PropTypes.object, title: PropTypes.string, metadata: PropTypes.object, }; export default main;
 
- 
- 
The modified file with the componentMappingobject:- 
/<project-path>/spa/src/magnolia.config.jsClick to expand or collapse import mainPage from './templates/pages/main.jsx' const config = { 'componentMappings':{ ... "spa-lm:pages/main": mainPage } }; export default config;
 
- 
- 
Create a new component and make it available in the mainpage created before.npm run mgnl -- create-component hero -a mainWindows users using PowerShell must enclose the two consecutive hyphens ( --) in quotes:npm run mgnl "--" ...
- 
Files created: - 
/<project-path>/light-modules/spa-lm/dialogs/components/hero.yamlClick to expand or collapse label: hero form: properties: text: label: hero Text $type: textField i18n: true
- 
/<project-path>/light-modules/spa-lm/templates/components/hero.yamlClick to expand or collapse title: hero dialog: spa-lm:components/hero
- 
/<project-path>/spa/src/templates/components/hero.jsxClick to expand or collapse import PropTypes from 'prop-types'; const hero = ({ text }) => { return <h2>{text}</h2>; }; hero.propTypes = { text: PropTypes.string, }; export default hero;
 
- 
- 
The modified mainpage file:- 
/<project-path>/light-modules/spa-lm/templates/pages/main.yamlClick to expand or collapse ... areas: main: title: Main Area availableComponents: hero: id: spa-lm:components/hero ...
 
- 
- 
The modified file with the componentMappingobject:- 
/<project-path>/spa/react-minimal/src/magnolia.config.jsClick to expand or collapse import heroComponent from './templates/components/hero.jsx' ... const config = { 'componentMappings':{ ... "spa-lm:components/hero": heroComponent } }; export default config;
 
-