Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions semcore/data-table/src/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
gridTemplateAreas,
gridTemplateColumns,
expandedRows,
columns,
onExpandRow,
loading,
hasGroups,
Expand All @@ -128,7 +127,6 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
sideIndents,
selectedRows,
onSelectRow,
getFixedStyle,
accordionDuration,
accordionAnimationRows,
getI18nText,
Expand Down Expand Up @@ -156,7 +154,6 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
uid,
gridTemplateAreas,
gridTemplateColumns,
columns,
rowIndex: index,
gridRowIndex,
rows,
Expand All @@ -168,7 +165,6 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
inert: loading ? '' : undefined,
scrollAreaRef,
sideIndents: sideIndentsValue,
getFixedStyle,
mergedRow: props.mergedRow,
accordionDuration,
accordionAnimationRows,
Expand Down Expand Up @@ -237,6 +233,7 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
rows,
renderCellOverlay,
selectedRows,
getFixedStyle,
} = this.asProps;

let rowsToRender = rows;
Expand Down Expand Up @@ -360,7 +357,7 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa

return sstyled(styles)(
<SBody render={Box} __excludeProps={['data']} ref={this.bodyRef}>
{emptyRow && <Body.Row row={emptyRow} isNonInteractive />}
{emptyRow && <Body.Row row={emptyRow} isNonInteractive columns={columns} getFixedStyle={getFixedStyle} />}
{needMarginTop && rowMarginTop && <Box h={rowMarginTop} />}
{rowsToRender.map((row, index) => {
if (Array.isArray(row)) {
Expand All @@ -376,6 +373,7 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
rowIndex={index}
handleRef={this.handleRef}
handleComponentRef={this.handleComponentRef}
getFixedStyle={getFixedStyle}
/>
);
}
Expand All @@ -386,6 +384,8 @@ class BodyRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
row={row}
ref={virtualScroll ? this.handleRef(this.startIndex + index, row) : undefined}
componentRef={this.handleComponentRef(row)}
columns={columns}
getFixedStyle={getFixedStyle}
/>
);
})}
Expand Down
3 changes: 1 addition & 2 deletions semcore/data-table/src/components/Body/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Box, Flex } from '@semcore/base-components';
import type { Intergalactic } from '@semcore/core';
import { Root, sstyled, createComponent, Component } from '@semcore/core';
import { getFocusableIn } from '@semcore/core/lib/utils/focus-lock/getFocusableIn';
import { isFocusInside } from '@semcore/core/lib/utils/focus-lock/isFocusInside';
Expand Down Expand Up @@ -105,7 +104,7 @@ class CellRoot<Data extends DataTableData, UniqKeyType>
gridArea={gridArea}
fixed={column.fixed}
style={style}
shadowVertical={column.showShadowVertical ? shadowVertical : undefined}
shadowVertical={shadowVertical}
>
<SCell
ref={this.cellRef}
Expand Down
37 changes: 34 additions & 3 deletions semcore/data-table/src/components/Body/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Collapse } from '@semcore/base-components';
import { ButtonLink } from '@semcore/button';
import { Component, Root, sstyled, createComponent } from '@semcore/core';
import propsObserver from '@semcore/core/lib/decorators/propsObserver';
import { callAllEventHandlers } from '@semcore/core/lib/utils/assignProps';
import { isInteractiveElement } from '@semcore/core/lib/utils/isInteractiveElement';
import ChevronRightM from '@semcore/icon/ChevronRight/m';
Expand All @@ -27,6 +28,7 @@ type DefaultProps = {
'aria-level': undefined;
};

@propsObserver(['columns'])
export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
DataTableRowProps<Data, UniqKeyType>,
[],
Expand All @@ -45,6 +47,7 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
private cellName: string = '';
private closeAccordionTimeout = 0;
private openAccordionTimeout = 0;
private readonly cellStyle = new Map<string, React.CSSProperties>();

rowElementRef = React.createRef<HTMLDivElement>();

Expand All @@ -58,6 +61,8 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
super(props);

this.handleClickRow = this.handleClickRow.bind(this);

this.recalculateCellStyle();
}

componentDidMount() {
Expand All @@ -77,6 +82,33 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<

componentWillUnmount() {
this.asProps.componentRef?.(null);

this.cellStyle.clear();
}

onPropsChange(changedProps: Record<string, unknown>) {
if ('columns' in changedProps) {
this.recalculateCellStyle();
}
}

recalculateCellStyle() {
const { columns, getFixedStyle } = this.props;

columns.forEach((column) => {
if (column.fixed) {
const styles: React.CSSProperties = {};
this.cellStyle.set(column.name, styles);

const [name, value] = getFixedStyle(column);

if (name !== undefined && value !== undefined) {
styles[name] = value;
}
} else {
this.cellStyle.delete(column.name);
}
});
}

setAccordion() {
Expand Down Expand Up @@ -267,7 +299,6 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
tableRef,
onCellClick,
rawData,
shadowVertical,
flatRows,
variant,
isAccordionRow,
Expand Down Expand Up @@ -313,7 +344,6 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
children: props?.children ?? defaultRender(),
onClick: onCellClick,
flatRows: this.asProps.flatRows,
shadowVertical,
withoutBorder,
theme,
};
Expand Down Expand Up @@ -575,7 +605,8 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
accordionRowIndex={accordionRowIndex}
rows={rows}
aria-hidden={isCellHidden}
style={style}
style={this.cellStyle.get(column.name)}
shadowVertical={column.showShadowVertical ? shadowVertical : undefined}
data-aria-level={index === 0 ? ariaLevel : undefined}
/>
);
Expand Down
10 changes: 6 additions & 4 deletions semcore/data-table/src/components/Body/Row.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export type DataTableRowProps<Data extends DataTableData, UniqKeyType> = {
accordionIndex?: number;

theme?: Theme;

columns: DTColumn[];

getFixedStyle: (
cell: Pick<DTColumn, 'name' | 'fixed'>,
) => [side: 'left' | 'right', style: string | number] | [side: undefined, style: undefined];
};

export type RowPropsInner<Data extends DataTableData, UniqKeyType> = JSX.IntrinsicElements['div'] & {
Expand All @@ -57,7 +63,6 @@ export type RowPropsInner<Data extends DataTableData, UniqKeyType> = JSX.Intrins
*/
mergedRow?: boolean;

columns: DTColumn[];
row: DTRow<UniqKeyType> | DTRow<UniqKeyType>[];
rows: DTRows<UniqKeyType>;
flatRows: DTRow<UniqKeyType>[];
Expand Down Expand Up @@ -86,9 +91,6 @@ export type RowPropsInner<Data extends DataTableData, UniqKeyType> = JSX.Intrins
scrollAreaRef: React.RefObject<HTMLDivElement>;
uid: string;
sideIndents?: 'wide';
getFixedStyle: (
cell: Pick<DTColumn, 'name' | 'fixed'>,
) => [side: 'left' | 'right', style: string | number] | [side: undefined, style: undefined];

renderCell?: (props: CellRenderProps<Data[number], UniqKeyType>) => React.ReactNode | Record<string, any>;
getI18nText: (key: string) => string;
Expand Down
6 changes: 4 additions & 2 deletions semcore/data-table/src/components/Body/RowGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ type RowGroupProps<Data extends DataTableData, UniqKeyType> = {
rowIndex: number;
handleRef: (index: number, row: DTRow<UniqKeyType>) => (node: HTMLElement | null) => void;
handleComponentRef: (row: DTRow<UniqKeyType>) => (component: RowRoot<Data, UniqKeyType> | null) => void;

getFixedStyle: DataTableRowProps<Data, UniqKeyType>['getFixedStyle'];
};

export class RowGroup<Data extends DataTableData, UniqKeyType> extends React.PureComponent<RowGroupProps<Data, UniqKeyType>> {
render() {
const SRowGroup = Box;
const { rows, selectedRows, columns, startIndex, rowIndex } = this.props;
const { rows, selectedRows, columns, startIndex, rowIndex, getFixedStyle } = this.props;

const groupUniqKey = rows[0][UNIQ_ROW_KEY];

Expand All @@ -50,6 +50,8 @@ export class RowGroup<Data extends DataTableData, UniqKeyType> extends React.Pur
row: item,
mergedRow: i > 0 ? true : false,
componentRef: this.props.handleComponentRef(item),
columns,
getFixedStyle,
};

return (
Expand Down
2 changes: 1 addition & 1 deletion semcore/data-table/src/components/Head/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { handleFocusCell, handleKeydownFocusCell } from '../../enhancers/focusab
import type { ROW_GROUP } from '../DataTable/DataTable';
import type { DataTableData, SortDirection } from '../DataTable/DataTable.types';

const SORTING_ICON: { [key in SortDirection]: React.FC<React.SVGProps<SVGSVGElement>> } = {
const SORTING_ICON: { [key in SortDirection]: typeof SortAsc | typeof SortDesc } = {
desc: SortDesc,
asc: SortAsc,
} as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const Table = (props: TableProps) => {
aria-label='Table example with selectable rows'
defaultGridTemplateColumnWidth='auto'
selectedRows={props.selectedRows}
// onSelectedRowsChange={props.handleChangeSelectedRows}
ref={props.tableRef}
sideIndents={props.sideIndents}
loading={props.loading}
Expand Down
Loading