semantic-react
Version:
React components for Semantic UI.
163 lines (129 loc) • 7.26 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _utilities = require('../../utilities');
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _defaultProps = require('../../defaultProps');
var _defaultProps2 = _interopRequireDefault(_defaultProps);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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; }
var validProps = {
aligned: ['top', 'bottom'],
basic: ['very'],
padded: ['very'],
valigned: ['center', 'right']
};
var Table = (_temp = _class = function (_React$PureComponent) {
_inherits(Table, _React$PureComponent);
function Table() {
_classCallCheck(this, Table);
return _possibleConstructorReturn(this, (Table.__proto__ || Object.getPrototypeOf(Table)).apply(this, arguments));
}
_createClass(Table, [{
key: 'render',
value: function render() {
/* eslint-disable no-use-before-define */
var _props = this.props,
aligned = _props.aligned,
basic = _props.basic,
celled = _props.celled,
children = _props.children,
className = _props.className,
collapsing = _props.collapsing,
compact = _props.compact,
color = _props.color,
component = _props.component,
defaultClasses = _props.defaultClasses,
columns = _props.columns,
definition = _props.definition,
fixed = _props.fixed,
inverted = _props.inverted,
padded = _props.padded,
selectable = _props.selectable,
singleLine = _props.singleLine,
size = _props.size,
sortable = _props.sortable,
stackable = _props.stackable,
striped = _props.striped,
structured = _props.structured,
unstackable = _props.unstackable,
valigned = _props.valigned,
width = _props.width,
other = _objectWithoutProperties(_props, ['aligned', 'basic', 'celled', 'children', 'className', 'collapsing', 'compact', 'color', 'component', 'defaultClasses', 'columns', 'definition', 'fixed', 'inverted', 'padded', 'selectable', 'singleLine', 'size', 'sortable', 'stackable', 'striped', 'structured', 'unstackable', 'valigned', 'width']);
/* eslint-enable no-use-before-define */
other.className = (0, _classnames2.default)(className, this.getClasses(), this.mobileFormat('stackable', stackable), this.mobileFormat('unstackable', unstackable));
return _react2.default.createElement(component, other, children);
}
}, {
key: 'getClasses',
value: function getClasses() {
var classes = {
ui: this.props.defaultClasses,
basic: this.props.basic,
collapsing: this.props.collapsing,
compact: this.props.compact,
celled: this.props.celled,
definition: this.props.definition,
fixed: this.props.fixed,
inverted: this.props.inverted,
selectable: this.props.selectable,
'single line': this.props.singleLine,
sortable: this.props.sortable,
striped: this.props.striped,
structured: this.props.structured,
table: this.props.defaultClasses
};
classes[this.props.color] = !!this.props.color;
classes[this.props.size] = !!this.props.size;
if (this.props.columns !== false) {
if (this.props.columns > 0 && this.props.columns <= 16) {
classes[_utilities.Numbers[this.props.columns] + ' column'] = true;
}
}
if (this.props.width !== false) {
if (this.props.width > 0 && this.props.width <= 16) {
classes[_utilities.Numbers[this.props.width] + ' wide'] = true;
}
}
return (0, _utilities.validateClassProps)(classes, this.props, validProps, { valigned: 'aligned' });
}
}, {
key: 'mobileFormat',
value: function mobileFormat(name, options) {
var classes = {};
Object.keys(options).forEach(function (value) {
if (options[value]) classes[value + ' ' + name] = true;
});
// all of the options are true?
return classes;
}
}]);
return Table;
}(_react2.default.PureComponent), _class.defaultProps = _extends({}, _defaultProps2.default.defaultProps, {
component: 'table',
stackable: {
computer: false,
mobile: false,
tablet: false
},
unstackable: {
computer: false,
mobile: false,
tablet: false
}
}), _temp);
exports.default = Table;
//# sourceMappingURL=table.js.map