Skip to content

Commit

Permalink
const-ify destructured DataGrid props (adazzle#3027)
Browse files Browse the repository at this point in the history
  • Loading branch information
nstepien authored Sep 17, 2022
1 parent dfe9a1b commit 40c5ad0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
*/
renderers?: Maybe<Renderers<R, SR>>;
rowClass?: Maybe<(row: R) => Maybe<string>>;
/** @default 'ltr' */
direction?: Maybe<Direction>;
'data-testid'?: Maybe<string>;
}
Expand All @@ -192,7 +193,10 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
* <DataGrid columns={columns} rows={rows} />
*/
function DataGrid<R, SR, K extends Key>(
{
props: DataGridProps<R, SR, K>,
ref: React.Ref<DataGridHandle>
) {
const {
// Grid and data Props
columns: rawColumns,
rows: rawRows,
Expand All @@ -201,7 +205,7 @@ function DataGrid<R, SR, K extends Key>(
rowKeyGetter,
onRowsChange,
// Dimensions props
rowHeight,
rowHeight: rawRowHeight,
headerRowHeight: rawHeaderRowHeight,
summaryRowHeight: rawSummaryRowHeight,
// Feature props
Expand All @@ -224,26 +228,25 @@ function DataGrid<R, SR, K extends Key>(
onPaste,
// Toggles and modes
cellNavigationMode: rawCellNavigationMode,
enableVirtualization,
enableVirtualization: rawEnableVirtualization,
// Miscellaneous
renderers,
className,
style,
rowClass,
direction,
direction: rawDirection,
// ARIA
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledBy,
'aria-describedby': ariaDescribedBy,
'data-testid': testId
}: DataGridProps<R, SR, K>,
ref: React.Ref<DataGridHandle>
) {
} = props;

/**
* defaults
*/
const defaultComponents = useDefaultComponents<R, SR>();
rowHeight ??= 35;
const rowHeight = rawRowHeight ?? 35;
const headerRowHeight = rawHeaderRowHeight ?? (typeof rowHeight === 'number' ? rowHeight : 35);
const summaryRowHeight = rawSummaryRowHeight ?? (typeof rowHeight === 'number' ? rowHeight : 35);
const rowRenderer =
Expand All @@ -255,8 +258,8 @@ function DataGrid<R, SR, K extends Key>(
defaultCheckboxFormatter;
const noRowsFallback = renderers?.noRowsFallback ?? defaultComponents?.noRowsFallback;
const cellNavigationMode = rawCellNavigationMode ?? 'NONE';
enableVirtualization ??= true;
direction ??= 'ltr';
const enableVirtualization = rawEnableVirtualization ?? true;
const direction = rawDirection ?? 'ltr';

/**
* states
Expand Down

0 comments on commit 40c5ad0

Please sign in to comment.