UNPKG

ssc-refer

Version:
127 lines (104 loc) 3.52 kB
'use strict'; exports.__esModule = true; var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _reactBootstrap = require('react-bootstrap'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var BaseContainer = function BaseContainer(props) { return _react2['default'].createElement( 'ul', (0, _extends3['default'])({}, props, { className: (0, _classnames2['default'])('dropdown-menu', props.className) }), props.children ); }; /** * Menu component that automatically handles pagination and empty state when * passed a set of filtered and truncated results. */ var Table = _react2['default'].createClass({ displayName: 'Table', propTypes: { /** * Specify menu alignment. The default value is `justify`, which makes the * menu as wide as the input and truncates long values. Specifying `left` * or `right` will align the menu to that side and the width will be * determined by the length of menu item values. */ align: _propTypes2['default'].oneOf(['justify', 'left', 'right']), /** * Message to display in the menu if there are no valid results. */ emptyLabel: _propTypes2['default'].string, /** * Maximum height of the dropdown menu, in px. */ maxHeight: _propTypes2['default'].number, /** * Prompt displayed when large data sets are paginated. */ paginationText: _propTypes2['default'].string }, getDefaultProps: function getDefaultProps() { return { align: 'justify', emptyLabel: '无数据.', maxHeight: 300, paginate: true, paginationText: '显示更多...' }; }, render: function render() { var _props = this.props, align = _props.align, children = _props.children, className = _props.className, emptyLabel = _props.emptyLabel; var noResults = _react.Children.count(children) === 0; // If an empty string is passed, suppress menu when there are no results. if (noResults && emptyLabel === '') { return null; } var contents = children; return _react2['default'].createElement( BaseContainer, { className: (0, _classnames2['default'])('bootstrap-typeahead-menu', { 'dropdown-menu-justify': align === 'justify', 'dropdown-menu-right': align === 'right' }, className), style: this._getMenuStyle() }, contents ); }, _getMenuStyle: function _getMenuStyle() { var _props2 = this.props, align = _props2.align, dropup = _props2.dropup, maxHeight = _props2.maxHeight, style = _props2.style; var menuStyle = (0, _extends3['default'])({}, style, { display: 'block', maxHeight: maxHeight + 'px', overflow: 'hidden' }); if (style) { if (dropup) { menuStyle.top = 'auto'; } else { delete menuStyle.bottom; } menuStyle.left = align === 'right' ? 'auto' : style.left; menuStyle.right = align === 'left' ? 'auto' : style.right; } return menuStyle; } }); exports['default'] = Table; module.exports = exports['default'];