@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.
87 lines (72 loc) • 3.64 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _defaultTheme = _interopRequireDefault(require("../../../defaultTheme"));
var _Loading = _interopRequireDefault(require("../../../Loading"));
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 = (0, _objectWithoutProperties2.default)(_ref, ["height", "theme", "active"]);
return /*#__PURE__*/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.paletteBlueNormal : theme.orbit.paletteBlueLightActive;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
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, (0, _toConsumableArray2.default)(data));
var highlightFrom = Array.isArray(value) ? value[0] : 0;
var highlightTo = Array.isArray(value) ? value[value.length - 1] : value;
return /*#__PURE__*/React.createElement(StyledHistogram, {
role: "presentation"
}, loading ? /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(_Loading.default, {
type: "inlineLoader",
text: loadingText
})) : data && data.map(function (column, index) {
var properIndex = (index + min) * step;
return /*#__PURE__*/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;