Skip to content

Commit

Permalink
fix(Table): make marginLeft of icon be congifurable, close #1474
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Dec 30, 2019
1 parent 8fe69f9 commit 84a0c69
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/table/base/cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class Cell extends React.Component {
className: PropTypes.string,
record: PropTypes.any,
value: PropTypes.any,
isIconLeft: PropTypes.bool,
colIndex: PropTypes.number,
rowIndex: PropTypes.number,
title: PropTypes.any,
Expand Down Expand Up @@ -40,6 +41,7 @@ export default class Cell extends React.Component {
static defaultProps = {
component: 'td',
type: 'body',
isIconLeft: false,
cell: value => value,
prefix: 'next-',
};
Expand Down Expand Up @@ -83,6 +85,7 @@ export default class Cell extends React.Component {
locale,
expandedIndexSimulate,
rtl,
isIconLeft,
...others
} = this.props;
const tagStyle = { ...style };
Expand Down Expand Up @@ -115,8 +118,8 @@ export default class Cell extends React.Component {
className={`${prefix}table-cell-wrapper`}
style={innerStyle}
>
{children}
{content}
{isIconLeft ? children : content}
{isIconLeft ? content : children}
</div>
</Tag>
);
Expand Down
9 changes: 8 additions & 1 deletion src/table/base/filter.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Dropdown from '../../dropdown';
import Menu from '../../menu';
import Button from '../../button';
Expand Down Expand Up @@ -123,6 +124,7 @@ export default class Filter extends React.Component {
filters,
prefix,
locale,
className,
filterMode,
filterMenuProps,
filterProps,
Expand Down Expand Up @@ -168,6 +170,11 @@ export default class Filter extends React.Component {
</div>
);

const cls = classnames({
[`${prefix}table-filter`]: true,
[className]: className,
});

return (
<Dropdown
trigger={
Expand All @@ -176,7 +183,7 @@ export default class Filter extends React.Component {
aria-label={locale.filter}
onKeyDown={this.filterKeydown}
tabIndex="0"
className={`${prefix}table-filter`}
className={cls}
>
<Icon type="filter" size="small" />
</span>
Expand Down
2 changes: 2 additions & 0 deletions src/table/base/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class Header extends React.Component {
sortElement = (
<Sort
prefix={prefix}
className={`${prefix}table-header-icon`}
dataIndex={dataIndex}
onSort={this.onSort}
sortIcons={sortIcons}
Expand All @@ -140,6 +141,7 @@ export default class Header extends React.Component {
filterElement = filters.length ? (
<Filter
dataIndex={dataIndex}
className={`${prefix}table-header-icon`}
filters={filters}
prefix={prefix}
locale={locale}
Expand Down
18 changes: 16 additions & 2 deletions src/table/base/sort.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Icon from '../../icon';
import { KEYCODE } from '../../util';

Expand All @@ -20,7 +21,15 @@ export default class Sort extends React.Component {
};
// 渲染排序
renderSort() {
const { prefix, sort, sortIcons, dataIndex, locale, rtl } = this.props,
const {
prefix,
sort,
sortIcons,
className,
dataIndex,
locale,
rtl,
} = this.props,
sortStatus = sort[dataIndex],
map = {
desc: 'descending',
Expand All @@ -42,12 +51,17 @@ export default class Sort extends React.Component {
);
});

const cls = classnames({
[`${prefix}table-sort`]: true,
[className]: className,
});

return (
<span
role="button"
tabIndex="0"
aria-label={locale[sortStatus]}
className={`${prefix}table-sort`}
className={cls}
onClick={this.handleClick.bind(this)}
onKeyDown={this.keydownHandler}
>
Expand Down
8 changes: 5 additions & 3 deletions src/table/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
.#{$css-prefix}icon-arrow-down.#{$css-prefix}table-tree-arrow,
.#{$css-prefix}icon-arrow-right.#{$css-prefix}table-tree-arrow,
#{$table-prefix}-tree-placeholder {
margin-right: 3px;
float: left;
margin-right: $table-header-icon-margin-left;
outline: 0;
cursor: pointer;
}
Expand Down Expand Up @@ -332,7 +331,6 @@
}

#{$table-prefix}-filter {
margin-left: 5px;
cursor: pointer;
width: 20px;
display: inline-block;
Expand All @@ -345,6 +343,10 @@
}
}

#{$table-prefix}-header-icon {
margin-left: $table-header-icon-margin-left;
}

#{$table-prefix}-expanded-ctrl {
cursor: pointer;
&:focus {
Expand Down
3 changes: 3 additions & 0 deletions src/table/scss/variable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ $table-header-padding-top: $s-3 !default;
/// padding (l, r)
/// @namespace size/header
$table-header-padding-left: $s-4 !default;
/// icon margin
/// @namespace size/header
$table-header-icon-margin-left: $s-2 !default;

/// padding (t, b)
/// @namespace size/cell
Expand Down
6 changes: 5 additions & 1 deletion src/table/tree/cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export default class TreeCell extends React.Component {
}
}
return (
<CellComponent {...this.props} innerStyle={firstCellStyle}>
<CellComponent
{...this.props}
innerStyle={firstCellStyle}
isIconLeft
>
{children}
{treeArrowNode}
</CellComponent>
Expand Down

0 comments on commit 84a0c69

Please sign in to comment.