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.

89 lines (74 loc) 3.22 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; 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")); const _excluded = ["height", "theme", "active"]; const StyledHistogram = _styledComponents.default.div.withConfig({ displayName: "Histogram__StyledHistogram", componentId: "sc-238qiz-0" })(["display:flex;justify-content:flex-start;align-items:flex-end;width:100%;height:52px;padding-bottom:3px;overflow:hidden;"]); const StyledLoadingContainer = _styledComponents.default.div.withConfig({ displayName: "Histogram__StyledLoadingContainer", componentId: "sc-238qiz-1" })(["display:flex;width:100%;height:100%;align-items:center;justify-content:center;"]); const StyledHistogramColumn = (0, _styledComponents.default)((_ref) => { let { height, theme, active } = _ref, props = (0, _objectWithoutProperties2.default)(_ref, _excluded); return /*#__PURE__*/React.createElement("div", props); }).attrs(({ height }) => { return { style: { height: `${height.toFixed(2)}%` } }; }).withConfig({ displayName: "Histogram__StyledHistogramColumn", componentId: "sc-238qiz-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;}"], ({ theme, active }) => active ? theme.orbit.paletteBlueNormal : theme.orbit.paletteBlueLightActive); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledHistogramColumn.defaultProps = { theme: _defaultTheme.default }; const Histogram = ({ data, value, min, loading = false, loadingText, step }) => { const maxValue = !!data && Math.max(...data); const highlightFrom = Array.isArray(value) ? value[0] : 0; const 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((column, index) => { const 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;