mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Add dynamically addable components to table component
This commit is contained in:
parent
f4700e9842
commit
526b241fea
@ -0,0 +1,3 @@
|
||||
.ascribe-table-header-column {
|
||||
font-weight: bold;
|
||||
}
|
@ -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>
|
||||
|
@ -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': {
|
||||
|
@ -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} />
|
||||
|
@ -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>
|
||||
);
|
||||
|
@ -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) {
|
||||
return (
|
||||
<div className={columnClasses}>
|
||||
<TableItemImg src={this.props.columnContent[key]} width="50" key={i} />
|
||||
</div>
|
||||
);
|
||||
} else if(this.props.columnMap[key].display_type === TableItemText) {
|
||||
return (
|
||||
<div className={columnClasses}>
|
||||
<TableItemText text={this.props.columnContent[key]} key={i} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
let TypeElement = this.props.columnMap[key].display_type;
|
||||
|
||||
return (
|
||||
<div className={columnClasses} key={i}>
|
||||
<TypeElement content={this.props.columnContent[key]} width="50" />
|
||||
</div>
|
||||
);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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" />
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user