|
@@ -11,7 +11,8 @@ import {
|
|
|
isLastLeftFixed,
|
|
|
isFixedLeft,
|
|
|
isFixedRight,
|
|
|
- sliceColumnsByLevel
|
|
|
+ sliceColumnsByLevel,
|
|
|
+ getRTLAlign
|
|
|
} from '@douyinfe/semi-foundation/table/utils';
|
|
|
import BaseComponent from '../_base/baseComponent';
|
|
|
import TableContext, { TableContextProps } from './table-context';
|
|
@@ -65,7 +66,7 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
|
|
|
|
|
|
headerNode: HTMLElement;
|
|
|
context: TableContextProps;
|
|
|
-
|
|
|
+
|
|
|
constructor(props: TableHeaderRowProps) {
|
|
|
super(props);
|
|
|
this.headerNode = null;
|
|
@@ -100,7 +101,8 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
|
|
|
|
|
|
render() {
|
|
|
const { components, row, prefixCls, onHeaderRow, index, style, columns } = this.props;
|
|
|
- const { getCellWidths } = this.context;
|
|
|
+ const { getCellWidths, direction } = this.context;
|
|
|
+ const isRTL = direction === 'rtl';
|
|
|
const slicedColumns = sliceColumnsByLevel(columns, index);
|
|
|
const headWidths = getCellWidths(slicedColumns);
|
|
|
|
|
@@ -116,22 +118,36 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
|
|
|
typeof column.onHeaderCell === 'function' ? column.onHeaderCell(column, cellIndex, index) : {};
|
|
|
let cellStyle = { ...customProps.style };
|
|
|
if (column.align) {
|
|
|
- cellStyle = { ...cellStyle, textAlign: column.align };
|
|
|
+ const textAlign = getRTLAlign(column.align, direction);
|
|
|
+ cellStyle = { ...cellStyle, textAlign };
|
|
|
customProps.className = classnames(customProps.className, column.className, {
|
|
|
- [`${prefixCls}-align-${column.align}`]: Boolean(column.align),
|
|
|
+ [`${prefixCls}-align-${textAlign}`]: Boolean(textAlign),
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ let fixedLeft, fixedRight, fixedLeftLast, fixedRightFirst;
|
|
|
+ if (isRTL) {
|
|
|
+ fixedLeft = isFixedRight(column);
|
|
|
+ fixedRight = isFixedLeft(column);
|
|
|
+ fixedLeftLast = isFirstFixedRight(slicedColumns, column);
|
|
|
+ fixedRightFirst = isLastLeftFixed(slicedColumns, column);
|
|
|
+ } else {
|
|
|
+ fixedLeft = isFixedLeft(column);
|
|
|
+ fixedRight = isFixedRight(column);
|
|
|
+ fixedLeftLast = isLastLeftFixed(slicedColumns, column);
|
|
|
+ fixedRightFirst = isFirstFixedRight(slicedColumns, column);
|
|
|
+ }
|
|
|
+
|
|
|
customProps.className = classnames(
|
|
|
`${prefixCls}-row-head`,
|
|
|
column.className,
|
|
|
customProps.className,
|
|
|
// `${prefixCls}-fixed-columns`,
|
|
|
{
|
|
|
- [`${prefixCls}-cell-fixed-left`]: isFixedLeft(column),
|
|
|
- [`${prefixCls}-cell-fixed-left-last`]: isLastLeftFixed(slicedColumns, column),
|
|
|
- [`${prefixCls}-cell-fixed-right`]: isFixedRight(column),
|
|
|
- [`${prefixCls}-cell-fixed-right-first`]: isFirstFixedRight(slicedColumns, column),
|
|
|
+ [`${prefixCls}-cell-fixed-left`]: fixedLeft,
|
|
|
+ [`${prefixCls}-cell-fixed-left-last`]: fixedLeftLast,
|
|
|
+ [`${prefixCls}-cell-fixed-right`]: fixedRight,
|
|
|
+ [`${prefixCls}-cell-fixed-right-first`]: fixedRightFirst,
|
|
|
}
|
|
|
);
|
|
|
|
|
@@ -142,16 +158,18 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
|
|
|
);
|
|
|
if (indexOfSlicedColumns > -1) {
|
|
|
if (isFixedLeft(column)) {
|
|
|
+ const xPositionKey = isRTL ? 'right' : 'left';
|
|
|
cellStyle = {
|
|
|
...cellStyle,
|
|
|
position: 'sticky',
|
|
|
- left: arrayAdd(headWidths, 0, indexOfSlicedColumns),
|
|
|
+ [xPositionKey]: arrayAdd(headWidths, 0, indexOfSlicedColumns),
|
|
|
};
|
|
|
} else if (isFixedRight(column)) {
|
|
|
+ const xPositionKey = isRTL ? 'left' : 'right';
|
|
|
cellStyle = {
|
|
|
...cellStyle,
|
|
|
position: 'sticky',
|
|
|
- right: arrayAdd(headWidths, indexOfSlicedColumns + 1),
|
|
|
+ [xPositionKey]: arrayAdd(headWidths, indexOfSlicedColumns + 1),
|
|
|
};
|
|
|
}
|
|
|
}
|
|
@@ -175,8 +193,8 @@ export default class TableHeaderRow extends BaseComponent<TableHeaderRowProps, R
|
|
|
role="columnheader"
|
|
|
aria-colindex={cellIndex + 1}
|
|
|
{...props}
|
|
|
- style={cellStyle}
|
|
|
- key={column.key || column.dataIndex || cellIndex}
|
|
|
+ style={cellStyle}
|
|
|
+ key={column.key || column.dataIndex || cellIndex}
|
|
|
/>
|
|
|
);
|
|
|
});
|