UNPKG

baseui

Version:

A React Component library implementing the Base design language

150 lines (146 loc) • 6.5 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 _styledComponents = require("./styled-components"); 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. */ // @ts-ignore const ConsumerLocationPuckHeading = ({ heading }) => { const [css, theme] = (0, _styles.useStyletron)(); return /*#__PURE__*/React.createElement("svg", { className: css({ height: `${6}px`, width: `${11}px`, position: 'absolute', color: theme.colors.contentAccent, transition: `${theme.animation.timing300} ${theme.animation.easeOutCurve} all` }), style: { transform: `rotate(${heading}deg) translateY(-16px)` }, width: "11", height: "6", viewBox: "0 0 11 6", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /*#__PURE__*/React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M5.5 0L0 6L5.5 5L11 6L5.5 0Z", fill: "currentColor" })); }; const ConsumerLocationPuck = ({ heading, showHeading, confidenceRadius, overrides }) => { const [, theme] = (0, _styles.useStyletron)(); const [Root, rootProps] = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.LocationPuckContainer); const [ConsumerLocationPuckCore, consumerLocationPuckCoreProps] = (0, _overrides.getOverrides)(overrides.ConsumerLocationPuckCore, _styledComponents.StyledConsumerLocationPuckCore); const [LocationPuckApproximation, locationPuckApproximationProps] = (0, _overrides.getOverrides)(overrides.LocationPuckApproximation, _styledComponents.StyledLocationPuckApproximation); return /*#__PURE__*/React.createElement(Root, rootProps, /*#__PURE__*/React.createElement(LocationPuckApproximation, _extends({ $color: theme.colors.contentAccent, $radius: confidenceRadius }, locationPuckApproximationProps)), /*#__PURE__*/React.createElement(ConsumerLocationPuckCore, consumerLocationPuckCoreProps), showHeading && /*#__PURE__*/React.createElement(ConsumerLocationPuckHeading, { heading: heading })); }; // @ts-ignore const EarnerLocationPuckHeading = ({ size, color, heading }) => { const [css, theme] = (0, _styles.useStyletron)(); return /*#__PURE__*/React.createElement("svg", { className: css({ position: 'absolute', transition: `${theme.animation.timing300} ${theme.animation.easeOutCurve} all` }), style: { // @ts-ignore transform: `rotate(${heading}deg) scale(${_constants.EARNER_LOCATION_PUCK_CORE_SCALES[size]})` }, width: "72", height: "72", viewBox: "0 0 72 72", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /*#__PURE__*/React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M36 20L52 52L36 42.8571L20 52L36 20Z", fill: color })); }; const EarnerLocationPuck = ({ heading, confidenceRadius, size, overrides }) => { const [, theme] = (0, _styles.useStyletron)(); const color = theme.colors.contentPrimary; // @ts-ignore const [Root, rootProps] = (0, _overrides.getOverrides)(overrides.Root, _styledComponents.LocationPuckContainer); const [LocationPuckApproximation, locationPuckApproximationProps] = (0, _overrides.getOverrides)( // @ts-ignore overrides.LocationPuckApproximation, _styledComponents.StyledLocationPuckApproximation); const [EarnerLocationPuckCore, earnerLocationPuckCoreProps] = (0, _overrides.getOverrides)( // @ts-ignore overrides.EarnerLocationPuckCore, _styledComponents.StyledEarnerLocationPuckCore); return /*#__PURE__*/React.createElement(Root, rootProps, /*#__PURE__*/React.createElement(LocationPuckApproximation, _extends({ $color: color, $radius: confidenceRadius }, locationPuckApproximationProps)), /*#__PURE__*/React.createElement(EarnerLocationPuckCore, _extends({ $color: color, $size: size }, earnerLocationPuckCoreProps)), /*#__PURE__*/React.createElement(EarnerLocationPuckHeading, { size: size, color: color, heading: heading })); }; const LocationPuck = ({ size = _constants.LOCATION_PUCK_SIZES.medium, heading = 0, showHeading = true, confidenceRadius = 0, type = _constants.LOCATION_PUCK_TYPES.consumer, overrides = {} }) => { if (process.env.NODE_ENV !== "production") { if (size !== _constants.LOCATION_PUCK_SIZES.medium && type === _constants.LOCATION_PUCK_TYPES.consumer) { console.warn(`Location puck size can only be applied to type === LOCATION_PUCK_TYPES.earner`); } if (!showHeading && type === _constants.LOCATION_PUCK_TYPES.earner) { console.warn(`Earner location puck must show the heading indicator`); } } const sharedProps = { heading, confidenceRadius, overrides }; return type === _constants.LOCATION_PUCK_TYPES.consumer ? /*#__PURE__*/React.createElement(ConsumerLocationPuck, _extends({}, sharedProps, { showHeading: showHeading })) : /*#__PURE__*/React.createElement(EarnerLocationPuck, _extends({}, sharedProps, { size: size })); }; var _default = exports.default = LocationPuck;