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.

101 lines (85 loc) 3.49 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.StyledBarPart = exports.calculateBarPosition = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var React = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); var _rtl = require("../../../utils/rtl"); var _defaultTheme = _interopRequireDefault(require("../../../defaultTheme")); var StyledBar = _styledComponents.default.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;"]); 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) }; }; exports.calculateBarPosition = calculateBarPosition; var StyledBarPart = (0, _styledComponents.default)(function (_ref) { var width = _ref.width, left = _ref.left, theme = _ref.theme, active = _ref.active, props = (0, _objectWithoutProperties2.default)(_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: (0, _defineProperty2.default)({ width: "".concat(width, "%") }, (0, _rtl.left)({ 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 exports.StyledBarPart = StyledBarPart; StyledBarPart.defaultProps = { theme: _defaultTheme.default }; 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"; var _default = Bar; exports.default = _default;