UNPKG

@atlaskit/atlassian-navigation

Version:

A horizontal navigation component for Atlassian apps.

204 lines (201 loc) 10.6 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "AppHome", { enumerable: true, get: function get() { return _appHome.AppHome; } }); exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireWildcard(require("react")); var _react2 = require("@emotion/react"); var _constants = require("../../common/constants"); var _theme = require("../../theme"); var _utils = require("../../utils"); var _utils2 = require("./utils"); var _appHome = require("./app-home"); var _excluded = ["aria-label", "href", "icon", "logo", "logoMaxWidth", "onClick", "onMouseDown", "siteTitle", "testId"]; /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 // eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var VAR_LOGO_MAX_WIDTH = '--logo-max-width'; var VAR_PRODUCT_HOME_COLOR_ACTIVE = '--product-home-color-active'; var VAR_PRODUCT_HOME_BACKGROUND_COLOR_ACTIVE = '--product-home-bg-color-active'; var VAR_PRODUCT_HOME_BOX_SHADOW_ACTIVE = '--product-home-box-shadow-active'; var VAR_PRODUCT_HOME_COLOR_FOCUS = '--product-home-color-focus'; var VAR_PRODUCT_HOME_BACKGROUND_COLOR_FOCUS = '--product-home-bg-color-focus'; var VAR_PRODUCT_HOME_BOX_SHADOW_FOCUS = '--product-home-box-shadow-focus'; var VAR_PRODUCT_HOME_COLOR_HOVER = '--product-home-color-hover'; var VAR_PRODUCT_HOME_BACKGROUND_COLOR_HOVER = '--product-home-bg-color-hover'; var VAR_PRODUCT_HOME_BOX_SHADOW_HOVER = '--product-home-box-shadow-hover'; var productHomeButtonStyles = (0, _react2.css)((0, _defineProperty2.default)((0, _defineProperty2.default)({ display: 'flex', padding: "var(--ds-space-050, 4px)", alignItems: 'center', background: 'none', border: 0, borderRadius: "var(--ds-radius-small, 3px)", color: 'inherit', cursor: 'pointer', // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766 '&::-moz-focus-inner': { border: 0 }, // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766 '&:first-of-type': { marginInlineStart: 0 }, '&:hover': { backgroundColor: "var(".concat(VAR_PRODUCT_HOME_BACKGROUND_COLOR_HOVER, ")"), boxShadow: "var(".concat(VAR_PRODUCT_HOME_BOX_SHADOW_HOVER, ")"), color: "var(".concat(VAR_PRODUCT_HOME_COLOR_HOVER, ")") }, '&:active': { backgroundColor: "var(".concat(VAR_PRODUCT_HOME_BACKGROUND_COLOR_ACTIVE, ")"), boxShadow: "var(".concat(VAR_PRODUCT_HOME_BOX_SHADOW_ACTIVE, ")"), color: "var(".concat(VAR_PRODUCT_HOME_COLOR_ACTIVE, ")") }, '&:focus-visible': { backgroundColor: "var(".concat(VAR_PRODUCT_HOME_BACKGROUND_COLOR_FOCUS, ")"), color: "var(".concat(VAR_PRODUCT_HOME_COLOR_FOCUS, ")"), outline: "var(--ds-border-width-focused, 2px)".concat(" solid ", "var(--ds-border-focused, #4688EC)") }, // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766 'div&': { pointerEvents: 'none' } }, "@media (max-width: ".concat(_constants.PRODUCT_HOME_BREAKPOINT - 0.1, "px)"), { margin: "0 ".concat("var(--ds-space-100, 8px)") }), "@media (min-width: ".concat(_constants.PRODUCT_HOME_BREAKPOINT, "px)"), { margin: "0 ".concat("var(--ds-space-200, 16px)") })); var productLogoStyles = (0, _react2.css)((0, _defineProperty2.default)({ // Ensure anything passed into // productHome is aligned correctly display: 'flex', maxWidth: "var(".concat(VAR_LOGO_MAX_WIDTH, ")"), // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '& > *': { maxHeight: 24 }, // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '& > span > svg': { maxWidth: "var(".concat(VAR_LOGO_MAX_WIDTH, ")") } }, "@media (max-width: ".concat(_constants.PRODUCT_HOME_BREAKPOINT - 0.1, "px)"), { display: 'none' })); var customMaxHeightStyles = (0, _react2.css)({ maxHeight: 28 }); var productIconStyles = (0, _react2.css)((0, _defineProperty2.default)({ // Ensure anything passed into // productHome is aligned correctly display: 'flex', // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 '& > *': { maxHeight: 24 } }, "@media (min-width: ".concat(_constants.PRODUCT_HOME_BREAKPOINT, "px)"), { display: 'none' })); var siteTitleStyles = (0, _react2.css)({ display: 'flex', alignItems: 'center', marginInlineEnd: "var(--ds-space-050, 4px)", marginInlineStart: "var(--ds-space-050, 4px)", paddingInlineEnd: "var(--ds-space-200, 16px)" }); /** * __Product home__ * * The ProductHome component displays the product visual identity composed of: * logo, icon, and optional text. Values for logo and icon are never displayed * at the same time, where icon is used only when space is restricted. Should be * passed into `AtlassianNavigation`'s `renderProductHome` prop. * * - [Examples](https://atlassian.design/components/atlassian-navigation/examples#product-home) * - [Code](https://atlassian.design/components/atlassian-navigation/code) * * @deprecated `@atlaskit/atlassian-navigation` is deprecated. Use `@atlaskit/navigation-system` instead. */ var ProductHome = function ProductHome(_ref) { var ariaLabel = _ref['aria-label'], href = _ref.href, Icon = _ref.icon, Logo = _ref.logo, _ref$logoMaxWidth = _ref.logoMaxWidth, logoMaxWidth = _ref$logoMaxWidth === void 0 ? 260 : _ref$logoMaxWidth, onClick = _ref.onClick, onMouseDown = _ref.onMouseDown, siteTitle = _ref.siteTitle, testId = _ref.testId, rest = (0, _objectWithoutProperties2.default)(_ref, _excluded); var theme = (0, _theme.useTheme)(); var primaryButton = theme.mode.primaryButton; var _theme$mode$productHo = theme.mode.productHome, _theme$mode$productHo2 = _theme$mode$productHo.iconColor, iconColor = _theme$mode$productHo2 === void 0 ? undefined : _theme$mode$productHo2, _theme$mode$productHo3 = _theme$mode$productHo.textColor, textColor = _theme$mode$productHo3 === void 0 ? undefined : _theme$mode$productHo3; // If the theme returns the default Atlassian theme, rely on the Logo default behaviour instead if (iconColor === '#357DE8' && textColor === "var(--ds-text, #292A2E)") { iconColor = undefined; textColor = undefined; } var Tag = (0, _utils2.getTag)(onClick, href); var preventFocusRing = function preventFocusRing(e) { e.preventDefault(); onMouseDown && onMouseDown(e); }; var productHomeButtonDynamicStyles = (0, _utils.stripEmptyProperties)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, VAR_PRODUCT_HOME_COLOR_ACTIVE, primaryButton.active.color), VAR_PRODUCT_HOME_BACKGROUND_COLOR_ACTIVE, primaryButton.active.backgroundColor), VAR_PRODUCT_HOME_BOX_SHADOW_ACTIVE, primaryButton.active.boxShadow), VAR_PRODUCT_HOME_COLOR_FOCUS, primaryButton.focus.color), VAR_PRODUCT_HOME_BACKGROUND_COLOR_FOCUS, primaryButton.focus.backgroundColor), VAR_PRODUCT_HOME_BOX_SHADOW_FOCUS, primaryButton.focus.boxShadow), VAR_PRODUCT_HOME_COLOR_HOVER, primaryButton.hover.color), VAR_PRODUCT_HOME_BACKGROUND_COLOR_HOVER, primaryButton.hover.backgroundColor), VAR_PRODUCT_HOME_BOX_SHADOW_HOVER, primaryButton.hover.boxShadow), VAR_LOGO_MAX_WIDTH, "".concat(logoMaxWidth, "px"))); return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(Tag // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766 , (0, _extends2.default)({ style: productHomeButtonDynamicStyles, css: productHomeButtonStyles, href: href, onClick: onClick, onMouseDown: preventFocusRing, "data-testid": testId && "".concat(testId, "-container"), "aria-label": ariaLabel // Made all props explicit, leaving just in case // eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props }, rest), (0, _react2.jsx)("div", { css: [customMaxHeightStyles, productLogoStyles], "data-testid": testId && "".concat(testId, "-logo") }, (0, _react2.jsx)(Logo, { iconColor: iconColor, textColor: textColor // @ts-ignore - The new icons don't have an appearance prop at the moment , appearance: iconColor || textColor ? undefined : 'brand' })), (0, _react2.jsx)("div", { css: [customMaxHeightStyles, productIconStyles], "data-testid": testId && "".concat(testId, "-icon") }, (0, _react2.jsx)(Icon, { iconColor: iconColor, size: 'small' // @ts-ignore - The new icons don't have an appearance prop at the moment , appearance: iconColor || textColor ? undefined : 'brand' }))), siteTitle && (0, _react2.jsx)("div", { style: { borderRight: theme.mode.productHome.borderRight }, css: siteTitleStyles, "data-testid": testId && "".concat(testId, "-site-title") }, siteTitle)); }; var _default = exports.default = ProductHome;