feat: 新增demo

This commit is contained in:
huyueb 2017-09-22 14:58:09 +08:00
parent 7f541c372e
commit 269e6f19de
5 changed files with 268 additions and 1 deletions

View File

@ -8,6 +8,7 @@
@import "../node_modules/bee-form-control/src/FormControl.scss";
@import "../node_modules/bee-pagination/src/Pagination.scss";
@import "../node_modules/bee-checkbox/src/Checkbox.scss";
@import "../node_modules/bee-select/src/Select.scss";
.editable-cell {
position: relative;

82
demo/demolist/Demo14.js Normal file
View File

@ -0,0 +1,82 @@
/**
*
* @title 合计表格
* @description
*
*/
import React, { Component } from "react";
import Table from "../../src";
const columns14 = [
{ title: "用户名", dataIndex: "a", key: "a", width: 100 },
{ id: "123", title: "性别", dataIndex: "b", key: "b", width: 100 },
{
title: "年龄",
dataIndex: "c",
key: "c",
width: 200,
heji: true,
render(data) {
return <a href="#">一些操作</a>;
}
},
{
title: "操作",
dataIndex: "d",
key: "d",
render(data) {
return <a href="#">一些操作</a>;
}
}
];
const columns14_ = [
{ title: "用户名", dataIndex: "a", key: "a", width: 100 },
{ id: "123", title: "性别", dataIndex: "b", key: "b", width: 100 },
{
title: "年龄",
dataIndex: "c",
key: "c",
width: 200,
heji: true
},
{
title: "操作",
dataIndex: "d",
key: "d"
}
];
const data14 = [
{ a: "令狐冲", b: "男", c: 41, key: "1" },
{ a: "杨过", b: "男", c: 67, key: "2" },
{ a: "郭靖", b: "男", c: 25, key: "3" },
{ a: "合计", d: "11", key: "31" }
];
const data14_ = [
{ a: "郭靖", b: "男", c: 25,d:11, key: "3" }
];
class Demo14 extends Component {
render() {
return (
<Table
columns={columns14}
data={data14}
heji={true}
title={currentData => <div>标题: 这是一个标题</div>}
footer={currentData => (
<Table
showHeader={false}
columns={columns14_}
data={data14_}
heji={true}
/>
)}
/>
);
}
}
export default Demo14;

183
demo/demolist/Demo15.js Normal file
View File

@ -0,0 +1,183 @@
/**
*
* @title edittype表格
* @description 这是带有增删改功能的表格
*
*/
import Button from "bee-button";
import React, { Component } from "react";
import Table from "../../src";
import Animate from "bee-animate";
import Icon from "bee-icon";
import Input from "bee-form-control";
import Checkbox from "bee-checkbox";
import Select from 'bee-select';
import Popconfirm from "bee-popconfirm";
import InputRender from "../../src/render/InputRender.js";
class Demo15 extends React.Component {
constructor(props) {
super(props);
this.state = {
dataSource: [
{
key: "0",
name: "沉鱼",
age: "y",
address: "96, 77, 89"
},
{
key: "1",
name: "落雁",
age: "y",
address: "90, 70, 80"
},
{
key: "2",
name: "闭月",
age: "n",
address: "80, 60, 80"
},
{
key: "3",
name: "羞花",
age: "y",
address: "120, 60, 90"
}
],
count: 4
};
this.columns = [
{
title: "姓名",
dataIndex: "name",
key: "name",
width: "30%",
render: (text, record, index) => (
<InputRender
value={text}
isclickTrigger={true}
onChange={this.onCellChange(index, "name")}
/>
)
},
{
title: "年龄",
dataIndex: "age",
key: "age",
render: (text, record, index) => (
<Checkbox
checked={record.age}
onChange={this.onCheckChange(index, "age")}
/>
)
},
{
title: "你懂的",
dataIndex: "address",
key: "address",
render: (text, record, index) => {
return (
<Select
defaultValue="lucy"
style={{ width: 200, marginRight: 6 }}
onChange={this.handleChange}
>
<Option value="jack">boyuzhou</Option>
<Option value="lucy">renhualiu</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="yiminghe">yuzhao</Option>
</Select>
);
}
},
{
title: "操作",
dataIndex: "operation",
key: "operation",
render: (text, record, index) => {
return this.state.dataSource.length > 1 ? (
<Popconfirm content="确认删除?" id="aa" onClose={this.onDelete(index)}>
<Icon type="uf-del" />
</Popconfirm>
) : null;
}
}
];
}
handleChange = value => {
console.log(`selected ${value}`);
};
onCheckChange = (index, key) => {
return value => {
const dataSource = [...this.state.dataSource];
dataSource[index][key] = value;
this.setState({ dataSource });
};
};
onCellChange = (index, key) => {
return value => {
const dataSource = [...this.state.dataSource];
dataSource[index][key] = value;
this.setState({ dataSource });
};
};
onDelete = index => {
return () => {
const dataSource = [...this.state.dataSource];
dataSource.splice(index, 1);
this.setState({ dataSource });
};
};
handleAdd = () => {
const { count, dataSource } = this.state;
const newData = {
key: count,
name: `凤姐 ${count}`,
age: 32,
address: `100 100 100`
};
this.setState({
dataSource: [...dataSource, newData],
count: count + 1
});
};
getBodyWrapper = body => {
return (
<Animate
transitionName="move"
component="tbody"
className={body.props.className}
>
{body.props.children}
</Animate>
);
};
render() {
const { dataSource } = this.state;
const columns = this.columns;
return (
<div>
<Button
className="editable-add-btn"
type="ghost"
onClick={this.handleAdd}
>
添加
</Button>
<Table
bordered
data={dataSource}
columns={columns}
getBodyWrapper={this.getBodyWrapper}
/>
</div>
);
}
}
export default Demo15;

File diff suppressed because one or more lines are too long

View File

@ -50,6 +50,7 @@
"bee-pagination": "^0.1.7",
"bee-panel": "latest",
"bee-popconfirm": "^0.2.2",
"bee-select": "^0.1.6",
"bee-tools": "^0.3.2",
"chai": "^3.5.0",
"console-polyfill": "~0.2.1",