You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
4.0 KiB

  1. "use strict";
  2. function _interopDefault(ex) {
  3. return ex && "object" == typeof ex && "default" in ex ? ex.default : ex;
  4. }
  5. var React = require("react"), React__default = _interopDefault(React);
  6. function _extends() {
  7. return (_extends = Object.assign || function(target) {
  8. for (var i = 1; i < arguments.length; i++) {
  9. var source = arguments[i];
  10. for (var key in source) Object.prototype.hasOwnProperty.call(source, key) && (target[key] = source[key]);
  11. }
  12. return target;
  13. }).apply(this, arguments);
  14. }
  15. function _objectWithoutPropertiesLoose(source, excluded) {
  16. if (null == source) return {};
  17. var key, i, target = {}, sourceKeys = Object.keys(source);
  18. for (i = 0; i < sourceKeys.length; i++) key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
  19. return target;
  20. }
  21. function _inheritsLoose(subClass, superClass) {
  22. subClass.prototype = Object.create(superClass.prototype), subClass.prototype.constructor = subClass,
  23. subClass.__proto__ = superClass;
  24. }
  25. var defaultProps = {
  26. defaultInputValue: "",
  27. defaultMenuIsOpen: !1,
  28. defaultValue: null
  29. }, manageState = function(SelectComponent) {
  30. var _class, _temp;
  31. return _temp = _class = function(_Component) {
  32. function StateManager() {
  33. for (var _this, _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
  34. return (_this = _Component.call.apply(_Component, [ this ].concat(args)) || this).select = void 0,
  35. _this.state = {
  36. inputValue: void 0 !== _this.props.inputValue ? _this.props.inputValue : _this.props.defaultInputValue,
  37. menuIsOpen: void 0 !== _this.props.menuIsOpen ? _this.props.menuIsOpen : _this.props.defaultMenuIsOpen,
  38. value: void 0 !== _this.props.value ? _this.props.value : _this.props.defaultValue
  39. }, _this.onChange = function(value, actionMeta) {
  40. _this.callProp("onChange", value, actionMeta), _this.setState({
  41. value: value
  42. });
  43. }, _this.onInputChange = function(value, actionMeta) {
  44. var newValue = _this.callProp("onInputChange", value, actionMeta);
  45. _this.setState({
  46. inputValue: void 0 !== newValue ? newValue : value
  47. });
  48. }, _this.onMenuOpen = function() {
  49. _this.callProp("onMenuOpen"), _this.setState({
  50. menuIsOpen: !0
  51. });
  52. }, _this.onMenuClose = function() {
  53. _this.callProp("onMenuClose"), _this.setState({
  54. menuIsOpen: !1
  55. });
  56. }, _this;
  57. }
  58. _inheritsLoose(StateManager, _Component);
  59. var _proto = StateManager.prototype;
  60. return _proto.focus = function() {
  61. this.select.focus();
  62. }, _proto.blur = function() {
  63. this.select.blur();
  64. }, _proto.getProp = function(key) {
  65. return void 0 !== this.props[key] ? this.props[key] : this.state[key];
  66. }, _proto.callProp = function(name) {
  67. if ("function" == typeof this.props[name]) {
  68. for (var _this$props, _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) args[_key2 - 1] = arguments[_key2];
  69. return (_this$props = this.props)[name].apply(_this$props, args);
  70. }
  71. }, _proto.render = function() {
  72. var _this2 = this, _this$props2 = this.props, props = (_this$props2.defaultInputValue,
  73. _this$props2.defaultMenuIsOpen, _this$props2.defaultValue, _objectWithoutPropertiesLoose(_this$props2, [ "defaultInputValue", "defaultMenuIsOpen", "defaultValue" ]));
  74. return React__default.createElement(SelectComponent, _extends({}, props, {
  75. ref: function(_ref) {
  76. _this2.select = _ref;
  77. },
  78. inputValue: this.getProp("inputValue"),
  79. menuIsOpen: this.getProp("menuIsOpen"),
  80. onChange: this.onChange,
  81. onInputChange: this.onInputChange,
  82. onMenuClose: this.onMenuClose,
  83. onMenuOpen: this.onMenuOpen,
  84. value: this.getProp("value")
  85. }));
  86. }, StateManager;
  87. }(React.Component), _class.defaultProps = defaultProps, _temp;
  88. };
  89. exports.manageState = manageState;