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/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 main
-
Files created:
-
/<project-path>/light-modules/spa-lm/dialogs/pages/main.yaml
Click 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.yaml
Click 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.jsx
Click 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
componentMapping
object:-
/<project-path>/spa/src/magnolia.config.js
Click 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
main
page created before.npm run mgnl -- create-component hero -a main
-
Files created:
-
/<project-path>/light-modules/spa-lm/dialogs/components/hero.yaml
Click 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.yaml
Click to expand or collapse
title: hero dialog: spa-lm:components/hero
-
/<project-path>/spa/src/templates/components/hero.jsx
Click 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
main
page file:-
/<project-path>/light-modules/spa-lm/templates/pages/main.yaml
Click to expand or collapse
... areas: main: title: Main Area availableComponents: hero: id: spa-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 './templates/components/hero.jsx' ... const config = { 'componentMappings':{ ... "spa-lm:components/hero": heroComponent } }; export default config;
-