@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
93 lines (74 loc) • 4.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _defaultTheme = _interopRequireDefault(require("../../../defaultTheme"));
var _Loading = _interopRequireDefault(require("../../../Loading"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var StyledHistogram = _styledComponents.default.div.withConfig({
displayName: "Histogram__StyledHistogram",
componentId: "sc-1yhgut7-0"
})(["display:flex;justify-content:flex-start;align-items:flex-end;width:100%;height:52px;padding-bottom:3px;overflow:hidden;"]);
var StyledLoadingContainer = _styledComponents.default.div.withConfig({
displayName: "Histogram__StyledLoadingContainer",
componentId: "sc-1yhgut7-1"
})(["display:flex;width:100%;height:100%;align-items:center;justify-content:center;"]);
var StyledHistogramColumn = (0, _styledComponents.default)(function (_ref) {
var height = _ref.height,
theme = _ref.theme,
active = _ref.active,
props = _objectWithoutProperties(_ref, ["height", "theme", "active"]);
return React.createElement("div", props);
}).attrs(function (_ref2) {
var height = _ref2.height;
return {
style: {
height: "".concat(height.toFixed(2), "%")
}
};
}).withConfig({
displayName: "Histogram__StyledHistogramColumn",
componentId: "sc-1yhgut7-2"
})(["position:relative;min-width:3px;flex:1 0 auto;border-radius:1px;background-color:", ";margin-right:1px;:last-child{margin:0;}:after{display:block;position:absolute;bottom:-3px;content:\" \";width:100%;height:1px;border-radius:1px;background-color:inherit;}"], function (_ref3) {
var theme = _ref3.theme,
active = _ref3.active;
return active ? theme.orbit.paletteProductNormal : theme.orbit.paletteProductLight;
});
StyledHistogramColumn.defaultProps = {
theme: _defaultTheme.default
};
var Histogram = function Histogram(_ref4) {
var data = _ref4.data,
value = _ref4.value,
min = _ref4.min,
_ref4$loading = _ref4.loading,
loading = _ref4$loading === void 0 ? false : _ref4$loading,
loadingText = _ref4.loadingText,
step = _ref4.step;
var maxValue = !!data && Math.max.apply(Math, _toConsumableArray(data));
var highlightFrom = Array.isArray(value) ? value[0] : 0;
var highlightTo = Array.isArray(value) ? value[value.length - 1] : value;
return React.createElement(StyledHistogram, null, loading ? React.createElement(StyledLoadingContainer, null, React.createElement(_Loading.default, {
type: "inlineLoader",
text: loadingText
})) : data && data.map(function (column, index) {
var properIndex = (index + min) * step;
return React.createElement(StyledHistogramColumn, {
key: encodeURIComponent(properIndex.toString()),
height: maxValue && +(column / maxValue * 100).toFixed(1),
active: properIndex >= highlightFrom && properIndex <= highlightTo
});
}));
};
var _default = Histogram;
exports.default = _default;