all files / src/ActionBar/ ActionBar.jsx

77.55% Statements 76/98
51.61% Branches 32/62
61.9% Functions 13/21
94.44% Lines 68/72
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202                                                                              13× 13× 11×               13×                                                     13× 13×       13×     13×             11×     13× 13×                     13×                         13× 13×   13×   13×                                                  
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
 
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
 
var _classnames = require('classnames');
 
var _classnames2 = _interopRequireDefault(_classnames);
 
var _propTypes = require('prop-types');
 
var _propTypes2 = _interopRequireDefault(_propTypes);
 
var _uxcoreButton = require('uxcore-button');
 
var _uxcoreButton2 = _interopRequireDefault(_uxcoreButton);
 
var _react = require('react');
 
var _react2 = _interopRequireDefault(_react);
 
var _SearchBar = require('./SearchBar');
 
var _SearchBar2 = _interopRequireDefault(_SearchBar);
 
var _ColumnPicker = require('./ColumnPicker');
 
var _ColumnPicker2 = _interopRequireDefault(_ColumnPicker);
 
var _LinkBar = require('./LinkBar');
 
var _LinkBar2 = _interopRequireDefault(_LinkBar);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
function _possibleConstructorReturn(self, call) { Iif (!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) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Grid Component for uxcore
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * @author zhouquan.yezq
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                *
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * Copyright 2014-2015, UXCore Team, Alinw.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * All rights reserved.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */
 
var ActionBar = function (_React$Component) {
  _inherits(ActionBar, _React$Component);
 
  function ActionBar() {
    _classCallCheck(this, ActionBar);
 
    return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
  }
 
  /**
   *  convert ActionBar config from hash to array
   */
  ActionBar.getActionItem = function getActionItem(config) {
    var items = [];
    if (config instanceof Array) {
      items = config;
    } else Iif ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object') {
      Object.keys(config).forEach(function (item) {
        items.push({
          title: item,
          callback: config[item]
        });
      });
    }
    return items;
  };
 
  ActionBar.prototype.handleSearch = function handleSearch(value) {
    this.props.onSearch(value);
  };
 
  ActionBar.prototype.renderActionBtn = function renderActionBtn(item, index) {
    var me = this;
    var itemProps = {
      className: me.props.prefixCls + '-item',
      onClick: item.callback || function () {},
      type: 'secondary',
      key: index
    };
    Iif (!!item.render && typeof item.render === 'function') {
      return _react2['default'].createElement(
        'div',
        itemProps,
        item.render(item.title)
      );
    }
    if (index === 0) {
      itemProps.type = 'outline';
    }
    return _react2['default'].createElement(
      _uxcoreButton2['default'],
      _extends({
        size: 'medium',
        disabled: item.disabled || false
      }, itemProps),
      item.title
    );
  };
 
  ActionBar.prototype.renderLinkBar = function renderLinkBar() {
    var me = this;
    var _me$props = me.props,
        linkBar = _me$props.linkBar,
        tablePrefixCls = _me$props.tablePrefixCls;
 
    return _react2['default'].createElement(_LinkBar2['default'], { config: linkBar, prefixCls: tablePrefixCls + '-linkbar' });
  };
 
  ActionBar.prototype.renderSearchBar = function renderSearchBar() {
    if (this.props.showSearch) {
      var me = this;
      var searchBarProps = {
        onSearch: me.handleSearch.bind(me),
        key: 'searchbar',
        placeholder: me.props.searchBarPlaceholder,
        prefixCls: me.props.tablePrefixCls + '-searchbar'
      };
      return _react2['default'].createElement(_SearchBar2['default'], searchBarProps);
    }
    return null;
  };
 
  ActionBar.prototype.renderColumnPicker = function renderColumnPicker() {
    var me = this;
    var _me$props2 = me.props,
        showColumnPicker = _me$props2.showColumnPicker,
        columns = _me$props2.columns,
        handleColumnPickerChange = _me$props2.handleColumnPickerChange,
        handleColumnPickerCheckAll = _me$props2.handleColumnPickerCheckAll,
        checkboxColumnKey = _me$props2.checkboxColumnKey,
        showColumnPickerCheckAll = _me$props2.showColumnPickerCheckAll,
        width = _me$props2.width,
        locale = _me$props2.locale,
        tablePrefixCls = _me$props2.tablePrefixCls;
 
    if (!showColumnPicker) {
      return null;
    }
    return _react2['default'].createElement(_ColumnPicker2['default'], {
      columns: columns,
      locale: locale,
      dropdownMaxWidth: width,
      checkboxColumnKey: checkboxColumnKey,
      handleColumnPickerChange: handleColumnPickerChange,
      handleColumnPickerCheckAll: handleColumnPickerCheckAll,
      showColumnPickerCheckAll: showColumnPickerCheckAll,
      prefixCls: tablePrefixCls + '-column-picker'
    });
  };
 
  ActionBar.prototype.render = function render() {
    var me = this;
    var props = me.props;
 
    var barConfig = props.actionBarConfig;
 
    return _react2['default'].createElement(
      'div',
      {
        className: (0, _classnames2['default'])(props.tablePrefixCls + '-actionbar', {
          'fn-clear': true
        })
      },
      ActionBar.getActionItem(barConfig).map(function (item, index) {
        return me.renderActionBtn(item, index);
      }),
      me.renderSearchBar(),
      me.renderColumnPicker(),
      me.renderLinkBar()
    );
  };
 
  return ActionBar;
}(_react2['default'].Component);
 
ActionBar.propTypes = {
  showSearch: _propTypes2['default'].bool,
  onSearch: _propTypes2['default'].func
};
 
ActionBar.defaultProps = {
  showSearch: false,
  onSearch: function onSearch() {}
};
 
exports['default'] = ActionBar;
module.exports = exports['default'];