@knovator/pagecreator 0.0.1 → 0.0.3
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/README.md +209 -4
- package/index.js +36 -76
- package/lib/components/common/collection-item/collection-item.d.ts +1 -1
- package/lib/components/widget/carousel-widget/carousel-widget.d.ts +1 -1
- package/lib/components/widget/fixed-widget/fixed-widget.d.ts +1 -1
- package/lib/components/widget/widget.d.ts +1 -1
- package/lib/types/components.d.ts +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,212 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 -->
|
|
2
|
+
<a name="readme-top"></a>
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
[![Contributors][contributors-shield]][contributors-url]
|
|
5
|
+
[![Forks][forks-shield]][forks-url]
|
|
6
|
+
[![Stargazers][stars-shield]][stars-url]
|
|
7
|
+
[![Issues][issues-shield]][issues-url]
|
|
8
|
+
[![MIT License][license-shield]][license-url]
|
|
4
9
|
|
|
5
|
-
## Running unit tests
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
<!-- PROJECT LOGO -->
|
|
12
|
+
<br />
|
|
13
|
+
<div align="center">
|
|
14
|
+
<!-- <a href="https://github.com/knovator/pagecreator">
|
|
15
|
+
<img src="images/logo.png" alt="Logo" width="80" height="80">
|
|
16
|
+
</a> -->
|
|
17
|
+
|
|
18
|
+
<h3 align="center">@knovator/pagecreator</h3>
|
|
19
|
+
|
|
20
|
+
<p align="center">
|
|
21
|
+
Plug & Play functionality to Build dynamic pages on the fly
|
|
22
|
+
<br />
|
|
23
|
+
<a href="https://github.com/knovator/pagecreator"><strong>Explore the docs »</strong></a>
|
|
24
|
+
<br />
|
|
25
|
+
<br />
|
|
26
|
+
<a href="https://github.com/knovator/pagecreator">View Demo</a>
|
|
27
|
+
·
|
|
28
|
+
<a href="https://github.com/knovator/pagecreator/issues">Report Bug</a>
|
|
29
|
+
·
|
|
30
|
+
<a href="https://github.com/knovator/pagecreator/issues">Request Feature</a>
|
|
31
|
+
</p>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<!-- TABLE OF CONTENTS -->
|
|
37
|
+
<details>
|
|
38
|
+
<summary>Table of Contents</summary>
|
|
39
|
+
<ol>
|
|
40
|
+
<li>
|
|
41
|
+
<a href="#about-the-project">About The Project</a>
|
|
42
|
+
<ul>
|
|
43
|
+
<li><a href="#built-with">Built With</a></li>
|
|
44
|
+
</ul>
|
|
45
|
+
</li>
|
|
46
|
+
<li>
|
|
47
|
+
<a href="#getting-started">Getting Started</a>
|
|
48
|
+
<ul>
|
|
49
|
+
<li><a href="#prerequisites">Prerequisites</a></li>
|
|
50
|
+
<li><a href="#installation">Installation</a></li>
|
|
51
|
+
</ul>
|
|
52
|
+
</li>
|
|
53
|
+
<li><a href="#usage">Usage</a></li>
|
|
54
|
+
<li><a href="#contributing">Contributing</a></li>
|
|
55
|
+
<li><a href="#license">License</a></li>
|
|
56
|
+
<li><a href="#contact">Contact</a></li>
|
|
57
|
+
</ol>
|
|
58
|
+
</details>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
<!-- ABOUT THE PROJECT -->
|
|
63
|
+
## About The Project
|
|
64
|
+
|
|
65
|
+
`@knovator/pagecreator` is built with intent to build pages that are depend on backend data, and admin can change how page will look like.
|
|
66
|
+
|
|
67
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Built With
|
|
72
|
+
|
|
73
|
+
* [React.js](https://reactjs.org/)
|
|
74
|
+
* [react-slick](https://www.npmjs.com/package/react-slick)
|
|
75
|
+
|
|
76
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
<!-- GETTING STARTED -->
|
|
81
|
+
## Getting Started
|
|
82
|
+
|
|
83
|
+
To integrate `@knovator/pagecreator` is designed to be used in ReactJS/NextJS project.
|
|
84
|
+
|
|
85
|
+
### Prerequisites
|
|
86
|
+
|
|
87
|
+
We can use `@knovator/pagecreator` in React/Next application, we can create one using following commands
|
|
88
|
+
* Project
|
|
89
|
+
```sh
|
|
90
|
+
npx create-react-app my-app
|
|
91
|
+
# or
|
|
92
|
+
npx create-next-app@latest
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Installation
|
|
96
|
+
|
|
97
|
+
1. Install NPM packages
|
|
98
|
+
```sh
|
|
99
|
+
npm install @knovator/pagecreator
|
|
100
|
+
# or
|
|
101
|
+
yarn add @knovator/pagecreator
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
<!-- USAGE EXAMPLES -->
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
### Widget
|
|
111
|
+
```jsx
|
|
112
|
+
import { Widget } from '@knovator/pagecreator';
|
|
113
|
+
|
|
114
|
+
<Widget
|
|
115
|
+
apiBaseUrl=''
|
|
116
|
+
widgetData={}
|
|
117
|
+
onClick={...}
|
|
118
|
+
>
|
|
119
|
+
```
|
|
120
|
+
**Props**
|
|
121
|
+
- `widgetData`
|
|
122
|
+
- [widgetData](data-formats.md#widgetdata)
|
|
123
|
+
- `apiBaseUrl`
|
|
124
|
+
- baseUrl to start prefix image urls
|
|
125
|
+
- `formatItem` (optional): `(item: TileData) => JSX.Element`
|
|
126
|
+
- Customize look of Items
|
|
127
|
+
- `onClick` (optional): `(item: TileData) => void;`
|
|
128
|
+
- OnItem click handler
|
|
129
|
+
|
|
130
|
+
### Page
|
|
131
|
+
```jsx
|
|
132
|
+
import { Page } from '@knovator/pagecreator';
|
|
133
|
+
|
|
134
|
+
<Page
|
|
135
|
+
apiBaseUrl=''
|
|
136
|
+
pageData={...}
|
|
137
|
+
onClick={...}
|
|
138
|
+
>
|
|
139
|
+
```
|
|
140
|
+
**Props**
|
|
141
|
+
- `title` (optional)
|
|
142
|
+
- Title to show on page
|
|
143
|
+
- `apiBaseUrl`
|
|
144
|
+
- baseUrl to start prefix image urls
|
|
145
|
+
- `pageData`
|
|
146
|
+
- [PageData](data-formats.md#pagedata)
|
|
147
|
+
- `formatItem` (optional): `(CODE: string, item: TileData) => JSX.Element;`
|
|
148
|
+
- Customize look of Items
|
|
149
|
+
- `onClick` (optional): `(CODE: string, item: TileData) => JSX.Element;`
|
|
150
|
+
- On Item click handler
|
|
151
|
+
|
|
152
|
+
### getData
|
|
153
|
+
It's possible to fetch data by yourself and pass them to `Widget` or `Page` components, but if you need easy solution you can use `getData` function.
|
|
154
|
+
```js
|
|
155
|
+
const pageData = await getData({
|
|
156
|
+
url: '...',
|
|
157
|
+
code: 'HOMEPAGE',
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
162
|
+
|
|
163
|
+
<!-- CONTRIBUTING -->
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
|
167
|
+
|
|
168
|
+
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
|
|
169
|
+
Don't forget to give the project a star! Thanks again!
|
|
170
|
+
|
|
171
|
+
1. Fork the Project
|
|
172
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
173
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
|
174
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
|
175
|
+
5. Open a Pull Request
|
|
176
|
+
|
|
177
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<!-- LICENSE -->
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
Distributed under the MIT License. See `LICENSE.txt` for more information.
|
|
185
|
+
|
|
186
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
<!-- CONTACT -->
|
|
190
|
+
## Contact
|
|
191
|
+
|
|
192
|
+
Knovator Technologies
|
|
193
|
+
- Twitter [@knovator](https://twitter.com/knovator)
|
|
194
|
+
- Web [https://knovator.com/](https://knovator.com/)
|
|
195
|
+
|
|
196
|
+
Project Link: [https://github.com/knovator/masters-admin](https://github.com/knovator/masters-admin)
|
|
197
|
+
|
|
198
|
+
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
<!-- MARKDOWN LINKS & IMAGES -->
|
|
202
|
+
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
203
|
+
[contributors-shield]: https://img.shields.io/github/contributors/knovator/pagecreator.svg?style=for-the-badge
|
|
204
|
+
[contributors-url]: https://github.com/knovator/pagecreator/graphs/contributors
|
|
205
|
+
[forks-shield]: https://img.shields.io/github/forks/knovator/pagecreator.svg?style=for-the-badge
|
|
206
|
+
[forks-url]: https://github.com/knovator/pagecreator/network/members
|
|
207
|
+
[stars-shield]: https://img.shields.io/github/stars/knovator/pagecreator.svg?style=for-the-badge
|
|
208
|
+
[stars-url]: https://github.com/knovator/pagecreator/stargazers
|
|
209
|
+
[issues-shield]: https://img.shields.io/github/issues/knovator/pagecreator.svg?style=for-the-badge
|
|
210
|
+
[issues-url]: https://github.com/knovator/pagecreator/issues
|
|
211
|
+
[license-shield]: https://img.shields.io/github/license/knovator/pagecreator.svg?style=for-the-badge
|
|
212
|
+
[license-url]: https://github.com/knovator/pagecreator/blob/main/LICENSE.txt
|
package/index.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import Slider from 'react-slick';
|
|
3
3
|
|
|
4
4
|
function FixedWidget(_ref) {
|
|
5
5
|
var widgetData = _ref.widgetData,
|
|
6
|
-
formatTile = _ref.formatTile,
|
|
7
6
|
formatItem = _ref.formatItem;
|
|
8
|
-
return
|
|
7
|
+
return jsx("div", Object.assign({
|
|
9
8
|
className: "grid grid-cols-".concat(widgetData.mobilePerRow, " md:grid-cols-").concat(widgetData.tabletPerRow, " lg:grid-cols-").concat(widgetData.webPerRow)
|
|
10
9
|
}, {
|
|
11
|
-
children:
|
|
12
|
-
return
|
|
10
|
+
children: widgetData.widgetType === 'Image' ? widgetData.tiles.map(function (tile) {
|
|
11
|
+
return formatItem(tile);
|
|
13
12
|
}) : widgetData.collectionItems.map(function (item) {
|
|
14
13
|
return formatItem(item);
|
|
15
|
-
})
|
|
16
|
-
return formatTile(tile);
|
|
17
|
-
})]
|
|
14
|
+
})
|
|
18
15
|
}));
|
|
19
16
|
}
|
|
20
17
|
|
|
@@ -117,7 +114,7 @@ var SlickArrowRight = function SlickArrowRight(_a) {
|
|
|
117
114
|
|
|
118
115
|
function CarouselWidget(_ref) {
|
|
119
116
|
var widgetData = _ref.widgetData,
|
|
120
|
-
|
|
117
|
+
formatItem = _ref.formatItem,
|
|
121
118
|
settings = _ref.settings;
|
|
122
119
|
var defaultSettings = {
|
|
123
120
|
dots: false,
|
|
@@ -144,57 +141,18 @@ function CarouselWidget(_ref) {
|
|
|
144
141
|
};
|
|
145
142
|
if (!widgetData) return null;
|
|
146
143
|
return jsx(Slider, Object.assign({}, settings ? settings : defaultSettings, {
|
|
147
|
-
children: widgetData.tiles.map(function (tile) {
|
|
148
|
-
return
|
|
144
|
+
children: widgetData.widgetType === 'Image' ? widgetData.tiles.map(function (tile) {
|
|
145
|
+
return jsx("div", {
|
|
146
|
+
children: formatItem(tile)
|
|
147
|
+
});
|
|
148
|
+
}) : widgetData.collectionItems.map(function (item) {
|
|
149
|
+
return jsx("div", {
|
|
150
|
+
children: formatItem(item)
|
|
151
|
+
});
|
|
149
152
|
})
|
|
150
153
|
}));
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
function SimpleCard(_ref) {
|
|
154
|
-
var imageUrl = _ref.imageUrl,
|
|
155
|
-
imageAltText = _ref.imageAltText,
|
|
156
|
-
subTitle = _ref.subTitle,
|
|
157
|
-
label = _ref.label,
|
|
158
|
-
title = _ref.title,
|
|
159
|
-
_onClick = _ref.onClick;
|
|
160
|
-
return jsxs("div", Object.assign({
|
|
161
|
-
className: "kpc_simple-card",
|
|
162
|
-
onClick: function onClick() {
|
|
163
|
-
return _onClick && _onClick();
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
children: [jsx("div", Object.assign({
|
|
167
|
-
className: "kpc_simple-card-heading"
|
|
168
|
-
}, {
|
|
169
|
-
children: jsx("img", {
|
|
170
|
-
src: imageUrl,
|
|
171
|
-
className: "kpc_simple-card-image",
|
|
172
|
-
alt: imageAltText
|
|
173
|
-
})
|
|
174
|
-
})), jsxs("div", Object.assign({
|
|
175
|
-
className: "kpc_simple-card-body"
|
|
176
|
-
}, {
|
|
177
|
-
children: [label && jsx("p", Object.assign({
|
|
178
|
-
className: "kpc_simple-card-label"
|
|
179
|
-
}, {
|
|
180
|
-
children: label
|
|
181
|
-
})), jsxs("div", Object.assign({
|
|
182
|
-
className: "kpc_simple-card-content"
|
|
183
|
-
}, {
|
|
184
|
-
children: [jsx("h4", Object.assign({
|
|
185
|
-
className: "kpc_simple-card-title"
|
|
186
|
-
}, {
|
|
187
|
-
children: title
|
|
188
|
-
})), subTitle && jsx("p", Object.assign({
|
|
189
|
-
className: "kpc_simple-card-subtitle"
|
|
190
|
-
}, {
|
|
191
|
-
children: subTitle
|
|
192
|
-
}))]
|
|
193
|
-
}))]
|
|
194
|
-
}))]
|
|
195
|
-
}));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
156
|
function Banner(_ref) {
|
|
199
157
|
var imageAltText = _ref.imageAltText,
|
|
200
158
|
imageUrl = _ref.imageUrl,
|
|
@@ -214,14 +172,18 @@ function Banner(_ref) {
|
|
|
214
172
|
}
|
|
215
173
|
|
|
216
174
|
function CollectionItem(_ref) {
|
|
217
|
-
var name = _ref.name
|
|
175
|
+
var name = _ref.name,
|
|
176
|
+
_onClick = _ref.onClick;
|
|
218
177
|
return jsx("div", Object.assign({
|
|
219
|
-
className: "kpc_item"
|
|
178
|
+
className: "kpc_item",
|
|
179
|
+
onClick: function onClick() {
|
|
180
|
+
return _onClick && _onClick();
|
|
181
|
+
}
|
|
220
182
|
}, {
|
|
221
183
|
children: jsx("p", Object.assign({
|
|
222
184
|
className: "kpc_item-text"
|
|
223
185
|
}, {
|
|
224
|
-
children: name
|
|
186
|
+
children: name || 'Laurem Ipsum'
|
|
225
187
|
}))
|
|
226
188
|
}));
|
|
227
189
|
}
|
|
@@ -230,26 +192,25 @@ function Widget(_ref) {
|
|
|
230
192
|
var widgetData = _ref.widgetData,
|
|
231
193
|
apiBaseUrl = _ref.apiBaseUrl,
|
|
232
194
|
formatItem = _ref.formatItem,
|
|
233
|
-
_onClick = _ref.onClick
|
|
195
|
+
_onClick = _ref.onClick,
|
|
196
|
+
settings = _ref.settings;
|
|
234
197
|
|
|
235
198
|
var formatTile = function formatTile(tile) {
|
|
236
|
-
var _a
|
|
199
|
+
var _a;
|
|
237
200
|
|
|
238
201
|
if (typeof formatItem === 'function' && formatItem) return formatItem(tile);else if (widgetData.widgetType === 'Image') return jsx(Banner, {
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
203
|
+
// @ts-ignore
|
|
239
204
|
imageUrl: "".concat(apiBaseUrl).concat((_a = tile.img) === null || _a === void 0 ? void 0 : _a.uri),
|
|
240
|
-
imageAltText: tile.
|
|
241
|
-
}, tile._id);else return jsx(SimpleCard, {
|
|
205
|
+
imageAltText: tile._id,
|
|
242
206
|
onClick: function onClick() {
|
|
243
207
|
return _onClick && _onClick(tile);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
var formatCollectionItem = function formatCollectionItem(item) {
|
|
252
|
-
return jsx(CollectionItem, Object.assign({}, item), item._id);
|
|
208
|
+
}
|
|
209
|
+
}, tile._id);else return jsx(CollectionItem, Object.assign({
|
|
210
|
+
onClick: function onClick() {
|
|
211
|
+
return _onClick && _onClick(tile);
|
|
212
|
+
}
|
|
213
|
+
}, tile), tile._id);
|
|
253
214
|
};
|
|
254
215
|
|
|
255
216
|
if (!widgetData) return null;
|
|
@@ -264,15 +225,14 @@ function Widget(_ref) {
|
|
|
264
225
|
className: "kpc_widget-body"
|
|
265
226
|
}, {
|
|
266
227
|
children: widgetData.selectionType === 'Carousel' ? jsx(CarouselWidget, {
|
|
228
|
+
settings: settings,
|
|
267
229
|
apiBaseUrl: apiBaseUrl,
|
|
268
230
|
widgetData: widgetData,
|
|
269
|
-
formatItem:
|
|
270
|
-
formatTile: formatTile
|
|
231
|
+
formatItem: formatTile
|
|
271
232
|
}) : jsx(FixedWidget, {
|
|
272
233
|
apiBaseUrl: apiBaseUrl,
|
|
273
234
|
widgetData: widgetData,
|
|
274
|
-
formatItem:
|
|
275
|
-
formatTile: formatTile
|
|
235
|
+
formatItem: formatTile
|
|
276
236
|
})
|
|
277
237
|
}))]
|
|
278
238
|
}));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { WidgetTypeProps } from '../../../types';
|
|
2
|
-
export declare function CarouselWidget({ widgetData,
|
|
2
|
+
export declare function CarouselWidget({ widgetData, formatItem, settings, }: WidgetTypeProps): JSX.Element | null;
|
|
3
3
|
export default CarouselWidget;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { WidgetTypeProps } from '../../../types';
|
|
2
|
-
export declare function FixedWidget({ widgetData,
|
|
2
|
+
export declare function FixedWidget({ widgetData, formatItem }: WidgetTypeProps): JSX.Element;
|
|
3
3
|
export default FixedWidget;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { WidgetProps } from '../../types';
|
|
2
|
-
export declare function Widget({ widgetData, apiBaseUrl, formatItem, onClick, }: WidgetProps): JSX.Element | null;
|
|
2
|
+
export declare function Widget({ widgetData, apiBaseUrl, formatItem, onClick, settings, }: WidgetProps): JSX.Element | null;
|
|
3
3
|
export default Widget;
|
|
@@ -33,22 +33,22 @@ export interface ReviewCardProps extends UserCardProps {
|
|
|
33
33
|
export interface WidgetProps {
|
|
34
34
|
widgetData: WidgetData;
|
|
35
35
|
apiBaseUrl: string;
|
|
36
|
-
formatItem?: (item: TileData) => JSX.Element;
|
|
37
|
-
onClick?: (item: TileData) => void;
|
|
36
|
+
formatItem?: (item: TileData | CollectionItemType) => JSX.Element;
|
|
37
|
+
onClick?: (item: TileData | CollectionItemType) => void;
|
|
38
|
+
settings?: Settings;
|
|
38
39
|
}
|
|
39
40
|
export interface WidgetTypeProps extends WidgetProps {
|
|
40
|
-
|
|
41
|
-
formatItem: (item: CollectionItemType) => JSX.Element;
|
|
42
|
-
settings?: Settings;
|
|
41
|
+
formatItem: (item: CollectionItemType | TileData) => JSX.Element;
|
|
43
42
|
}
|
|
44
43
|
export interface PageProps {
|
|
45
44
|
title?: string;
|
|
46
45
|
apiBaseUrl: string;
|
|
47
46
|
pageData: PageData;
|
|
48
|
-
formatItem?: (CODE: string, item: TileData) => JSX.Element;
|
|
49
|
-
onClick?: (CODE: string, item: TileData) => JSX.Element;
|
|
47
|
+
formatItem?: (CODE: string, item: TileData | CollectionItemType) => JSX.Element;
|
|
48
|
+
onClick?: (CODE: string, item: TileData | CollectionItemType) => JSX.Element;
|
|
50
49
|
}
|
|
51
50
|
export interface CollectionItemProps {
|
|
52
51
|
name?: string;
|
|
52
|
+
onClick?: () => void;
|
|
53
53
|
}
|
|
54
54
|
export {};
|