-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from kadirahq/props-in-source-code
Props in source code
- Loading branch information
Showing
7 changed files
with
493 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
|
||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
|
||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
|
||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
|
||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
|
||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
|
||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
|
||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
|
||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
|
||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
|
||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
|
||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
|
||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
|
||
var _keys2 = _interopRequireDefault(_keys); | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
var _reactAddonsCreateFragment = require('react-addons-create-fragment'); | ||
|
||
var _reactAddonsCreateFragment2 = _interopRequireDefault(_reactAddonsCreateFragment); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var valueStyles = { | ||
func: { | ||
color: '#170' | ||
}, | ||
|
||
attr: { | ||
color: '#666' | ||
}, | ||
|
||
object: { | ||
color: '#666' | ||
}, | ||
|
||
array: { | ||
color: '#666' | ||
}, | ||
|
||
number: { | ||
color: '#a11' | ||
}, | ||
|
||
string: { | ||
color: '#22a', | ||
wordBreak: 'break-word' | ||
}, | ||
|
||
bool: { | ||
color: '#a11' | ||
}, | ||
|
||
empty: { | ||
color: '#777' | ||
} | ||
}; | ||
|
||
function previewArray(val) { | ||
var items = {}; | ||
val.slice(0, 3).forEach(function (item, i) { | ||
items['n' + i] = _react2.default.createElement(PropVal, { val: item, nested: true }); | ||
items['c' + i] = ', '; | ||
}); | ||
if (val.length > 3) { | ||
items.last = '…'; | ||
} else { | ||
delete items['c' + (val.length - 1)]; | ||
} | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.array }, | ||
'[', | ||
(0, _reactAddonsCreateFragment2.default)(items), | ||
']' | ||
); | ||
} | ||
|
||
function previewObject(val) { | ||
var names = (0, _keys2.default)(val); | ||
var items = {}; | ||
names.slice(0, 3).forEach(function (name, i) { | ||
items['k' + i] = _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.attr }, | ||
name | ||
); | ||
items['c' + i] = ': '; | ||
items['v' + i] = _react2.default.createElement(PropVal, { val: val[name], nested: true }); | ||
items['m' + i] = ', '; | ||
}); | ||
if (names.length > 3) { | ||
items.rest = '…'; | ||
} else { | ||
delete items['m' + (names.length - 1)]; | ||
} | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.object }, | ||
'{', | ||
(0, _reactAddonsCreateFragment2.default)(items), | ||
'}' | ||
); | ||
} | ||
|
||
function previewProp(val) { | ||
if (typeof val === 'number') { | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.number }, | ||
val | ||
); | ||
} | ||
if (typeof val === 'string') { | ||
if (val.length > 50) { | ||
val = val.slice(0, 50) + '…'; | ||
} | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.string }, | ||
'"', | ||
val, | ||
'"' | ||
); | ||
} | ||
if (typeof val === 'boolean') { | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.bool }, | ||
'' + val | ||
); | ||
} | ||
if (Array.isArray(val)) { | ||
return previewArray(val); | ||
} | ||
if (!val) { | ||
return _react2.default.createElement( | ||
'span', | ||
{ style: valueStyles.empty }, | ||
'' + val | ||
); | ||
} | ||
if ((typeof val === 'undefined' ? 'undefined' : (0, _typeof3.default)(val)) !== 'object') { | ||
return _react2.default.createElement( | ||
'span', | ||
null, | ||
'…' | ||
); | ||
} | ||
|
||
return previewObject(val); | ||
} | ||
|
||
var PropVal = function (_React$Component) { | ||
(0, _inherits3.default)(PropVal, _React$Component); | ||
|
||
function PropVal() { | ||
(0, _classCallCheck3.default)(this, PropVal); | ||
return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(PropVal).apply(this, arguments)); | ||
} | ||
|
||
(0, _createClass3.default)(PropVal, [{ | ||
key: 'render', | ||
value: function render() { | ||
return previewProp(this.props.val); | ||
} | ||
}]); | ||
return PropVal; | ||
}(_react2.default.Component); | ||
|
||
exports.default = PropVal; | ||
|
||
|
||
module.exports = PropVal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
|
||
var _keys2 = _interopRequireDefault(_keys); | ||
|
||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
|
||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
|
||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
|
||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
|
||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
|
||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
|
||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
|
||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
|
||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
|
||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
|
||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
|
||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
|
||
var _react = require('react'); | ||
|
||
var _react2 = _interopRequireDefault(_react); | ||
|
||
var _PropVal = require('./PropVal'); | ||
|
||
var _PropVal2 = _interopRequireDefault(_PropVal); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var Props = function (_React$Component) { | ||
(0, _inherits3.default)(Props, _React$Component); | ||
|
||
function Props() { | ||
var _Object$getPrototypeO; | ||
|
||
var _temp, _this, _ret; | ||
|
||
(0, _classCallCheck3.default)(this, Props); | ||
|
||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
|
||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_Object$getPrototypeO = (0, _getPrototypeOf2.default)(Props)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.stylesheet = { | ||
propStyle: { | ||
paddingLeft: 8 | ||
}, | ||
propNameStyle: {}, | ||
propValueStyle: {} | ||
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret); | ||
} | ||
|
||
(0, _createClass3.default)(Props, [{ | ||
key: 'render', | ||
value: function render() { | ||
var props = this.props.node.props; | ||
var defaultProps = this.props.node.type.defaultProps; | ||
if (!props || (typeof props === 'undefined' ? 'undefined' : (0, _typeof3.default)(props)) !== 'object') { | ||
return _react2.default.createElement('span', null); | ||
} | ||
|
||
var _stylesheet = this.stylesheet; | ||
var propStyle = _stylesheet.propStyle; | ||
var propValueStyle = _stylesheet.propValueStyle; | ||
var propNameStyle = _stylesheet.propNameStyle; | ||
|
||
|
||
var names = (0, _keys2.default)(props).filter(function (name) { | ||
return name[0] !== '_' && name !== 'children' && (!defaultProps || props[name] != defaultProps[name]); | ||
}); | ||
|
||
var items = []; | ||
names.slice(0, 3).forEach(function (name) { | ||
items.push(_react2.default.createElement( | ||
'span', | ||
{ style: propStyle }, | ||
_react2.default.createElement( | ||
'span', | ||
{ style: propNameStyle }, | ||
name | ||
), | ||
'=', | ||
_react2.default.createElement( | ||
'span', | ||
{ style: propValueStyle }, | ||
_react2.default.createElement(_PropVal2.default, { val: props[name] }) | ||
) | ||
)); | ||
}); | ||
|
||
return _react2.default.createElement( | ||
'span', | ||
null, | ||
items | ||
); | ||
} | ||
}]); | ||
return Props; | ||
}(_react2.default.Component); | ||
|
||
exports.default = Props; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.