zmp-cli 3.8.3 → 3.9.1

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 (88) hide show
  1. package/create/templates/app-parameters.js +4 -2
  2. package/create/templates/copy-assets.js +0 -4
  3. package/create/templates/generate-recoil.js +56 -0
  4. package/create/templates/generate-store.js +2 -4
  5. package/create/templates/generate-styles.js +1 -10
  6. package/create/templates/react/components/user-card.jsx +3 -3
  7. package/create/templates/react/copy-assets.js +38 -22
  8. package/create/templates/react/generate-home-page.js +10 -15
  9. package/create/templates/react/generate-root.js +22 -32
  10. package/create/templates/react/generate-scripts.js +6 -14
  11. package/create/templates/react/pages/404.js +27 -0
  12. package/create/templates/react/pages/about.js +52 -0
  13. package/create/templates/react/pages/catalog.js +112 -0
  14. package/create/templates/react/pages/dynamic-route.js +80 -0
  15. package/create/templates/react/pages/form.js +152 -0
  16. package/create/templates/react/pages/index copy.js +17 -0
  17. package/create/templates/react/pages/index.js +17 -0
  18. package/create/templates/react/pages/settings.js +76 -0
  19. package/create/templates/react/pages/user.js +56 -0
  20. package/create/templates/react-typescript/_tsconfig.json +0 -1
  21. package/create/templates/react-typescript/components/app-items.js +1 -1
  22. package/create/templates/react-typescript/components/user-card.js +6 -12
  23. package/create/templates/react-typescript/copy-assets.js +17 -9
  24. package/create/templates/react-typescript/generate-home-page.js +9 -12
  25. package/create/templates/react-typescript/generate-root.js +41 -53
  26. package/create/templates/react-typescript/generate-scripts.js +6 -14
  27. package/create/templates/react-typescript/pages/about.js +2 -9
  28. package/create/templates/react-typescript/pages/catalog.js +52 -0
  29. package/create/templates/react-typescript/pages/form.js +81 -13
  30. package/create/templates/react-typescript/pages/settings.js +37 -0
  31. package/create/templates/react-typescript/pages/user.js +16 -11
  32. package/create/templates/vue/generate-scripts.js +5 -1
  33. package/create/utils/generate-package-json.js +11 -2
  34. package/create/utils/get-options.js +21 -1
  35. package/package.json +1 -1
  36. package/build/dist/index.dev.js +0 -185
  37. package/config/dist/index.dev.js +0 -52
  38. package/create/dist/index.dev.js +0 -300
  39. package/create/templates/common/tailwind/styles.css +0 -0
  40. package/create/templates/core/dist/copy-assets.dev.js +0 -85
  41. package/create/templates/core/dist/generate-home-page.dev.js +0 -24
  42. package/create/templates/core/dist/generate-routes.dev.js +0 -43
  43. package/create/templates/core/dist/generate-scripts.dev.js +0 -40
  44. package/create/templates/dist/app-parameters.dev.js +0 -21
  45. package/create/templates/dist/copy-assets.dev.js +0 -113
  46. package/create/templates/dist/create-folders.dev.js +0 -25
  47. package/create/templates/dist/generate-routes.dev.js +0 -15
  48. package/create/templates/dist/generate-zmp-custom.dev.js +0 -46
  49. package/create/templates/react/dist/copy-assets.dev.js +0 -64
  50. package/create/templates/react/dist/generate-home-page.dev.js +0 -23
  51. package/create/templates/react/dist/generate-root.dev.js +0 -33
  52. package/create/templates/react/dist/generate-routes.dev.js +0 -20
  53. package/create/templates/react/dist/generate-scripts.dev.js +0 -22
  54. package/create/templates/react/pages/404.jsx +0 -17
  55. package/create/templates/react/pages/about.jsx +0 -42
  56. package/create/templates/react/pages/catalog.jsx +0 -39
  57. package/create/templates/react/pages/dynamic-route.jsx +0 -70
  58. package/create/templates/react/pages/form-tabs.jsx +0 -64
  59. package/create/templates/react/pages/form.jsx +0 -61
  60. package/create/templates/react/pages/left-page-1.jsx +0 -17
  61. package/create/templates/react/pages/left-page-2.jsx +0 -16
  62. package/create/templates/react/pages/product.jsx +0 -25
  63. package/create/templates/react/pages/settings.jsx +0 -28
  64. package/create/templates/react/pages/user-tabs.jsx +0 -31
  65. package/create/templates/react/pages/user.jsx +0 -28
  66. package/create/templates/svelte/dist/copy-assets.dev.js +0 -55
  67. package/create/templates/svelte/dist/generate-home-page.dev.js +0 -23
  68. package/create/templates/svelte/dist/generate-root.dev.js +0 -35
  69. package/create/templates/svelte/dist/generate-routes.dev.js +0 -25
  70. package/create/templates/svelte/dist/generate-scripts.dev.js +0 -22
  71. package/create/templates/vue/dist/copy-assets.dev.js +0 -55
  72. package/create/templates/vue/dist/generate-home-page.dev.js +0 -23
  73. package/create/templates/vue/dist/generate-root.dev.js +0 -35
  74. package/create/templates/vue/dist/generate-routes.dev.js +0 -27
  75. package/create/templates/vue/dist/generate-scripts.dev.js +0 -22
  76. package/create/utils/dist/generate-app-config.dev.js +0 -29
  77. package/create/utils/dist/generate-gitignore.dev.js +0 -7
  78. package/create/utils/dist/generate-package-json.dev.js +0 -72
  79. package/deploy/dist/index.dev.js +0 -196
  80. package/deploy/utils/dist/upload-app.dev.js +0 -113
  81. package/dist/index.dev.js +0 -355
  82. package/login/dist/index.dev.js +0 -236
  83. package/login/utils/dist/get-options.dev.js +0 -66
  84. package/scripts/dist/release.dev.js +0 -105
  85. package/start/dist/index.dev.js +0 -247
  86. package/ui/dist/server.dev.js +0 -208
  87. package/utils/dist/constants.dev.js +0 -10
  88. package/utils/dist/error.dev.js +0 -18
@@ -2,15 +2,17 @@ const indent = require('../utils/indent');
2
2
  const templateIf = require('../utils/template-if');
3
3
 
4
4
  module.exports = (options) => {
5
- const { framework, pkg, name, bundler } = options;
5
+ const { framework, pkg, name, bundler, stateManagement } = options;
6
6
 
7
7
  return indent(
8
8
  0,
9
9
  `
10
10
  name: '${name}', // App name
11
11
  theme: 'auto', // Automatic theme detection
12
+ ${templateIf(stateManagement === 'store', () => `
12
13
  // App store
13
14
  store: store,
15
+ `)}
14
16
  ${templateIf(framework === 'core', () => `el: '#app', // App root element`)}
15
17
  ${templateIf(
16
18
  framework === 'core' && bundler,
@@ -26,6 +28,6 @@ module.exports = (options) => {
26
28
  },
27
29
  `
28
30
  )}
29
- `
31
+ `
30
32
  ).trim();
31
33
  };
@@ -43,10 +43,6 @@ module.exports = (options, iconFile) => {
43
43
  from: path.resolve(__dirname, 'common', 'tailwind', 'tailwind.css'),
44
44
  to: path.resolve(cwd, srcFolder, 'css', 'tailwind.css'),
45
45
  },
46
- {
47
- from: path.resolve(__dirname, 'common', 'tailwind', 'styles.css'),
48
- to: path.resolve(cwd, srcFolder, 'css', 'styles.css'),
49
- },
50
46
  {
51
47
  from: path.resolve(
52
48
  __dirname,
@@ -0,0 +1,56 @@
1
+ const indent = require('../utils/indent');
2
+ const templateIf = require('../utils/template-if');
3
+
4
+ module.exports = (options) => {
5
+ const { framework, template } = options;
6
+
7
+ const productState = `
8
+
9
+ export const productsState = atom({
10
+ key: "products",
11
+ default: [
12
+ {
13
+ id: '1',
14
+ title: 'Apple iPhone 8',
15
+ description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi tempora similique reiciendis, error nesciunt vero, blanditiis pariatur dolor, minima sed sapiente rerum, dolorem corrupti hic modi praesentium unde saepe perspiciatis.'
16
+ },
17
+ {
18
+ id: '2',
19
+ title: 'Apple iPhone 8 Plus',
20
+ description: 'Velit odit autem modi saepe ratione totam minus, aperiam, labore quia provident temporibus quasi est ut aliquid blanditiis beatae suscipit odio vel! Nostrum porro sunt sint eveniet maiores, dolorem itaque!'
21
+ },
22
+ {
23
+ id: '3',
24
+ title: 'Apple iPhone X',
25
+ description: 'Expedita sequi perferendis quod illum pariatur aliquam, alias laboriosam! Vero blanditiis placeat, mollitia necessitatibus reprehenderit. Labore dolores amet quos, accusamus earum asperiores officiis assumenda optio architecto quia neque, quae eum.'
26
+ },
27
+ ]
28
+ });`;
29
+
30
+ if (framework === 'react-typescript') {
31
+ return `
32
+ import { atom } from "recoil";
33
+ import { userInfo } from 'zmp-sdk';
34
+
35
+ export const userState = atom<userInfo>({
36
+ key: "user",
37
+ default: {
38
+ id: '12345678',
39
+ name: 'Zalo',
40
+ avatar: 'ZA',
41
+ }
42
+ })
43
+ ${templateIf(template === 'tabs', () => productState)}`;
44
+ }
45
+ return `import { atom } from "recoil";
46
+
47
+ export const userState = atom({
48
+ key: "user",
49
+ default: {
50
+ id: '12345678',
51
+ name: 'Zalo',
52
+ avatar: 'ZA',
53
+ }
54
+ })
55
+ ${templateIf(template === 'tabs', () => productState)}`;
56
+ };
@@ -42,11 +42,9 @@ module.exports = (options) => {
42
42
  const store = createStore({
43
43
  state: {
44
44
  user: {
45
- displayName: 'Zalo',
46
- email: 'zte@zalo.me',
45
+ id: '12345678',
46
+ name: 'Zalo',
47
47
  avatar: 'ZA',
48
- online: true,
49
- story: true
50
48
  },
51
49
  products: [
52
50
  {
@@ -2,7 +2,7 @@ const indent = require('../utils/indent');
2
2
  const { colorThemeCSSProperties } = require('../utils/colors');
3
3
 
4
4
  module.exports = (options) => {
5
- const { template, theming, includeTailwind } = options;
5
+ const { template, theming } = options;
6
6
  const { customColor, color, fillBars } = theming;
7
7
 
8
8
  let styles = '';
@@ -44,15 +44,6 @@ module.exports = (options) => {
44
44
  );
45
45
  }
46
46
 
47
- if (includeTailwind) {
48
- styles += indent(
49
- 0,
50
- `
51
- @import "./tailwind.css";
52
- `
53
- );
54
- }
55
-
56
47
  if (template === 'split-view') {
57
48
  styles += indent(
58
49
  0,
@@ -4,10 +4,10 @@ import { Avatar, Title } from 'zmp-framework/react';
4
4
  const UserCard = ({ user }) => {
5
5
  return (
6
6
  <div style={{ display: 'flex', width: '100%' }}>
7
- <Avatar story={user.story} online={user.online}>{user.avatar}</Avatar>
7
+ <Avatar story online src={user.avatar.startsWith('http') ? user.avatar : null}>{user.avatar}</Avatar>
8
8
  <div style={{ marginLeft: 16 }}>
9
- <Title style={{ marginBottom: 0 }}>{user.displayName}</Title>
10
- <div>{user.email}</div>
9
+ <Title style={{ marginBottom: 0 }}>{user.name}</Title>
10
+ <div>{user.id}</div>
11
11
  </div>
12
12
  </div>
13
13
  )
@@ -2,36 +2,45 @@ const path = require('path');
2
2
  const generateHomePage = require('./generate-home-page');
3
3
  const generateRoot = require('./generate-root');
4
4
  const generateStore = require('../generate-store');
5
+ const generateRecoil = require('../generate-recoil');
6
+ const copyPages = require('./pages');
5
7
 
6
8
  module.exports = (options) => {
7
9
  const cwd = options.cwd || process.cwd();
8
- const { template } = options;
10
+ const { template, stateManagement } = options;
9
11
  const toCopy = [];
10
12
 
11
13
  // Copy Pages
14
+
12
15
  let pages = [];
13
- if (template !== 'blank') pages.push(...['404', 'about', 'dynamic-route']);
14
- if (template !== 'blank' && template !== 'tabs')
15
- pages.push(...['user', 'form']);
16
- if (template === 'tabs')
17
- pages.push(...['catalog', 'settings', 'form-tabs', 'user-tabs']);
18
- if (template === 'split-view') pages.push(...['left-page-1', 'left-page-2']);
16
+ if (template !== 'blank')
17
+ pages.push(
18
+ ...[
19
+ { fileName: '404', content: 'copy404' },
20
+ { fileName: 'about', content: 'copyAbout' },
21
+ { fileName: 'dynamic-route', content: 'copyDynamicRoute' },
22
+ { fileName: 'user', content: 'copyUser' },
23
+ { fileName: 'form', content: 'copyForm' },
24
+ ]
25
+ );
26
+ if (template === 'tabs') {
27
+ pages.push(
28
+ ...[
29
+ { fileName: 'catalog', content: 'copyCatalog' },
30
+ { fileName: 'settings', content: 'copySettings' },
31
+ ]
32
+ );
33
+ }
19
34
 
20
- pages.forEach((p) => {
21
- const src = path.resolve(__dirname, 'pages', `${p}.jsx`);
22
- let destPage = p;
23
- if (p === 'user-tabs') {
24
- destPage = 'user';
25
- }
26
- if (p === 'form-tabs') {
27
- destPage = 'form';
28
- }
29
- const dest = path.resolve(cwd, 'src', 'pages', `${destPage}.jsx`);
35
+ pages.forEach(({ fileName, content }) => {
36
+ const dest = path.resolve(cwd, 'src', 'pages', `${fileName}.jsx`);
30
37
  toCopy.push({
31
- from: src,
38
+ content: copyPages[content](options),
32
39
  to: dest,
33
40
  });
34
41
  });
42
+
43
+
35
44
  toCopy.push({
36
45
  content: generateHomePage(options),
37
46
  to: path.resolve(cwd, 'src', 'pages', 'index.jsx'),
@@ -55,10 +64,17 @@ module.exports = (options) => {
55
64
  to: path.resolve(cwd, 'src', 'components', 'app.jsx'),
56
65
  });
57
66
 
58
- toCopy.push({
59
- content: generateStore(options),
60
- to: path.resolve(cwd, 'src', 'store.js'),
61
- });
67
+ if (stateManagement === 'recoil') {
68
+ toCopy.push({
69
+ content: generateRecoil(options),
70
+ to: path.resolve(cwd, 'src', 'state.js'),
71
+ });
72
+ } else {
73
+ toCopy.push({
74
+ content: generateStore(options),
75
+ to: path.resolve(cwd, 'src', 'store.js'),
76
+ });
77
+ }
62
78
 
63
79
  toCopy.push({
64
80
  from: path.resolve(__dirname, 'vite.config.js'),
@@ -1,6 +1,6 @@
1
1
  const indent = require('../../utils/indent');
2
2
  module.exports = (options) => {
3
- const { name, template, theming } = options;
3
+ const { name, template, theming, stateManagement } = options;
4
4
  const { fillBars } = theming;
5
5
 
6
6
  let description = '';
@@ -45,21 +45,21 @@ module.exports = (options) => {
45
45
  NavTitleLarge,
46
46
  List,
47
47
  ListItem,
48
- useStore,
49
48
  Card,
50
- } from 'zmp-framework/react';
49
+ ${stateManagement === 'store' ? 'useStore,' : ''}
50
+ } from 'zmp-framework/react';${stateManagement === 'recoil' ? `
51
+ import { useRecoilValue } from 'recoil';
52
+ import { userState } from '../state';` : ''}
51
53
  import AppItems from '../components/app-items';
52
54
  import UserCard from '../components/user-card';
53
55
  `.trim()
54
56
  }
55
57
 
56
58
  const HomePage = () => {
57
- ${template !== 'blank' ? "const user = useStore('user');" : ''}
59
+ ${template !== 'blank' ? (stateManagement === 'recoil' ? "const user = useRecoilValue(userState);" : "const user = useStore('user');") : ''}
58
60
  return (
59
- <Page name="home" ${template === 'tabs' ? '' : 'navbarLarge'}>
60
- ${
61
- template !== 'tabs'
62
- ? `{/* Top Navbar */}
61
+ <Page name="home" ${template === 'tabs' ? '' : 'navbarLarge'}>${template !== 'tabs' ? `
62
+ {/* Top Navbar */}
63
63
  <Navbar ${fillBars ? 'fill' : ''}>
64
64
  <NavTitleLarge>${name}</NavTitleLarge>
65
65
  </Navbar>`
@@ -90,10 +90,7 @@ module.exports = (options) => {
90
90
  </List>
91
91
  `.trim()
92
92
  : ''
93
- }
94
- ${
95
- template === 'tabs'
96
- ? `
93
+ }${template === 'tabs' ? `
97
94
  {/* Grid apps */}
98
95
  <AppItems />
99
96
 
@@ -103,9 +100,7 @@ module.exports = (options) => {
103
100
  <ListItem title="Default Route (404)" link="/something-that-doesnt-exist" />
104
101
  <ListItem title="About" link="/about/" />
105
102
  </List>
106
- `.trim()
107
- : ''
108
- }
103
+ `.trim() : ''}
109
104
  </Page>
110
105
  );
111
106
  }
@@ -1,14 +1,15 @@
1
+ const templateIf = require('../../utils/template-if');
1
2
  const indent = require('../../utils/indent');
2
3
  const appParameters = require('../app-parameters');
3
4
 
4
5
  module.exports = (options) => {
5
- const { template, theming } = options;
6
+ const { template, theming, stateManagement } = options;
6
7
 
7
8
  // Views
8
9
  let views = '';
9
10
  if (template === 'single-view' || template === 'blank') {
10
11
  views = indent(
11
- 12,
12
+ 0,
12
13
  `
13
14
  {/* Your main view, should have "view-main" class */}
14
15
  <View main className="safe-areas" url="/" />
@@ -17,7 +18,7 @@ module.exports = (options) => {
17
18
  }
18
19
  if (template === 'tabs') {
19
20
  views = indent(
20
- 12,
21
+ 0,
21
22
  `
22
23
  {/* TabView container */}
23
24
  <TabView className="safe-areas">
@@ -45,48 +46,37 @@ module.exports = (options) => {
45
46
  return indent(
46
47
  0,
47
48
  `
48
- import React, { useState, useEffect } from 'react';
49
- ${
50
- ['blank', 'single-view'].indexOf(template) >= 0
51
- ? `
52
- import {
53
- zmp,
54
- zmpready,
55
- App,
56
- View,
57
- } from 'zmp-framework/react';
49
+ import React, { useEffect } from 'react';
50
+ ${['blank', 'single-view'].indexOf(template) >= 0
51
+ ? `
52
+ import { zmpready, App, View } from 'zmp-framework/react';
58
53
  `.trim()
59
- : `
60
- import {
61
- zmp,
62
- zmpready,
63
- App,
64
- TabView,
65
- View,
66
- Tabbar,
67
- Link,
68
- } from 'zmp-framework/react';
54
+ : `
55
+ import { zmpready, App, TabView, View, Tabbar, Link } from 'zmp-framework/react';
69
56
  `.trim()
70
57
  }
71
- import store from '../store';
58
+ ${templateIf(stateManagement === 'recoil', () => `import { RecoilRoot } from 'recoil';`, () => `import store from '../store';`)}
72
59
 
73
60
  const MyApp = () => {
74
61
  // ZMP Parameters
75
62
  const zmpparams = {
76
- ${indent(10, appParameters(options)).trim()}
63
+ ${indent(8, appParameters(options))}
77
64
  };
78
- useEffect(()=>{
65
+ useEffect(() => {
79
66
  zmpready(() => {
80
67
  // Call ZMP APIs here
81
68
  });
69
+ }, [])
82
70
 
83
- },[])
84
-
85
- return (
86
- <App { ...zmpparams } ${theming.darkTheme ? 'themeDark' : ''}>
87
- ${views}
88
- </App>
71
+ ${`
72
+ return (${stateManagement === 'recoil' ? `
73
+ <RecoilRoot>` : ''}
74
+ ${indent(stateManagement === 'recoil' ? 2 : 0, `<App {...zmpparams} ${theming.darkTheme ? 'themeDark' : ''}>`)}
75
+ ${indent(stateManagement === 'recoil' ? 12 : 10, views.trim())}
76
+ ${indent(stateManagement === 'recoil' ? 2 : 0, `</App>`)}${stateManagement === 'recoil' ? `
77
+ </RecoilRoot>` : ''}
89
78
  );
79
+ `.trim()}
90
80
  }
91
81
  export default MyApp;
92
82
  `
@@ -12,7 +12,7 @@ module.exports = (options) => {
12
12
  `
13
13
  // Import React and ReactDOM
14
14
  import React from 'react';
15
- import ReactDOM from 'react-dom';
15
+ import { createRoot } from 'react-dom/client';
16
16
 
17
17
  // Import ZMP
18
18
  import ZMP from '${
@@ -20,16 +20,10 @@ module.exports = (options) => {
20
20
  }';
21
21
 
22
22
  // Import ZMP-React Plugin
23
- import ZMPReact from 'zmp-framework/react';
23
+ import ZMPReact from 'zmp-framework/react';${includeTailwind ? `
24
24
 
25
- ${templateIf(
26
- includeTailwind,
27
- () => `
28
- // Import tailwind styles
29
- import './css/styles.css';
30
- `,
31
- () => ''
32
- )}
25
+ // Import tailwind styles
26
+ import './css/tailwind.css';` : ''}
33
27
 
34
28
  // Import ZMP Styles
35
29
  ${templateIf(
@@ -65,10 +59,8 @@ module.exports = (options) => {
65
59
  ZMP.use(ZMPReact)
66
60
 
67
61
  // Mount React App
68
- ReactDOM.render(
69
- React.createElement(App),
70
- document.getElementById('app'),
71
- );
62
+ const root = createRoot(document.getElementById('app'));
63
+ root.render(React.createElement(App));
72
64
  `
73
65
  );
74
66
 
@@ -0,0 +1,27 @@
1
+ const indent = require('../../../utils/indent');
2
+
3
+ // eslint-disable-next-line no-unused-vars
4
+ module.exports = (options) => {
5
+ return indent(
6
+ 0,
7
+ `
8
+ import React from 'react';
9
+ import { Page, Card, Title, Box } from 'zmp-framework/react';
10
+ import NavbarBack from '../components/navbar-back';
11
+
12
+ const NotFoundPage = () => (
13
+ <Page>
14
+ <NavbarBack title="Not found" />
15
+ <Box mt="2">
16
+ <Card inset>
17
+ <Title>Sorry</Title>
18
+ <p>Requested content not found.</p>
19
+ </Card>
20
+ </Box>
21
+ </Page>
22
+ );
23
+
24
+ export default NotFoundPage;
25
+ `
26
+ ).trim();
27
+ };
@@ -0,0 +1,52 @@
1
+ const indent = require('../../../utils/indent');
2
+
3
+ // eslint-disable-next-line no-unused-vars
4
+ module.exports = (options) => {
5
+ return indent(
6
+ 0,
7
+ `
8
+ import React from 'react'
9
+ import { Actions, ActionsButton, ActionsGroup, ActionsLabel, Button, Card, Page, Box } from 'zmp-framework/react';
10
+ import NavbarBack from '../components/navbar-back';
11
+
12
+ const AboutPage = (props) => {
13
+ const [actionSheetOpened, setActionSheetOpened] = React.useState(false);
14
+
15
+ return (
16
+ <Page name="about">
17
+ <NavbarBack title="About" />
18
+ <Box mt="2">
19
+ <Card inset title="About My App">
20
+ <p>This is a demo ZMP App!</p>
21
+ </Card>
22
+ </Box>
23
+ <Box mb="4">
24
+ <Button
25
+ typeName="secondary"
26
+ responsive
27
+ onClick={() => setActionSheetOpened(true)}
28
+ >
29
+ Back
30
+ </Button>
31
+ </Box>
32
+ <Actions
33
+ opened={actionSheetOpened}
34
+ onActionsClosed={() => setActionSheetOpened(false)}
35
+ id="actions-two-groups"
36
+ >
37
+ <ActionsGroup>
38
+ <ActionsLabel>Are you sure?</ActionsLabel>
39
+ <ActionsButton onClick={() => props.zmprouter.back()}>Navigate back</ActionsButton>
40
+ </ActionsGroup>
41
+ <ActionsGroup>
42
+ <ActionsButton>Cancel</ActionsButton>
43
+ </ActionsGroup>
44
+ </Actions>
45
+ </Page>
46
+ )
47
+ }
48
+
49
+ export default AboutPage;
50
+ `
51
+ ).trim();
52
+ };
@@ -0,0 +1,112 @@
1
+ const indent = require('../../../utils/indent');
2
+
3
+ // eslint-disable-next-line no-unused-vars
4
+ module.exports = (options) => {
5
+ if (options.stateManagement === 'recoil') {
6
+ return indent(
7
+ 0,
8
+ `
9
+ import React from "react";
10
+ import { useRecoilState } from 'recoil';
11
+ import { Page, Title, List, ListItem, Box, Button } from 'zmp-framework/react';
12
+ import { productsState } from '../state';
13
+
14
+ const CatalogPage = () => {
15
+ const [products, setProducts] = useRecoilState(productsState)
16
+
17
+ const addProduct = () => {
18
+ setProducts(p => [
19
+ ...p,
20
+ {
21
+ id: '4',
22
+ title: 'Apple iPhone 12',
23
+ description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi tempora similique reiciendis, error nesciunt vero, blanditiis pariatur dolor, minima sed sapiente rerum, dolorem corrupti hic modi praesentium unde saepe perspiciatis.'
24
+ }
25
+ ])
26
+ }
27
+
28
+ return (
29
+ <Page name="catalog">
30
+ <Box m="0" p="4">
31
+ <Title>Catalog</Title>
32
+ <List>
33
+ {products.map((product) => (
34
+ <ListItem
35
+ key={product.id}
36
+ title={product.title}
37
+ link={\`/product/\${product.id}/\`}
38
+ />
39
+ ))}
40
+ </List>
41
+ {products.length === 3 && (
42
+ <Box>
43
+ <Button responsive typeName="secondary" onClick={addProduct}>
44
+ Add Product
45
+ </Button>
46
+ </Box>
47
+ )}
48
+ </Box>
49
+ </Page>
50
+ );
51
+ };
52
+
53
+ export default CatalogPage;
54
+ `
55
+ ).trim();
56
+ }
57
+ return indent(
58
+ 0,
59
+ `
60
+ import React from "react";
61
+ import {
62
+ Page,
63
+ Title,
64
+ List,
65
+ ListItem,
66
+ Box,
67
+ Button,
68
+ useStore
69
+ } from "zmp-framework/react";
70
+ import store from "../store";
71
+
72
+ const CatalogPage = () => {
73
+ const products = useStore("products");
74
+
75
+ const addProduct = () => {
76
+ store.dispatch("addProduct", {
77
+ id: "4",
78
+ title: "Apple iPhone 12",
79
+ description:
80
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi tempora similique reiciendis, error nesciunt vero, blanditiis pariatur dolor, minima sed sapiente rerum, dolorem corrupti hic modi praesentium unde saepe perspiciatis."
81
+ });
82
+ };
83
+
84
+ return (
85
+ <Page name="catalog">
86
+ <Box m="0" p="4">
87
+ <Title>Catalog</Title>
88
+ <List>
89
+ {products.map((product) => (
90
+ <ListItem
91
+ key={product.id}
92
+ title={product.title}
93
+ link={\`/product/\${product.id}/\`}
94
+ />
95
+ ))}
96
+ </List>
97
+ {products.length === 3 && (
98
+ <Box>
99
+ <Button responsive typeName="secondary" onClick={addProduct}>
100
+ Add Product
101
+ </Button>
102
+ </Box>
103
+ )}
104
+ </Box>
105
+ </Page>
106
+ );
107
+ };
108
+
109
+ export default CatalogPage;
110
+ `
111
+ ).trim();
112
+ };