mirror of
https://github.com/bakhirev/assayo.git
synced 2024-11-16 16:21:41 +00:00
update
This commit is contained in:
parent
df5c310497
commit
0871335286
|
@ -32,9 +32,11 @@ function Body({
|
||||||
?.formatter;
|
?.formatter;
|
||||||
|
|
||||||
rows?.forEach((row: any, rowIndex: number) => {
|
rows?.forEach((row: any, rowIndex: number) => {
|
||||||
|
let marginLeft = 0;
|
||||||
const rowConfig = (rowsConfig || {})[getRowId(row, rowIndex)];
|
const rowConfig = (rowsConfig || {})[getRowId(row, rowIndex)];
|
||||||
const cells = columns.map((column: IColumn, columnIndex: number) => {
|
const cells = columns.map((column: IColumn, columnIndex: number) => {
|
||||||
const key = `${column.title}_${columnIndex}`;
|
const key = `${column.title}_${columnIndex}`;
|
||||||
|
marginLeft += columns[columnIndex - 1]?.width || 0;
|
||||||
|
|
||||||
if (column.template === ColumnTypesEnum.DETAILS) {
|
if (column.template === ColumnTypesEnum.DETAILS) {
|
||||||
return (
|
return (
|
||||||
|
@ -43,6 +45,7 @@ function Body({
|
||||||
column={column}
|
column={column}
|
||||||
row={row}
|
row={row}
|
||||||
rowConfig={rowConfig}
|
rowConfig={rowConfig}
|
||||||
|
marginLeft={marginLeft}
|
||||||
updateRowsConfig={updateRowsConfig}
|
updateRowsConfig={updateRowsConfig}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -54,6 +57,7 @@ function Body({
|
||||||
column={column}
|
column={column}
|
||||||
row={row}
|
row={row}
|
||||||
rowIndex={rowIndex}
|
rowIndex={rowIndex}
|
||||||
|
marginLeft={marginLeft}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { IColumn } from '../interfaces/Column';
|
import { IColumn } from '../interfaces/Column';
|
||||||
|
import getClassName from '../helpers/getClassName';
|
||||||
import headerStyle from '../styles/header.module.scss';
|
import headerStyle from '../styles/header.module.scss';
|
||||||
import style from '../styles/index.module.scss';
|
import style from '../styles/index.module.scss';
|
||||||
|
|
||||||
|
@ -17,17 +18,19 @@ function Header({
|
||||||
updateSort,
|
updateSort,
|
||||||
}: ITitleProps) {
|
}: ITitleProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
let marginLeft = 0;
|
||||||
const cells = columns.map((column: IColumn, columnIndex: number) => {
|
const cells = columns.map((column: IColumn, columnIndex: number) => {
|
||||||
const columnClassName = typeof column.className === 'function'
|
marginLeft += columns[columnIndex - 1]?.width || 0;
|
||||||
? column.className('header', columnIndex)
|
const localClassName = getClassName(style.table_header_cell, column, ['header', columnIndex], className);
|
||||||
: column.className;
|
|
||||||
const formattedTitle = t(column.title || '');
|
const formattedTitle = t(column.title || '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={`${column.title}_${columnIndex}`}
|
key={`${column.title}_${columnIndex}`}
|
||||||
className={`${style.table_header_cell} ${className} ${columnClassName || ''}`}
|
className={localClassName}
|
||||||
style={{ width: column.width }}
|
style={{ width: column.width, left: marginLeft }}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
title={formattedTitle}
|
title={formattedTitle}
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { IColumn } from '../../interfaces/Column';
|
import { IColumn } from '../../interfaces/Column';
|
||||||
|
import getClassName from '../../helpers/getClassName';
|
||||||
import style from '../../styles/index.module.scss';
|
import style from '../../styles/index.module.scss';
|
||||||
|
|
||||||
interface IDefaultCellProps {
|
interface IDefaultCellProps {
|
||||||
column: IColumn,
|
column: IColumn,
|
||||||
row: any,
|
row: any,
|
||||||
rowIndex?: number,
|
rowIndex?: number,
|
||||||
|
marginLeft?: number,
|
||||||
className?: string,
|
className?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,11 +16,12 @@ function DefaultCell({
|
||||||
column,
|
column,
|
||||||
row,
|
row,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
|
marginLeft,
|
||||||
className,
|
className,
|
||||||
}: IDefaultCellProps): JSX.Element {
|
}: IDefaultCellProps): JSX.Element {
|
||||||
const columnClassName = typeof column.className === 'function'
|
const localClassName = getClassName(style.table_cell, column, ['body', row], className);
|
||||||
? column.className('body', row)
|
|
||||||
: column.className;
|
const left = column.isFixed ? marginLeft : 0;
|
||||||
|
|
||||||
const onClick = column.onClick
|
const onClick = column.onClick
|
||||||
? (() => { if (column.onClick) column.onClick(row); })
|
? (() => { if (column.onClick) column.onClick(row); })
|
||||||
|
@ -44,8 +47,9 @@ function DefaultCell({
|
||||||
<div
|
<div
|
||||||
key={column.title} // @ts-ignore
|
key={column.title} // @ts-ignore
|
||||||
title={cellTitle}
|
title={cellTitle}
|
||||||
className={`${style.table_cell} ${className || ''} ${columnClassName || ''}`}
|
className={localClassName}
|
||||||
style={{
|
style={{
|
||||||
|
left,
|
||||||
width: column.width,
|
width: column.width,
|
||||||
cursor: onClick ? 'pointer' : 'auto',
|
cursor: onClick ? 'pointer' : 'auto',
|
||||||
}} // @ts-ignore
|
}} // @ts-ignore
|
||||||
|
|
|
@ -8,6 +8,7 @@ interface IDefaultCellProps {
|
||||||
row: any,
|
row: any,
|
||||||
className?: string,
|
className?: string,
|
||||||
rowConfig?: IRowsConfig;
|
rowConfig?: IRowsConfig;
|
||||||
|
marginLeft?: number;
|
||||||
updateRowsConfig?: (config: IRowsConfig) => void;
|
updateRowsConfig?: (config: IRowsConfig) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +17,13 @@ function DetailsCell({
|
||||||
row,
|
row,
|
||||||
className,
|
className,
|
||||||
rowConfig,
|
rowConfig,
|
||||||
|
marginLeft,
|
||||||
updateRowsConfig,
|
updateRowsConfig,
|
||||||
}: IDefaultCellProps): JSX.Element {
|
}: IDefaultCellProps): JSX.Element {
|
||||||
const config = rowConfig || { id: 1 };
|
const config = rowConfig || { id: 1 };
|
||||||
|
|
||||||
|
const left = column?.isFixed ? marginLeft : 0;
|
||||||
|
|
||||||
const columnClassName = typeof column.className === 'function'
|
const columnClassName = typeof column.className === 'function'
|
||||||
? column.className('body', row)
|
? column.className('body', row)
|
||||||
: column.className;
|
: column.className;
|
||||||
|
@ -48,6 +52,7 @@ function DetailsCell({
|
||||||
style={{
|
style={{
|
||||||
width: column.width,
|
width: column.width,
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
|
left,
|
||||||
}} // @ts-ignore
|
}} // @ts-ignore
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
|
|
24
src/ts/components/Table/helpers/getClassName.ts
Normal file
24
src/ts/components/Table/helpers/getClassName.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { IColumn } from '../interfaces/Column';
|
||||||
|
|
||||||
|
import style from '../styles/index.module.scss';
|
||||||
|
|
||||||
|
export default function getClassName(defaultClassName: string, column: IColumn, args?: any, className?: string) {
|
||||||
|
const localClassName = [defaultClassName];
|
||||||
|
|
||||||
|
if (className) {
|
||||||
|
localClassName.push(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.className) {
|
||||||
|
const columnClassName = typeof column.className === 'function'
|
||||||
|
? column.className(...args)
|
||||||
|
: column.className;
|
||||||
|
localClassName.push(columnClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.isFixed) {
|
||||||
|
localClassName.push(style.table_fixed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return localClassName.join(' ');
|
||||||
|
}
|
|
@ -64,6 +64,14 @@
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&_fixed {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 1;
|
||||||
|
background-color: rgba(255, 255, 255, 0.9);
|
||||||
|
}
|
||||||
|
|
||||||
&_cell {
|
&_cell {
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
}
|
}
|
||||||
|
@ -75,18 +83,17 @@
|
||||||
line-height: var(--table-cell-height);
|
line-height: var(--table-cell-height);
|
||||||
background-color: var(--color-white);
|
background-color: var(--color-white);
|
||||||
}
|
}
|
||||||
|
//&_cell:first-child,
|
||||||
&_cell:first-child,
|
//&_header_cell:first-child {
|
||||||
&_header_cell:first-child {
|
// position: sticky;
|
||||||
position: sticky;
|
// top: 0;
|
||||||
top: 0;
|
// left: 0;
|
||||||
left: 0;
|
// z-index: 1;
|
||||||
z-index: 1;
|
//}
|
||||||
}
|
//
|
||||||
|
//&_cell:first-child {
|
||||||
&_cell:first-child {
|
// background-color: rgba(255, 255, 255, 0.9);
|
||||||
background-color: rgba(255, 255, 255, 0.9);
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
&_cell_number {
|
&_cell_number {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|
Loading…
Reference in a new issue