@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.
69 lines (64 loc) • 3.16 kB
JavaScript
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; }
import * as React from "react";
import styled from "styled-components";
import defaultTheme from "../../../defaultTheme";
import Loading from "../../../Loading";
const 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;"]);
const StyledLoadingContainer = styled.div.withConfig({
displayName: "Histogram__StyledLoadingContainer",
componentId: "sc-1yhgut7-1"
})(["display:flex;width:100%;height:100%;align-items:center;justify-content:center;"]);
const StyledHistogramColumn = styled((_ref) => {
let {
height,
theme,
active
} = _ref,
props = _objectWithoutProperties(_ref, ["height", "theme", "active"]);
return React.createElement("div", props);
}).attrs(({
height
}) => {
return {
style: {
height: `${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;}"], ({
theme,
active
}) => active ? theme.orbit.paletteProductNormal : theme.orbit.paletteProductLight);
StyledHistogramColumn.defaultProps = {
theme: defaultTheme
};
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 React.createElement(StyledHistogram, null, loading ? React.createElement(StyledLoadingContainer, null, React.createElement(Loading, {
type: "inlineLoader",
text: loadingText
})) : data && data.map((column, index) => {
const properIndex = (index + min) * step;
return React.createElement(StyledHistogramColumn, {
key: encodeURIComponent(properIndex.toString()),
height: maxValue && +(column / maxValue * 100).toFixed(1),
active: properIndex >= highlightFrom && properIndex <= highlightTo
});
}));
};
export default Histogram;