@atlaskit/atlassian-navigation
Version:
A horizontal navigation component for Atlassian apps.
172 lines (169 loc) • 7.9 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["aria-label", "href", "name", "icon", "onClick", "onMouseDown", "siteTitle", "testId"];
/**
* @jsxRuntime classic
* @jsx jsx
*/
import React, { Fragment } from 'react';
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
import { css, jsx } from '@emotion/react';
import { Inline, Text } from '@atlaskit/primitives/compiled';
import { PRODUCT_HOME_BREAKPOINT } from '../../common/constants';
import { useTheme } from '../../theme';
import { stripEmptyProperties } from '../../utils';
import { getTag } from './utils';
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 = css(_defineProperty(_defineProperty({
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(PRODUCT_HOME_BREAKPOINT - 0.1, "px)"), {
margin: "0 ".concat("var(--ds-space-100, 8px)")
}), "@media (min-width: ".concat(PRODUCT_HOME_BREAKPOINT, "px)"), {
margin: "0 ".concat("var(--ds-space-200, 16px)")
}));
var appHomeIconStyles = css({
borderRadius: '10px'
});
var appIconStyles = css({
display: 'flex',
maxWidth: 24
});
var appLogoTextStyles = css(_defineProperty({
// Logo text should never wrap or overflow
width: 'max-content',
paddingInlineEnd: "var(--ds-space-025, 2px)"
}, "@media (max-width: ".concat(PRODUCT_HOME_BREAKPOINT - 0.1, "px)"), {
display: 'none'
}));
var siteTitleStyles = css({
display: 'flex',
alignItems: 'center',
marginInlineEnd: "var(--ds-space-050, 4px)",
marginInlineStart: "var(--ds-space-050, 4px)",
paddingInlineEnd: "var(--ds-space-200, 16px)"
});
/**
* __App home__
*
* A variant of the ProductHome component designed for use with the updated app logos.
*
* Takes an icon, displayed at all viewport sizes, and a product name, which is
* displayed only at larger viewport sizes.
*
* - [Examples](https://atlassian.design/components/atlassian-navigation/examples#app-product-home)
* - [Code](https://atlassian.design/components/atlassian-navigation/code)
*
* @deprecated `@atlaskit/atlassian-navigation` is deprecated. Use `@atlaskit/navigation-system` instead.
*/
export var AppHome = function AppHome(_ref) {
var ariaLabel = _ref['aria-label'],
href = _ref.href,
name = _ref.name,
Icon = _ref.icon,
onClick = _ref.onClick,
onMouseDown = _ref.onMouseDown,
siteTitle = _ref.siteTitle,
testId = _ref.testId,
rest = _objectWithoutProperties(_ref, _excluded);
var theme = useTheme();
var primaryButton = theme.mode.primaryButton;
// After the brand refresh, iconColor and textColor should be set to 'undefined' to allow the original
// multi-color logo tile colors to be visible, rather than a hardcoded blue.
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;
// The default theme is set at module scope and immediately used in context.
// To allow the feature flag to switch the logo color at runtime, we also detect the original hardcoded
// values and override them to undefined.
if (iconColor === '#357DE8' && textColor === "var(--ds-text, #292A2E)") {
iconColor = undefined;
textColor = undefined;
}
var Tag = getTag(onClick, href);
var preventFocusRing = function preventFocusRing(e) {
e.preventDefault();
onMouseDown && onMouseDown(e);
};
var productHomeButtonDynamicStyles = stripEmptyProperties(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, 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));
return jsx(Fragment, null, jsx(Tag
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
, _extends({
style: productHomeButtonDynamicStyles,
css: [productHomeButtonStyles, appHomeIconStyles],
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), jsx(Inline, {
space: "space.075",
alignBlock: "center"
}, jsx("div", {
css: [appIconStyles],
"data-testid": testId && "".concat(testId, "-icon")
}, jsx(Icon, {
iconColor: iconColor,
shouldUseNewLogoDesign: true,
size: "small",
appearance: "brand"
})), jsx("span", {
css: appLogoTextStyles
}, jsx(Text, {
"aria-hidden": true,
color: "inherit",
weight: "semibold"
}, name)))), siteTitle && jsx("div", {
style: {
borderRight: theme.mode.productHome.borderRight
},
css: siteTitleStyles,
"data-testid": testId && "".concat(testId, "-site-title")
}, siteTitle));
};