UNPKG

2.54 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9import elementType from 'prop-types-extra/lib/elementType';
10
11import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
12import capitalize from './utils/capitalize';
13import { DEVICE_SIZES } from './utils/StyleConfig';
14
15var propTypes = {
16 componentClass: elementType,
17
18 /**
19 * Apply clearfix
20 *
21 * on Extra small devices Phones
22 *
23 * adds class `visible-xs-block`
24 */
25 visibleXsBlock: PropTypes.bool,
26 /**
27 * Apply clearfix
28 *
29 * on Small devices Tablets
30 *
31 * adds class `visible-sm-block`
32 */
33 visibleSmBlock: PropTypes.bool,
34 /**
35 * Apply clearfix
36 *
37 * on Medium devices Desktops
38 *
39 * adds class `visible-md-block`
40 */
41 visibleMdBlock: PropTypes.bool,
42 /**
43 * Apply clearfix
44 *
45 * on Large devices Desktops
46 *
47 * adds class `visible-lg-block`
48 */
49 visibleLgBlock: PropTypes.bool
50};
51
52var defaultProps = {
53 componentClass: 'div'
54};
55
56var Clearfix = function (_React$Component) {
57 _inherits(Clearfix, _React$Component);
58
59 function Clearfix() {
60 _classCallCheck(this, Clearfix);
61
62 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
63 }
64
65 Clearfix.prototype.render = function render() {
66 var _props = this.props,
67 Component = _props.componentClass,
68 className = _props.className,
69 props = _objectWithoutProperties(_props, ['componentClass', 'className']);
70
71 var _splitBsProps = splitBsProps(props),
72 bsProps = _splitBsProps[0],
73 elementProps = _splitBsProps[1];
74
75 var classes = getClassSet(bsProps);
76
77 DEVICE_SIZES.forEach(function (size) {
78 var propName = 'visible' + capitalize(size) + 'Block';
79 if (elementProps[propName]) {
80 classes['visible-' + size + '-block'] = true;
81 }
82
83 delete elementProps[propName];
84 });
85
86 return React.createElement(Component, _extends({}, elementProps, { className: classNames(className, classes) }));
87 };
88
89 return Clearfix;
90}(React.Component);
91
92Clearfix.propTypes = propTypes;
93Clearfix.defaultProps = defaultProps;
94
95export default bsClass('clearfix', Clearfix);
\No newline at end of file