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 main navbar, sidebar and tree node off Emotion (#84354)

Andrei Chernykh711cc81a7b2b
diff --git a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx
index d3ca1b23266..682ce13e294 100644
--- a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx
@@ -2,9 +2,7 @@ import { useId, useState } from "react";
import { t } from "ttag";
import { TreeNode } from "metabase/common/components/tree/TreeNode";
-import { PaddedSidebarLink } from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
import { SidebarLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
-import { ExpandToggleButton } from "metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.styled";
import { Box } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { DataApp } from "metabase-types/api";
@@ -22,7 +20,11 @@ export function DataAppNavbarLink({ dataApp, onItemSelect }: Props) {
dataApp;
const toggleButton = (
- <ExpandToggleButton
+ <TreeNode.ExpandToggleButton
+ c="core-brand"
+ py="xxs"
+ pl="xxxs"
+ pr={0}
aria-label={
isContentsExpanded
? t`Collapse ${displayName}`
@@ -37,7 +39,7 @@ export function DataAppNavbarLink({ dataApp, onItemSelect }: Props) {
isExpanded={isContentsExpanded}
size={12}
/>
- </ExpandToggleButton>
+ </TreeNode.ExpandToggleButton>
);
return (
@@ -55,13 +57,13 @@ export function DataAppNavbarLink({ dataApp, onItemSelect }: Props) {
{isContentsExpanded && (
<Box id={contentsId} pl="1.5rem">
- <PaddedSidebarLink
+ <SidebarLink
icon="folder"
url={`/collection/${collectionId}`}
onClick={onItemSelect}
>
{t`Contents`}
- </PaddedSidebarLink>
+ </SidebarLink>
</Box>
)}
</>
diff --git a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
index cb34eabab6c..c867e807dc5 100644
--- a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
@@ -4,7 +4,7 @@ import { CollapseSection } from "metabase/common/components/CollapseSection";
import {
SidebarHeading,
SidebarSection,
-} from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
+} from "metabase/nav/containers/MainNavbar/Sidebar";
import { useListDataAppsQuery } from "metabase-enterprise/api";
import { DataAppNavbarLink } from "./DataAppNavbarLink";
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx
index 9c9cc9a243f..a2f05a5ad3b 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx
@@ -6,7 +6,7 @@ import { Tree } from "metabase/common/components/tree";
import {
SidebarHeading,
SidebarSection,
-} from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
+} from "metabase/nav/containers/MainNavbar/Sidebar";
import { SidebarCollectionLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
import type { SyncedCollectionsSidebarSectionProps } from "metabase/plugins/types";
import { Box, Flex, Group, Text } from "metabase/ui";
diff --git a/enterprise/frontend/src/metabase-enterprise/tenants/components/MainNavSharedCollections/MainNavSharedCollections.tsx b/enterprise/frontend/src/metabase-enterprise/tenants/components/MainNavSharedCollections/MainNavSharedCollections.tsx
index 132a4fcd56b..53fe8459cdc 100644
--- a/enterprise/frontend/src/metabase-enterprise/tenants/components/MainNavSharedCollections/MainNavSharedCollections.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/tenants/components/MainNavSharedCollections/MainNavSharedCollections.tsx
@@ -11,11 +11,13 @@ import { buildCollectionTree } from "metabase/common/collections/utils";
import { Tree } from "metabase/common/components/tree";
import { getIsTenantUser, getUserIsAdmin } from "metabase/current-user";
import {
- PaddedSidebarLink,
SidebarHeading,
SidebarSection,
-} from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
-import { SidebarCollectionLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
+} from "metabase/nav/containers/MainNavbar/Sidebar";
+import {
+ SidebarCollectionLink,
+ SidebarLink,
+} from "metabase/nav/containers/MainNavbar/SidebarItems";
import { useSelector } from "metabase/redux";
import { useSetting } from "metabase/settings";
import { ActionIcon, Flex, Icon, Modal, Tooltip } from "metabase/ui";
@@ -147,17 +149,14 @@ export const MainNavSharedCollections = ({
}
/>
{canAccessTenantSpecificCollections && (
- <PaddedSidebarLink icon="group" url={tenantSpecificCollections()}>
+ <SidebarLink icon="group" url={tenantSpecificCollections()}>
{t`Tenant collections`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
{isAdmin && (
- <PaddedSidebarLink
- icon="group"
- url={tenantUsersPersonalCollections()}
- >
+ <SidebarLink icon="group" url={tenantUsersPersonalCollections()}>
{t`Tenant users' personal collections`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
</SidebarSection>
)}
diff --git a/frontend/src/metabase/admin/permissions/components/FilterableTree/AdminTreeNode.module.css b/frontend/src/metabase/admin/permissions/components/FilterableTree/AdminTreeNode.module.css
index 6a5070a1dc3..3a673a82cdc 100644
--- a/frontend/src/metabase/admin/permissions/components/FilterableTree/AdminTreeNode.module.css
+++ b/frontend/src/metabase/admin/permissions/components/FilterableTree/AdminTreeNode.module.css
@@ -1,10 +1,8 @@
/*
- * `:not([data-css-specificity-hack])` rather than a bare class: this needs
- * to beat `TreeNodeRoot`'s own emotion-generated color/background rules
- * (tree/TreeNode.styled.tsx), which are also single-class specificity, so
- * source order alone can't be trusted to pick a winner. See
- * ArchiveButton.module.css / MetricExpressionPill.module.css for the same
- * trick elsewhere.
+ * `:not([data-css-specificity-hack])` rather than a bare class: this beats the
+ * tree node's own color/background rules (tree/TreeNode.module.css) whatever
+ * the stylesheet order. See ArchiveButton.module.css /
+ * MetricExpressionPill.module.css for the same trick elsewhere.
*/
.adminSelected:not([data-css-specificity-hack="🦑"]) {
diff --git a/frontend/src/metabase/common/components/tree/TreeNode.module.css b/frontend/src/metabase/common/components/tree/TreeNode.module.css
new file mode 100644
index 00000000000..3251b6df840
--- /dev/null
+++ b/frontend/src/metabase/common/components/tree/TreeNode.module.css
@@ -0,0 +1,40 @@
+/* Zero specificity: the consumers that restyle a node (the admin tree, the navbar sidebar) override these with plain classes */
+:where(.root) {
+ padding-left: calc((var(--tree-depth) + 0.5) * 1rem);
+ color: var(--mb-color-core-brand);
+}
+
+:where(.root):hover {
+ background-color: var(--mb-color-background_surface-brand-subtle);
+}
+
+:where(.selected) {
+ color: var(--mb-color-text-primary-inverse);
+ background-color: var(--mb-color-core-brand);
+}
+
+:where(.selected):hover {
+ background-color: var(--mb-color-core-brand);
+}
+
+/* Padding and color stay in the class so that consumers can override them with style props */
+.expandToggle {
+ padding: var(--mantine-spacing-sm) var(--mantine-spacing-xxs);
+ color: inherit;
+
+ &[hidden] {
+ visibility: hidden;
+ }
+}
+
+.expandIcon {
+ transition: transform 200ms;
+}
+
+.expanded {
+ transform: rotate(90deg);
+}
+
+.name {
+ word-break: break-word;
+}
diff --git a/frontend/src/metabase/common/components/tree/TreeNode.styled.tsx b/frontend/src/metabase/common/components/tree/TreeNode.styled.tsx
deleted file mode 100644
index 715edee7d45..00000000000
--- a/frontend/src/metabase/common/components/tree/TreeNode.styled.tsx
+++ /dev/null
@@ -1,75 +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 type { IconProps } from "metabase/ui";
-import { Icon } from "metabase/ui";
-import { lighten } from "metabase/ui/colors";
-import { color } from "metabase/ui/utils/colors";
-
-interface TreeNodeRootProps {
- isSelected: boolean;
- depth: number;
-}
-
-export const TreeNodeRoot = styled.li<TreeNodeRootProps>`
- display: flex;
- align-items: center;
- color: ${(props) =>
- props.isSelected ? color("text-primary-inverse") : color("core-brand")};
- background-color: ${(props) =>
- props.isSelected ? color("core-brand") : "unset"};
- padding-left: ${(props) => props.depth + 0.5}rem;
- padding-right: 0.5rem;
- cursor: pointer;
- font-weight: 700;
-
- &:hover {
- background-color: ${(props) =>
- props.isSelected ? color("core-brand") : lighten("core-brand", 0.6)};
- }
-`;
-
-export const ExpandToggleButton = styled.button`
- cursor: pointer;
- padding: 0.5rem 0.25rem 0.5rem 0.25rem;
- display: block;
- color: inherit;
- visibility: ${(props) => (props.hidden ? "hidden" : "visible")};
-`;
-
-interface ExpandToggleIconProps extends IconProps {
- isExpanded: boolean;
-}
-
-export const ExpandToggleIcon = styled(
- ({ isExpanded, ...props }: ExpandToggleIconProps) => (
- <Icon
- {...props}
- name={props.name ?? "chevronright"}
- size={props.size ?? 12}
- />
- ),
-)`
- transition: transform 200ms;
-
- ${(props) =>
- props.isExpanded &&
- css`
- transform: rotate(90deg);
- `}
-`;
-
-export const NameContainer = styled.div`
- word-break: break-word;
- padding: 0.5rem 0.5rem 0.5rem 0.25rem;
- flex: 1;
-`;
-
-export const IconContainer = styled.div<{ transparent?: boolean }>`
- display: flex;
- align-items: center;
- padding: 0.25rem;
- opacity: ${({ transparent = true }) => (transparent ? 0.5 : 1)};
-`;
diff --git a/frontend/src/metabase/common/components/tree/TreeNode.tsx b/frontend/src/metabase/common/components/tree/TreeNode.tsx
index 7fceb494e49..8b1e5c76cc2 100644
--- a/frontend/src/metabase/common/components/tree/TreeNode.tsx
+++ b/frontend/src/metabase/common/components/tree/TreeNode.tsx
@@ -1,17 +1,117 @@
+import cx from "classnames";
import * as React from "react";
+import type { CSSProperties } from "react";
import _ from "underscore";
-import { Icon } from "metabase/ui";
-
+import CS from "metabase/css/core/index.css";
import {
- ExpandToggleButton,
- ExpandToggleIcon,
- IconContainer,
- NameContainer,
- TreeNodeRoot,
-} from "./TreeNode.styled";
+ Box,
+ type BoxProps,
+ type ElementProps,
+ Flex,
+ type FlexProps,
+ Icon,
+ type IconProps,
+} from "metabase/ui";
+
+import S from "./TreeNode.module.css";
import type { TreeNodeProps } from "./types";
+type TreeNodeCssVariables = CSSProperties & {
+ "--tree-depth": number;
+};
+
+type TreeNodeRootProps = FlexProps & {
+ isSelected: boolean;
+ depth: number;
+};
+
+const TreeNodeRoot = React.forwardRef<HTMLLIElement, TreeNodeRootProps>(
+ function TreeNodeRoot(
+ { isSelected, depth, className, style, ...props },
+ ref,
+ ) {
+ const vars: TreeNodeCssVariables = { "--tree-depth": depth };
+
+ return (
+ <Flex
+ component="li"
+ ref={ref}
+ className={cx(
+ S.root,
+ { [S.selected]: isSelected },
+ CS.cursorPointer,
+ className,
+ )}
+ style={style ? [vars, style] : vars}
+ align="center"
+ pr="sm"
+ fw={700}
+ {...props}
+ />
+ );
+ },
+);
+
+type ExpandToggleButtonProps = BoxProps & ElementProps<"button">;
+
+function ExpandToggleButton({ className, ...props }: ExpandToggleButtonProps) {
+ return (
+ <Box
+ component="button"
+ className={cx(S.expandToggle, CS.cursorPointer, className)}
+ display="block"
+ {...props}
+ />
+ );
+}
+
+interface ExpandToggleIconProps extends IconProps {
+ isExpanded: boolean;
+}
+
+function ExpandToggleIcon({
+ isExpanded,
+ className,
+ ...props
+}: ExpandToggleIconProps) {
+ return (
+ <Icon
+ className={cx(S.expandIcon, { [S.expanded]: isExpanded }, className)}
+ {...props}
+ />
+ );
+}
+
+type NameContainerProps = BoxProps & ElementProps<"div">;
+
+// The sidebar wraps it in a Tooltip, which needs the ref
+const NameContainer = React.forwardRef<HTMLDivElement, NameContainerProps>(
+ function NameContainer({ className, ...props }, ref) {
+ return (
+ <Box
+ ref={ref}
+ className={cx(S.name, className)}
+ flex={1}
+ py="sm"
+ pr="sm"
+ pl="xxs"
+ {...props}
+ />
+ );
+ },
+);
+
+type IconContainerProps = FlexProps & {
+ transparent?: boolean;
+};
+
+function IconContainer({ transparent = true, ...props }: IconContainerProps) {
+ return (
+ <Flex align="center" p="xxs" opacity={transparent ? 0.5 : 1} {...props} />
+ );
+}
+
const BaseTreeNode = React.forwardRef<HTMLLIElement, TreeNodeProps>(
function TreeNode(
{
diff --git a/frontend/src/metabase/common/components/tree/types.ts b/frontend/src/metabase/common/components/tree/types.ts
index abd4f266514..0dc588a8674 100644
--- a/frontend/src/metabase/common/components/tree/types.ts
+++ b/frontend/src/metabase/common/components/tree/types.ts
@@ -19,11 +19,6 @@ export interface TreeNodeProps<TData = unknown> {
onSelect?: () => void;
onToggleExpand: () => void;
className?: string;
- classNames?: {
- root?: string;
- expandToggleButton?: string;
- iconContainer?: string;
- };
}
export type TreeNodeComponent<TData = unknown> = React.ComponentType<
diff --git a/frontend/src/metabase/metabot/components/Metabot.tsx b/frontend/src/metabase/metabot/components/Metabot.tsx
index 1d113848da8..ff473ca10c6 100644
--- a/frontend/src/metabase/metabot/components/Metabot.tsx
+++ b/frontend/src/metabase/metabot/components/Metabot.tsx
@@ -11,7 +11,7 @@ import {
useMetabotAgent,
useUserMetabotPermissions,
} from "metabase/metabot/hooks";
-import { Sidebar } from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
+import { Sidebar } from "metabase/nav/containers/MainNavbar/Sidebar";
import { useDispatch, useSelector } from "metabase/redux";
import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";
import {
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.module.css b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.module.css
new file mode 100644
index 00000000000..d64a8423e1a
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.module.css
@@ -0,0 +1,9 @@
+.nav {
+ width: 100%;
+ overflow-x: hidden;
+ overflow-y: auto;
+
+ @media (--breakpoint-max-sm) {
+ width: 90vw;
+ }
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.styled.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.styled.tsx
deleted file mode 100644
index f01a20120f9..00000000000
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.styled.tsx
+++ /dev/null
@@ -1,109 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { NAV_SIDEBAR_WIDTH } from "metabase/nav/constants";
-import {
- breakpointMaxSmall,
- breakpointMinSmall,
-} from "metabase/styled-components/theme";
-import { Box, type BoxProps } from "metabase/ui";
-
-import { SidebarLink } from "./SidebarItems";
-import { ExpandToggleButton } from "./SidebarItems/SidebarItems.styled";
-
-export const Sidebar = styled.aside<{
- isOpen: boolean;
- side: "left" | "right";
- width?: string;
-}>`
- ${({ isOpen }) => (isOpen ? "" : "display: none")};
-
- height: 100%;
- position: relative;
- flex-shrink: 0;
- align-items: center;
- background-color: var(--mb-color-background_page-primary);
- z-index: 4;
- width: ${(props) => props.width ?? NAV_SIDEBAR_WIDTH};
- ${(props) =>
- props.side === "left"
- ? "border-inline-end: 1px solid var(--mb-color-border-neutral);"
- : "border-inline-start: 1px solid var(--mb-color-border-neutral);"}
-
- ${breakpointMaxSmall} {
- width: 90vw;
- position: absolute;
- top: 0;
- ${(props) =>
- props.side === "left" ? "inset-inline-start: 0;" : "inset-inline-end: 0;"}
- }
-`;
-
-export const NavRoot = styled.nav<{ isOpen: boolean }>`
- display: flex;
- flex-direction: column;
- box-sizing: border-box;
- padding-top: var(--mantine-spacing-sm);
- height: 100%;
- background-color: transparent;
- overflow-x: hidden;
- overflow-y: auto;
-
- ${breakpointMinSmall} {
- width: ${(props) => (props.isOpen ? "100%" : 0)};
- }
-
- ${breakpointMaxSmall} {
- width: ${(props) => (props.isOpen ? "90vw" : 0)};
- }
-`;
-
-export const SidebarContentRoot = styled.div`
- display: flex;
- flex: 1;
- flex-direction: column;
- justify-content: space-between;
-`;
-
-// Unjustified type cast. FIXME
-export const SidebarSection = styled(Box)<BoxProps>`
- margin-top: var(--mantine-spacing-sm);
- margin-bottom: var(--mantine-spacing-lg);
- padding-inline-start: var(--mantine-spacing-lg);
- padding-inline-end: var(--mantine-spacing-lg);
-` as unknown as typeof Box;
-
-// Unjustified type cast. FIXME
-export const TrashSidebarSection = styled(SidebarSection)`
- ${ExpandToggleButton} {
- width: 12px;
- }
-` as unknown as typeof Box;
-
-export const SidebarHeading = styled.h4`
- color: var(--mb-color-text-secondary);
- font-weight: 700;
- font-size: 11px;
- text-transform: uppercase;
- letter-spacing: 0.45px;
- padding-inline-start: var(--mantine-spacing-lg);
-`;
-
-export const LoadingAndErrorContainer = styled.div`
- display: flex;
- flex: 1;
- align-items: center;
- justify-content: center;
-`;
-
-export const LoadingAndErrorContent = styled.div`
- display: flex;
- flex-direction: column;
- align-items: center;
- color: var(--mb-color-core-brand);
- text-align: center;
-`;
-
-export const PaddedSidebarLink = styled(SidebarLink)`
- padding-inline-start: 12px;
-`;
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.tsx
index 7bd64972cd3..6d729ae6378 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.tsx
@@ -10,12 +10,14 @@ import { connect } from "metabase/redux";
import { closeNavbar, openNavbar } from "metabase/redux/app";
import type { State } from "metabase/redux/store";
import { useNavigate } from "metabase/router";
+import { Flex } from "metabase/ui";
import * as Urls from "metabase/urls";
import Question from "metabase-lib/v1/Question";
import type { CollectionId } from "metabase-types/api";
-import { NavRoot, Sidebar } from "./MainNavbar.styled";
+import S from "./MainNavbar.module.css";
import MainNavbarContainer from "./MainNavbarContainer";
+import { Sidebar } from "./Sidebar";
import {
getSelectedItems,
isCollectionPath,
@@ -116,7 +118,13 @@ function MainNavbarInner({
data-testid="main-navbar-root"
data-element-id="navbar-root"
>
- <NavRoot isOpen={isOpen}>
+ <Flex
+ component="nav"
+ className={S.nav}
+ direction="column"
+ pt="sm"
+ h="100%"
+ >
<MainNavbarContainer
isOpen={isOpen}
location={location}
@@ -128,7 +136,7 @@ function MainNavbarInner({
{...props}
/>
<NavbarPromoSlot />
- </NavRoot>
+ </Flex>
</Sidebar>
);
}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css
new file mode 100644
index 00000000000..debd46b42e3
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.module.css
@@ -0,0 +1,11 @@
+.removeButton {
+ margin-top: 3px;
+ color: var(--mb-color-core-brand);
+ opacity: 0;
+}
+
+.bookmark:hover .removeButton,
+.bookmark:focus-within .removeButton,
+:focus .bookmark .removeButton {
+ opacity: 0.5;
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.styled.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.styled.tsx
deleted file mode 100644
index c81d76dacb4..00000000000
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.styled.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { color } from "metabase/ui/utils/colors";
-
-import { DraggableSidebarLink } from "../../SidebarItems";
-
-export const SidebarBookmarkItem = styled(DraggableSidebarLink)`
- padding-left: 0.75rem;
-
- &:hover,
- &:focus,
- &:focus-within,
- :focus & {
- button {
- color: var(--mb-color-core-brand);
- opacity: 0.5;
-
- > svg:focus {
- outline: none;
- }
- }
- }
-
- button {
- opacity: 0;
- color: ${(props) =>
- props.isSelected ? color("text-primary-inverse") : color("core-brand")};
- cursor: pointer;
- margin-top: 3px;
-
- > svg:focus {
- outline: none;
- }
- }
-`;
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
index c6d080fba04..9d27de1532a 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx
@@ -8,6 +8,7 @@ import {
SortableContext,
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
+import cx from "classnames";
import { useCallback, useEffect, useState } from "react";
import { t } from "ttag";
@@ -15,18 +16,19 @@ import { useDeleteBookmarkMutation } from "metabase/api";
import { CollapseSection } from "metabase/common/components/CollapseSection";
import { Sortable } from "metabase/common/components/Sortable";
import GrabberS from "metabase/css/components/grabber.module.css";
+import CS from "metabase/css/core/index.css";
import { getIsTenantUser } from "metabase/current-user";
import { useGetIcon } from "metabase/hooks/use-icon";
-import { PLUGIN_COLLECTIONS } from "metabase/plugins";
import { useSelector } from "metabase/redux";
import { Icon, Tooltip } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { Bookmark } from "metabase-types/api";
-import { SidebarHeading } from "../../MainNavbar.styled";
+import { SidebarHeading } from "../../Sidebar";
+import { DraggableSidebarLink } from "../../SidebarItems";
import type { SelectedItem } from "../../types";
-import { SidebarBookmarkItem } from "./BookmarkList.styled";
+import S from "./BookmarkList.module.css";
interface CollectionSidebarBookmarksProps {
bookmarks: Bookmark[];
@@ -98,25 +100,23 @@ const BookmarkItem = ({
);
const onRemove = () => onDeleteBookmark(bookmark);
- const isIrregularCollection =
- bookmark.type === "collection" &&
- !PLUGIN_COLLECTIONS.isRegularCollection(bookmark);
-
const iconName = isSelected ? "bookmark_filled" : "bookmark";
return (
<Sortable id={bookmark.id} key={bookmark.id}>
- <SidebarBookmarkItem
- key={`bookmark-${bookmark.id}`}
+ <DraggableSidebarLink
+ className={S.bookmark}
url={url}
icon={icon}
isSelected={isSelected}
isDragging={isSorting}
isDraggable={isDraggable}
- hasDefaultIconStyle={!isIrregularCollection}
onClick={onSelect}
right={
- <button onClick={onRemove}>
+ <button
+ className={cx(S.removeButton, CS.cursorPointer)}
+ onClick={onRemove}
+ >
<Tooltip label={t`Remove bookmark`} position="bottom">
<Icon name={iconName} />
</Tooltip>
@@ -124,7 +124,7 @@ const BookmarkItem = ({
}
>
{bookmark.name}
- </SidebarBookmarkItem>
+ </DraggableSidebarLink>
</Sortable>
);
};
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BrowseNavSection.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BrowseNavSection.tsx
index 921d70a8dda..32bda06d8bc 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BrowseNavSection.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BrowseNavSection.tsx
@@ -7,7 +7,8 @@ import { useUserSetting } from "metabase/settings";
import { ActionIcon, Icon, Tooltip } from "metabase/ui";
import { isWithinIframe } from "metabase/utils/iframe";
-import { PaddedSidebarLink, SidebarHeading } from "../MainNavbar.styled";
+import { SidebarHeading } from "../Sidebar";
+import { SidebarLink } from "../SidebarItems";
import { trackAddDataModalOpened } from "../analytics";
import type { SelectedItem } from "../types";
@@ -70,7 +71,7 @@ export const BrowseNavSection = ({
>
{hasDataAccess &&
(!isEmbeddingIframe || entityTypes.includes("table")) && (
- <PaddedSidebarLink
+ <SidebarLink
icon="database"
url={BROWSE_DATA_URL}
isSelected={nonEntityItem?.url?.startsWith(BROWSE_DATA_URL)}
@@ -78,11 +79,11 @@ export const BrowseNavSection = ({
aria-label={t`Browse databases`}
>
{t`Databases`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
{(!isEmbeddingIframe || entityTypes.includes("model")) && (
- <PaddedSidebarLink
+ <SidebarLink
icon="model"
url={BROWSE_MODELS_URL}
isSelected={nonEntityItem?.url?.startsWith(BROWSE_MODELS_URL)}
@@ -90,11 +91,11 @@ export const BrowseNavSection = ({
aria-label={t`Browse models`}
>
{t`Models`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
{!isEmbeddingIframe && (
- <PaddedSidebarLink
+ <SidebarLink
icon="metric"
url={BROWSE_METRICS_URL}
isSelected={nonEntityItem?.url?.startsWith(BROWSE_METRICS_URL)}
@@ -102,7 +103,7 @@ export const BrowseNavSection = ({
aria-label={t`Browse metrics`}
>
{t`Metrics`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
</CollapseSection>
);
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/GettingStartedSection.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/GettingStartedSection.tsx
index c289cf545c6..dc03b3d45da 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/GettingStartedSection.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/GettingStartedSection.tsx
@@ -5,7 +5,8 @@ import { t } from "ttag";
import CS from "metabase/css/core/index.css";
import { Collapse, Group, Icon, UnstyledButton } from "metabase/ui";
-import { PaddedSidebarLink, SidebarHeading } from "../MainNavbar.styled";
+import { SidebarHeading } from "../Sidebar";
+import { SidebarLink } from "../SidebarItems";
import { trackOnboardingChecklistOpened } from "../analytics";
import type { SelectedItem } from "../types";
@@ -47,12 +48,12 @@ export const GettingStartedSection = ({
aria-expanded={opened}
>
{canAddData && (
- <PaddedSidebarLink icon="add_data" onClick={onAddDataModalOpen}>
+ <SidebarLink icon="add_data" onClick={onAddDataModalOpen}>
{t`Add your data`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
- <PaddedSidebarLink
+ <SidebarLink
icon="learn"
url={ONBOARDING_URL}
isSelected={isOnboardingPageSelected}
@@ -60,7 +61,7 @@ export const GettingStartedSection = ({
>
{/* eslint-disable-next-line metabase/no-literal-metabase-strings -- We only show this to non-whitelabelled instances */}
{t`How to use Metabase`}
- </PaddedSidebarLink>
+ </SidebarLink>
{children}
</Collapse>
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarView.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarView.tsx
index 7fa0fcc9cf6..6ffc9598fbf 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarView.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/MainNavbarView.tsx
@@ -32,19 +32,13 @@ import {
getIsNewInstance,
} from "metabase/selectors/onboarding";
import { useSetting, useUserSetting } from "metabase/settings";
-import { ActionIcon, Icon, Tooltip } from "metabase/ui";
+import { ActionIcon, Flex, Icon, Tooltip } from "metabase/ui";
import * as Urls from "metabase/urls";
import { isSmallScreen } from "metabase/utils/dom";
import type { Bookmark, Collection } from "metabase-types/api";
-import {
- PaddedSidebarLink,
- SidebarContentRoot,
- SidebarHeading,
- SidebarSection,
- TrashSidebarSection,
-} from "../MainNavbar.styled";
-import { SidebarCollectionLink } from "../SidebarItems";
+import { SidebarHeading, SidebarSection } from "../Sidebar";
+import { SidebarCollectionLink, SidebarLink } from "../SidebarItems";
import {
trackAddDataModalOpened,
trackNewCollectionFromNavInitiated,
@@ -182,17 +176,17 @@ export function MainNavbarView({
return (
<ErrorBoundary>
- <SidebarContentRoot>
+ <Flex direction="column" justify="space-between" flex={1}>
<div>
<SidebarSection>
- <PaddedSidebarLink
+ <SidebarLink
isSelected={nonEntityItem?.url === "/"}
icon="home"
onClick={handleHomeClick}
url="/"
>
{t`Home`}
- </PaddedSidebarLink>
+ </SidebarLink>
</SidebarSection>
{shouldDisplayGettingStarted && (
@@ -296,13 +290,13 @@ export function MainNavbarView({
/>
)}
{showOtherUsersCollections && (
- <PaddedSidebarLink
+ <SidebarLink
icon="group"
url={OTHER_USERS_COLLECTIONS_URL}
isSelected={collectionItem?.id === "users"}
>
{t`Other users' personal collections`}
- </PaddedSidebarLink>
+ </SidebarLink>
)}
</CollapseSection>
</ErrorBoundary>
@@ -324,7 +318,7 @@ export function MainNavbarView({
</SidebarSection>
{trashCollection && (
- <TrashSidebarSection>
+ <SidebarSection>
<ErrorBoundary>
<Tree
data={[trashCollection]}
@@ -334,10 +328,10 @@ export function MainNavbarView({
role="tree"
/>
</ErrorBoundary>
- </TrashSidebarSection>
+ </SidebarSection>
)}
</div>
- </SidebarContentRoot>
+ </Flex>
<AddDataModal opened={addDataModalOpened} onClose={closeAddDataModal} />
</ErrorBoundary>
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/NavbarErrorView.tsx b/frontend/src/metabase/nav/containers/MainNavbar/NavbarErrorView.tsx
index 63f4b53bce9..c98652de91f 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/NavbarErrorView.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/NavbarErrorView.tsx
@@ -1,24 +1,16 @@
import { t } from "ttag";
-import { Icon, Text } from "metabase/ui";
-
-import {
- LoadingAndErrorContainer,
- LoadingAndErrorContent,
-} from "./MainNavbar.styled";
+import { Flex, Icon, Text } from "metabase/ui";
export function NavbarErrorView() {
return (
- <LoadingAndErrorContainer>
- <LoadingAndErrorContent>
+ <Flex flex={1} align="center" justify="center">
+ <Flex direction="column" align="center" c="core-brand" ta="center">
<Icon name="warning" size={24} />
- <Text
- fw={400}
- mt="0.5rem"
- color="text-disabled"
- size="lg"
- >{t`An error occurred`}</Text>
- </LoadingAndErrorContent>
- </LoadingAndErrorContainer>
+ <Text fw={400} mt="0.5rem" c="text-disabled" size="lg">
+ {t`An error occurred`}
+ </Text>
+ </Flex>
+ </Flex>
);
}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/NavbarLibrarySection/NavbarLibrarySection.tsx b/frontend/src/metabase/nav/containers/MainNavbar/NavbarLibrarySection/NavbarLibrarySection.tsx
index 48d833fac96..b37726ae1d3 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/NavbarLibrarySection/NavbarLibrarySection.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/NavbarLibrarySection/NavbarLibrarySection.tsx
@@ -13,7 +13,7 @@ import { Tree } from "metabase/common/components/tree";
import {
SidebarHeading,
SidebarSection,
-} from "metabase/nav/containers/MainNavbar/MainNavbar.styled";
+} from "metabase/nav/containers/MainNavbar/Sidebar";
import { SidebarCollectionLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";
import { useUserSetting } from "metabase/settings";
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/NavbarLoadingView.tsx b/frontend/src/metabase/nav/containers/MainNavbar/NavbarLoadingView.tsx
index ffa432a29c0..6029a437825 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/NavbarLoadingView.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/NavbarLoadingView.tsx
@@ -1,6 +1,6 @@
import { Flex, Repeat, Skeleton } from "metabase/ui";
-import { SidebarSection } from "./MainNavbar.styled";
+import { SidebarSection } from "./Sidebar";
const NavLinkSkeleton = () => (
<Flex my="1rem" gap="sm" px="1rem">
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.module.css b/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.module.css
new file mode 100644
index 00000000000..8cf3398d800
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.module.css
@@ -0,0 +1,27 @@
+.sidebar {
+ position: relative;
+ z-index: 4;
+ width: var(--sidebar-width);
+
+ @media (--breakpoint-max-sm) {
+ position: absolute;
+ top: 0;
+ width: 90vw;
+ }
+}
+
+.left {
+ border-inline-end: 1px solid var(--mb-color-border-neutral);
+
+ @media (--breakpoint-max-sm) {
+ inset-inline-start: 0;
+ }
+}
+
+.right {
+ border-inline-start: 1px solid var(--mb-color-border-neutral);
+
+ @media (--breakpoint-max-sm) {
+ inset-inline-end: 0;
+ }
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.tsx b/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.tsx
new file mode 100644
index 00000000000..b3078ef5a0e
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/Sidebar.tsx
@@ -0,0 +1,73 @@
+import cx from "classnames";
+import type { CSSProperties, ReactNode } from "react";
+
+import CS from "metabase/css/core/index.css";
+import { NAV_SIDEBAR_WIDTH } from "metabase/nav/constants";
+import { Box, type BoxProps, Text, type TextProps } from "metabase/ui";
+
+import S from "./Sidebar.module.css";
+
+type SidebarCssVariables = CSSProperties & {
+ "--sidebar-width": string;
+};
+
+interface SidebarProps extends BoxProps {
+ isOpen: boolean;
+ side: "left" | "right";
+ width?: string;
+ children?: ReactNode;
+}
+
+export const Sidebar = ({
+ isOpen,
+ side,
+ width = NAV_SIDEBAR_WIDTH,
+ className,
+ style,
+ ...props
+}: SidebarProps) => {
+ const vars: SidebarCssVariables = { "--sidebar-width": width };
+
+ return (
+ <Box
+ component="aside"
+ className={cx(
+ S.sidebar,
+ side === "left" ? S.left : S.right,
+ CS.flexNoShrink,
+ className,
+ )}
+ style={style ? [vars, style] : vars}
+ display={isOpen ? undefined : "none"}
+ h="100%"
+ bg="background_page-primary"
+ {...props}
+ />
+ );
+};
+
+interface SidebarSectionProps extends BoxProps {
+ children?: ReactNode;
+}
+
+export const SidebarSection = (props: SidebarSectionProps) => (
+ <Box mt="sm" mb="lg" px="lg" {...props} />
+);
+
+interface SidebarHeadingProps extends TextProps {
+ children?: ReactNode;
+}
+
+export const SidebarHeading = (props: SidebarHeadingProps) => (
+ <Text
+ component="h4"
+ c="text-secondary"
+ fz="xs"
+ fw={700}
+ lh="normal"
+ tt="uppercase"
+ lts="0.45px"
+ ps="lg"
+ {...props}
+ />
+);
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.styled.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.styled.tsx
deleted file mode 100644
index 9ef3ac8f7bd..00000000000
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.styled.tsx
+++ /dev/null
@@ -1,41 +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";
-
-import SidebarLink from "./SidebarLink";
-
-export const DragIcon = styled(Icon)`
- left: 2px;
- opacity: 0;
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- cursor: grab;
-`;
-
-export const StyledSidebarLink = styled(SidebarLink)<{ isDragging: boolean }>`
- position: relative;
-
- &:hover {
- ${DragIcon} {
- opacity: 0.3;
- }
- }
-
- ${(props) =>
- props.isDragging &&
- css`
- pointer-events: none;
-
- &:hover {
- background: var(--mb-color-background_page-primary);
-
- ${SidebarLink.RightElement} {
- opacity: 0;
- }
- }
- `}
-`;
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx
index f9e1110afdd..ee9e7a7de07 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx
@@ -1,16 +1,37 @@
-import { DragIcon, StyledSidebarLink } from "./DraggableSidebarLink.styled";
-import type { SidebarLinkProps } from "./SidebarLink";
+import cx from "classnames";
-interface Props extends Omit<SidebarLinkProps, "left"> {
+import CS from "metabase/css/core/index.css";
+import { Icon } from "metabase/ui";
+
+import S from "./SidebarItems.module.css";
+import { SidebarLink, type SidebarLinkProps } from "./SidebarLink";
+
+interface DraggableSidebarLinkProps extends Omit<SidebarLinkProps, "left"> {
isDraggable?: boolean;
isDragging: boolean;
}
-export function DraggableSidebarLink({ isDraggable, ...props }: Props) {
+export function DraggableSidebarLink({
+ isDraggable,
+ isDragging,
+ className,
+ ...props
+}: DraggableSidebarLinkProps) {
return (
- <StyledSidebarLink
+ <SidebarLink
{...props}
- left={isDraggable && <DragIcon name="grabber" />}
+ className={cx(S.draggable, { [S.dragging]: isDragging }, className)}
+ left={
+ isDraggable && (
+ <Icon
+ className={cx(S.dragIcon, CS.cursorGrab)}
+ name="grabber"
+ pos="absolute"
+ left={2}
+ top="50%"
+ />
+ )
+ }
/>
);
}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
index 10d32d92061..defa35e3759 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx
@@ -1,28 +1,25 @@
+import cx from "classnames";
import type { KeyboardEvent } from "react";
import { forwardRef, useCallback, useEffect, useRef } from "react";
import { usePrevious } from "react-use";
import { getCollectionIcon } from "metabase/common/collections/utils";
+import { ForwardRefLink } from "metabase/common/components/Link";
import { CollectionDropTarget } from "metabase/common/components/dnd/CollectionDropTarget";
import { TreeNode } from "metabase/common/components/tree/TreeNode";
import type {
ITreeNodeItem,
TreeNodeProps,
} from "metabase/common/components/tree/types";
+import CS from "metabase/css/core/index.css";
import { getIsTenantUser } from "metabase/current-user";
-import { PLUGIN_COLLECTIONS } from "metabase/plugins";
import { useSelector } from "metabase/redux";
+import { Flex, Icon } from "metabase/ui";
import * as Urls from "metabase/urls";
import type { Collection } from "metabase-types/api";
-import {
- CollectionNodeRoot,
- ExpandToggleButton,
- FullWidthContainer,
- FullWidthLink,
- NameContainer,
- SidebarIcon,
-} from "./SidebarItems.styled";
+import { SidebarItemName } from "./SidebarItemName";
+import S from "./SidebarItems.module.css";
type DroppableProps = {
hovered: boolean;
@@ -95,84 +92,105 @@ const SidebarCollectionLink = forwardRef<HTMLLIElement, Props>(
);
const icon = getCollectionIcon(collection, { isTenantUser });
- const isRegularCollection =
- PLUGIN_COLLECTIONS.isRegularCollection(collection);
const content = (
<>
- <TreeNode.IconContainer transparent={false}>
- <SidebarIcon {...icon} isSelected={isSelected} />
+ <TreeNode.IconContainer transparent={false} c="core-brand">
+ <Icon {...icon} />
</TreeNode.IconContainer>
- <NameContainer>{collection.name}</NameContainer>
+ <SidebarItemName>{collection.name}</SidebarItemName>
{/* Unjustified type cast. FIXME */}
{rightSection?.(collection as unknown as ITreeNodeItem)}
</>
);
return (
- <CollectionNodeRoot
+ <TreeNode.Root
role="treeitem"
depth={depth}
- aria-selected={isSelected}
isSelected={isSelected}
- hovered={isHovered}
+ className={cx(S.nodeRoot, {
+ [S.selected]: isSelected,
+ [S.dropTarget]: isHovered,
+ })}
+ bdrs="xxs"
+ aria-selected={isSelected}
onClick={isSelected ? onToggleExpand : undefined}
- hasDefaultIconStyle={isRegularCollection}
ref={ref}
>
- <ExpandToggleButton hidden={!hasChildren} onClick={onToggleExpand}>
+ <TreeNode.ExpandToggleButton
+ c="core-brand"
+ py="xxs"
+ pl="xxxs"
+ pr={0}
+ hidden={!hasChildren}
+ onClick={onToggleExpand}
+ >
<TreeNode.ExpandToggleIcon
isExpanded={isExpanded}
name="chevronright"
size={12}
/>
- </ExpandToggleButton>
+ </TreeNode.ExpandToggleButton>
{nonNavigable ? (
- <FullWidthContainer onKeyDown={onKeyDown}>
+ <Flex
+ className={CS.cursorPointer}
+ align="center"
+ w="100%"
+ miw={0}
+ onKeyDown={onKeyDown}
+ >
{content}
- </FullWidthContainer>
+ </Flex>
) : (
- <FullWidthLink to={url} onClick={onSelect} onKeyDown={onKeyDown}>
+ <Flex
+ component={ForwardRefLink}
+ className={S.link}
+ align="center"
+ w="100%"
+ miw={0}
+ to={url}
+ onClick={onSelect}
+ onKeyDown={onKeyDown}
+ >
{content}
- </FullWidthLink>
- )}
- </CollectionNodeRoot>
- );
- },
-);
-
-const DroppableSidebarCollectionLink = forwardRef<HTMLLIElement, TreeNodeProps>(
- function DroppableSidebarCollectionLink(
- { item, ...props }: TreeNodeProps,
- ref,
- ) {
- // Unjustified type cast. FIXME
- const collection = item as unknown as Collection;
-
- const link = (droppableProps?: DroppableProps) => (
- <SidebarCollectionLink
- {...props}
- hovered={droppableProps?.hovered ?? false}
- highlighted={droppableProps?.highlighted ?? false}
- collection={collection}
- nonNavigable={item.nonNavigable}
- ref={ref}
- />
- );
-
- return (
- <div data-testid="sidebar-collection-link-root">
- {item.nonNavigable ? (
- link()
- ) : (
- <CollectionDropTarget collection={collection}>
- {(droppableProps: DroppableProps) => link(droppableProps)}
- </CollectionDropTarget>
+ </Flex>
)}
- </div>
+ </TreeNode.Root>
);
},
);
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default DroppableSidebarCollectionLink;
+export const DroppableSidebarCollectionLink = forwardRef<
+ HTMLLIElement,
+ TreeNodeProps
+>(function DroppableSidebarCollectionLink(
+ { item, ...props }: TreeNodeProps,
+ ref,
+) {
+ // Unjustified type cast. FIXME
+ const collection = item as unknown as Collection;
+
+ const link = (droppableProps?: DroppableProps) => (
+ <SidebarCollectionLink
+ {...props}
+ hovered={droppableProps?.hovered ?? false}
+ highlighted={droppableProps?.highlighted ?? false}
+ collection={collection}
+ nonNavigable={item.nonNavigable}
+ ref={ref}
+ />
+ );
+
+ return (
+ <div data-testid="sidebar-collection-link-root">
+ {item.nonNavigable ? (
+ link()
+ ) : (
+ <CollectionDropTarget collection={collection}>
+ {(droppableProps: DroppableProps) => link(droppableProps)}
+ </CollectionDropTarget>
+ )}
+ </div>
+ );
+});
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx
new file mode 100644
index 00000000000..00a9f451b12
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItemName.tsx
@@ -0,0 +1,41 @@
+import cx from "classnames";
+
+import { TreeNode } from "metabase/common/components/tree/TreeNode";
+import CS from "metabase/css/core/index.css";
+import { type BoxProps, Tooltip } from "metabase/ui";
+
+const ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD = 35;
+
+interface SidebarItemNameProps extends BoxProps {
+ children: string;
+}
+
+export function SidebarItemName({
+ children: itemName,
+ className,
+ ...props
+}: SidebarItemNameProps) {
+ if (itemName.length >= ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD) {
+ return (
+ <Tooltip label={itemName} withArrow maw="none">
+ <TreeNode.NameContainer
+ className={cx(
+ CS.textNoWrap,
+ CS.overflowHidden,
+ CS.textEllipsis,
+ className,
+ )}
+ miw={0}
+ {...props}
+ >
+ {itemName}
+ </TreeNode.NameContainer>
+ </Tooltip>
+ );
+ }
+ return (
+ <TreeNode.NameContainer className={className} {...props}>
+ {itemName}
+ </TreeNode.NameContainer>
+ );
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css
new file mode 100644
index 00000000000..70b468b3cce
--- /dev/null
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.module.css
@@ -0,0 +1,49 @@
+.nodeRoot {
+ padding-left: calc(var(--tree-depth) * 1rem);
+ color: var(--mb-color-text-primary);
+
+ &:focus-within {
+ outline: 2px solid var(--mb-color-input-focus);
+ outline-offset: -2px;
+ }
+
+ &:hover {
+ color: var(--mb-color-core-brand);
+ background-color: var(--mb-color-background_surface-brand-subtle-hover);
+ }
+}
+
+.selected {
+ color: var(--mb-color-core-brand);
+ background-color: var(--mb-color-background_surface-brand-subtle);
+}
+
+.dropTarget {
+ color: var(--mb-color-text-primary-inverse);
+ background-color: var(--mb-color-core-brand);
+}
+
+.button,
+.link {
+ &:focus {
+ outline: none;
+ }
+}
+
+.draggable {
+ position: relative;
+
+ &:hover .dragIcon {
+ opacity: 0.3;
+ }
+}
+
+/* Rows cannot be hovered while the bookmarks are being sorted */
+.dragging {
+ pointer-events: none;
+}
+
+.dragIcon {
+ opacity: 0;
+ transform: translateY(-50%);
+}
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.styled.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.styled.tsx
deleted file mode 100644
index 630becc1f9a..00000000000
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarItems.styled.tsx
+++ /dev/null
@@ -1,157 +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 type { ComponentProps } from "react";
-import { forwardRef } from "react";
-
-import { Link } from "metabase/common/components/Link";
-import { TreeNode } from "metabase/common/components/tree/TreeNode";
-import type { IconProps } from "metabase/ui";
-import { Icon, Tooltip } from "metabase/ui";
-import { alpha } from "metabase/ui/colors";
-import type { ColorName } from "metabase/ui/colors/types";
-import { color } from "metabase/ui/utils/colors";
-
-export const SidebarIcon = styled(
- forwardRef<SVGSVGElement, IconProps & { isSelected: boolean }>(
- function SidebarIcon({ isSelected, ...props }, ref) {
- return <Icon {...props} size={props.size ?? 16} ref={ref} />;
- },
- ),
-)<{
- color?: ColorName | string;
- isSelected: boolean;
-}>`
- ${(props) =>
- !props.color &&
- css`
- color: var(--mb-color-core-brand);
- `}
-`;
-
-export const ExpandToggleButton = styled(TreeNode.ExpandToggleButton)`
- padding: 4px 0 4px 2px;
- color: var(--mb-color-core-brand);
-`;
-
-const activeColorCSS = css`
- color: var(--mb-color-core-brand);
-`;
-
-function getTextColor(isSelected: boolean) {
- return isSelected ? color("core-brand") : color("text-primary");
-}
-
-type NodeRootProps = ComponentProps<typeof TreeNode.Root> & {
- hasDefaultIconStyle?: boolean;
-};
-
-export const NodeRoot = styled(TreeNode.Root)<NodeRootProps>`
- color: ${(props) => getTextColor(props.isSelected)};
- background-color: ${(props) =>
- props.isSelected ? alpha("core-brand", 0.2) : "unset"};
- padding-left: ${(props) => props.depth}rem;
- border-radius: 4px;
-
- &:focus-within {
- outline: 2px solid var(--mb-color-input-focus);
- outline-offset: -2px;
- }
-
- ${ExpandToggleButton} {
- ${(props) => props.isSelected && activeColorCSS}
- }
-
- &:hover {
- background-color: ${() => alpha("core-brand", 0.35)};
- color: var(--mb-color-core-brand);
-
- ${ExpandToggleButton} {
- color: var(--mb-color-core-brand);
- }
- }
-
- &:hover,
- &:focus,
- &:focus-within {
- ${SidebarIcon} {
- ${({ hasDefaultIconStyle = true }) =>
- hasDefaultIconStyle && activeColorCSS};
- }
- }
-`;
-
-const collectionDragAndDropHoverStyle = css`
- color: var(--mb-color-text-primary-inverse);
- background-color: var(--mb-color-core-brand);
-`;
-
-export const CollectionNodeRoot = styled(NodeRoot)<{ hovered?: boolean }>`
- ${(props) => props.hovered && collectionDragAndDropHoverStyle}
-`;
-
-const itemContentStyle = css`
- display: flex;
- align-items: center;
- width: 100%;
- min-width: 0;
-`;
-
-export const FullWidthButton = styled.button<{ isSelected: boolean }>`
- color: inherit;
- cursor: pointer;
-
- ${itemContentStyle}
- ${TreeNode.NameContainer} {
- font-weight: 700;
- color: ${(props) => (props.isSelected ? color("core-brand") : "inherit")};
- text-align: start;
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
- }
-
- &:focus,
- &:focus-visible {
- outline: none;
- }
-`;
-
-export const FullWidthLink = styled(Link)`
- ${itemContentStyle}
-
- &:focus,
- &:focus-visible {
- outline: none !important;
- }
-`;
-
-export const FullWidthContainer = styled.div`
- ${itemContentStyle}
- cursor: pointer;
-`;
-
-const ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD = 35;
-
-export const ItemName = styled(TreeNode.NameContainer)`
- min-width: 0;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
-`;
-
-export function NameContainer({ children: itemName }: { children: string }) {
- if (itemName.length >= ITEM_NAME_LENGTH_TOOLTIP_THRESHOLD) {
- return (
- <Tooltip label={itemName} withArrow maw="none">
- <ItemName>{itemName}</ItemName>
- </Tooltip>
- );
- }
- return <TreeNode.NameContainer>{itemName}</TreeNode.NameContainer>;
-}
-
-export const LeftElementContainer = styled.div``;
-export const RightElementContainer = styled.div``;
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
index 0db9b70fb25..dd0ca73acfa 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarLink.tsx
@@ -1,41 +1,32 @@
+import cx from "classnames";
import type { MouseEvent, ReactNode } from "react";
-import { isValidElement, useCallback, useMemo } from "react";
+import { isValidElement } from "react";
import _ from "underscore";
import { EntityIcon } from "metabase/common/components/EntityIcon";
+import { ForwardRefLink } from "metabase/common/components/Link";
import { TreeNode } from "metabase/common/components/tree/TreeNode";
import type { IconData } from "metabase/common/utils/icon";
-import type { IconProps } from "metabase/ui";
+import CS from "metabase/css/core/index.css";
+import { Flex, Icon, type IconProps } from "metabase/ui";
import type { IconName } from "metabase-types/api";
-import {
- FullWidthButton,
- FullWidthLink,
- ItemName,
- LeftElementContainer,
- NameContainer,
- NodeRoot,
- RightElementContainer,
- SidebarIcon,
-} from "./SidebarItems.styled";
+import { SidebarItemName } from "./SidebarItemName";
+import S from "./SidebarItems.module.css";
-interface SidebarLinkProps {
+export interface SidebarLinkProps {
children: string;
url?: string;
icon?: IconName | IconProps | IconData;
isSelected?: boolean;
- hasDefaultIconStyle?: boolean;
left?: ReactNode;
right?: ReactNode;
onClick?: (event: MouseEvent) => void;
target?: string;
rel?: string;
+ className?: string;
}
-type ContentProps = {
- children: ReactNode;
-};
-
function isIconPropsObject(
icon: string | IconProps | IconData,
): icon is IconProps | IconData {
@@ -50,95 +41,96 @@ function disableImageDragging(e: MouseEvent) {
e.preventDefault();
}
-function SidebarLink({
+interface SidebarLinkIconProps {
+ icon: IconName | IconProps | IconData;
+}
+
+function SidebarLinkIcon({ icon }: SidebarLinkIconProps) {
+ if (isValidElement(icon)) {
+ return icon;
+ }
+ const iconProps = isIconPropsObject(icon) ? icon : { name: icon };
+ const hasIconUrl = "iconUrl" in iconProps && iconProps.iconUrl;
+
+ return (
+ <TreeNode.IconContainer transparent={false} c="core-brand">
+ {hasIconUrl ? (
+ <EntityIcon
+ name={iconProps.name}
+ iconUrl={iconProps.iconUrl}
+ size="1rem"
+ color="core-brand"
+ />
+ ) : (
+ <Icon {...iconProps} />
+ )}
+ </TreeNode.IconContainer>
+ );
+}
+
+export function SidebarLink({
children,
icon,
url,
isSelected = false,
- hasDefaultIconStyle,
left = null,
right = null,
onClick,
target,
rel,
+ className,
...props
}: SidebarLinkProps) {
- const renderIcon = useCallback(() => {
- if (!icon) {
- return null;
- }
- if (isValidElement(icon)) {
- return icon;
- }
- const iconProps = isIconPropsObject(icon) ? icon : { name: icon };
- const hasIconUrl = "iconUrl" in iconProps && iconProps.iconUrl;
-
- return (
- <TreeNode.IconContainer transparent={false}>
- {hasIconUrl ? (
- <EntityIcon
- name={iconProps.name}
- iconUrl={iconProps.iconUrl}
- size="1rem"
- color="core-brand"
- />
- ) : (
- <SidebarIcon {...iconProps} isSelected={isSelected} />
- )}
- </TreeNode.IconContainer>
- );
- }, [icon, isSelected]);
-
- const Content = useMemo(() => {
- return url
- ? (props: ContentProps) => (
- <FullWidthLink
- {...props}
- to={url}
- target={target}
- rel={rel}
- onClick={onClick}
- />
- )
- : (props: ContentProps) => (
- <FullWidthButton
- {...props}
- isSelected={isSelected}
- onClick={onClick}
- />
- );
- }, [url, isSelected, onClick, target, rel]);
+ const content = (
+ <>
+ {icon && <SidebarLinkIcon icon={icon} />}
+ <SidebarItemName>{children}</SidebarItemName>
+ </>
+ );
return (
- <NodeRoot
+ <TreeNode.Root
depth={0}
isSelected={isSelected}
- hasDefaultIconStyle={hasDefaultIconStyle}
+ className={cx(S.nodeRoot, { [S.selected]: isSelected }, className)}
+ bdrs="xxs"
+ pl="md"
aria-label={children}
aria-selected={isSelected}
onMouseDown={disableImageDragging}
{...props}
>
- {isValidElement(left) && (
- <LeftElementContainer>{left}</LeftElementContainer>
+ {isValidElement(left) && <div>{left}</div>}
+ {url ? (
+ <Flex
+ component={ForwardRefLink}
+ className={S.link}
+ align="center"
+ w="100%"
+ miw={0}
+ to={url}
+ target={target}
+ rel={rel}
+ onClick={onClick}
+ >
+ {content}
+ </Flex>
+ ) : (
+ <Flex
+ component="button"
+ className={cx(S.button, CS.cursorPointer)}
+ align="center"
+ w="100%"
+ miw={0}
+ c="inherit"
+ fw={700}
+ ta="start"
+ onClick={onClick}
+ >
+ {content}
+ </Flex>
)}
- <Content>
- {icon && renderIcon()}
- <NameContainer>{children}</NameContainer>
- </Content>
- {isValidElement(right) && (
- <RightElementContainer>{right}</RightElementContainer>
- )}
- </NodeRoot>
+ {isValidElement(right) && <div>{right}</div>}
+ </TreeNode.Root>
);
}
-
-export type { SidebarLinkProps };
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default Object.assign(SidebarLink, {
- NameContainers: [ItemName, TreeNode.NameContainer],
- Icon: SidebarIcon,
- LeftElement: LeftElementContainer,
- RightElement: RightElementContainer,
-});
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/index.ts b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/index.ts
index f8201b95300..34bba30a8b7 100644
--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/index.ts
+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/index.ts
@@ -1,3 +1,3 @@
export { DraggableSidebarLink } from "./DraggableSidebarLink";
-export { default as SidebarCollectionLink } from "./SidebarCollectionLink";
-export { default as SidebarLink } from "./SidebarLink";
+export { DroppableSidebarCollectionLink as SidebarCollectionLink } from "./SidebarCollectionLink";
+export { SidebarLink, type SidebarLinkProps } from "./SidebarLink";
diff --git a/frontend/src/metabase/ui/components/utils/Box/index.ts b/frontend/src/metabase/ui/components/utils/Box/index.ts
index 320e0657bce..4c3ddb8aae0 100644
--- a/frontend/src/metabase/ui/components/utils/Box/index.ts
+++ b/frontend/src/metabase/ui/components/utils/Box/index.ts
@@ -1,2 +1,2 @@
export { Box } from "@mantine/core";
-export type { BoxProps, BoxComponentProps } from "@mantine/core";
+export type { BoxProps, BoxComponentProps, ElementProps } from "@mantine/core";