powr-sdk-web 2.0.16 → 2.2.0

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.
@@ -0,0 +1,435 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
18
+ var PowrTable = function PowrTable(_ref) {
19
+ var data = _ref.data,
20
+ columns = _ref.columns,
21
+ title = _ref.title,
22
+ description = _ref.description,
23
+ gradientColors = _ref.gradientColors,
24
+ onAction = _ref.onAction,
25
+ mobileCardConfig = _ref.mobileCardConfig,
26
+ customHeader = _ref.customHeader;
27
+ var _useState = (0, _react.useState)(false),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ isMobile = _useState2[0],
30
+ setIsMobile = _useState2[1];
31
+
32
+ // Detect mobile screen size
33
+ (0, _react.useEffect)(function () {
34
+ var checkMobile = function checkMobile() {
35
+ setIsMobile(window.innerWidth < 640);
36
+ };
37
+ checkMobile();
38
+ window.addEventListener('resize', checkMobile);
39
+ return function () {
40
+ return window.removeEventListener('resize', checkMobile);
41
+ };
42
+ }, []);
43
+ var getStatusColor = function getStatusColor(status) {
44
+ var colors = {
45
+ 'Complete': '#d4edda',
46
+ 'In Progress': '#d4edda',
47
+ 'Planning': '#fff3cd',
48
+ 'Proposed': '#e3f2fd',
49
+ 'In Review': '#fff3cd',
50
+ 'Approved': '#d4edda',
51
+ 'Rejected': '#f8d7da'
52
+ };
53
+ return colors[status] || '#e9ecef';
54
+ };
55
+ var getStatusTextColor = function getStatusTextColor(status) {
56
+ var colors = {
57
+ 'Complete': '#155724',
58
+ 'In Progress': '#155724',
59
+ 'Planning': '#856404',
60
+ 'Proposed': '#1976d2',
61
+ 'In Review': '#856404',
62
+ 'Approved': '#155724',
63
+ 'Rejected': '#721c24'
64
+ };
65
+ return colors[status] || '#6c757d';
66
+ };
67
+ var renderCell = function renderCell(column, value, row) {
68
+ switch (column.type) {
69
+ case 'badge':
70
+ return /*#__PURE__*/_react["default"].createElement("span", {
71
+ style: {
72
+ background: getStatusColor(value || 'Proposed'),
73
+ color: getStatusTextColor(value || 'Proposed'),
74
+ padding: '4px 8px',
75
+ borderRadius: '12px',
76
+ fontSize: '0.8em',
77
+ fontWeight: '500'
78
+ }
79
+ }, value || 'Proposed');
80
+ case 'progress':
81
+ return /*#__PURE__*/_react["default"].createElement("div", {
82
+ style: {
83
+ display: 'flex',
84
+ alignItems: 'center',
85
+ justifyContent: 'center',
86
+ gap: '8px'
87
+ }
88
+ }, /*#__PURE__*/_react["default"].createElement("div", {
89
+ style: {
90
+ width: '60px',
91
+ height: '8px',
92
+ background: '#e9ecef',
93
+ borderRadius: '4px',
94
+ overflow: 'hidden'
95
+ }
96
+ }, /*#__PURE__*/_react["default"].createElement("div", {
97
+ style: {
98
+ width: "".concat(value, "%"),
99
+ height: '100%',
100
+ background: '#28a745',
101
+ borderRadius: '4px'
102
+ }
103
+ })), /*#__PURE__*/_react["default"].createElement("span", {
104
+ style: {
105
+ fontSize: '0.8em',
106
+ fontWeight: '600',
107
+ color: '#28a745'
108
+ }
109
+ }, value, "%"));
110
+ case 'vote':
111
+ return /*#__PURE__*/_react["default"].createElement("button", {
112
+ onClick: function onClick() {
113
+ return onAction === null || onAction === void 0 ? void 0 : onAction('vote', row);
114
+ },
115
+ style: {
116
+ background: 'linear-gradient(135deg, #28a745 0%, #20c997 100%)',
117
+ color: 'white',
118
+ border: 'none',
119
+ padding: '8px 16px',
120
+ borderRadius: '20px',
121
+ fontSize: '0.9em',
122
+ fontWeight: '600',
123
+ cursor: 'pointer',
124
+ transition: 'all 0.3s ease',
125
+ boxShadow: '0 2px 8px rgba(40, 167, 69, 0.3)'
126
+ }
127
+ }, "\uD83D\uDC4D ", value, " Vote", value !== 1 ? 's' : '');
128
+ case 'action':
129
+ // Handle case where value might be undefined or not have the expected structure
130
+ if (!value || _typeof(value) !== 'object') {
131
+ return null;
132
+ }
133
+ return /*#__PURE__*/_react["default"].createElement("button", {
134
+ onClick: function onClick() {
135
+ return onAction === null || onAction === void 0 ? void 0 : onAction(value.action || 'action', row);
136
+ },
137
+ style: {
138
+ background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
139
+ color: 'white',
140
+ border: 'none',
141
+ padding: '8px 16px',
142
+ borderRadius: '8px',
143
+ fontSize: '0.9em',
144
+ fontWeight: '600',
145
+ cursor: 'pointer',
146
+ transition: 'all 0.3s ease',
147
+ whiteSpace: 'nowrap'
148
+ }
149
+ }, value.text || 'Action');
150
+ case 'link':
151
+ // Handle case where value might be undefined or not have the expected structure
152
+ if (!value || _typeof(value) !== 'object') {
153
+ return null;
154
+ }
155
+ return /*#__PURE__*/_react["default"].createElement("a", {
156
+ href: value.url || '#',
157
+ target: "_blank",
158
+ rel: "noopener noreferrer",
159
+ style: {
160
+ color: '#007bff',
161
+ textDecoration: 'none',
162
+ fontSize: '0.9em',
163
+ fontWeight: '500'
164
+ },
165
+ onMouseEnter: function onMouseEnter(e) {
166
+ return e.target.style.color = '#0056b3';
167
+ },
168
+ onMouseLeave: function onMouseLeave(e) {
169
+ return e.target.style.color = '#007bff';
170
+ }
171
+ }, value.text || 'Link');
172
+ default:
173
+ return value;
174
+ }
175
+ };
176
+ return /*#__PURE__*/_react["default"].createElement("div", {
177
+ style: {
178
+ background: 'white',
179
+ margin: '20px 0',
180
+ padding: '30px',
181
+ borderRadius: '15px',
182
+ boxShadow: '0 4px 20px rgba(0,0,0,0.1)'
183
+ }
184
+ }, /*#__PURE__*/_react["default"].createElement("div", {
185
+ style: {
186
+ display: 'flex',
187
+ justifyContent: 'space-between',
188
+ alignItems: 'center',
189
+ marginBottom: '25px',
190
+ borderBottom: "3px solid ".concat(gradientColors),
191
+ paddingBottom: '15px'
192
+ }
193
+ }, /*#__PURE__*/_react["default"].createElement("h2", {
194
+ style: {
195
+ color: '#2c3e50',
196
+ fontSize: '2em',
197
+ margin: 0
198
+ }
199
+ }, title), customHeader), description && /*#__PURE__*/_react["default"].createElement("p", {
200
+ style: {
201
+ textAlign: 'center',
202
+ color: '#7f8c8d',
203
+ fontSize: '1.1em',
204
+ marginBottom: '30px'
205
+ }
206
+ }, description), /*#__PURE__*/_react["default"].createElement("div", {
207
+ style: {
208
+ overflowX: 'auto',
209
+ WebkitOverflowScrolling: 'touch',
210
+ display: isMobile ? 'none' : 'block'
211
+ }
212
+ }, /*#__PURE__*/_react["default"].createElement("table", {
213
+ style: {
214
+ width: '100%',
215
+ borderCollapse: 'collapse',
216
+ background: 'white',
217
+ borderRadius: '8px',
218
+ overflow: 'hidden',
219
+ boxShadow: '0 2px 10px rgba(0,0,0,0.1)'
220
+ }
221
+ }, /*#__PURE__*/_react["default"].createElement("thead", null, /*#__PURE__*/_react["default"].createElement("tr", {
222
+ style: {
223
+ background: "linear-gradient(135deg, ".concat(gradientColors, " 0%, ").concat(gradientColors, "dd 100%)"),
224
+ color: 'white'
225
+ }
226
+ }, columns.map(function (column) {
227
+ return /*#__PURE__*/_react["default"].createElement("th", {
228
+ key: column.key,
229
+ style: {
230
+ padding: '15px 12px',
231
+ textAlign: column.align || 'left',
232
+ fontWeight: '600',
233
+ fontSize: '0.9em',
234
+ width: column.width
235
+ }
236
+ }, column.label);
237
+ }))), /*#__PURE__*/_react["default"].createElement("tbody", null, data.map(function (row, index) {
238
+ return /*#__PURE__*/_react["default"].createElement("tr", {
239
+ key: index,
240
+ style: {
241
+ borderBottom: '1px solid #e9ecef'
242
+ }
243
+ }, columns.map(function (column) {
244
+ return /*#__PURE__*/_react["default"].createElement("td", {
245
+ key: column.key,
246
+ style: {
247
+ padding: '12px',
248
+ textAlign: column.align || 'left',
249
+ fontSize: column.type === 'text' ? '0.95em' : '0.9em',
250
+ fontWeight: column.type === 'text' ? '600' : 'normal'
251
+ }
252
+ }, column.render ? column.render(row[column.key] || null, row) : renderCell(column, row[column.key], row));
253
+ }));
254
+ })))), mobileCardConfig && /*#__PURE__*/_react["default"].createElement("div", {
255
+ style: {
256
+ display: isMobile ? 'block' : 'none'
257
+ }
258
+ }, /*#__PURE__*/_react["default"].createElement("div", {
259
+ style: {
260
+ display: 'flex',
261
+ flexDirection: 'column',
262
+ gap: '16px'
263
+ }
264
+ }, data.map(function (row, index) {
265
+ var _columns$find, _columns$find2;
266
+ return /*#__PURE__*/_react["default"].createElement("div", {
267
+ key: index,
268
+ style: {
269
+ background: 'white',
270
+ borderRadius: '12px',
271
+ padding: '20px',
272
+ boxShadow: '0 2px 10px rgba(0,0,0,0.1)',
273
+ border: '1px solid #e9ecef'
274
+ }
275
+ }, /*#__PURE__*/_react["default"].createElement("div", {
276
+ style: {
277
+ display: 'flex',
278
+ alignItems: 'flex-start',
279
+ gap: '12px',
280
+ marginBottom: '12px'
281
+ }
282
+ }, mobileCardConfig.iconKey && /*#__PURE__*/_react["default"].createElement("span", {
283
+ style: {
284
+ fontSize: '1.5em'
285
+ }
286
+ }, row[mobileCardConfig.iconKey]), /*#__PURE__*/_react["default"].createElement("div", {
287
+ style: {
288
+ flex: 1
289
+ }
290
+ }, /*#__PURE__*/_react["default"].createElement("h3", {
291
+ style: {
292
+ margin: '0 0 4px 0',
293
+ fontSize: '1.1rem',
294
+ fontWeight: '600',
295
+ color: '#2c3e50'
296
+ }
297
+ }, mobileCardConfig.renderTitle ? mobileCardConfig.renderTitle(row) : row[mobileCardConfig.titleKey]), mobileCardConfig.subtitleKey && /*#__PURE__*/_react["default"].createElement("p", {
298
+ style: {
299
+ margin: 0,
300
+ fontSize: '0.9rem',
301
+ color: '#6c757d',
302
+ lineHeight: '1.4'
303
+ }
304
+ }, mobileCardConfig.renderSubtitle ? mobileCardConfig.renderSubtitle(row) : row[mobileCardConfig.subtitleKey]))), mobileCardConfig.tags && /*#__PURE__*/_react["default"].createElement("div", {
305
+ style: {
306
+ display: 'flex',
307
+ gap: '8px',
308
+ marginBottom: '16px',
309
+ flexWrap: 'wrap'
310
+ }
311
+ }, mobileCardConfig.tags.map(function (tagKey) {
312
+ var value = row[tagKey];
313
+ var column = columns.find(function (col) {
314
+ return col.key === tagKey;
315
+ });
316
+ if (!value && tagKey !== 'status') return null;
317
+
318
+ // Use custom render function if available, otherwise use default styling
319
+ if (column !== null && column !== void 0 && column.render) {
320
+ return /*#__PURE__*/_react["default"].createElement("span", {
321
+ key: tagKey
322
+ }, column.render(value, row));
323
+ }
324
+ return /*#__PURE__*/_react["default"].createElement("span", {
325
+ key: tagKey,
326
+ style: {
327
+ background: getStatusColor(value || 'Proposed'),
328
+ color: getStatusTextColor(value || 'Proposed'),
329
+ padding: '4px 8px',
330
+ borderRadius: '12px',
331
+ fontSize: '0.8rem',
332
+ fontWeight: '500'
333
+ }
334
+ }, value || 'Proposed');
335
+ })), columns.find(function (col) {
336
+ return col.type === 'progress';
337
+ }) && /*#__PURE__*/_react["default"].createElement("div", {
338
+ style: {
339
+ marginBottom: '16px'
340
+ }
341
+ }, /*#__PURE__*/_react["default"].createElement("div", {
342
+ style: {
343
+ display: 'flex',
344
+ justifyContent: 'space-between',
345
+ alignItems: 'center',
346
+ marginBottom: '8px'
347
+ }
348
+ }, /*#__PURE__*/_react["default"].createElement("span", {
349
+ style: {
350
+ fontSize: '0.9rem',
351
+ fontWeight: '600'
352
+ }
353
+ }, "Progress"), /*#__PURE__*/_react["default"].createElement("span", {
354
+ style: {
355
+ fontSize: '0.9rem',
356
+ fontWeight: '600',
357
+ color: '#28a745'
358
+ }
359
+ }, row[((_columns$find = columns.find(function (col) {
360
+ return col.type === 'progress';
361
+ })) === null || _columns$find === void 0 ? void 0 : _columns$find.key) || ''], "%")), /*#__PURE__*/_react["default"].createElement("div", {
362
+ style: {
363
+ width: '100%',
364
+ height: '8px',
365
+ background: '#e9ecef',
366
+ borderRadius: '4px',
367
+ overflow: 'hidden'
368
+ }
369
+ }, /*#__PURE__*/_react["default"].createElement("div", {
370
+ style: {
371
+ width: "".concat(row[((_columns$find2 = columns.find(function (col) {
372
+ return col.type === 'progress';
373
+ })) === null || _columns$find2 === void 0 ? void 0 : _columns$find2.key) || ''], "%"),
374
+ height: '100%',
375
+ background: '#28a745',
376
+ borderRadius: '4px'
377
+ }
378
+ }))), mobileCardConfig.metaInfo && /*#__PURE__*/_react["default"].createElement("div", {
379
+ style: {
380
+ display: 'flex',
381
+ justifyContent: 'space-between',
382
+ alignItems: 'center',
383
+ fontSize: '0.85rem',
384
+ color: '#6c757d'
385
+ }
386
+ }, mobileCardConfig.metaInfo.map(function (infoKey) {
387
+ var column = columns.find(function (col) {
388
+ return col.key === infoKey;
389
+ });
390
+ var value = row[infoKey];
391
+ return /*#__PURE__*/_react["default"].createElement("span", {
392
+ key: infoKey
393
+ }, column !== null && column !== void 0 && column.render ? column.render(value, row) : value);
394
+ })), /*#__PURE__*/_react["default"].createElement("div", {
395
+ style: {
396
+ display: 'flex',
397
+ gap: '8px',
398
+ marginTop: '16px',
399
+ justifyContent: 'flex-start'
400
+ }
401
+ }, columns.filter(function (col) {
402
+ return col.type === 'action' || col.type === 'vote';
403
+ }).map(function (column) {
404
+ return /*#__PURE__*/_react["default"].createElement("div", {
405
+ key: column.key
406
+ }, column.render ? column.render(row[column.key] || null, row) : renderCell(column, row[column.key], row));
407
+ })));
408
+ }))));
409
+ };
410
+ PowrTable.propTypes = {
411
+ data: _propTypes["default"].array.isRequired,
412
+ columns: _propTypes["default"].arrayOf(_propTypes["default"].shape({
413
+ key: _propTypes["default"].string.isRequired,
414
+ label: _propTypes["default"].string.isRequired,
415
+ type: _propTypes["default"].oneOf(['text', 'badge', 'progress', 'action', 'link', 'vote']).isRequired,
416
+ align: _propTypes["default"].oneOf(['left', 'center', 'right']),
417
+ width: _propTypes["default"].string,
418
+ render: _propTypes["default"].func
419
+ })).isRequired,
420
+ title: _propTypes["default"].string.isRequired,
421
+ description: _propTypes["default"].string,
422
+ gradientColors: _propTypes["default"].string.isRequired,
423
+ onAction: _propTypes["default"].func,
424
+ mobileCardConfig: _propTypes["default"].shape({
425
+ titleKey: _propTypes["default"].string.isRequired,
426
+ subtitleKey: _propTypes["default"].string,
427
+ iconKey: _propTypes["default"].string,
428
+ tags: _propTypes["default"].arrayOf(_propTypes["default"].string),
429
+ metaInfo: _propTypes["default"].arrayOf(_propTypes["default"].string),
430
+ renderTitle: _propTypes["default"].func,
431
+ renderSubtitle: _propTypes["default"].func
432
+ }),
433
+ customHeader: _propTypes["default"].node
434
+ };
435
+ var _default = exports["default"] = PowrTable;
package/package.json CHANGED
@@ -1,43 +1,43 @@
1
- {
2
- "name": "powr-sdk-web",
3
- "version": "2.0.16",
4
- "main": "dist/index.js",
5
-
6
- "scripts": {
7
- "build": "babel src -d dist --copy-files",
8
- "prepublishOnly": "npm run build"
9
- },
10
- "keywords": [
11
- "react",
12
- "component",
13
- "npm",
14
- "file-upload",
15
- "powrbase",
16
- "comments"
17
- ],
18
- "author": "Lawazia Tech",
19
- "license": "MIT",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/lawaziatech/react-byto.git"
23
- },
24
- "peerDependencies": {
25
- "react": "*",
26
- "react-dom": "*",
27
- "react-toastify": "*",
28
- "filepond": "*"
29
- },
30
- "dependencies": {
31
- "react-hook-form": "^7.58.0",
32
- "axios": "^1.7.7",
33
- "react-filepond": "^7.1.2",
34
- "filepond": "^4.30.4"
35
- },
36
- "devDependencies": {
37
- "@babel/cli": "^7.24.1",
38
- "@babel/core": "^7.24.4",
39
- "@babel/preset-env": "^7.24.4",
40
- "@babel/preset-react": "^7.24.1",
41
- "prop-types": "^15.8.1"
42
- }
43
- }
1
+ {
2
+ "name": "powr-sdk-web",
3
+ "version": "2.2.0",
4
+ "main": "dist/index.js",
5
+ "scripts": {
6
+ "build": "babel src -d dist --copy-files",
7
+ "prepublishOnly": "npm run build"
8
+ },
9
+ "keywords": [
10
+ "react",
11
+ "component",
12
+ "npm",
13
+ "file-upload",
14
+ "powrbase",
15
+ "comments"
16
+ ],
17
+ "author": "Lawazia Tech",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/lawaziatech/react-byto.git"
22
+ },
23
+ "peerDependencies": {
24
+ "filepond": "*",
25
+ "react": "*",
26
+ "react-dom": "*",
27
+ "react-toastify": "*"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^1.7.7",
31
+ "filepond": "*",
32
+ "powr-sdk-web": "^2.1.0",
33
+ "react-filepond": "^7.1.2",
34
+ "react-hook-form": "^7.58.0"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/cli": "^7.24.1",
38
+ "@babel/core": "^7.24.4",
39
+ "@babel/preset-env": "^7.24.4",
40
+ "@babel/preset-react": "^7.24.1",
41
+ "prop-types": "^15.8.1"
42
+ }
43
+ }