1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Add dynamically addable components to table component

This commit is contained in:
Tim Daubenschütz 2015-05-20 15:44:15 +02:00
parent f4700e9842
commit 526b241fea
8 changed files with 32 additions and 24 deletions

View File

@ -0,0 +1,3 @@
.ascribe-table-header-column {
font-weight: bold;
}

View File

@ -6,6 +6,7 @@
<title>ascribe</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"></link>
<link rel="stylesheet" href="css/main.css"></link>
</head>
<body>
<div id="main" class="container"></div>

View File

@ -19,9 +19,11 @@ let PieceList = React.createClass({
render() {
// TODO:
// Specifiy how a TableItemX should look like
let columnMap = {
'thumbnail': {
'display_name': 'thumbnail',
'display_name': 'Thumbnail',
'display_type': TableItemImg
},
'artist_name': {

View File

@ -13,7 +13,7 @@ let Table = React.createClass({
return (
<div>
<TableHeader className="ascribe-table-header" columnMap={this.props.columnMap}/>
<TableHeader columnMap={this.props.columnMap}/>
{this.props.itemList.map((item, i) => {
return (
<TableItem columnMap={this.props.columnMap} columnContent={item} key={i} />

View File

@ -19,7 +19,7 @@ let TableHeader = React.createClass({
<div className="row">
{columnMapValuesList.map((val, i) => {
return (
<div className={columnClasses} key={i}>
<div className={columnClasses + ' ascribe-table-header-column'} key={i}>
{val.display_name}
</div>
);

View File

@ -6,6 +6,15 @@ import TableItemText from './table_item_text';
let TableItem = React.createClass({
mixins: [TableColumnMixin],
// ToDo: Specify that every columnMap should look like this:
// {
// 'name-of-the-data-point': {
// 'display_name': String,
// 'display_type': ReactComponent
// }
//
// }
propTypes: {
columnMap: React.PropTypes.object.isRequired,
columnContent: React.PropTypes.object.isRequired
@ -18,24 +27,19 @@ let TableItem = React.createClass({
/**
* An element in the Table can have a certain display_type.
* For example it can be an Image or a text, or a button.
* This method is recognizing different types and injecting them into the DOM.
* A display_type is just
*/
let calcColumnElementContent = () => {
return columnMapKeysList.map((key, i) => {
if(this.props.columnMap[key].display_type === TableItemImg) {
let TypeElement = this.props.columnMap[key].display_type;
return (
<div className={columnClasses}>
<TableItemImg src={this.props.columnContent[key]} width="50" key={i} />
<div className={columnClasses} key={i}>
<TypeElement content={this.props.columnContent[key]} width="50" />
</div>
);
} else if(this.props.columnMap[key].display_type === TableItemText) {
return (
<div className={columnClasses}>
<TableItemText text={this.props.columnContent[key]} key={i} />
</div>
);
}
});
};

View File

@ -5,14 +5,12 @@ import React from 'react';
*/
let TableItemImg = React.createClass({
propTypes: {
src: React.PropTypes.string.isRequired,
width: React.PropTypes.number,
height: React.PropTypes.number
content: React.PropTypes.string.isRequired,
},
render() {
return (
<img src={this.props.src} width={this.props.width} height={this.props.height} />
<img src={this.props.content} width="50" />
);
}
});

View File

@ -2,13 +2,13 @@ import React from 'react';
let TableItemText = React.createClass({
propTypes: {
text: React.PropTypes.string.isRequired
content: React.PropTypes.string.isRequired
},
render() {
return (
<span>
{this.props.text}
{this.props.content}
</span>
);
}