Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Migrate the app bar off Emotion (#83987)

Andrei Chernykh59e9f732a41c
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.module.css b/frontend/src/metabase/nav/components/AppBar/AppBar.module.css
index 69e84f7613b..019f670fab4 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBar.module.css
+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.module.css
@@ -1,14 +1,81 @@
-.AppBarRoot {
+.appBarRoot {
position: relative;
z-index: 4;
}
-.AppBarRoot[data-with-border="true"] {
+.appBarRoot[data-with-border="true"] {
border-bottom: 1px solid var(--mb-color-border-neutral);
}
@media print {
- .AppBarRoot {
+ .appBarRoot {
display: none;
}
}
+
+/* Border and fade states of the bars; classes, so the transitions and the visibility timing stay together */
+.navBar {
+ border-bottom: 1px solid transparent;
+
+ &.withBorder {
+ border-bottom-color: var(--mb-color-border-neutral);
+ }
+
+ &.withTransition {
+ transition: border-bottom-color 200ms ease;
+ }
+}
+
+.fade {
+ transition: opacity 0.5s;
+
+ &.hidden {
+ visibility: hidden;
+ transition:
+ opacity 0.5s,
+ visibility 0s;
+ }
+}
+
+.logoFade {
+ transition: opacity 0.3s linear 0.2s;
+
+ &.hidden {
+ visibility: hidden;
+ transition: none;
+ }
+}
+
+.translateCenter {
+ transform: translate(-50%, -50%);
+}
+
+/* Element-qualified so the disabled logo keeps full opacity over Link's own disabled style, whatever the load order */
+a.logoLink {
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: 0.375rem;
+ height: 3.25rem;
+ min-width: 2.25rem;
+ max-width: 14rem;
+ line-height: 0;
+ opacity: 1;
+}
+
+.logoLinkSpaced {
+ margin-inline-end: 2rem;
+}
+
+.logoLinkSpacedGitSync {
+ margin-inline-end: 1rem;
+}
+
+.toggleIconDimmed {
+ color: var(--mb-color-text-secondary);
+
+ &:hover {
+ color: var(--mb-color-core-brand);
+ }
+}
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
index e613843f28f..57b17e170c5 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
@@ -38,7 +38,7 @@ export const AppBar = (props: AppBarProps): JSX.Element => {
return (
<header
- className={S.AppBarRoot}
+ className={S.appBarRoot}
data-element-id="app-bar"
data-testid="app-bar"
data-with-border={props.detailView != null}
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.styled.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.styled.tsx
deleted file mode 100644
index e75ec727c8d..00000000000
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.styled.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { APP_BAR_HEIGHT } from "metabase/nav/constants";
-
-interface AppBarRootProps {
- hasSidebarOpen?: boolean;
-}
-
-export const AppBarRoot = styled.div<AppBarRootProps>`
- display: flex;
- align-items: center;
- gap: 1rem;
- height: ${APP_BAR_HEIGHT};
- padding-left: 1.325rem;
- padding-right: 1rem;
- border-bottom: 1px solid
- ${(props) =>
- props.hasSidebarOpen ? "var(--mb-color-border-neutral)" : "transparent"};
- background-color: var(--mb-color-background_page-primary);
- transition: border-bottom-color 200ms ease;
-`;
-
-interface AppBarInfoContainerProps {
- isVisible?: boolean;
-}
-
-export const AppBarInfoContainer = styled.div<AppBarInfoContainerProps>`
- display: flex;
- min-width: 0;
- opacity: ${(props) => (props.isVisible ? 1 : 0)};
- visibility: ${(props) => (props.isVisible ? "visible" : "hidden")};
- transition: ${(props) =>
- props.isVisible ? `opacity 0.5s` : `opacity 0.5s, visibility 0s`};
-`;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
index 8cf9d1b95a6..57957a312f2 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
@@ -1,9 +1,11 @@
+import cx from "classnames";
import type { ReactNode } from "react";
import { t } from "ttag";
import { Nav as DetailViewNav } from "metabase/detail-view/components";
import { MetabotAppBarButton } from "metabase/metabot/components/MetabotAppBarButton";
import { useUserMetabotPermissions } from "metabase/metabot/hooks";
+import { APP_BAR_HEIGHT } from "metabase/nav/constants";
import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";
import type { DetailViewState } from "metabase/redux/store";
import { Box, Flex } from "metabase/ui";
@@ -14,7 +16,7 @@ import NewItemButton from "../NewItemButton";
import { SearchBar } from "../search/SearchBar";
import { SearchButton } from "../search/SearchButton/SearchButton";
-import { AppBarInfoContainer, AppBarRoot } from "./AppBarLarge.styled";
+import S from "./AppBar.module.css";
import { AppBarLogo } from "./AppBarLogo";
import { AppBarToggle } from "./AppBarToggle";
@@ -60,6 +62,7 @@ export const AppBarLarge = ({
onToggleNavbar,
}: AppBarLargeProps): JSX.Element => {
const isNavBarVisible = isNavBarOpen && isNavBarEnabled;
+ const isInfoVisible = !isNavBarVisible || isQuestionLineageVisible;
const { isVisible: isGitSyncVisible } =
PLUGIN_REMOTE_SYNC.useGitSyncVisible();
@@ -67,13 +70,20 @@ export const AppBarLarge = ({
useUserMetabotPermissions();
return (
- <AppBarRoot
- hasSidebarOpen={
- isNavBarVisible ||
- isMetabotVisible ||
- isDocumentSidebarOpen ||
- isMetricsViewer
- }
+ <Flex
+ className={cx(S.navBar, S.withTransition, {
+ [S.withBorder]:
+ isNavBarVisible ||
+ isMetabotVisible ||
+ isDocumentSidebarOpen ||
+ isMetricsViewer,
+ })}
+ align="center"
+ gap="lg"
+ h={APP_BAR_HEIGHT}
+ pl="1.325rem"
+ pr="lg"
+ bg="background_page-primary"
>
<Flex align="center" miw="5rem" flex="1 1 auto">
<AppBarToggle
@@ -87,8 +97,10 @@ export const AppBarLarge = ({
isGitSyncVisible={isGitSyncVisible}
/>
<PLUGIN_REMOTE_SYNC.GitSyncAppBarControls />
- <AppBarInfoContainer
- isVisible={!isNavBarVisible || isQuestionLineageVisible}
+ <Flex
+ className={cx(S.fade, { [S.hidden]: !isInfoVisible })}
+ opacity={isInfoVisible ? 1 : 0}
+ miw={0}
>
{detailView ? (
<DetailViewNav
@@ -100,7 +112,7 @@ export const AppBarLarge = ({
) : isCollectionPathVisible ? (
collectionBreadcrumbs
) : null}
- </AppBarInfoContainer>
+ </Flex>
</Flex>
{(isSearchVisible ||
isNewButtonVisible ||
@@ -128,6 +140,6 @@ export const AppBarLarge = ({
)}
</Flex>
)}
- </AppBarRoot>
+ </Flex>
);
};
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLogo.styled.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLogo.styled.tsx
deleted file mode 100644
index 22f2d6d3d32..00000000000
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLogo.styled.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Link } from "metabase/common/components/Link";
-import { doNotForwardProps } from "metabase/common/utils/doNotForwardProps";
-
-export const LogoLink = styled(
- Link,
- doNotForwardProps("isSmallAppBar", "isGitSyncVisible"),
-)<{
- isSmallAppBar: boolean;
- isGitSyncVisible: boolean;
-}>`
- cursor: pointer;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 0.375rem;
- height: 3.25rem;
- min-width: 2.25rem;
- max-width: 14rem;
- line-height: 0;
- opacity: 1;
- ${(props) =>
- !props.isSmallAppBar &&
- css`
- margin-inline-end: ${props.isGitSyncVisible ? "1rem" : "2rem"};
- `}
-`;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLogo.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLogo.tsx
index f58f16c97dc..7ff8535805e 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLogo.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarLogo.tsx
@@ -1,9 +1,11 @@
+import cx from "classnames";
import type { MouseEvent } from "react";
+import { Link } from "metabase/common/components/Link";
import { LogoIcon } from "metabase/common/components/LogoIcon";
import { useIsAtHomepageDashboard } from "metabase/common/hooks/use-is-at-homepage-dashboard";
-import { LogoLink } from "./AppBarLogo.styled";
+import S from "./AppBar.module.css";
export interface AppBarLogoProps {
isSmallAppBar?: boolean;
@@ -36,15 +38,17 @@ export function AppBarLogo({
};
return (
- <LogoLink
+ <Link
to="/"
- isSmallAppBar={Boolean(isSmallAppBar)}
- isGitSyncVisible={Boolean(isGitSyncVisible)}
+ className={cx(S.logoLink, {
+ [S.logoLinkSpaced]: !isSmallAppBar && !isGitSyncVisible,
+ [S.logoLinkSpacedGitSync]: !isSmallAppBar && isGitSyncVisible,
+ })}
onClick={handleClick}
disabled={!isNavBarEnabled}
data-testid="main-logo-link"
>
<LogoIcon height={32} />
- </LogoLink>
+ </Link>
);
}
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.styled.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarSmall.styled.tsx
deleted file mode 100644
index a7c5d83c4bd..00000000000
--- a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.styled.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { APP_BAR_HEIGHT, APP_SUBHEADER_HEIGHT } from "metabase/nav/constants";
-
-interface AppBarHeaderProps {
- isSubheaderVisible?: boolean;
-}
-
-export const AppBarHeader = styled.div<AppBarHeaderProps>`
- position: relative;
- height: ${APP_BAR_HEIGHT};
- padding: 0 1rem;
- border-bottom: 1px solid transparent;
- border-color: ${(props) =>
- !props.isSubheaderVisible && "var(--mb-color-border-neutral)"};
-`;
-
-interface AppBarSubheaderProps {
- isNavBarOpen?: boolean;
-}
-
-export const AppBarSubheader = styled.div<AppBarSubheaderProps>`
- height: ${APP_SUBHEADER_HEIGHT};
- padding: 1rem 1rem 1rem 1.25rem;
- transition: border-bottom-color 200ms ease;
- border-bottom: 1px solid
- ${(props) =>
- props.isNavBarOpen ? "var(--mb-color-border-neutral)" : "transparent"};
-`;
-
-export const AppBarToggleContainer = styled.div`
- flex: 0 0 auto;
-`;
-
-export const AppBarSearchContainer = styled.div`
- flex: 1 1 auto;
-`;
-
-interface AppBarLogoContainerProps {
- isVisible?: boolean;
-}
-
-export const AppBarLogoContainer = styled.div<AppBarLogoContainerProps>`
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- opacity: ${(props) => (props.isVisible ? 1 : 0)};
- visibility: ${(props) => (props.isVisible ? "visible" : "hidden")};
- transition: ${(props) =>
- props.isVisible ? "opacity 0.3s linear 0.2s" : "none"};
-`;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
index 7e7f3de4e3e..193c71dc06f 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
@@ -1,8 +1,10 @@
+import cx from "classnames";
import { type ReactNode, useCallback, useState } from "react";
import { Nav as DetailViewNav } from "metabase/detail-view/components";
import { MetabotAppBarButton } from "metabase/metabot/components/MetabotAppBarButton";
import { SearchBar } from "metabase/nav/components/search/SearchBar";
+import { APP_BAR_HEIGHT, APP_SUBHEADER_HEIGHT } from "metabase/nav/constants";
import type { DetailViewState } from "metabase/redux/store";
import { Box, Flex } from "metabase/ui";
import type { SearchResult } from "metabase-types/api";
@@ -10,14 +12,8 @@ import type { SearchResult } from "metabase-types/api";
import { AppSwitcher } from "../AppSwitcher";
import { SearchButton } from "../search/SearchButton/SearchButton";
+import S from "./AppBar.module.css";
import { AppBarLogo } from "./AppBarLogo";
-import {
- AppBarHeader,
- AppBarLogoContainer,
- AppBarSearchContainer,
- AppBarSubheader,
- AppBarToggleContainer,
-} from "./AppBarSmall.styled";
import { AppBarToggle } from "./AppBarToggle";
export interface AppBarSmallProps {
@@ -60,6 +56,7 @@ export const AppBarSmall = ({
const isHeaderVisible =
isLogoVisible || isNavBarEnabled || isSearchVisible || isAppSwitcherVisible;
const isSubheaderVisible = !isNavBarVisible && isInfoVisible;
+ const isLogoShown = isLogoVisible && !isSearchActive;
const handleSearchActive = useCallback(() => {
setSearchActive(true);
@@ -73,17 +70,24 @@ export const AppBarSmall = ({
return (
<Box bg="background_page-primary">
{isHeaderVisible && (
- <AppBarHeader isSubheaderVisible={isSubheaderVisible}>
+ <Box
+ className={cx(S.navBar, {
+ [S.withBorder]: !isSubheaderVisible,
+ })}
+ pos="relative"
+ h={APP_BAR_HEIGHT}
+ px="lg"
+ >
<Flex justify="space-between" align="center" gap="sm" h="100%">
- <AppBarToggleContainer>
+ <Box flex="0 0 auto">
<AppBarToggle
isSmallAppBar
isNavBarEnabled={isNavBarEnabled}
isNavBarOpen={isNavBarVisible}
onToggleClick={onToggleNavbar}
/>
- </AppBarToggleContainer>
- <AppBarSearchContainer>
+ </Box>
+ <Box flex="1 1 auto">
{isSearchVisible &&
(isEmbeddingIframe ? (
<SearchBar
@@ -96,22 +100,38 @@ export const AppBarSmall = ({
<SearchButton />
</Flex>
))}
- </AppBarSearchContainer>
+ </Box>
{!isEmbeddingIframe && <MetabotAppBarButton />}
{isAppSwitcherVisible && <AppSwitcher />}
</Flex>
- <AppBarLogoContainer isVisible={isLogoVisible && !isSearchActive}>
+ <Box
+ className={cx(S.translateCenter, S.logoFade, {
+ [S.hidden]: !isLogoShown,
+ })}
+ opacity={isLogoShown ? 1 : 0}
+ pos="absolute"
+ top="50%"
+ left="50%"
+ >
<AppBarLogo
isSmallAppBar
isLogoVisible={isLogoVisible}
isNavBarEnabled={isNavBarEnabled}
onLogoClick={onCloseNavbar}
/>
- </AppBarLogoContainer>
- </AppBarHeader>
+ </Box>
+ </Box>
)}
{isSubheaderVisible && (
- <AppBarSubheader isNavBarOpen={isNavBarVisible}>
+ <Box
+ className={cx(S.navBar, S.withTransition, {
+ [S.withBorder]: isNavBarVisible,
+ })}
+ h={APP_SUBHEADER_HEIGHT}
+ py="lg"
+ pr="lg"
+ pl="1.25rem"
+ >
{detailView ? (
<DetailViewNav
rowName={detailView.rowName}
@@ -122,7 +142,7 @@ export const AppBarSmall = ({
) : isCollectionPathVisible ? (
collectionBreadcrumbs
) : null}
- </AppBarSubheader>
+ </Box>
)}
</Box>
);
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarToggle.styled.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarToggle.styled.tsx
deleted file mode 100644
index e072d7f3dcd..00000000000
--- a/frontend/src/metabase/nav/components/AppBar/AppBarToggle.styled.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Icon } from "metabase/ui";
-
-interface SidebarButtonProps {
- isSmallAppBar?: boolean;
- isNavBarEnabled?: boolean;
- isLogoVisible?: boolean;
-}
-
-export const SidebarButton = styled.button<SidebarButtonProps>`
- cursor: pointer;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 2.25rem;
- padding: ${({ isSmallAppBar }) => (isSmallAppBar ? `0.5rem 0` : `1rem 0`)};
-`;
-
-interface SidebarIconProps {
- isLogoVisible?: boolean;
-}
-
-export const SidebarIcon = styled(Icon, {
- shouldForwardProp: (propName) => propName !== "isLogoVisible",
-})<SidebarIconProps>`
- color: var(--mb-color-core-brand);
- display: block;
-
- ${(props) =>
- !props.isLogoVisible &&
- css`
- color: var(--mb-color-text-secondary);
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
- `}
-`;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarToggle.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarToggle.tsx
index a413ef0427e..7b6c89bd769 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarToggle.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarToggle.tsx
@@ -1,13 +1,15 @@
import { useHover } from "@mantine/hooks";
+import cx from "classnames";
import type React from "react";
import { useEffect, useState } from "react";
import { t } from "ttag";
+import CS from "metabase/css/core/index.css";
import { useRegisterShortcut } from "metabase/palette/hooks/useRegisterShortcut";
-import { Tooltip } from "metabase/ui";
+import { Flex, Icon, Tooltip } from "metabase/ui";
import { isMac } from "metabase/utils/browser";
-import { SidebarButton, SidebarIcon } from "./AppBarToggle.styled";
+import S from "./AppBar.module.css";
export interface AppBarToggleProps {
isSmallAppBar?: boolean;
@@ -61,16 +63,25 @@ export function AppBarToggle({
offset={-12}
openDelay={1000}
>
- <SidebarButton
- isSmallAppBar={isSmallAppBar}
- isNavBarEnabled={isNavBarEnabled}
- isLogoVisible={isLogoVisible}
+ <Flex
+ component="button"
+ className={CS.cursorPointer}
+ align="center"
+ justify="center"
+ w="2.25rem"
+ px={0}
+ py={isSmallAppBar ? "sm" : "lg"}
onClick={handleToggleClick}
data-testid="sidebar-toggle"
aria-label={t`Toggle sidebar`}
>
- <SidebarIcon isLogoVisible={isLogoVisible} size={20} name="burger" />
- </SidebarButton>
+ <Icon
+ className={cx({ [S.toggleIconDimmed]: !isLogoVisible })}
+ c={isLogoVisible ? "core-brand" : undefined}
+ size={20}
+ name="burger"
+ />
+ </Flex>
</Tooltip>
</div>
);