@portnet/ui 3.0.7 → 3.1.2

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,427 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/esnext.iterator.filter.js");
4
+ require("core-js/modules/esnext.iterator.for-each.js");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ require("core-js/modules/esnext.iterator.constructor.js");
10
+ require("core-js/modules/esnext.iterator.map.js");
11
+ var _react = _interopRequireDefault(require("react"));
12
+ var _propTypes = _interopRequireDefault(require("prop-types"));
13
+ var _material = require("@mui/material");
14
+ var _styles = require("@mui/material/styles");
15
+ var _apperance = require("../../config/apperance");
16
+ var _PuiButton = _interopRequireDefault(require("../buttons/PuiButton"));
17
+ var _iconsMaterial = require("@mui/icons-material");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ const _excluded = ["title", "data", "columns", "actions", "loading", "pagination", "currentPage", "totalPages", "onPageChange", "emptyMessage", "className"]; // Container principal du tableau moderne
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
25
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
27
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
28
+ const ModernTableContainer = (0, _styles.styled)(_material.Box)(() => ({
29
+ display: 'flex',
30
+ flexDirection: 'column',
31
+ gap: '16px',
32
+ padding: '24px',
33
+ backgroundColor: _apperance.palette.background.default,
34
+ borderRadius: '12px',
35
+ minHeight: '400px'
36
+ }));
37
+
38
+ // Header du tableau
39
+ const TableHeader = (0, _styles.styled)(_material.Box)(() => ({
40
+ display: 'flex',
41
+ justifyContent: 'space-between',
42
+ alignItems: 'center',
43
+ marginBottom: '16px',
44
+ borderBottom: "2px solid ".concat(_apperance.palette.border.light),
45
+ paddingBottom: '16px'
46
+ }));
47
+
48
+ // Conteneur des cartes
49
+ const CardsContainer = (0, _styles.styled)(_material.Box)(() => ({
50
+ display: 'flex',
51
+ flexDirection: 'column',
52
+ gap: '12px',
53
+ flex: 1
54
+ }));
55
+
56
+ // Card individuelle pour chaque ligne
57
+ const TableCard = (0, _styles.styled)(_material.Box)(() => ({
58
+ display: 'flex',
59
+ alignItems: 'center',
60
+ justifyContent: 'space-between',
61
+ padding: '16px 20px',
62
+ backgroundColor: _apperance.palette.background.paper,
63
+ borderRadius: '8px',
64
+ border: "1px solid ".concat(_apperance.palette.border.light),
65
+ boxShadow: _apperance.palette.shadow.card,
66
+ transition: 'all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1)',
67
+ '&:hover': {
68
+ transform: 'translateY(-1px)',
69
+ boxShadow: _apperance.palette.shadow.medium,
70
+ borderColor: "".concat(_apperance.palette.primary, "30")
71
+ },
72
+ // Responsive
73
+ '@media (max-width: 768px)': {
74
+ flexDirection: 'column',
75
+ alignItems: 'stretch',
76
+ gap: '12px'
77
+ }
78
+ }));
79
+
80
+ // Section des données dans la card
81
+ const DataSection = (0, _styles.styled)(_material.Box)(() => ({
82
+ display: 'flex',
83
+ alignItems: 'center',
84
+ gap: '24px',
85
+ flex: 1,
86
+ '@media (max-width: 768px)': {
87
+ flexDirection: 'column',
88
+ alignItems: 'stretch',
89
+ gap: '8px'
90
+ }
91
+ }));
92
+
93
+ // Colonne de données
94
+ const DataColumn = (0, _styles.styled)(_material.Box)(() => ({
95
+ display: 'flex',
96
+ flexDirection: 'column',
97
+ gap: '2px',
98
+ minWidth: '0',
99
+ flex: 1
100
+ }));
101
+
102
+ // Label de colonne
103
+ const ColumnLabel = (0, _styles.styled)(_material.Typography)(() => ({
104
+ fontSize: '11px',
105
+ fontWeight: 600,
106
+ color: _apperance.palette.gray[500],
107
+ textTransform: 'uppercase',
108
+ letterSpacing: '0.5px'
109
+ }));
110
+
111
+ // Valeur de colonne
112
+ const ColumnValue = (0, _styles.styled)(_material.Typography)(() => ({
113
+ fontSize: '14px',
114
+ fontWeight: 500,
115
+ color: _apperance.palette.dark,
116
+ wordBreak: 'break-word'
117
+ }));
118
+
119
+ // Section des actions
120
+ const ActionsSection = (0, _styles.styled)(_material.Box)(() => ({
121
+ display: 'flex',
122
+ alignItems: 'center',
123
+ gap: '8px',
124
+ flexShrink: 0,
125
+ '@media (max-width: 768px)': {
126
+ justifyContent: 'center'
127
+ }
128
+ }));
129
+
130
+ // Footer avec pagination
131
+ const TableFooter = (0, _styles.styled)(_material.Box)(() => ({
132
+ display: 'flex',
133
+ justifyContent: 'center',
134
+ alignItems: 'center',
135
+ marginTop: '16px',
136
+ padding: '16px 0',
137
+ borderTop: "1px solid ".concat(_apperance.palette.border.light)
138
+ }));
139
+
140
+ // États de statut avec couleurs
141
+ const statusConfig = {
142
+ active: {
143
+ color: _apperance.palette.success,
144
+ icon: _iconsMaterial.CheckCircleRounded,
145
+ label: 'Actif'
146
+ },
147
+ expired: {
148
+ color: _apperance.palette.error,
149
+ icon: _iconsMaterial.ErrorRounded,
150
+ label: 'Expiré'
151
+ },
152
+ pending: {
153
+ color: _apperance.palette.warning,
154
+ icon: _iconsMaterial.AccessTimeRounded,
155
+ label: 'En attente'
156
+ },
157
+ processing: {
158
+ color: _apperance.palette.info,
159
+ icon: _iconsMaterial.RefreshRounded,
160
+ label: 'En cours'
161
+ }
162
+ };
163
+
164
+ // Types d'actions avec couleurs exactes extraites des maquettes
165
+ const actionConfig = {
166
+ validate: {
167
+ color: 'success',
168
+ icon: _iconsMaterial.CheckCircleRounded,
169
+ label: 'Validé',
170
+ bgColor: _apperance.palette.actions.validate,
171
+ // Vert Material Design des maquettes
172
+ textColor: '#fff'
173
+ },
174
+ expire: {
175
+ color: 'error',
176
+ icon: _iconsMaterial.ErrorRounded,
177
+ label: 'Expiré',
178
+ bgColor: _apperance.palette.actions.expire,
179
+ // Rouge Material Design des maquettes
180
+ textColor: '#fff'
181
+ },
182
+ renew: {
183
+ color: 'warning',
184
+ icon: _iconsMaterial.RefreshRounded,
185
+ label: 'Renouveler',
186
+ bgColor: _apperance.palette.actions.renew,
187
+ // Orange Material Design des maquettes
188
+ textColor: '#fff'
189
+ },
190
+ download: {
191
+ color: 'info',
192
+ icon: _iconsMaterial.DownloadRounded,
193
+ label: 'Télécharger',
194
+ bgColor: _apperance.palette.actions.download,
195
+ // Bleu Material Design des maquettes
196
+ textColor: '#fff'
197
+ },
198
+ processing: {
199
+ color: 'info',
200
+ icon: _iconsMaterial.AccessTimeRounded,
201
+ label: 'En cours',
202
+ bgColor: _apperance.palette.actions.processing,
203
+ // Violet Material Design des maquettes
204
+ textColor: '#fff'
205
+ },
206
+ souscrit: {
207
+ color: 'secondary',
208
+ icon: _iconsMaterial.CheckCircleRounded,
209
+ label: 'Souscrit',
210
+ bgColor: _apperance.palette.actions.souscrit,
211
+ // Gris bleu Material Design des maquettes
212
+ textColor: '#fff'
213
+ }
214
+ };
215
+
216
+ /**
217
+ * Composant de tableau moderne basé sur la maquette
218
+ */
219
+ const PuiModernTable = _ref => {
220
+ let {
221
+ title,
222
+ data = [],
223
+ columns = [],
224
+ actions = [],
225
+ loading = false,
226
+ pagination = true,
227
+ currentPage = 1,
228
+ totalPages = 1,
229
+ onPageChange,
230
+ emptyMessage = "Aucune donnée disponible",
231
+ className = ''
232
+ } = _ref,
233
+ props = _objectWithoutProperties(_ref, _excluded);
234
+ const renderColumnValue = (item, column) => {
235
+ if (column.render) {
236
+ return column.render(item[column.key], item);
237
+ }
238
+ if (column.type === 'status') {
239
+ const status = statusConfig[item[column.key]] || statusConfig.pending;
240
+ const IconComponent = status.icon;
241
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
242
+ sx: {
243
+ display: 'flex',
244
+ alignItems: 'center',
245
+ gap: '6px'
246
+ },
247
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, {
248
+ sx: {
249
+ fontSize: '16px',
250
+ color: status.color
251
+ }
252
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
253
+ style: {
254
+ color: status.color
255
+ },
256
+ children: status.label
257
+ })]
258
+ });
259
+ }
260
+ if (column.type === 'currency') {
261
+ return new Intl.NumberFormat('fr-FR', {
262
+ style: 'currency',
263
+ currency: 'MAD'
264
+ }).format(item[column.key] || 0);
265
+ }
266
+ if (column.type === 'date') {
267
+ return new Date(item[column.key]).toLocaleDateString('fr-FR');
268
+ }
269
+ return item[column.key] || '-';
270
+ };
271
+ const renderActions = item => {
272
+ return actions.map((action, index) => {
273
+ var _action$disabled;
274
+ const config = actionConfig[action.type] || actionConfig.validate;
275
+ const IconComponent = action.icon || config.icon;
276
+ const isDisabled = (_action$disabled = action.disabled) === null || _action$disabled === void 0 ? void 0 : _action$disabled.call(action, item);
277
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiButton.default, {
278
+ color: "primary",
279
+ size: "small",
280
+ startIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, {
281
+ sx: {
282
+ fontSize: '14px'
283
+ }
284
+ }),
285
+ onClick: () => {
286
+ var _action$onClick;
287
+ return (_action$onClick = action.onClick) === null || _action$onClick === void 0 ? void 0 : _action$onClick.call(action, item);
288
+ },
289
+ disabled: isDisabled,
290
+ sx: {
291
+ minWidth: 'auto',
292
+ padding: '6px 12px',
293
+ fontSize: '11px',
294
+ fontWeight: 500,
295
+ backgroundColor: isDisabled ? _apperance.palette.gray[300] : action.bgColor || config.bgColor,
296
+ color: isDisabled ? _apperance.palette.gray[500] : action.textColor || config.textColor,
297
+ border: 'none',
298
+ borderRadius: '6px',
299
+ textTransform: 'none',
300
+ '&:hover': {
301
+ backgroundColor: isDisabled ? _apperance.palette.gray[300] : "".concat(action.bgColor || config.bgColor, "dd"),
302
+ transform: isDisabled ? 'none' : 'translateY(-1px)'
303
+ },
304
+ '&:active': {
305
+ transform: isDisabled ? 'none' : 'translateY(0)'
306
+ }
307
+ },
308
+ children: action.label || config.label
309
+ }, index);
310
+ });
311
+ };
312
+ if (loading) {
313
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ModernTableContainer, _objectSpread(_objectSpread({
314
+ className: className
315
+ }, props), {}, {
316
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
317
+ sx: {
318
+ borderRadius: '4px'
319
+ }
320
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
321
+ sx: {
322
+ textAlign: 'center',
323
+ py: 4
324
+ },
325
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
326
+ variant: "body2",
327
+ color: "textSecondary",
328
+ children: "Chargement des donn\xE9es..."
329
+ })
330
+ })]
331
+ }));
332
+ }
333
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ModernTableContainer, _objectSpread(_objectSpread({
334
+ className: className
335
+ }, props), {}, {
336
+ children: [title && /*#__PURE__*/(0, _jsxRuntime.jsxs)(TableHeader, {
337
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
338
+ variant: "h5",
339
+ sx: {
340
+ fontWeight: 600,
341
+ color: _apperance.palette.dark
342
+ },
343
+ children: title
344
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
345
+ variant: "body2",
346
+ color: "textSecondary",
347
+ children: [data.length, " \xE9l\xE9ment", data.length > 1 ? 's' : '']
348
+ })]
349
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(CardsContainer, {
350
+ children: data.length === 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
351
+ sx: {
352
+ textAlign: 'center',
353
+ py: 6,
354
+ color: _apperance.palette.gray[500]
355
+ },
356
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
357
+ variant: "body1",
358
+ children: emptyMessage
359
+ })
360
+ }) : data.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(TableCard, {
361
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(DataSection, {
362
+ children: columns.map(column => /*#__PURE__*/(0, _jsxRuntime.jsxs)(DataColumn, {
363
+ style: {
364
+ flex: column.flex || 1
365
+ },
366
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(ColumnLabel, {
367
+ children: column.label
368
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(ColumnValue, {
369
+ children: renderColumnValue(item, column)
370
+ })]
371
+ }, column.key))
372
+ }), actions.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(ActionsSection, {
373
+ children: renderActions(item)
374
+ })]
375
+ }, item.id || index))
376
+ }), pagination && totalPages > 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(TableFooter, {
377
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Pagination, {
378
+ count: totalPages,
379
+ page: currentPage,
380
+ onChange: (event, page) => onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange(page),
381
+ color: "primary",
382
+ size: "medium",
383
+ showFirstButton: true,
384
+ showLastButton: true,
385
+ sx: {
386
+ '& .MuiPaginationItem-root': {
387
+ borderRadius: '6px',
388
+ '&.Mui-selected': {
389
+ backgroundColor: _apperance.palette.primary,
390
+ color: _apperance.palette.white,
391
+ '&:hover': {
392
+ backgroundColor: _apperance.palette.blue.dark
393
+ }
394
+ }
395
+ }
396
+ }
397
+ })
398
+ })]
399
+ }));
400
+ };
401
+ PuiModernTable.propTypes = {
402
+ title: _propTypes.default.string,
403
+ data: _propTypes.default.arrayOf(_propTypes.default.object),
404
+ columns: _propTypes.default.arrayOf(_propTypes.default.shape({
405
+ key: _propTypes.default.string.isRequired,
406
+ label: _propTypes.default.string.isRequired,
407
+ type: _propTypes.default.oneOf(['text', 'status', 'currency', 'date']),
408
+ flex: _propTypes.default.number,
409
+ render: _propTypes.default.func
410
+ })),
411
+ actions: _propTypes.default.arrayOf(_propTypes.default.shape({
412
+ type: _propTypes.default.oneOf(['renew', 'validate', 'expire', 'download']),
413
+ label: _propTypes.default.string,
414
+ color: _propTypes.default.oneOf(['primary', 'secondary', 'tertiary']),
415
+ icon: _propTypes.default.elementType,
416
+ onClick: _propTypes.default.func,
417
+ disabled: _propTypes.default.func
418
+ })),
419
+ loading: _propTypes.default.bool,
420
+ pagination: _propTypes.default.bool,
421
+ currentPage: _propTypes.default.number,
422
+ totalPages: _propTypes.default.number,
423
+ onPageChange: _propTypes.default.func,
424
+ emptyMessage: _propTypes.default.string,
425
+ className: _propTypes.default.string
426
+ };
427
+ var _default = exports.default = PuiModernTable;