@portnet/ui 0.1.37 → 0.1.38

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.
@@ -18,8 +18,9 @@ var _PuiCheckbox = _interopRequireDefault(require("../inputs/PuiCheckbox"));
18
18
  var _PuiIcon = _interopRequireDefault(require("../others/PuiIcon"));
19
19
  var _PuiTooltip = _interopRequireDefault(require("../others/PuiTooltip"));
20
20
  var _PuiTableAction = _interopRequireDefault(require("./PuiTableAction"));
21
- var _ActionPopover = _interopRequireDefault(require("./ActionPopover"));
22
21
  var _system = require("@mui/system");
22
+ var _KeyboardArrowDown = _interopRequireDefault(require("@mui/icons-material/KeyboardArrowDown"));
23
+ var _KeyboardArrowUp = _interopRequireDefault(require("@mui/icons-material/KeyboardArrowUp"));
23
24
  var _jsxRuntime = require("react/jsx-runtime");
24
25
  const _excluded = ["id", "className", "sx", "elevate", "rows", "rowCount", "columns", "paginationMode", "page", "pageSize", "checkboxSelection", "loading", "stripped", "actions", "oneActionOnly", "onSelect", "onPageChange", "onPageSizeChange", "rowDetailPanel"];
25
26
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
@@ -34,122 +35,107 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
34
35
  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); }
35
36
  const StyledMuiTable = (0, _styles.styled)( /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_xDataGrid.DataGrid, _objectSpread({
36
37
  ref: ref
37
- }, props))))(() => {
38
- return {
39
- "&.MuiDataGrid-root": {
40
- fontSize: ".8em",
41
- "& .tableActionColumn": {
42
- "& .MuiDataGrid-columnHeaderTitle": {
43
- justifyContent: "center",
44
- display: "flex"
45
- },
46
- "& .MuiDataGrid-columnHeaderTitleContainer": {
47
- justifyContent: "center"
48
- }
38
+ }, props))))(() => ({
39
+ "&.MuiDataGrid-root": {
40
+ fontSize: ".8em",
41
+ "& .tableActionColumn": {
42
+ "& .MuiDataGrid-columnHeaderTitle": {
43
+ justifyContent: "center",
44
+ display: "flex"
49
45
  },
50
- "&.elevate": {
51
- boxShadow: "0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 1px 3px 0px rgb(0 0 0 / 12%)"
52
- },
53
- backgroundColor: _apperance.palette.gray.light,
54
- border: "2px solid ".concat(_apperance.palette.gray.dark),
55
- "& .MuiPaginationItem-root": {
56
- "&.Mui-selected": {
57
- color: _apperance.palette.white,
58
- backgroundColor: _apperance.palette.primary
59
- }
60
- },
61
- "&.table-loading .MuiDataGrid-virtualScroller, &.table-loading .MuiDataGrid-footerContainer": {
62
- filter: "blur(1px)",
63
- "&::before": {
64
- content: "''",
65
- width: "100%",
66
- height: "100%",
67
- backgroundColor: _apperance.palette.white,
68
- position: "absolute",
69
- zIndex: 1,
70
- display: "block",
71
- opacity: 0
72
- }
73
- },
74
- "&.table-stripped .MuiDataGrid-row": {
75
- "&:nth-of-type(even)": {
76
- backgroundColor: _apperance.palette.gray.light
77
- }
78
- },
79
- "& .MuiLinearProgress-root": {
80
- zIndex: 1,
81
- backgroundColor: _apperance.palette.info,
82
- "& .MuiLinearProgress-bar": {
83
- backgroundColor: _apperance.palette.primary
84
- }
85
- },
86
- "& .MuiDataGrid-columnHeaders": {
87
- "& .MuiDataGrid-columnHeader": {
88
- "& .MuiDataGrid-columnHeaderTitle": {
89
- display: "flex",
90
- alignItems: "center",
91
- fontWeight: "600",
92
- color: _apperance.palette.primary,
93
- whiteSpace: "normal",
94
- lineHeight: "1.2em"
95
- },
96
- "&:focus-within": {
97
- outline: "none"
98
- },
99
- "&:last-of-type .MuiDataGrid-columnSeparator": {
100
- display: "none"
101
- }
102
- },
103
- "& .MuiDataGrid-columnSeparator": {
104
- color: _apperance.palette.gray.dark
105
- }
106
- },
107
- "& .MuiDataGrid-cell": {
108
- paddingTop: "2px",
109
- paddingBottom: "2px",
110
- whiteSpace: "normal",
111
- textOverflow: "ellipsis",
112
- overflow: "hidden",
113
- maxHeight: "none",
114
- minWidth: 'maxWidth',
115
- wordBreak: "break-word",
116
- "&.tableAction": {
117
- justifyContent: "center",
118
- position: "relative",
119
- overflow: "initial !important"
46
+ "& .MuiDataGrid-columnHeaderTitleContainer": {
47
+ justifyContent: "center"
48
+ }
49
+ },
50
+ "&.elevate": {
51
+ boxShadow: "0px 2px 1px -1px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 1px 3px 0px rgb(0 0 0 / 12%)"
52
+ },
53
+ backgroundColor: _apperance.palette.gray.light,
54
+ border: "2px solid ".concat(_apperance.palette.gray.dark),
55
+ "& .MuiPaginationItem-root": {
56
+ "&.Mui-selected": {
57
+ color: _apperance.palette.white,
58
+ backgroundColor: _apperance.palette.primary
59
+ }
60
+ },
61
+ "& .table-stripped .MuiDataGrid-row": {
62
+ "&:nth-of-type(even)": {
63
+ backgroundColor: _apperance.palette.gray.light
64
+ }
65
+ },
66
+ "& .MuiLinearProgress-root": {
67
+ zIndex: 1,
68
+ backgroundColor: _apperance.palette.info,
69
+ "& .MuiLinearProgress-bar": {
70
+ backgroundColor: _apperance.palette.primary
71
+ }
72
+ },
73
+ "& .MuiDataGrid-columnHeaders": {
74
+ "& .MuiDataGrid-columnHeader": {
75
+ "& .MuiDataGrid-columnHeaderTitle": {
76
+ display: "flex",
77
+ alignItems: "center",
78
+ fontWeight: "600",
79
+ color: _apperance.palette.primary,
80
+ whiteSpace: "normal",
81
+ lineHeight: "1.2em"
120
82
  },
121
83
  "&:focus-within": {
122
84
  outline: "none"
123
- }
124
- },
125
- "& .MuiDataGrid-row": {
126
- maxHeight: "none !important",
127
- "&:nth-of-type(odd)": {
128
- backgroundColor: "#ffffff" // color for odd rows
129
- },
130
- "&:nth-of-type(even)": {
131
- backgroundColor: "#F6F9FF" // color for even rows
132
85
  },
133
- "&:hover": {
134
- backgroundColor: "#95C7FC"
86
+ "&:last-of-type .MuiDataGrid-columnSeparator": {
87
+ display: "none"
135
88
  }
136
89
  },
137
- "& .MuiDataGrid-virtualScrollerContent": {
138
- "& .MuiDataGrid-row": {
139
- maxHeight: "none !important"
140
- }
90
+ "& .MuiDataGrid-columnSeparator": {
91
+ color: _apperance.palette.gray.dark
92
+ }
93
+ },
94
+ "& .MuiDataGrid-cell": {
95
+ paddingTop: "2px",
96
+ paddingBottom: "2px",
97
+ whiteSpace: "normal",
98
+ textOverflow: "ellipsis",
99
+ overflow: "hidden",
100
+ maxHeight: "none",
101
+ minWidth: "maxWidth",
102
+ wordBreak: "break-word",
103
+ "&.tableAction": {
104
+ justifyContent: "center",
105
+ position: "relative",
106
+ overflow: "initial !important"
141
107
  },
142
- "& .MuiDataGrid-virtualScroller": {
143
- backgroundColor: _apperance.palette.white
108
+ "&:focus-within": {
109
+ outline: "none"
110
+ }
111
+ },
112
+ "& .MuiDataGrid-row": {
113
+ maxHeight: "none !important",
114
+ "&:nth-of-type(odd)": {
115
+ backgroundColor: "#ffffff" // color for odd rows
116
+ },
117
+ "&:nth-of-type(even)": {
118
+ backgroundColor: "#F6F9FF" // color for even rows
144
119
  },
145
- "& .MuiDataGrid-footerContainer": {
146
- backgroundColor: _apperance.palette.white,
147
- height: "28px",
148
- minHeight: "28px"
120
+ "&:hover": {
121
+ backgroundColor: "#95C7FC"
122
+ }
123
+ },
124
+ "& .MuiDataGrid-virtualScrollerContent": {
125
+ "& .MuiDataGrid-row": {
126
+ maxHeight: "none !important"
149
127
  }
128
+ },
129
+ "& .MuiDataGrid-virtualScroller": {
130
+ backgroundColor: _apperance.palette.white
131
+ },
132
+ "& .MuiDataGrid-footerContainer": {
133
+ backgroundColor: _apperance.palette.white,
134
+ height: "28px",
135
+ minHeight: "28px"
150
136
  }
151
- };
152
- });
137
+ }
138
+ }));
153
139
  const localeText = {
154
140
  noRowsLabel: "Aucune ligne",
155
141
  footerRowSelected: count => count !== 1 ? "".concat(count.toLocaleString(), " lignes s\xE9lectionn\xE9es") : "".concat(count.toLocaleString(), " ligne s\xE9lectionn\xE9e"),
@@ -166,76 +152,6 @@ const localeText = {
166
152
  labelRowsPerPage: "Lignes par page"
167
153
  }
168
154
  };
169
- const TableActions = _ref2 => {
170
- let {
171
- row,
172
- actions
173
- } = _ref2;
174
- const [isOpen, setIsOpen] = React.useState(false);
175
- const actionsRef = React.useRef();
176
- const outsideClickHandler = React.useCallback(event => {
177
- if (Boolean(actionsRef.current) && !actionsRef.current.contains(event.target)) {
178
- closeHandler();
179
- }
180
- if (!Boolean(actionsRef.current)) {
181
- document.removeEventListener("mouseup", outsideClickHandler, false);
182
- }
183
- // eslint-disable-next-line react-hooks/exhaustive-deps
184
- }, []);
185
- const openHandler = () => {
186
- document.addEventListener("mouseup", outsideClickHandler, false);
187
- setIsOpen(true);
188
- };
189
- const closeHandler = () => {
190
- document.removeEventListener("mouseup", outsideClickHandler, false);
191
- setIsOpen(false);
192
- };
193
- React.useEffect(() => {
194
- return () => {
195
- document.removeEventListener("mouseup", outsideClickHandler, false);
196
- };
197
- // eslint-disable-next-line react-hooks/exhaustive-deps
198
- }, []);
199
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
200
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiTableAction.default, {
201
- title: "Voir plus",
202
- color: "primary",
203
- onClick: openHandler,
204
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiIcon.default, {
205
- type: "voir-plus"
206
- })
207
- }), Boolean(isOpen) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Paper, {
208
- ref: actionsRef,
209
- elevation: 1,
210
- sx: {
211
- borderRadius: "5px",
212
- position: "absolute",
213
- right: "0",
214
- top: "50%",
215
- transform: "translate(0, -50%)",
216
- display: "flex",
217
- alignItems: "center",
218
- gap: "8px",
219
- paddingX: "11px",
220
- height: "calc(100% - 4px)",
221
- backgroundColor: _apperance.palette.gray.light,
222
- border: "2px solid ".concat(_apperance.palette.gray.dark)
223
- },
224
- children: [actions.map((action, index) => /*#__PURE__*/React.cloneElement(action, {
225
- row,
226
- key: index
227
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiTableAction.default, {
228
- size: "small",
229
- title: "Fermer",
230
- color: "primary",
231
- onClick: closeHandler,
232
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiIcon.default, {
233
- type: "voir-plus"
234
- })
235
- })]
236
- })]
237
- });
238
- };
239
155
  const TablePagination = () => {
240
156
  const apiRef = (0, _xDataGrid.useGridApiContext)();
241
157
  const page = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridPageSelector);
@@ -275,7 +191,7 @@ const autosizeOptions = {
275
191
  includeHeaders: true,
276
192
  includeOutliers: true
277
193
  };
278
- const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
194
+ const PuiTable = /*#__PURE__*/React.forwardRef((_ref2, ref) => {
279
195
  let {
280
196
  id,
281
197
  className,
@@ -296,82 +212,53 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
296
212
  onPageChange,
297
213
  onPageSizeChange,
298
214
  rowDetailPanel
299
- } = _ref3,
300
- rest = _objectWithoutProperties(_ref3, _excluded);
301
- const [appColumns, setAppColumns] = React.useState(columns);
302
- React.useEffect(() => {
303
- const newColumns = Boolean(actions.length) ? [...columns, {
304
- field: "action",
305
- headerName: "Actions",
306
- sortable: false,
307
- filterable: false,
308
- width: 100,
309
- renderCell: _ref4 => {
310
- let {
311
- row
312
- } = _ref4;
313
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_system.Box, {
314
- sx: {
315
- display: 'flex',
316
- gap: '8px',
317
- // Adjust the space between icons as needed
318
- flexWrap: 'wrap',
319
- // Keep icons on the same line; remove if you want them to wrap
320
- justifyContent: 'center',
321
- // Center the icons horizontally
322
- alignItems: 'center',
323
- // Align icons vertically
324
- minWidth: 0 // Prevent the flex container from stretching past its content width
325
- },
326
- children: actions.map((action, index) => /*#__PURE__*/React.cloneElement(action, {
327
- row,
328
- key: index,
329
- sx: _objectSpread(_objectSpread({}, action.props.sx), {}, {
330
- marginRight: 0,
331
- // Remove any outer margins
332
- '&:last-child': {
333
- marginRight: 0 // Ensure the last item doesn't push the container width
334
- }
335
- })
336
- }))
337
- });
338
- },
339
- cellClassName: "tableAction",
340
- headerClassName: "tableActionColumn"
341
- }] : columns;
342
- setAppColumns(newColumns.map(column => {
343
- const renderCell = Boolean(column.renderCell) ? column.renderCell : Boolean(column.valueGetter) ? columnData => /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiTooltip.default, {
344
- title: Boolean(column.titleGetter) ? column.titleGetter(columnData.row) : String(column.valueGetter(columnData)),
345
- children: column.valueGetter(columnData)
346
- }) : Boolean(column.field) ? _ref5 => {
347
- let {
348
- row
349
- } = _ref5;
350
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PuiTooltip.default, {
351
- title: Boolean(column.titleGetter) ? column.titleGetter(row) : String(row[column.field]),
352
- children: row[column.field]
353
- });
354
- } : undefined;
355
- return _objectSpread(_objectSpread({}, column), {}, {
356
- renderCell
357
- });
215
+ } = _ref2,
216
+ rest = _objectWithoutProperties(_ref2, _excluded);
217
+ const [expandedRows, setExpandedRows] = React.useState({});
218
+ const toggleRowExpansion = rowId => {
219
+ setExpandedRows(prevState => _objectSpread(_objectSpread({}, prevState), {}, {
220
+ [rowId]: !prevState[rowId]
358
221
  }));
359
- // eslint-disable-next-line react-hooks/exhaustive-deps
360
- }, [actions, columns]);
361
- const renderRowDetailPanel = params => {
362
- const {
363
- data
364
- } = params;
365
- // Render the passed rowDetailPanel component with the row data
366
- return /*#__PURE__*/React.cloneElement(rowDetailPanel, {
367
- rowData: data
222
+ };
223
+ const renderRowDetails = row => {
224
+ console.log("row ==", row);
225
+ if (!row) return null; // Ensure row exists
226
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Collapse, {
227
+ in: expandedRows[row.id],
228
+ timeout: "auto",
229
+ unmountOnExit: true,
230
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_system.Box, {
231
+ sx: {
232
+ padding: 2
233
+ },
234
+ children: rowDetailPanel && /*#__PURE__*/React.cloneElement(rowDetailPanel, {
235
+ rowData: row
236
+ })
237
+ })
368
238
  });
369
239
  };
370
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
240
+ const appColumns = React.useMemo(() => [{
241
+ field: "expand",
242
+ headerName: "",
243
+ sortable: false,
244
+ width: 50,
245
+ renderCell: _ref3 => {
246
+ let {
247
+ row
248
+ } = _ref3;
249
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
250
+ "aria-label": "expand row",
251
+ size: "small",
252
+ onClick: () => toggleRowExpansion(row.id),
253
+ children: expandedRows[row.id] ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_KeyboardArrowUp.default, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_KeyboardArrowDown.default, {})
254
+ });
255
+ }
256
+ }, ...columns], [columns, expandedRows]);
257
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
371
258
  style: {
372
- width: '100%'
259
+ width: "100%"
373
260
  },
374
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledMuiTable, _objectSpread({
261
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(StyledMuiTable, _objectSpread({
375
262
  ref: ref,
376
263
  id: id,
377
264
  components: {
@@ -404,13 +291,14 @@ const PuiTable = /*#__PURE__*/React.forwardRef((_ref3, ref) => {
404
291
  loading: loading,
405
292
  paginationMode: paginationMode,
406
293
  localeText: localeText,
407
- getRowHeight: () => 'auto',
294
+ getRowHeight: () => "auto",
408
295
  onPageChange: onPageChange,
409
296
  onPageSizeChange: onPageSizeChange,
410
297
  onSelectionModelChange: onSelect,
411
- autosizeOptions: autosizeOptions,
412
- rowDetailPanel: renderRowDetailPanel
413
- }, rest))
298
+ autosizeOptions: autosizeOptions
299
+ }, rest)), rows.map(row => /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
300
+ children: expandedRows[row.id] && renderRowDetails(row)
301
+ }, row.id))]
414
302
  });
415
303
  });
416
304
  PuiTable.propTypes = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portnet/ui",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "Portnet UI",
5
5
  "keywords": [
6
6
  "react",