UNPKG

baseui

Version:

A React Component library implementing the Base design language

110 lines (108 loc) 5.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var React = _interopRequireWildcard(require("react")); var _styles = require("../styles"); var _overrides = require("../helpers/overrides"); var _constants = require("./constants"); var _pinHead = _interopRequireDefault(require("./pin-head")); var _needle = _interopRequireDefault(require("./needle")); var _dragShadow = _interopRequireDefault(require("./drag-shadow")); var _styledComponents = require("./styled-components"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /* Copyright (c) Uber Technologies, Inc. This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. */ function getColors(kind, theme) { if (kind === _constants.KIND.accent) { return { color: theme.colors.contentInversePrimary, backgroundColor: theme.colors.backgroundAccent }; } if (kind === _constants.KIND.negative) { return { color: theme.colors.contentInversePrimary, backgroundColor: theme.colors.backgroundNegative }; } return { color: theme.colors.contentInversePrimary, backgroundColor: theme.colors.backgroundInversePrimary }; } const FixedMarker = ({ size = _constants.PINHEAD_SIZES_SHAPES.medium, needle = _constants.NEEDLE_SIZES.medium, label, startEnhancer, endEnhancer, kind = _constants.KIND.default, dragging = false, overrides = {}, // @ts-ignore labelEnhancerContent = null, labelEnhancerPosition = _constants.LABEL_ENHANCER_POSITIONS.bottom, badgeEnhancerSize = null, // @ts-ignore badgeEnhancerContent = null, // eslint-disable-next-line @typescript-eslint/no-unused-vars ...restProps }) => { const [, theme] = (0, _styles.useStyletron)(); const { color, backgroundColor } = getColors(kind, theme); const doesPinHeadTransformOnDrag = needle !== _constants.NEEDLE_SIZES.none && size !== _constants.PINHEAD_SIZES_SHAPES.xxSmallCircle && size !== _constants.PINHEAD_SIZES_SHAPES.xxSmallSquare; const [Root, rootProps] = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.StyledFixedMarkerRoot); const [FixedMarkerDragContainer, fixedMarkerDragContainerProps] = (0, _overrides.getOverrides)(overrides.DragContainer, _styledComponents.StyledFixedMarkerDragContainer); const renderNeedle = needle !== _constants.NEEDLE_SIZES.none && ![_constants.PINHEAD_SIZES_SHAPES.xxSmallCircle, _constants.PINHEAD_SIZES_SHAPES.xxSmallSquare].includes(size); if (process.env.NODE_ENV !== "production") { if (needle !== _constants.NEEDLE_SIZES.none && [_constants.PINHEAD_SIZES_SHAPES.xxSmallCircle, _constants.PINHEAD_SIZES_SHAPES.xxSmallSquare].includes(size)) { console.warn(`Needles cannot be rendered with ${_constants.PINHEAD_SIZES_SHAPES.xxSmallCircle} or ${_constants.PINHEAD_SIZES_SHAPES.xxSmallSquare} pin heads`); } } const enhancers = {}; if (startEnhancer) { enhancers.startEnhancer = startEnhancer; } if (endEnhancer) { enhancers.endEnhancer = endEnhancer; } return /*#__PURE__*/React.createElement(Root, _extends({ "data-baseweb": "fixed-map-marker" }, rootProps), /*#__PURE__*/React.createElement(FixedMarkerDragContainer, _extends({ $translateAmount: _constants.dragShadowMarginTop + _constants.dragShadowHeight, $performTranslate: doesPinHeadTransformOnDrag && !dragging }, fixedMarkerDragContainerProps), /*#__PURE__*/React.createElement(_pinHead.default, _extends({ size: size, label: label }, enhancers, { color: color, background: backgroundColor, type: _constants.PINHEAD_TYPES.fixed, overrides: overrides, badgeEnhancerSize: badgeEnhancerSize, badgeEnhancerContent: badgeEnhancerContent, labelEnhancerContent: labelEnhancerContent, labelEnhancerPosition: labelEnhancerPosition, needle: needle })), renderNeedle && /*#__PURE__*/React.createElement(_needle.default, { size: needle, background: backgroundColor, overrides: overrides })), doesPinHeadTransformOnDrag && /*#__PURE__*/React.createElement(_dragShadow.default, { background: backgroundColor, dragging: dragging, height: _constants.dragShadowMarginTop + _constants.dragShadowHeight, overrides: overrides })); }; var _default = exports.default = FixedMarker;