Skip to content

Commit

Permalink
💄 Improve Table demo color style
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed May 14, 2019
1 parent 6379999 commit 5313777
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 88 deletions.
75 changes: 39 additions & 36 deletions components/table/demo/edit-cell.md
Expand Up @@ -16,7 +16,6 @@ Table with editable cells.
```jsx
import { Table, Input, Button, Popconfirm, Form } from 'antd';

const FormItem = Form.Item;
const EditableContext = React.createContext();

const EditableRow = ({ form, index, ...props }) => (
Expand Down Expand Up @@ -52,46 +51,50 @@ class EditableCell extends React.Component {
});
};

render() {
renderCell = form => {
this.form = form;
const { children, dataIndex, record, title } = this.props;
const { editing } = this.state;
const { editable, dataIndex, title, record, index, handleSave, ...restProps } = this.props;
return editing ? (
<Form.Item style={{ margin: 0 }}>
{form.getFieldDecorator(dataIndex, {
rules: [
{
required: true,
message: `${title} is required.`,
},
],
initialValue: record[dataIndex],
})(<Input ref={node => (this.input = node)} onPressEnter={this.save} onBlur={this.save} />)}
</Form.Item>
) : (
<div
className="editable-cell-value-wrap"
style={{ paddingRight: 24 }}
onClick={this.toggleEdit}
>
{children}
</div>
);
};

render() {
const {
editable,
dataIndex,
title,
record,
index,
handleSave,
children,
...restProps
} = this.props;
return (
<td {...restProps}>
{editable ? (
<EditableContext.Consumer>
{form => {
this.form = form;
return editing ? (
<FormItem style={{ margin: 0 }}>
{form.getFieldDecorator(dataIndex, {
rules: [
{
required: true,
message: `${title} is required.`,
},
],
initialValue: record[dataIndex],
})(
<Input
ref={node => (this.input = node)}
onPressEnter={this.save}
onBlur={this.save}
/>,
)}
</FormItem>
) : (
<div
className="editable-cell-value-wrap"
style={{ paddingRight: 24 }}
onClick={this.toggleEdit}
>
{restProps.children}
</div>
);
}}
</EditableContext.Consumer>
<EditableContext.Consumer>{this.renderCell}</EditableContext.Consumer>
) : (
restProps.children
children
)}
</td>
);
Expand Down
105 changes: 53 additions & 52 deletions components/table/demo/edit-row.md
Expand Up @@ -25,7 +25,6 @@ for (let i = 0; i < 100; i++) {
address: `London Park no. ${i}`,
});
}
const FormItem = Form.Item;
const EditableContext = React.createContext();

class EditableCell extends React.Component {
Expand All @@ -36,34 +35,40 @@ class EditableCell extends React.Component {
return <Input />;
};

render() {
const { editing, dataIndex, title, inputType, record, index, ...restProps } = this.props;
renderCell = ({ getFieldDecorator }) => {
const {
editing,
dataIndex,
title,
inputType,
record,
index,
children,
...restProps
} = this.props;
return (
<EditableContext.Consumer>
{form => {
const { getFieldDecorator } = form;
return (
<td {...restProps}>
{editing ? (
<FormItem style={{ margin: 0 }}>
{getFieldDecorator(dataIndex, {
rules: [
{
required: true,
message: `Please Input ${title}!`,
},
],
initialValue: record[dataIndex],
})(this.getInput())}
</FormItem>
) : (
restProps.children
)}
</td>
);
}}
</EditableContext.Consumer>
<td {...restProps}>
{editing ? (
<Form.Item style={{ margin: 0 }}>
{getFieldDecorator(dataIndex, {
rules: [
{
required: true,
message: `Please Input ${title}!`,
},
],
initialValue: record[dataIndex],
})(this.getInput())}
</Form.Item>
) : (
children
)}
</td>
);
};

render() {
return <EditableContext.Consumer>{this.renderCell}</EditableContext.Consumer>;
}
}

Expand Down Expand Up @@ -96,31 +101,27 @@ class EditableTable extends React.Component {
render: (text, record) => {
const { editingKey } = this.state;
const editable = this.isEditing(record);
return (
<div>
{editable ? (
<span>
<EditableContext.Consumer>
{form => (
<a
href="javascript:;"
onClick={() => this.save(form, record.key)}
style={{ marginRight: 8 }}
>
Save
</a>
)}
</EditableContext.Consumer>
<Popconfirm title="Sure to cancel?" onConfirm={() => this.cancel(record.key)}>
<a>Cancel</a>
</Popconfirm>
</span>
) : (
<a disabled={editingKey !== ''} onClick={() => this.edit(record.key)}>
Edit
</a>
)}
</div>
return editable ? (
<span>
<EditableContext.Consumer>
{form => (
<a
href="javascript:;"
onClick={() => this.save(form, record.key)}
style={{ marginRight: 8 }}
>
Save
</a>
)}
</EditableContext.Consumer>
<Popconfirm title="Sure to cancel?" onConfirm={() => this.cancel(record.key)}>
<a>Cancel</a>
</Popconfirm>
</span>
) : (
<a disabled={editingKey !== ''} onClick={() => this.edit(record.key)}>
Edit
</a>
);
},
},
Expand Down

0 comments on commit 5313777

Please sign in to comment.