Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Display prop values of type function and React element
Browse files Browse the repository at this point in the history
  • Loading branch information
roonyh committed Jun 22, 2016
1 parent b20a043 commit 4034092
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/PropVal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const valueStyles = {
function previewArray(val) {
const items = {};
val.slice(0, 3).forEach((item, i) => {
items[`n${i}`] = <PropVal val={item} nested />;
items[`n${i}`] = <PropVal val={item} />;
items[`c${i}`] = ', ';
});
if (val.length > 3) {
Expand All @@ -60,7 +60,7 @@ function previewObject(val) {
names.slice(0, 3).forEach((name, i) => {
items[`k${i}`] = <span style={valueStyles.attr}>{name}</span>;
items[`c${i}`] = ': ';
items[`v${i}`] = <PropVal val={val[name]} nested />;
items[`v${i}`] = <PropVal val={val[name]} />;
items[`m${i}`] = ', ';
});
if (names.length > 3) {
Expand Down Expand Up @@ -91,12 +91,18 @@ function previewProp(val) {
if (Array.isArray(val)) {
return previewArray(val);
}
if (typeof val === 'function') {
return <span style={valueStyles.func}>{val.name ? `${val.name}()` : 'anonymous()'}</span>;
}
if (!val) {
return <span style={valueStyles.empty}>{`${val}`}</span>;
}
if (typeof val !== 'object') {
return <span></span>;
}
if (React.isValidElement(val)) {
return <span style={valueStyles.object}>{`<${val.type.displayName || val.type.name }/>`}</span>
}

return previewObject(val);
}
Expand Down

0 comments on commit 4034092

Please sign in to comment.