react-select
Version:
A Select control built with and for ReactJS
68 lines (56 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.optionCSS = 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 _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 }; }
var optionCSS = exports.optionCSS = function optionCSS(_ref) {
var isDisabled = _ref.isDisabled,
isFocused = _ref.isFocused,
isSelected = _ref.isSelected;
return {
backgroundColor: isSelected ? _theme.colors.primary : isFocused ? _theme.colors.primary25 : 'transparent',
color: isDisabled ? _theme.colors.neutral20 : isSelected ? _theme.colors.neutral0 : 'inherit',
cursor: 'default',
display: 'block',
fontSize: 'inherit',
padding: _theme.spacing.baseUnit * 2 + 'px ' + _theme.spacing.baseUnit * 3 + 'px',
width: '100%',
userSelect: 'none',
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
// provide some affordance on touch devices
':active': {
backgroundColor: isSelected ? _theme.colors.primary : _theme.colors.primary50
}
};
};
var Option = function Option(props) {
var children = props.children,
className = props.className,
cx = props.cx,
getStyles = props.getStyles,
isDisabled = props.isDisabled,
isFocused = props.isFocused,
isSelected = props.isSelected,
innerRef = props.innerRef,
innerProps = props.innerProps;
return _react2.default.createElement(
'div',
_extends({
ref: innerRef,
className: cx( /*#__PURE__*/(0, _emotion.css)(getStyles('option', props)), {
'option': true,
'option--is-disabled': isDisabled,
'option--is-focused': isFocused,
'option--is-selected': isSelected
}, className)
}, innerProps),
children
);
};
exports.default = Option;