mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-28 18:49:57 +02:00
let's deploy this.
This commit is contained in:
33
components/decorators/keyhandling-decorator.jsx
Normal file
33
components/decorators/keyhandling-decorator.jsx
Normal file
@@ -0,0 +1,33 @@
|
||||
var React = require("react");
|
||||
var noop = require("../../lib/noop");
|
||||
|
||||
module.exports = function(Component) {
|
||||
var options = Component.keyHandlingOptions,
|
||||
propName = options.propName || "",
|
||||
values = options.values || {},
|
||||
controller = options.controller || noop,
|
||||
getDefaultProps = Component.getDefaultProps;
|
||||
|
||||
return React.createClass({
|
||||
values: values,
|
||||
|
||||
getDefaultProps: getDefaultProps,
|
||||
|
||||
onKeyDown: function(event, api) {
|
||||
var v = this.values[event.keyCode];
|
||||
if(v) {
|
||||
event.preventDefault();
|
||||
if (typeof v === "function") {
|
||||
v(api);
|
||||
} else {
|
||||
api[propName] += v;
|
||||
controller(api);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <Component {...this.props} onKeyDown={this.onKeyDown} />;
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user