bee-table/demo/index.js

76 lines
74 KiB
JavaScript
Raw Normal View History

2016-12-26 22:04:16 +08:00
import { Con, Row, Col } from 'bee-layout';
import { Panel } from 'bee-panel';
import Button from 'bee-button';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
2017-09-27 11:28:46 +08:00
2016-12-26 22:04:16 +08:00
2017-01-11 17:01:50 +08:00
const CARET = <i className="uf uf-arrow-down"></i>;
2016-12-26 22:04:16 +08:00
2017-01-11 17:01:50 +08:00
const CARETUP = <i className="uf uf-arrow-up"></i>;
2016-12-26 22:04:16 +08:00
2018-06-25 00:40:21 +08:00
var Demo1 = require("./demolist/Demo1");var Demo10 = require("./demolist/Demo10");var Demo11 = require("./demolist/Demo11");var Demo12 = require("./demolist/Demo12");var Demo13 = require("./demolist/Demo13");var Demo14 = require("./demolist/Demo14");var Demo15 = require("./demolist/Demo15");var Demo16 = require("./demolist/Demo16");var Demo17 = require("./demolist/Demo17");var Demo18 = require("./demolist/Demo18");var Demo19 = require("./demolist/Demo19");var Demo2 = require("./demolist/Demo2");var Demo21 = require("./demolist/Demo21");var Demo22 = require("./demolist/Demo22");var Demo23 = require("./demolist/Demo23");var Demo24 = require("./demolist/Demo24");var Demo25 = require("./demolist/Demo25");var Demo3 = require("./demolist/Demo3");var Demo4 = require("./demolist/Demo4");var Demo5 = require("./demolist/Demo5");var Demo6 = require("./demolist/Demo6");var Demo7 = require("./demolist/Demo7");var Demo8 = require("./demolist/Demo8");var Demo9 = require("./demolist/Demo9");var DemoArray = [{"example":<Demo1 />,"title":" 简单表格、两种tip、选中行背景色、文字过长","code":"/**\n*\n* @title 简单表格、两种tip、选中行背景色、文字过长\n* 【一种是bee-popover实现、一种是标签本身的tooltip】\n* @description\n*/\n\nimport React, { Component } from \"react\";\nimport { Table, Button, Popover } from 'tinper-bee';\n\nfunction getTitleTip(text){\n return(<div>\n <h3>{text}</h3> \n </div>)\n}\n\n\nconst columns = [\n { id: \"123\", title: \"性别\", dataIndex: \"b\", key: \"b\", width: 100 },\n { title: \"年龄\", dataIndex: \"c\", key: \"c\", width: 200 },\n { title: \"用户名\", dataIndex: \"a\", key: \"a\", width:80 , className:\"rowClassName\",\n render(text, record, index) {\n return(<div style={{position: 'relative'}}>\n <Popover\n placement=\"leftTop\"\n content={getTitleTip(text)}\n trigger=\"hover\"\n id=\"leftTop\"\n >\n <span\n style={{\n position: 'absolute',\n top: 5,\n left: 0,\n width: \"80px\",\n textOverflow:\"ellipsis\",\n overflow:\"hidden\",\n whiteSpace:\"nowrap\"\n }}>{text}</span>\n </Popover>\n </div>);\n }},\n {\n title: \"操作\",\n dataIndex: \"d\",\n key: \"d\",\n render(text, record, index) {\n return (\n <div style={{position: 'relative'}} title={text} >\n <a\n href=\"#\"\n tooltip={text}\n onClick={() => {\n alert('这是第'+index+'列,内容为:'+text);\n }}\n style={{\n position: 'absolute',\n top: 5,\n left: 0\n }}\n >\n 一些操作\n </a>\n </div>\n );\n }\n }\n];\n\nconst data = [\n { a: \"令狐冲\", b: \"男\", c: 41, d: \"操作\", key: \"1\" },\n { a: \"杨过叔叔的女儿黄蓉\", b: \"男\", c: 67, d: \"操作\", key: \"2\" },\n { a: \"郭靖\", b: \"男\", c: 25, d: \"操作\", key: \"3\" }\n];\n\nclass Demo1 extends Component {\n\n constructor(props){\n super(props);\n this.state = {\n data: data,\n factoryValue: 0,\n selectedRow: new Array(data.length)//状态同步\n }\n }\n\n render() {\n return (\n <Table\n columns={columns}\n data={data}\n rowClassName={(record,index,indent)=>{\n if (this.state.selectedRow[index]) {\n return 'selected';\n } else {\n return '';\n }\n }}\n onRowClick={(record,index,indent)=>{\n let selectedRow = new Array(this.state.data.length);\n selectedRow[index] = true;\n this.setState({\n factoryValue: record,\n selectedRow: selectedRow\n });\n }}\n title={currentData => <div>标题: 这
2016-12-26 22:04:16 +08:00
class Demo extends Component {
constructor(props){
super(props);
this.state = {
open: false
}
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState({ open: !this.state.open })
}
render () {
2018-01-16 10:11:10 +08:00
const { title, example, code, desc, scss_code } = this.props;
2016-12-26 22:04:16 +08:00
let caret = this.state.open ? CARETUP : CARET;
let text = this.state.open ? "隐藏代码" : "查看代码";
const header = (
2018-01-16 10:11:10 +08:00
<div>
{example}
2018-01-16 10:50:21 +08:00
<Button style={{"marginTop": "10px"}} shape="block" onClick={ this.handleClick }>
2018-01-16 10:11:10 +08:00
{ caret }
{ text }
</Button>
</div>
2016-12-26 22:04:16 +08:00
);
return (
<Col md={12} >
<h3>{ title }</h3>
<p>{ desc }</p>
2018-01-16 10:11:10 +08:00
<Panel collapsible headerContent expanded={ this.state.open } colors='bordered' header={ header } footerStyle = {{padding: 0}}>
2016-12-26 22:04:16 +08:00
<pre><code className="hljs javascript">{ code }</code></pre>
2018-01-16 10:11:10 +08:00
{ !!scss_code ? <pre><code className="hljs css">{ scss_code }</code></pre> : null }
2016-12-26 22:04:16 +08:00
</Panel>
</Col>
)
}
}
class DemoGroup extends Component {
constructor(props){
super(props)
}
render () {
return (
<Row>
{DemoArray.map((child,index) => {
return (
2018-01-16 10:11:10 +08:00
<Demo example= {child.example} title= {child.title} code= {child.code} scss_code= {child.scss_code} desc= {child.desc} key= {index}/>
2016-12-26 22:04:16 +08:00
)
})}
</Row>
)
}
}
ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));