cloudhubui
Version:
Various components to use in react projects
102 lines (89 loc) • 3.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var getPlacementStyles = function getPlacementStyles(placement) {
var styles = {
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
borderTopWidth: 0,
marginTop: -2,
boxShadow: '3px 3px 5px #ccc'
};
if (placement === 'top') {
styles = {
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
borderBottomWidth: 0,
marginBottom: -2,
boxShadow: '3px -3px 5px #ccc'
};
}
return styles;
};
var getCustomStyles = function getCustomStyles(_ref) {
var error = _ref.error,
isMulti = _ref.isMulti,
sizes = _ref.sizes,
colors = _ref.colors,
inputStyle = _ref.style;
var borderColor = error ? colors.error : colors.gray;
var customStyles = {
menu: function menu(provided, state) {
var placementStyles = getPlacementStyles(state.menuPlacement, colors);
return _objectSpread(_objectSpread({}, provided), {}, {
zIndex: 10,
backgroundColor: '#FFF',
border: "1.5px solid ".concat(colors.primary || '#2684FF')
}, placementStyles);
},
option: function option(provided, state) {
return _objectSpread({}, provided);
},
control: function control(provided, state) {
var placement = state.selectProps.menuPlacement;
var style = _objectSpread({}, inputStyle);
if (state.isFocused) {
style = _objectSpread({
boxShadow: placement !== 'top' ? '3px 3px 5px #ccc' : '3px -3px 5px #ccc',
borderWidth: 1.5,
borderColor: colors.primary || '#2684FF',
'&:hover': {
borderColor: colors.primary || '#2684FF'
}
}, style);
}
if (state.menuIsOpen) {
style = _objectSpread(_objectSpread({}, placement !== 'top' ? {
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0
} : {
borderTopLeftRadius: 0,
borderTopRightRadius: 0
}), {}, {
borderWidth: 1.5,
borderColor: colors.primary || '#2684FF'
}, style);
}
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, provided), isMulti && {
minHeight: sizes.inputHeight
}), !isMulti && {
height: sizes.inputHeight
}), {}, {
borderWidth: 1,
borderColor: borderColor || provided.borderColor,
backgroundColor: '#FFF',
'&:hover': {
borderColor: colors.dark || '#333'
}
}, style);
}
};
return customStyles;
};
var _default = getCustomStyles;
exports.default = _default;