react-select
Version:
A Select control built with and for ReactJS
144 lines (117 loc) • 5.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IndicatorsContainer = exports.indicatorsContainerCSS = exports.ValueContainer = exports.valueContainerCSS = exports.SelectContainer = exports.containerCSS = undefined;
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 _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 _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _emotion = require('emotion');
var _theme = require('../theme');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
// ==============================
// Root Container
// ==============================
var containerCSS = exports.containerCSS = function containerCSS(_ref) {
var isDisabled = _ref.isDisabled,
isRtl = _ref.isRtl;
return {
direction: isRtl ? 'rtl' : null,
pointerEvents: isDisabled ? 'none' : null, // cancel mouse events when disabled
position: 'relative'
};
};
var SelectContainer = exports.SelectContainer = function SelectContainer(props) {
var children = props.children,
className = props.className,
cx = props.cx,
getStyles = props.getStyles,
innerProps = props.innerProps,
isDisabled = props.isDisabled,
isRtl = props.isRtl;
return _react2.default.createElement(
'div',
_extends({
className: cx( /*#__PURE__*/(0, _emotion.css)(getStyles('container', props)), {
'--is-disabled': isDisabled,
'--is-rtl': isRtl
}, className)
}, innerProps),
children
);
};
// ==============================
// Value Container
// ==============================
var valueContainerCSS = exports.valueContainerCSS = function valueContainerCSS() {
return {
alignItems: 'center',
display: 'flex',
flex: 1,
flexWrap: 'wrap',
padding: _theme.spacing.baseUnit / 2 + 'px ' + _theme.spacing.baseUnit * 2 + 'px',
WebkitOverflowScrolling: 'touch',
position: 'relative'
};
};
var ValueContainer = exports.ValueContainer = function (_Component) {
_inherits(ValueContainer, _Component);
function ValueContainer() {
_classCallCheck(this, ValueContainer);
return _possibleConstructorReturn(this, (ValueContainer.__proto__ || Object.getPrototypeOf(ValueContainer)).apply(this, arguments));
}
_createClass(ValueContainer, [{
key: 'render',
value: function render() {
var _props = this.props,
children = _props.children,
className = _props.className,
cx = _props.cx,
isMulti = _props.isMulti,
getStyles = _props.getStyles,
hasValue = _props.hasValue;
return _react2.default.createElement(
'div',
{
className: cx( /*#__PURE__*/(0, _emotion.css)(getStyles('valueContainer', this.props)), {
'value-container': true,
'value-container--is-multi': isMulti,
'value-container--has-value': hasValue
}, className)
},
children
);
}
}]);
return ValueContainer;
}(_react.Component);
// ==============================
// Indicator Container
// ==============================
var indicatorsContainerCSS = exports.indicatorsContainerCSS = function indicatorsContainerCSS() {
return {
alignItems: 'center',
alignSelf: 'stretch',
display: 'flex',
flexShrink: 0
};
};
var IndicatorsContainer = exports.IndicatorsContainer = function IndicatorsContainer(props) {
var children = props.children,
className = props.className,
cx = props.cx,
getStyles = props.getStyles;
return _react2.default.createElement(
'div',
{
className: cx( /*#__PURE__*/(0, _emotion.css)(getStyles('indicatorsContainer', props)), {
'indicators': true
}, className)
},
children
);
};