UNPKG

@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.

68 lines (64 loc) 3.05 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import * as React from "react"; import styled from "styled-components"; import defaultTheme from "../../../defaultTheme"; import Loading from "../../../Loading"; var StyledHistogram = styled.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 = styled.div.withConfig({ displayName: "Histogram__StyledLoadingContainer", componentId: "sc-1yhgut7-1" })(["display:flex;width:100%;height:100%;align-items:center;justify-content:center;"]); var StyledHistogramColumn = styled(function (_ref) { var height = _ref.height, theme = _ref.theme, active = _ref.active, props = _objectWithoutProperties(_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 }; 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 /*#__PURE__*/React.createElement(StyledHistogram, { role: "presentation" }, loading ? /*#__PURE__*/React.createElement(StyledLoadingContainer, null, /*#__PURE__*/React.createElement(Loading, { 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 }); })); }; export default Histogram;