Skip to content

Commit

Permalink
fix(Cell): fix that the content cannot be styled through style (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed Aug 13, 2021
1 parent 1aaae88 commit 7823adb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 43 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const App = () => (

| Property | Type `(Default)` | Description |
| ------------ | ---------------- | -------------------------------------------- |
| contentStyle | CSSProperties | Add custom styles to cell content |
| dataKey | string | Data binding `key`, but also a sort of `key` |
| rowData | object | Row data |
| rowIndex | number | Row number |
Expand Down
12 changes: 1 addition & 11 deletions docs/md/CustomColumnTable.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const BaseCell = React.forwardRef((props, ref) => {
});

const CheckCell = ({ rowData, onChange, checkedKeys, dataKey, ...props }) => {
console.log(checkedKeys, 'checkedKeys');
return (
<BaseCell {...props} style={{ padding: 0 }}>
<div style={{ lineHeight: '46px' }}>
Expand Down Expand Up @@ -96,7 +95,7 @@ const App = () => {
};

return (
<Table height={400} data={data} headerHeight={50} virtualized>
<Table height={400} data={fakeLargeData} headerHeight={50} virtualized>
<Column width={50} align="center">
<HeaderCell style={{ padding: 0 }}>
<div style={{ lineHeight: '40px' }}>
Expand Down Expand Up @@ -128,15 +127,6 @@ const App = () => {
<BaseCell>{rowData => <a href={`mailto:${rowData.email}`}>{rowData.email}</a>}</BaseCell>
</Column>

<Column width={250} align="right">
<HeaderCell>Date</HeaderCell>
<BaseCell>
{rowData => {
return rowData.date.toLocaleString();
}}
</BaseCell>
</Column>

<Column width={200}>
<HeaderCell>Action</HeaderCell>
<ActionCell dataKey="id" />
Expand Down
13 changes: 5 additions & 8 deletions src/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export interface CellProps extends StandardProps {

/** Row Data */
rowData?: any;

/** Add custom styles to cell content */
contentStyle?: React.CSSProperties;
}

export interface InnerCellProps extends CellProps {
Expand All @@ -43,6 +40,7 @@ export interface InnerCellProps extends CellProps {
removed?: boolean;
treeCol?: boolean;
expanded?: boolean;
predefinedStyle?: React.CSSProperties;
onTreeToggle?: (
rowKey?: string | number,
rowIndex?: number,
Expand All @@ -65,7 +63,6 @@ const Cell = React.forwardRef((props: InnerCellProps, ref: React.Ref<HTMLDivElem
style,
className,
classPrefix,
contentStyle,
firstColumn,
lastColumn,
isHeaderCell,
Expand All @@ -84,6 +81,7 @@ const Cell = React.forwardRef((props: InnerCellProps, ref: React.Ref<HTMLDivElem
treeCol,
height,
hasChildren,
predefinedStyle,
renderCell,
renderTreeToggle,
onClick,
Expand Down Expand Up @@ -111,15 +109,15 @@ const Cell = React.forwardRef((props: InnerCellProps, ref: React.Ref<HTMLDivElem

const nextHeight = isHeaderCell ? headerHeight : cellHeight;
const styles = {
...style,
...predefinedStyle,
width,
height: nextHeight,
zIndex: depth,
[rtl ? 'right' : 'left']: left
};

const contentStyles: React.CSSProperties = {
...contentStyle,
...style,
width,
height: nextHeight,
textAlign: align,
Expand Down Expand Up @@ -216,8 +214,7 @@ Cell.propTypes = {
wordWrap: PropTypes.bool,
removed: PropTypes.bool,
treeCol: PropTypes.bool,
expanded: PropTypes.bool,
contentStyle: PropTypes.object
expanded: PropTypes.bool
};
Cell.defaultProps = {
classPrefix: 'cell',
Expand Down
4 changes: 1 addition & 3 deletions src/ColumnGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ const ColumnGroup = React.forwardRef((props: ColumnGroupProps, ref: React.Ref<HT
</div>

{React.Children.map(children, (node: React.ReactElement) => {
const nodeStyles = { height, ...node.props?.style, top: styles.height };

return React.cloneElement(node, {
className: prefix('cell'),
style: nodeStyles,
predefinedStyle: { height, top: styles.height },
headerHeight: height,
verticalAlign,
children: <span className={prefix('cell-content')}>{node.props.children}</span>
Expand Down
32 changes: 16 additions & 16 deletions test/CellGroupSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ import { getDOMNode } from './utils';
describe('CellGroup', () => {
it('Should output a cell group', () => {
const Title = 'Title';
const instanceDom = getDOMNode(<CellGroup>Title</CellGroup>);
assert.include(instanceDom.className, 'rs-cell-group');
assert.equal(instanceDom.style.transform, 'translate3d(0px, 0px, 0px)');
assert.equal(instanceDom.innerText, Title);
const instance = getDOMNode(<CellGroup>Title</CellGroup>);
assert.include(instance.className, 'rs-cell-group');
assert.equal(instance.style.transform, 'translate3d(0px, 0px, 0px)');
assert.equal(instance.innerText, Title);
});

it('Should be 100 the width', () => {
const instanceDom = getDOMNode(<CellGroup width={100} />);
const instance = getDOMNode(<CellGroup width={100} />);

assert.equal(instanceDom.style.width, '100px');
assert.equal(instance.style.width, '100px');
});

it('Should be 100 the height', () => {
const instanceDom = getDOMNode(<CellGroup height={100} />);
const instance = getDOMNode(<CellGroup height={100} />);

assert.equal(instanceDom.style.height, '100px');
assert.equal(instance.style.height, '100px');
});

it('Should be 100 the left', () => {
const instanceDom = getDOMNode(<CellGroup left={100} />);
const instance = getDOMNode(<CellGroup left={100} />);

assert.equal(instanceDom.style.transform, 'translate3d(100px, 0px, 0px)');
assert.equal(instance.style.transform, 'translate3d(100px, 0px, 0px)');
});

it('Should be fixed', () => {
const instanceDom = getDOMNode(<CellGroup fixed="left" />);
const instance = getDOMNode(<CellGroup fixed="left" />);

assert.ok(instanceDom.className.match(/\bfixed\b/));
assert.ok(instance.className.match(/\bfixed\b/));
});

it('Should have a custom className', () => {
const instanceDom = getDOMNode(<CellGroup className="custom" />);
assert.ok(instanceDom.className.match(/\bcustom\b/));
const instance = getDOMNode(<CellGroup className="custom" />);
assert.ok(instance.className.match(/\bcustom\b/));
});

it('Should have a custom style', () => {
const fontSize = '12px';
const instanceDom = getDOMNode(<CellGroup style={{ fontSize }} />);
assert.equal(instanceDom.style.fontSize, fontSize);
const instance = getDOMNode(<CellGroup style={{ fontSize }} />);
assert.equal(instance.style.fontSize, fontSize);
});
});
5 changes: 2 additions & 3 deletions test/CellSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ describe('Cell', () => {
});

it('Should have a custom style', () => {
const instance = getDOMNode(<Cell contentStyle={{ fontSize: 12 }} style={{ fontSize: 14 }} />);
assert.equal(instance.style.fontSize, '14px');
assert.equal(instance.querySelector('.rs-cell-content').style.fontSize, '12px');
const instance = getDOMNode(<Cell style={{ fontSize: 14 }} />);
assert.equal(instance.querySelector('.rs-cell-content').style.fontSize, '14px');
});

it('Should render custom children', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/ColumnGroupSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ColumnGroup', () => {
);

assert.equal(instance.querySelector('.rs-column-group-header').style.height, '10px');
assert.equal(instance.querySelector('.rs-column-group-cell').style.height, '10px');
assert.equal(instance.querySelector('.rs-column-group-header-content').style.height, '10px');
});

it('Should be centered vertically', () => {
Expand Down

0 comments on commit 7823adb

Please sign in to comment.