diff --git a/examples/settings.js b/examples/settings.js index b63dccc0..812d8415 100644 --- a/examples/settings.js +++ b/examples/settings.js @@ -227,9 +227,32 @@ export var settings = { } } ] + }, + { + id: 'highlight-row', + className: 'row', + children: [ + { + type: 'Highlight', + key: 'highlight1', + data: [ + { + cols: [ + {rows:[ + {label: 'label 1', val: 'Value 1'}, + {label: 'Full Link', val: 'This is a full link', url:'http://google.com', isLink:true} + ]}, + {rows:[ + {label: 'label 2', val: 'Value 2'} + ]} + ] + } + ] + } + ] } ] -} +}; let climateVars = { diff --git a/src/components/Highlight.js b/src/components/Highlight.js index 5cc5f595..c0e87549 100644 --- a/src/components/Highlight.js +++ b/src/components/Highlight.js @@ -7,6 +7,10 @@ export default class Highlight extends BaseComponent { render() { let cols = this.props.data[0].cols || []; + const existy = (obj) => { + return obj != null; + }; + return (
@@ -14,13 +18,44 @@ export default class Highlight extends BaseComponent { return
{ col.rows.map( (row, j) => { let output = []; + // Create label & val keys by stripping spaces from their values and appending the map index. + let labelKey = (row.label.replace(/\s/g,'-')).toLowerCase() + j; + let valKey = (row.val.slice(0,8)).replace(/\s/g,'-').toLowerCase() + j; + if (row.isLink) { - output.push( - { row.label ? row.label : row.val} - ) + let label = existy(row.label); + let value = existy(row.val); + let url = existy(row.url); + + switch (true) { + case (label && value && url) : + output.push({ row.label }); + output.push( + { row.val } + ); + break; + case (!label && value && url): + output.push( + { row.val } + ); + break; + case (label && !value && url): + output.push( + { row.label } + ); + break; + case ((label || value) && !url): + output.push( + { row.label ? row.label : row.val} + ); + break; + default: + console.log('invalid or empty row values.') + } + } else { - output.push({ row.label }) - output.push({ row.val }) + output.push({ row.label }); + output.push({ row.val }) } return (