@m4l/components 9.3.21-JT15102025.beta.1 → 9.3.21-JT20102025.beta.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.
@@ -38,8 +38,8 @@ function DataGrid(props) {
38
38
  size,
39
39
  externalSortSettings,
40
40
  externalFilterSettings,
41
- cardSettings,
42
- defaultViewMode
41
+ defaultViewMode,
42
+ cardsViewConfig
43
43
  } = props;
44
44
  const {
45
45
  withSettings,
@@ -93,8 +93,8 @@ function DataGrid(props) {
93
93
  size: currentSize,
94
94
  externalSortSettings,
95
95
  externalFilterSettings,
96
- cardSettings,
97
96
  defaultViewMode,
97
+ cardsViewConfig,
98
98
  children: /* @__PURE__ */ jsxs(FilterProvider, { initialActiveFilters: false, children: [
99
99
  withActions && actionsProps && /* @__PURE__ */ jsx(
100
100
  HeaderActions,
@@ -122,7 +122,7 @@ function DataGrid(props) {
122
122
  onSelectedRowsChange,
123
123
  rowKeyGetter,
124
124
  onRowsChange,
125
- cardSettings
125
+ cardsViewConfig
126
126
  }
127
127
  ),
128
128
  withPager && /* @__PURE__ */ jsx(
@@ -162,8 +162,8 @@ function DataGridProvider(props) {
162
162
  size,
163
163
  viewMode,
164
164
  onViewModeChange,
165
- cardSettings,
166
- defaultViewMode
165
+ defaultViewMode,
166
+ cardsViewConfig
167
167
  } = props;
168
168
  const isFirstRender = useFirstRender([columns, id]);
169
169
  const isMobile = useIsMobile();
@@ -270,7 +270,50 @@ function DataGridProvider(props) {
270
270
  }
271
271
  }
272
272
  }
273
- }, [columns, sortSettings, filterSettings]);
273
+ if (cardsViewConfig !== void 0) {
274
+ const hasCustomRender = cardsViewConfig.customRender !== void 0;
275
+ const hasColumnsConfig = cardsViewConfig.columnsConfig !== void 0 && cardsViewConfig.columnsConfig.length > 0;
276
+ if (!hasCustomRender && !hasColumnsConfig) {
277
+ throw new Error(
278
+ `DataGridProvider: cardsViewConfig.enabled=true requiere configurar al menos una de estas opciones:
279
+ - cardsViewConfig.customRender (renderizado personalizado)
280
+ - cardsViewConfig.columnsConfig (configuración de columnas con al menos 1 elemento)
281
+
282
+ Configuración actual:
283
+ - customRender: ${hasCustomRender ? "definido" : "undefined"}
284
+ - columnsConfig: ${cardsViewConfig.columnsConfig?.length || 0} columnas
285
+
286
+ Ejemplo válido con columnsConfig:
287
+ cardsViewConfig={{
288
+ enabled: true,
289
+ columnsConfig: [
290
+ { columnKey: 'name', showTitle: false },
291
+ { columnKey: 'email', showTitle: true }
292
+ ]
293
+ }}
294
+
295
+ Ejemplo válido con customRender:
296
+ cardsViewConfig={{
297
+ enabled: true,
298
+ customRender: {
299
+ renderContent: (row) => <CustomCard row={row} />,
300
+ minHeight: 200
301
+ }
302
+ }}
303
+ `
304
+ );
305
+ }
306
+ if (hasColumnsConfig && cardsViewConfig.columnsConfig) {
307
+ for (const cardCol of cardsViewConfig.columnsConfig) {
308
+ if (!keys.has(cardCol.columnKey)) {
309
+ throw new Error(
310
+ `DataGridProvider: cardsViewConfig.columnsConfig incluye columnKey="${cardCol.columnKey}", pero no existe ninguna columna con key="${cardCol.columnKey}".`
311
+ );
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }, [columns, sortSettings, filterSettings, cardsViewConfig]);
274
317
  const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
275
318
  let timerSaveColumns;
276
319
  useEffect(() => {
@@ -287,15 +330,29 @@ function DataGridProvider(props) {
287
330
  { originalFrozen: false }
288
331
  )
289
332
  );
333
+ const finalCardsConfig = (() => {
334
+ if (defaultUserColumns?.columnsConfigCards) {
335
+ return defaultUserColumns.columnsConfigCards;
336
+ }
337
+ if (cardsViewConfig?.columnsConfig) {
338
+ return cardsViewConfig.columnsConfig.map((colConfig, index) => ({
339
+ key: colConfig.columnKey,
340
+ visible: true,
341
+ index,
342
+ showTitle: colConfig.showTitle
343
+ }));
344
+ }
345
+ return void 0;
346
+ })();
290
347
  updateConfigColumns(
291
348
  "cards",
292
349
  getInitialColumnsConfig(
293
350
  id,
294
351
  columns,
295
352
  "cards",
296
- defaultUserColumns?.columnsConfigCards,
297
- { showTitle: true },
298
- { originalShowTitle: true }
353
+ finalCardsConfig,
354
+ { showTitle: false },
355
+ { originalShowTitle: false }
299
356
  )
300
357
  );
301
358
  }
@@ -335,9 +392,14 @@ function DataGridProvider(props) {
335
392
  );
336
393
  if (newColumnsForView.length > 0) {
337
394
  const colLength = currentConfig.length;
338
- const viewSpecific = getViewSpecificConfig(viewModeParam);
339
- const viewSpecificDefaults = viewSpecific.defaults;
340
- const originalViewSpecificDefaults = viewSpecific.originalDefaults;
395
+ const viewSpecificDefaults = viewModeParam === "cards" ? { showTitle: false } : {
396
+ frozen: false
397
+ };
398
+ const originalViewSpecificDefaults = viewModeParam === "cards" ? {
399
+ originalShowTitle: false
400
+ } : {
401
+ originalFrozen: false
402
+ };
341
403
  const newColConfig = getInitialColumnsConfig(
342
404
  id,
343
405
  newColumnsForView,
@@ -473,7 +535,7 @@ function DataGridProvider(props) {
473
535
  size,
474
536
  viewMode: viewModeState,
475
537
  onViewModeChange: handleViewModeChange,
476
- cardSettings
538
+ cardsViewConfig
477
539
  },
478
540
  children
479
541
  }
@@ -79,7 +79,7 @@ export interface IGridConfig {
79
79
  export interface IGridConfigExtended extends IGridConfig {
80
80
  columnsConfigCards?: BaseConfigColumnCards[];
81
81
  }
82
- export interface DataGridProviderProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<GridProps<TRow, TSummaryRow, TKey>, 'rows' | 'columns' | 'rowActionsGetter' | 'rowHeaderHeights' | 'rowHeights' | 'initialRowHeightVariant' | 'checkedRows' | 'onCheckedRowsChange' | 'rowKeyGetter' | 'onChangeUserColumns' | 'defaultUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'cardSettings' | 'defaultViewMode'> {
82
+ export interface DataGridProviderProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<GridProps<TRow, TSummaryRow, TKey>, 'rows' | 'columns' | 'rowActionsGetter' | 'rowHeaderHeights' | 'rowHeights' | 'initialRowHeightVariant' | 'checkedRows' | 'onCheckedRowsChange' | 'rowKeyGetter' | 'onChangeUserColumns' | 'defaultUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'defaultViewMode' | 'cardsViewConfig'> {
83
83
  id: number | string;
84
84
  children: ReactNode;
85
85
  rowsCount: number;
@@ -92,7 +92,7 @@ export type RowHeightState = {
92
92
  rowHeight: number;
93
93
  rowHeaderHeight: number;
94
94
  };
95
- export interface DataGridContextProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<DataGridProviderProps<TRow, TSummaryRow, TKey>, 'rows' | 'checkedRows' | 'onCheckedRowsChange' | 'rowHeights' | 'rowsCount' | 'rowActionsGetter' | 'rowKeyGetter' | 'onChangeUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'viewMode' | 'onViewModeChange' | 'cardSettings' | 'defaultViewMode'> {
95
+ export interface DataGridContextProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Pick<DataGridProviderProps<TRow, TSummaryRow, TKey>, 'rows' | 'checkedRows' | 'onCheckedRowsChange' | 'rowHeights' | 'rowsCount' | 'rowActionsGetter' | 'rowKeyGetter' | 'onChangeUserColumns' | 'externalSortSettings' | 'externalFilterSettings' | 'viewMode' | 'onViewModeChange' | 'defaultViewMode' | 'cardsViewConfig'> {
96
96
  getConfigColumns: (viewMode: ViewMode) => IViewConfig[];
97
97
  onChangeColumnsConfig: (viewMode: ViewMode, config: IViewConfig[]) => void;
98
98
  onChangeColumnsOrder: (viewMode: ViewMode, sourceKey: string, targetKey: string) => void;
@@ -11,7 +11,7 @@ function Cards(props) {
11
11
  selectedRows,
12
12
  onSelectedRowsChange,
13
13
  onRowsChange,
14
- cardSettings
14
+ cardsViewConfig
15
15
  } = props;
16
16
  const processedColumns = useProcessedColumns(columns);
17
17
  const allProcessedColumns = useProcessedColumns(columns, {
@@ -30,7 +30,7 @@ function Cards(props) {
30
30
  selectedRows,
31
31
  onSelectedRowsChange,
32
32
  onRowsChange,
33
- cardSettings
33
+ customRender: cardsViewConfig?.customRender
34
34
  },
35
35
  rowKeyGetter(row)
36
36
  )) }) });
@@ -3,4 +3,4 @@ import { CardRowProps } from '../../types';
3
3
  /**
4
4
  * Componente que muestra una fila de tarjetas.
5
5
  */
6
- export declare function CardRow<TRow, TKey extends RowKey = RowKey>({ row, columns, originalColumns, rowKeyGetter, selectedRows, onSelectedRowsChange, onRowsChange, cardSettings, }: CardRowProps<TRow, TKey>): import("react/jsx-runtime").JSX.Element;
6
+ export declare function CardRow<TRow, TKey extends RowKey = RowKey>({ row, columns, originalColumns, rowKeyGetter, selectedRows, onSelectedRowsChange, onRowsChange, customRender, }: CardRowProps<TRow, TKey>): import("react/jsx-runtime").JSX.Element;
@@ -13,10 +13,10 @@ function CardRow({
13
13
  selectedRows,
14
14
  onSelectedRowsChange,
15
15
  onRowsChange,
16
- cardSettings
16
+ customRender
17
17
  }) {
18
18
  const { checkedRows } = useDataGrid();
19
- const render = cardSettings !== void 0 && cardSettings.renderContent !== void 0;
19
+ const hasCustomRender = customRender !== void 0;
20
20
  const { cardContent, columnsCount, onOpenDetail } = useCardContent({
21
21
  row,
22
22
  columns,
@@ -28,14 +28,14 @@ function CardRow({
28
28
  [checkedRows, rowKeyGetter, row]
29
29
  );
30
30
  const content = useMemo(() => {
31
- if (render) {
32
- return cardSettings?.renderContent(row);
31
+ if (hasCustomRender) {
32
+ return customRender.renderContent(row);
33
33
  }
34
34
  return /* @__PURE__ */ jsxs(Fragment, { children: [
35
35
  /* @__PURE__ */ jsx(CardHeader, { row, onOpenDetail }),
36
36
  cardContent
37
37
  ] });
38
- }, [render, cardSettings, row, cardContent, onOpenDetail]);
38
+ }, [hasCustomRender, customRender, row, cardContent, onOpenDetail]);
39
39
  const onCardClick = () => {
40
40
  if (selectedRows && onSelectedRowsChange) {
41
41
  if (selectedRows.has(rowKeyGetter(row))) {
@@ -46,11 +46,11 @@ function CardRow({
46
46
  }
47
47
  };
48
48
  const dynamicMinHeight = useMemo(() => {
49
- if (render) {
50
- return cardSettings?.minHeight;
49
+ if (hasCustomRender) {
50
+ return customRender.minHeight;
51
51
  }
52
52
  return Math.max(120, columnsCount * 32 + 40);
53
- }, [render, cardSettings?.minHeight, columnsCount]);
53
+ }, [hasCustomRender, customRender, columnsCount]);
54
54
  return /* @__PURE__ */ jsx(LazyLoadCard, { threshold: 200, minHeight: dynamicMinHeight, children: /* @__PURE__ */ jsx(
55
55
  CardStyled,
56
56
  {
@@ -1,5 +1,5 @@
1
1
  import { Column, RowsChangeData } from 'react-data-grid';
2
- import { CardSettings, RowKey } from '../../types';
2
+ import { CardsViewConfig, RowKey } from '../../types';
3
3
  import { Maybe } from '@m4l/core';
4
4
  import { IViewConfig } from '../../contexts/DataGridContext/types';
5
5
  import { Sizes } from '@m4l/styles';
@@ -95,9 +95,9 @@ export interface CardRowProps<TRow, TKey extends RowKey = RowKey> {
95
95
  */
96
96
  onRowsChange?: Maybe<(rows: TRow[], data: RowsChangeData<TRow, any>) => void>;
97
97
  /**
98
- * Configuración personalizada para renderizado de cards
98
+ * Indica si se debe renderizar el contenido personalizado de la tarjeta
99
99
  */
100
- cardSettings?: CardSettings<TRow>;
100
+ customRender?: CardsViewConfig<TRow>['customRender'];
101
101
  }
102
102
  /**
103
103
  * Props para el componente CardDetails
@@ -17,11 +17,10 @@ function HeaderActions(props) {
17
17
  rightActions,
18
18
  withPager,
19
19
  size,
20
- columns,
21
- withViewMode = true
20
+ columns
22
21
  } = props;
23
22
  const isMobile = useIsMobile();
24
- const { rowHeights, viewMode, cardSettings } = useDataGrid();
23
+ const { rowHeights, viewMode, cardsViewConfig } = useDataGrid();
25
24
  const { currentSize } = useComponentSize(size);
26
25
  return /* @__PURE__ */ jsx(ActionsRootStyled, { ownerState: { size: currentSize }, children: isMobile ? /* @__PURE__ */ jsxs(Fragment, { children: [
27
26
  leftActions,
@@ -32,8 +31,8 @@ function HeaderActions(props) {
32
31
  leftActions,
33
32
  typeof rowHeights !== "number" && /* @__PURE__ */ jsx(Density, {}),
34
33
  withLocalFilters && /* @__PURE__ */ jsx(Filter, {}),
35
- withSettings && !(viewMode === "cards" && !!cardSettings) && /* @__PURE__ */ jsx(Settings, { ...settingsProps, columns }),
36
- withViewMode && /* @__PURE__ */ jsx(ViewMode, {})
34
+ withSettings && !(viewMode === "cards" && cardsViewConfig?.customRender) && /* @__PURE__ */ jsx(Settings, { ...settingsProps, columns }),
35
+ cardsViewConfig !== void 0 && /* @__PURE__ */ jsx(ViewMode, {})
37
36
  ] }),
38
37
  rightActions && /* @__PURE__ */ jsx(ContainerRightActionsStyled, { children: rightActions })
39
38
  ] }) });
@@ -0,0 +1,24 @@
1
+ import { CardsViewConfig } from '../../types';
2
+ interface UseCardsViewConfigProps {
3
+ /**
4
+ * Si es true, retorna cardsViewConfig con columnsConfig básica
5
+ */
6
+ withBasicConfig?: boolean;
7
+ /**
8
+ * Si es true, retorna cardsViewConfig con customRender
9
+ */
10
+ withCustomRender?: boolean;
11
+ /**
12
+ * Si es true, retorna cardsViewConfig solo con enabled=true (para demostrar error)
13
+ */
14
+ withEnabledOnly?: boolean;
15
+ /**
16
+ * Si es true, retorna cardsViewConfig con columnKey inválido (para demostrar error)
17
+ */
18
+ withInvalidColumnKey?: boolean;
19
+ }
20
+ /**
21
+ * Hook helper que genera configuraciones de cardsViewConfig para testing
22
+ */
23
+ export declare const useCardsViewConfigHelper: <TRow = any>(props?: UseCardsViewConfigProps) => CardsViewConfig<TRow> | undefined;
24
+ export {};
@@ -150,14 +150,15 @@ export interface GridProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> exte
150
150
  * @default 'medium'
151
151
  */
152
152
  size?: Extract<Sizes, 'small' | 'medium'>;
153
- /**
154
- * Configuración personalizada para renderizado de cards
155
- */
156
- cardSettings?: CardSettings<TRow>;
157
153
  /**
158
154
  * Modo por defecto de visualización
159
155
  */
160
156
  defaultViewMode?: ViewMode;
157
+ /**
158
+ * Configuración de la vista de "cards"
159
+ * Incluye habilitación, configuración de columnas y renderizado personalizado
160
+ */
161
+ cardsViewConfig?: CardsViewConfig<TRow>;
161
162
  }
162
163
  export declare const DATAGRID_TEST_ID = "m4ldatagrid";
163
164
  export declare const PREFIX_TEST_ATTRIBUTE = "data-testid";
@@ -177,7 +178,6 @@ export interface ActionsProps {
177
178
  withLocalFilters?: boolean;
178
179
  leftActions?: React.ReactNode;
179
180
  rightActions?: React.ReactNode;
180
- withViewMode?: boolean;
181
181
  }
182
182
  /**
183
183
  * Props para el hook useModalDetail
@@ -189,12 +189,44 @@ export interface UseModalDetailProps<TRow> {
189
189
  onRowsChange?: Maybe<(rows: TRow[], data: RowsChangeData<TRow, any>) => void>;
190
190
  }
191
191
  /**
192
- * Configuración personalizada para renderizado de cards
192
+ * Configuración de una columna específica en vista "cards"
193
193
  */
194
- export interface CardSettings<TRow> {
195
- renderContent: (row: TRow) => React.ReactNode;
196
- minHeight: number;
194
+ export interface CardColumnConfig {
195
+ /**
196
+ * Key de la columna (debe coincidir con la key de la columna)
197
+ */
198
+ columnKey: string;
199
+ /**
200
+ * Si se debe mostrar el título/label de esta columna en la card (Solo si no existe una config previa)
201
+ */
202
+ showTitle: boolean;
197
203
  }
204
+ /**
205
+ * Cards con columnsConfig
206
+ */
207
+ export interface CardsViewConfigWithColumns {
208
+ columnsConfig: CardColumnConfig[];
209
+ customRender?: never;
210
+ }
211
+ /**
212
+ * Cards con customRender
213
+ */
214
+ export interface CardsViewConfigWithCustomRender<TRow> {
215
+ columnsConfig?: never;
216
+ customRender: {
217
+ renderContent: (row: TRow) => React.ReactNode;
218
+ minHeight: number;
219
+ };
220
+ }
221
+ /**
222
+ * Configuración para la vista de "cards"
223
+ *
224
+ * IMPORTANTE:
225
+ * Es OBLIGATORIO configurar al menos 1 columna cuando customRender=undefined
226
+ * Se ignora completamente si customRender está definido
227
+ * @throws Error si customRender=undefined y array está vacío
228
+ */
229
+ export type CardsViewConfig<TRow> = CardsViewConfigWithColumns | CardsViewConfigWithCustomRender<TRow>;
198
230
  /**
199
231
  * Opciones para el procesamiento de columnas
200
232
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/components",
3
- "version": "9.3.21-JT15102025.beta.1",
3
+ "version": "9.3.21-JT20102025.beta.1",
4
4
  "license": "UNLICENSED",
5
5
  "description": "M4L Components",
6
6
  "lint-staged": {