From f37dce51922b15926c2cb58eaacd4ac41580cc00 Mon Sep 17 00:00:00 2001 From: Julian Roeland Date: Fri, 31 May 2024 16:44:39 +0200 Subject: [PATCH] :sparkles: #70 - feat: improved datagrid --- src/components/data/datagrid/datagrid.scss | 16 +++ src/components/data/datagrid/datagrid.tsx | 151 +++++++++++++-------- 2 files changed, 112 insertions(+), 55 deletions(-) diff --git a/src/components/data/datagrid/datagrid.scss b/src/components/data/datagrid/datagrid.scss index 5257c92a..a039c1d3 100644 --- a/src/components/data/datagrid/datagrid.scss +++ b/src/components/data/datagrid/datagrid.scss @@ -55,6 +55,22 @@ background-color: var(--page-color-highlight); } + @keyframes skeleton-loading { + 0% { + background-color: var(--typography-color-background); + } + + 100% { + background-color: var(--page-color-secondary); + } + } + + &__row--loading { + height: 42px; + width: 100%; + animation: skeleton-loading 1s linear infinite alternate; + } + &__cell { border-block-start: 1px solid transparent; border-block-end: 1px solid var(--typography-color-border); diff --git a/src/components/data/datagrid/datagrid.tsx b/src/components/data/datagrid/datagrid.tsx index ede1f7b3..6f87bd33 100644 --- a/src/components/data/datagrid/datagrid.tsx +++ b/src/components/data/datagrid/datagrid.tsx @@ -434,6 +434,7 @@ export const DataGrid: React.FC = ({ sortDirection={sortDirection} sortField={sortField} urlFields={urlFields} + loading={loading} > {/* Paginator */} @@ -765,6 +766,7 @@ export type DataGridBodyProps = { sortDirection: "ASC" | "DESC" | undefined; sortField: string | undefined; urlFields: string[]; + loading?: boolean; }; /** @@ -796,65 +798,73 @@ export const DataGridBody: React.FC = ({ sortDirection, sortField, urlFields, + loading, }) => ( - {renderableRows.map((rowData, index) => ( - - {selectable && ( - - + ) : ( + renderableRows.map((rowData, index) => ( + + {selectable && ( + + + + )} + {renderableFields.map((field) => ( + - - )} - {renderableFields.map((field) => ( - { - if (editable) { - setEditingState([rowData, renderableFields.indexOf(field)]); - e.preventDefault(); + editable={editable} + isEditingRow={editingRow === rowData} + isEditingField={ + editingRow === rowData && + editingFieldIndex === renderableFields.indexOf(field) } - e.currentTarget.nodeName === "A" && onClick?.(e, rowData); - }} - onEdit={onEdit} - /> - ))} - - ))} + field={field} + renderableFields={renderableFields} + urlFields={urlFields} + onChange={onChange} + onClick={(e, rowData) => { + if (editable) { + setEditingState([rowData, renderableFields.indexOf(field)]); + e.preventDefault(); + } + e.currentTarget.nodeName === "A" && onClick?.(e, rowData); + }} + onEdit={onEdit} + /> + ))} + + )) + )} ); @@ -1136,6 +1146,37 @@ export const DataGridContentCell: React.FC = ({ ); }; +export type DataGridSkeletonCellsProps = { + fields?: number; + rows?: number; +}; + +/** + * DataGrid skeleton rows + */ +export const DataGridSkeletonRows: React.FC = ({ + fields = 1, + rows = 5, +}) => + Array.from({ length: rows }).map((_, rowIndex) => ( + + {Array.from({ length: fields }).map((_, colIndex) => ( + +

+ + ))} + + )); + export type DataGridSelectionCheckboxProps = { amountSelected: number; checked: boolean;