Skip to content

Commit

Permalink
Objects with type: link should be displayed as links
Browse files Browse the repository at this point in the history
  • Loading branch information
snowak-cb committed Jul 25, 2017
1 parent f6fa82f commit 3cfa4c1
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Properties you can pass to the console element

| Member | Type | Description
| ---- | ---- | ----
| log | (...messages: any)=>void | Log messages to the console. If string, print the value, otherwise, print the JSON value of the message.
| log | (...messages: any)=>void | Log messages to the console. If string, print the value, otherwise, print the JSON value of the message. Objects with `type: 'link'` will be output as links using the objects `href`, `target`, and `text` properties.
| updateLastLog| (...messages: any)=>void | Replace the last message in the console. Useful for progress indicators.
| logX | (type: string, ...messages: any)=>void | Log messages of a particular type to the console. The messages will be given the class `react-console-message-{type}`.
| logTable | (tableObject: Object[, type: string])=>void | Log tabular data to the console. `tableObject` has the format `{ headers: ['header 1', 'header 2'], rows: [['row 1, col 1', 'row 1, col 2'], ['row 2, col 1', 'row 2, col 2']]}`. `headers` is optional. The optional `type` argument will be handled the same as in `logX`
| logTable | (tableObject: Object[, type: string])=>void | Log tabular data to the console. `tableObject` has the format `{ headers: ['header 1', 'header 2'], rows: [['row 1, col 1', 'row 1, col 2'], ['row 2, col 1', 'row 2, col 2']]}`. `headers` is optional. Rows can also contain objects which will be output as JSON strings or according to the `type: link` rules listed above. The optional `type` argument will be handled the same as in `logX`
| return | ()=>void | Signal the current command has finished and a new prompt should be displayed.
| clearScreen | ()=>void | Clear the visible log in the console. Does not clear command history.

Expand Down
Binary file modified dist/dist-min.tar.gz
Binary file not shown.
Binary file modified dist/dist-min.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js.map

Large diffs are not rendered by default.

Binary file modified dist/dist.tar.gz
Binary file not shown.
Binary file modified dist/dist.zip
Binary file not shown.
21 changes: 16 additions & 5 deletions dist/dist/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/dist/react-console.js.map

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions lib/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-console.js.map

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions src/react-console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,34 @@ let ConsoleMessage: React.SFC<ConsoleMessageProps> = function(props: ConsoleMess
<table>
<ConsoleTableHeader headers={data.headers} />
<tbody>
{data.rows && data.rows.map((row: string[], index: number) => {
return <tr key={index}>{row.map((cell: string, cellIndex: number) => {
return <td key={cellIndex}>{cell}</td>; })
}</tr>;
{data.rows && data.rows.map((row: any[], index: number) => {
return <tr key={index}>{row.map((cell: any, cellIndex: number) => {
if(typeof cell === 'string'){
return <td key={cellIndex}>{cell}</td>;
}else if(typeof cell === 'object' && cell.type === 'link'){
return <td key={cellIndex}><a href={cell.href} target={cell.target ? cell.target : ''}>{cell.text}</a></td>;
}else{
return <td key={cellIndex}>{JSON.stringify(cell)}</td>;
}

})}
</tr>;

})}
</tbody>
</table>
</div>;
}else{
return <div className={"react-console-message" + (props.type?" react-console-message-"+props.type:"")}>
{props.value.map((val: any)=>{
{props.value.map((val: any, i: number)=>{
if(typeof val == 'string') {
return val;
return <div key={i}>{val}</div>;
} else if(typeof val === 'object' && val.type === 'link') {
return <div key={i}><a href={val.href} target={val.target ? val.target : ''}>{val.text}</a></div>;
} else {
return JSON.stringify(val);
return <div key={i}>{JSON.stringify(val)}</div>;
}
}).join("\n")}
})}
</div>;
}
}
Expand All @@ -128,7 +139,7 @@ ConsoleMessage.defaultProps = {
}

export interface ConsoleTableObject {
rows: Array<string[]>;
rows: Array<any[]>;
headers?: Array<string>;
}

Expand Down

0 comments on commit 3cfa4c1

Please sign in to comment.