tinper-bee-core
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -1,5 +0,3 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import React, { PropTypes, Component } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import createReactClass from 'create-react-class'; | ||
import align from 'dom-align'; | ||
@@ -35,4 +33,4 @@ import addEventListener from './addEventListener'; | ||
const Align = React.createClass({ | ||
propTypes: { | ||
class Align extends Component{ | ||
static propTypes = { | ||
childrenProps: PropTypes.object, | ||
@@ -46,8 +44,7 @@ align: PropTypes.object.isRequired, | ||
children: PropTypes.any, | ||
}, | ||
}; | ||
getDefaultProps() { | ||
return { | ||
static defaultProps = { | ||
target() { | ||
return window; | ||
return window; | ||
}, | ||
@@ -59,4 +56,3 @@ onAlign() { | ||
disabled: false, | ||
}; | ||
}, | ||
} | ||
@@ -70,3 +66,3 @@ componentDidMount() { | ||
} | ||
}, | ||
} | ||
@@ -100,9 +96,9 @@ componentDidUpdate(prevProps) { | ||
} | ||
}, | ||
} | ||
componentWillUnmount() { | ||
this.stopMonitorWindowResize(); | ||
}, | ||
} | ||
startMonitorWindowResize() { | ||
startMonitorWindowResize = () => { | ||
if (!this.resizeHandler) { | ||
@@ -112,5 +108,5 @@ this.bufferMonitor = buffer(this.forceAlign, this.props.monitorBufferTime); | ||
} | ||
}, | ||
} | ||
stopMonitorWindowResize() { | ||
stopMonitorWindowResize = () => { | ||
if (this.resizeHandler) { | ||
@@ -121,5 +117,5 @@ this.bufferMonitor.clear(); | ||
} | ||
}, | ||
} | ||
forceAlign() { | ||
forceAlign = () => { | ||
const props = this.props; | ||
@@ -130,3 +126,3 @@ if (!props.disabled) { | ||
} | ||
}, | ||
} | ||
@@ -146,5 +142,5 @@ render() { | ||
return child; | ||
}, | ||
}); | ||
} | ||
}; | ||
export default Align; |
127
lib/Align.js
@@ -13,6 +13,2 @@ 'use strict'; | ||
var _createReactClass = require('create-react-class'); | ||
var _createReactClass2 = _interopRequireDefault(_createReactClass); | ||
var _domAlign = require('dom-align'); | ||
@@ -28,2 +24,8 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
//import isWindow from './isWindow'; | ||
@@ -57,27 +59,35 @@ | ||
var Align = _react2.default.createClass({ | ||
propTypes: { | ||
childrenProps: _react.PropTypes.object, | ||
align: _react.PropTypes.object.isRequired, | ||
target: _react.PropTypes.func, | ||
onAlign: _react.PropTypes.func, | ||
monitorBufferTime: _react.PropTypes.number, | ||
monitorWindowResize: _react.PropTypes.bool, | ||
disabled: _react.PropTypes.bool, | ||
children: _react.PropTypes.any | ||
}, | ||
var Align = function (_Component) { | ||
_inherits(Align, _Component); | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
target: function target() { | ||
return window; | ||
}, | ||
onAlign: function onAlign() {}, | ||
function Align() { | ||
var _temp, _this, _ret; | ||
monitorBufferTime: 50, | ||
monitorWindowResize: false, | ||
disabled: false | ||
}; | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
_classCallCheck(this, Align); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.startMonitorWindowResize = function () { | ||
if (!_this.resizeHandler) { | ||
_this.bufferMonitor = buffer(_this.forceAlign, _this.props.monitorBufferTime); | ||
_this.resizeHandler = (0, _addEventListener2.default)(window, 'resize', _this.bufferMonitor); | ||
} | ||
}, _this.stopMonitorWindowResize = function () { | ||
if (_this.resizeHandler) { | ||
_this.bufferMonitor.clear(); | ||
_this.resizeHandler.remove(); | ||
_this.resizeHandler = null; | ||
} | ||
}, _this.forceAlign = function () { | ||
var props = _this.props; | ||
if (!props.disabled) { | ||
var source = _reactDom2.default.findDOMNode(_this); | ||
props.onAlign(source, (0, _domAlign2.default)(source, props.target(), props.align)); | ||
} | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
Align.prototype.componentDidMount = function componentDidMount() { | ||
var props = this.props; | ||
@@ -89,4 +99,5 @@ // if parent ref not attached .... use document.getElementById | ||
} | ||
}, | ||
componentDidUpdate: function componentDidUpdate(prevProps) { | ||
}; | ||
Align.prototype.componentDidUpdate = function componentDidUpdate(prevProps) { | ||
var reAlign = false; | ||
@@ -118,27 +129,9 @@ var props = this.props; | ||
} | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
}; | ||
Align.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.stopMonitorWindowResize(); | ||
}, | ||
startMonitorWindowResize: function startMonitorWindowResize() { | ||
if (!this.resizeHandler) { | ||
this.bufferMonitor = buffer(this.forceAlign, this.props.monitorBufferTime); | ||
this.resizeHandler = (0, _addEventListener2.default)(window, 'resize', this.bufferMonitor); | ||
} | ||
}, | ||
stopMonitorWindowResize: function stopMonitorWindowResize() { | ||
if (this.resizeHandler) { | ||
this.bufferMonitor.clear(); | ||
this.resizeHandler.remove(); | ||
this.resizeHandler = null; | ||
} | ||
}, | ||
forceAlign: function forceAlign() { | ||
var props = this.props; | ||
if (!props.disabled) { | ||
var source = _reactDom2.default.findDOMNode(this); | ||
props.onAlign(source, (0, _domAlign2.default)(source, props.target(), props.align)); | ||
} | ||
}, | ||
render: function render() { | ||
}; | ||
Align.prototype.render = function render() { | ||
var _props = this.props, | ||
@@ -159,5 +152,29 @@ childrenProps = _props.childrenProps, | ||
return child; | ||
} | ||
}); | ||
}; | ||
return Align; | ||
}(_react.Component); | ||
Align.propTypes = { | ||
childrenProps: _react.PropTypes.object, | ||
align: _react.PropTypes.object.isRequired, | ||
target: _react.PropTypes.func, | ||
onAlign: _react.PropTypes.func, | ||
monitorBufferTime: _react.PropTypes.number, | ||
monitorWindowResize: _react.PropTypes.bool, | ||
disabled: _react.PropTypes.bool, | ||
children: _react.PropTypes.any | ||
}; | ||
Align.defaultProps = { | ||
target: function target() { | ||
return window; | ||
}, | ||
onAlign: function onAlign() {}, | ||
monitorBufferTime: 50, | ||
monitorWindowResize: false, | ||
disabled: false | ||
}; | ||
; | ||
exports.default = Align; |
{ | ||
"name": "tinper-bee-core", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "style core and js util for tinper-bee", | ||
@@ -27,3 +27,2 @@ "main": "lib/index.js", | ||
"babel-cli": "^6.18.0", | ||
"prop-types": "^15.5.10", | ||
"babel-plugin-istanbul": "^3.0.0", | ||
@@ -30,0 +29,0 @@ "babel-plugin-transform-object-assign": "^6.8.0", |
@@ -74,1 +74,84 @@ # bee-core | ||
- UI组件的预设 | ||
### js方法 | ||
#### keyCode对象 | ||
引入方法: | ||
``` | ||
import keyCode from 'tinper-bee-core/lib/keyCode'; | ||
//或者 | ||
import { keyCode } from 'tinper-bee-core'; | ||
``` | ||
方法: | ||
- isTextModifyingKeyEvent 验证是否是特殊按键或组合按键 | ||
``` | ||
handleKeyDown = (e) => { | ||
if(keyCode.isTextModifyingKeyEvent(e)){ | ||
//一些操作 | ||
} | ||
} | ||
... | ||
<Input onKeyDown={this.handleKeyDown} /> | ||
``` | ||
- isCharacterKey 验证是否是文本键 | ||
``` | ||
handleKeyDown = (e) => { | ||
if(keyCode.isCharacterKey(e)){ | ||
//一些操作 | ||
} | ||
} | ||
... | ||
<Input onKeyDown={this.handleKeyDown} /> | ||
``` | ||
#### toArray 将数组安全的转换为react element 数组 | ||
#### splitComponentProps 通过父组件的propTypes拆分分别传给父子组件的props | ||
``` | ||
const propTypes = { | ||
color: PropTypes.string, | ||
size: PropTypes.string | ||
} | ||
class ParentClass extends React.Component{ | ||
render() { | ||
let props = this.props; | ||
let [parentProps, childProps] = splitComponentProps(props); | ||
return ( | ||
<div> | ||
<ChildrenClass {...childProps} /> | ||
</div> | ||
) | ||
} | ||
} | ||
ParentClass.propTypes = propTypes; | ||
``` | ||
#### createChainedFunction 创建链式调用方法 | ||
用法: | ||
``` | ||
``` | ||
#### contains 检验是否包含 | ||
#### | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
858554
9
63
2675
157