@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.
80 lines (75 loc) • 2.83 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import * as React from "react";
import styled from "styled-components";
import { left as leftRight } from "../../../utils/rtl";
import defaultTheme from "../../../defaultTheme";
var StyledBar = styled.div.withConfig({
displayName: "Bar__StyledBar",
componentId: "rdurdt-0"
})(["display:block;position:relative;width:100%;height:24px;cursor:pointer;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-user-select:none;"]);
export var calculateBarPosition = function calculateBarPosition(value, max, min, hasHistogram) {
if (Array.isArray(value)) {
return {
left: +((value[0] - min) / (max - min + 1) * 100).toFixed(1),
width: +((value[value.length - 1] - value[0] + 1) / (max - min + 1) * 100).toFixed(1)
};
}
var addition = hasHistogram ? 1 : 0;
return {
left: 0,
width: +((value - min + addition) / (max - min + addition) * 100).toFixed(1)
};
};
export var StyledBarPart = styled(function (_ref) {
var width = _ref.width,
left = _ref.left,
theme = _ref.theme,
active = _ref.active,
props = _objectWithoutProperties(_ref, ["width", "left", "theme", "active"]);
return /*#__PURE__*/React.createElement("div", props);
}).attrs(function (_ref2) {
var width = _ref2.width,
left = _ref2.left,
theme = _ref2.theme;
return {
style: _defineProperty({
width: "".concat(width, "%")
}, leftRight({
theme: theme
}), "".concat(left, "%"))
};
}).withConfig({
displayName: "Bar__StyledBarPart",
componentId: "rdurdt-1"
})(["position:absolute;height:4px;top:10px;border-radius:4px;background-color:", ";"], function (_ref3) {
var theme = _ref3.theme,
active = _ref3.active;
return active ? theme.orbit.paletteBlueNormal : theme.orbit.paletteCloudDarker;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledBarPart.defaultProps = {
theme: defaultTheme
};
var Bar = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
var onMouseDown = _ref4.onMouseDown,
value = _ref4.value,
max = _ref4.max,
min = _ref4.min,
hasHistogram = _ref4.hasHistogram;
var _calculateBarPosition = calculateBarPosition(value, max, min, hasHistogram),
left = _calculateBarPosition.left,
width = _calculateBarPosition.width;
return /*#__PURE__*/React.createElement(StyledBar, {
ref: ref,
onMouseDown: onMouseDown
}, /*#__PURE__*/React.createElement(StyledBarPart, {
width: 100,
left: 0
}), /*#__PURE__*/React.createElement(StyledBarPart, {
active: true,
left: left,
width: width
}));
});
Bar.displayName = "Bar";
export default Bar;