Skip to content

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

Migrate nav search and search result components from Emotion to Mantine (#77332)

Andrei Chernykh12ce1e67e774
diff --git a/frontend/src/metabase/common/components/SearchResult/components/Context.styled.tsx b/frontend/src/metabase/common/components/SearchResult/components/Context.styled.tsx
deleted file mode 100644
index 5356c0c70ba..00000000000
--- a/frontend/src/metabase/common/components/SearchResult/components/Context.styled.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const ContextText = styled("p")`
- line-height: 1.4em;
- color: var(--mb-color-text-secondary);
- margin-top: 0;
-`;
-
-export const ContextContainer = styled.div`
- margin-left: 42px;
- margin-top: 12px;
- max-width: 620px;
-`;
diff --git a/frontend/src/metabase/common/components/SearchResult/components/Context.tsx b/frontend/src/metabase/common/components/SearchResult/components/Context.tsx
index 4ad07c88b0f..c8fe1272869 100644
--- a/frontend/src/metabase/common/components/SearchResult/components/Context.tsx
+++ b/frontend/src/metabase/common/components/SearchResult/components/Context.tsx
@@ -1,8 +1,6 @@
// I think it's very likely that this is a dead codepath: RL 2023-06-21
-import { color } from "metabase/ui/utils/colors";
-
-import { ContextContainer, ContextText } from "./Context.styled";
+import { Box, Text, rem } from "metabase/ui";
export function Context({ context }: { context: any[] }) {
if (!context) {
@@ -10,21 +8,21 @@ export function Context({ context }: { context: any[] }) {
}
return (
- <ContextContainer>
- <ContextText>
+ <Box ml={rem(42)} mt={rem(12)} maw={rem(620)}>
+ <Text component="p" c="text-secondary" lh="lg">
{context.map(({ is_match, text }, i: number) => {
if (!is_match) {
return <span key={i}> {text}</span>;
}
return (
- <strong key={i} style={{ color: color("core-brand") }}>
+ <Box component="strong" key={i} c="core-brand">
{" "}
{text}
- </strong>
+ </Box>
);
})}
- </ContextText>
- </ContextContainer>
+ </Text>
+ </Box>
);
}
diff --git a/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.styled.tsx b/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.styled.tsx
deleted file mode 100644
index cc4621c6662..00000000000
--- a/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.styled.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { lighten } from "metabase/ui/colors";
-import { color } from "metabase/ui/utils/colors";
-import type { SearchModel } from "metabase-types/api";
-
-function getColorForIconWrapper(
- active: boolean,
- archived: boolean,
- type: SearchModel,
-) {
- if (!active || archived) {
- return color("text-secondary");
- }
- if (type === "collection") {
- return lighten("core-brand", 0.35);
- }
- return color("core-brand");
-}
-
-export const IconWrapper = styled.div<{
- active: boolean;
- archived: boolean;
- type: SearchModel;
-}>`
- border: 1px solid var(--mb-color-border-neutral);
- border-radius: ${({ theme }) => theme.radius.sm};
- display: flex;
- align-items: center;
- justify-content: center;
- width: 32px;
- height: 32px;
- color: ${({ active, archived, type }) =>
- getColorForIconWrapper(active, archived, type)};
- flex-shrink: 0;
- background: var(--mb-color-background_page-primary);
-`;
diff --git a/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.tsx b/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.tsx
index bdf1ee1c3b9..5678d9f00ac 100644
--- a/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.tsx
+++ b/frontend/src/metabase/common/components/SearchResult/components/ItemIcon.tsx
@@ -1,9 +1,24 @@
-import { Icon } from "metabase/ui";
+import { Flex, Icon, rem } from "metabase/ui";
+import { lighten } from "metabase/ui/colors";
+import { color } from "metabase/ui/utils/colors";
import type { RecentItem, SearchModel, SearchResult } from "metabase-types/api";
import { CollectionIcon } from "./CollectionIcon";
import { DefaultIcon } from "./DefaultIcon";
-import { IconWrapper } from "./ItemIcon.styled";
+
+function getColorForIconWrapper(
+ active: boolean,
+ archived: boolean,
+ type: SearchModel,
+) {
+ if (!active || archived) {
+ return color("text-secondary");
+ }
+ if (type === "collection") {
+ return lighten("core-brand", 0.35);
+ }
+ return color("core-brand");
+}
export interface IconComponentProps {
item: SearchResult | RecentItem;
@@ -38,13 +53,19 @@ export const ItemIcon = ({
const archived = Boolean("archived" in item && item.archived);
return (
- <IconWrapper
- type={type}
- active={active}
- archived={archived}
+ <Flex
+ align="center"
+ justify="center"
+ w={rem(32)}
+ h={rem(32)}
+ flex="0 0 auto"
+ bd="1px solid var(--mb-color-border-neutral)"
+ bdrs="sm"
+ bg="background_page-primary"
+ style={{ color: getColorForIconWrapper(active, archived, type) }}
data-testid={dataTestId}
>
<IconComponent item={item} type={type} />
- </IconWrapper>
+ </Flex>
);
};
diff --git a/frontend/src/metabase/common/components/SearchResult/tests/SearchResult.unit.spec.tsx b/frontend/src/metabase/common/components/SearchResult/tests/SearchResult.unit.spec.tsx
index 742689b677c..64a347efb1d 100644
--- a/frontend/src/metabase/common/components/SearchResult/tests/SearchResult.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/SearchResult/tests/SearchResult.unit.spec.tsx
@@ -173,10 +173,7 @@ describe("SearchResult", () => {
it("renders x-ray button for indexed entity search result", () => {
setup({ result: TEST_RESULT_INDEXED_ENTITY });
- expect(screen.getByTestId("search-result-item-icon")).toHaveAttribute(
- "type",
- "indexed-entity",
- );
+ expect(screen.getByTestId("search-result-item-icon")).toBeInTheDocument();
expect(getIcon("bolt")).toBeInTheDocument();
});
diff --git a/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.module.css b/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.module.css
new file mode 100644
index 00000000000..870821ee6ec
--- /dev/null
+++ b/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.module.css
@@ -0,0 +1,16 @@
+.resultLink {
+ color: var(--mb-color-text-secondary);
+ line-height: unset;
+ transition: color 0.2s ease-in-out;
+}
+
+.resultLink[href]:hover,
+.resultLink[href]:focus,
+.resultLink[href]:focus-within {
+ color: var(--mb-color-core-brand);
+ outline: 0;
+}
+
+.resultLinkWrapper {
+ overflow: hidden;
+}
diff --git a/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.styled.tsx b/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.styled.tsx
deleted file mode 100644
index da2ebf2c75e..00000000000
--- a/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.styled.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import type { AnchorProps, TextProps } from "metabase/ui";
-import { Group } from "metabase/ui";
-
-type ResultLinkProps = AnchorProps | TextProps;
-
-export const ResultLink = styled.a<ResultLinkProps>`
- line-height: unset;
- ${({ href }) => {
- return (
- href &&
- css`
- &:hover,
- &:focus,
- &:focus-within {
- color: var(--mb-color-core-brand);
- outline: 0;
- }
- `
- );
- }};
- transition: color 0.2s ease-in-out;
-`;
-
-export const ResultLinkWrapper = styled(Group)`
- overflow: hidden;
-`;
diff --git a/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.tsx b/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.tsx
index ba782b9232a..f76192697af 100644
--- a/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.tsx
+++ b/frontend/src/metabase/common/components/SearchResultLink/SearchResultLink.tsx
@@ -1,9 +1,9 @@
import type { MouseEvent } from "react";
-import { Anchor, Text, Tooltip } from "metabase/ui";
+import { Anchor, Group, Text, Tooltip } from "metabase/ui";
import { useIsTruncated } from "metabase/ui/hooks/use-is-truncated";
-import { ResultLink, ResultLinkWrapper } from "./SearchResultLink.styled";
+import S from "./SearchResultLink.module.css";
export const SearchResultLink = ({
children,
@@ -17,37 +17,40 @@ export const SearchResultLink = ({
const { isTruncated, ref: truncatedRef } =
useIsTruncated<HTMLAnchorElement>();
- const componentProps = href
- ? {
- as: Anchor,
- href,
- td: "underline",
- onClick: (e: MouseEvent<HTMLAnchorElement>) => e.stopPropagation(),
- }
- : {
- as: Text,
- td: "none",
- };
-
return (
<Tooltip disabled={!isTruncated || !children} label={children}>
- <ResultLinkWrapper
+ <Group
+ className={S.resultLinkWrapper}
data-testid="result-link-wrapper"
gap="xs"
wrap="nowrap"
>
{leftIcon}
- <ResultLink
- {...componentProps}
- span
- c="text-secondary"
- size="sm"
- truncate
- ref={truncatedRef}
- >
- {children}
- </ResultLink>
- </ResultLinkWrapper>
+ {href ? (
+ <Anchor
+ href={href}
+ td="underline"
+ onClick={(e: MouseEvent<HTMLAnchorElement>) => e.stopPropagation()}
+ className={S.resultLink}
+ size="sm"
+ truncate
+ ref={truncatedRef}
+ >
+ {children}
+ </Anchor>
+ ) : (
+ <Text
+ td="none"
+ component="span"
+ className={S.resultLink}
+ size="sm"
+ truncate
+ ref={truncatedRef}
+ >
+ {children}
+ </Text>
+ )}
+ </Group>
</Tooltip>
);
};
diff --git a/frontend/src/metabase/common/hooks/use-list-keyboard-navigation/use-list-keyboard-navigation.ts b/frontend/src/metabase/common/hooks/use-list-keyboard-navigation/use-list-keyboard-navigation.ts
index c72cfe94b96..9dac0f75922 100644
--- a/frontend/src/metabase/common/hooks/use-list-keyboard-navigation/use-list-keyboard-navigation.ts
+++ b/frontend/src/metabase/common/hooks/use-list-keyboard-navigation/use-list-keyboard-navigation.ts
@@ -70,6 +70,12 @@ export const useListKeyboardNavigation = <
reset,
cursorIndex,
selectedItem,
- getRef: (item: T) => (item === selectedItem ? selectedRef : undefined),
+ // a ref callback (not the ref object) so it can attach to elements narrower than R
+ getRef: (item: T) =>
+ item === selectedItem
+ ? (element: R | null) => {
+ selectedRef.current = element;
+ }
+ : undefined,
};
};
diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.module.css b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.module.css
new file mode 100644
index 00000000000..543d1e0a6e6
--- /dev/null
+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.module.css
@@ -0,0 +1,109 @@
+.container {
+ border: 1px solid var(--mb-color-border-neutral);
+ background-color: var(--mb-color-background_page-primary);
+ overflow: hidden;
+ transition:
+ background 150ms,
+ width 0.2s;
+
+ &:not(.active):hover {
+ background-color: var(--mb-color-background_page-secondary);
+ }
+
+ &.active {
+ background-color: var(--mb-color-background_page-tertiary);
+ }
+}
+
+.input {
+ background-color: transparent;
+ border: none;
+ color: var(--mb-color-text-primary);
+ font-weight: 700;
+ font-size: var(--mantine-font-size-md);
+ flex-basis: 0;
+ flex-grow: 1;
+
+ &:focus {
+ outline: none;
+ }
+
+ &::placeholder {
+ color: var(--mb-color-text-primary);
+ }
+}
+
+.searchIcon {
+ flex-basis: 1rem;
+}
+
+.closeButton {
+ align-items: center;
+ justify-content: center;
+ color: var(--mb-color-text-disabled);
+
+ &:hover {
+ color: var(--mb-color-text-secondary);
+ }
+}
+
+@media (prefers-reduced-motion) {
+ .container {
+ transition: none;
+ }
+}
+
+@media screen and (--breakpoint-max-sm) {
+ .container {
+ justify-content: center;
+ margin-left: auto;
+ width: 2rem;
+ height: 2rem;
+ border-radius: var(--mantine-radius-xl);
+ border-color: transparent;
+
+ &.active {
+ width: 100%;
+ border-color: var(--mb-color-border-neutral);
+ border-radius: var(--mantine-radius-sm);
+ justify-content: flex-start;
+ }
+ }
+
+ .input {
+ width: 0;
+ flex-grow: 0;
+ padding: 0;
+
+ &.active {
+ flex-grow: 1;
+ padding-top: var(--mantine-spacing-sm);
+ padding-bottom: var(--mantine-spacing-sm);
+ }
+ }
+
+ .searchIcon {
+ transition: margin 0.3s;
+
+ &.active {
+ margin-left: var(--mantine-spacing-sm);
+ margin-right: var(--mantine-spacing-sm);
+ }
+ }
+}
+
+@media screen and (--breakpoint-min-sm) {
+ .container {
+ max-width: 50em;
+ border-radius: var(--mantine-radius-sm);
+ justify-content: flex-start;
+ }
+
+ .input {
+ padding: var(--mantine-spacing-sm) 0.75rem;
+ }
+
+ .searchIcon {
+ margin-left: var(--mantine-spacing-sm);
+ }
+}
diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx
deleted file mode 100644
index 686182239a6..00000000000
--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx
+++ /dev/null
@@ -1,168 +0,0 @@
-import isPropValid from "@emotion/is-prop-valid";
-// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { APP_BAR_HEIGHT } from "metabase/nav/constants";
-import {
- breakpointMaxSmall,
- breakpointMinSmall,
-} from "metabase/styled-components/theme";
-import { Icon } from "metabase/ui";
-
-const activeInputCSS = css`
- border-radius: 6px;
- justify-content: flex-start;
-`;
-
-export const SearchBarRoot = styled.div`
- width: 100%;
-
- ${breakpointMinSmall} {
- max-width: 14.5rem;
- position: relative;
- }
-`;
-
-export const SearchInputContainer = styled.div<{
- isActive: boolean;
-}>`
- display: flex;
- flex: 1 1 auto;
- align-items: center;
- position: relative;
- ${({ isActive }) => {
- if (isActive) {
- return css`
- background-color: var(--mb-color-background_page-tertiary);
- `;
- }
- return css`
- background-color: var(--mb-color-background_page-primary);
-
- &:hover {
- background-color: var(--mb-color-background_page-secondary);
- }
- `;
- }}
- border: 1px solid var(--mb-color-border-neutral);
- overflow: hidden;
- transition:
- background 150ms,
- width 0.2s;
-
- @media (prefers-reduced-motion) {
- transition: none;
- }
-
- ${breakpointMaxSmall} {
- justify-content: center;
- margin-left: auto;
- width: 2rem;
- height: 2rem;
- border-radius: 99px;
- border-color: transparent;
- ${(props) =>
- props.isActive &&
- css`
- width: 100%;
- border-color: var(--mb-color-border-neutral);
- ${activeInputCSS};
- `};
- }
-
- ${breakpointMinSmall} {
- max-width: 50em;
- ${activeInputCSS};
- }
-`;
-
-export const SearchInput = styled.input<{
- isActive: boolean;
-}>`
- background-color: transparent;
- border: none;
- color: var(--mb-color-text-primary);
- font-weight: 700;
- font-size: 0.875rem;
- flex-basis: 0;
- flex-grow: 1;
-
- &:focus {
- outline: none;
- }
-
- &::placeholder {
- color: var(--mb-color-text-primary);
- }
-
- ${breakpointMinSmall} {
- padding: 9px 12px;
- }
-
- ${breakpointMaxSmall} {
- width: 0;
- flex-grow: 0;
- padding: 0;
-
- ${(props) =>
- props.isActive &&
- css`
- flex-grow: 1;
- padding-top: 10px;
- padding-bottom: 10px;
- `}
- }
-`;
-
-const ICON_MARGIN = "10px";
-
-export const SearchIcon = styled(Icon, { shouldForwardProp: isPropValid })<{
- isActive: boolean;
-}>`
- flex-basis: 1rem;
- ${breakpointMaxSmall} {
- transition: margin 0.3s;
-
- ${(props) =>
- props.isActive &&
- css`
- margin-left: ${ICON_MARGIN};
- margin-right: ${ICON_MARGIN};
- `}
- }
-
- ${breakpointMinSmall} {
- margin-left: ${ICON_MARGIN};
- }
-`;
-
-export const CloseSearchButton = styled.button`
- display: flex;
- align-items: center;
- justify-content: center;
- width: 3rem;
- height: 100%;
- color: var(--mb-color-text-disabled);
- cursor: pointer;
-
- &:hover {
- color: var(--mb-color-text-secondary);
- }
-`;
-
-export const SearchResultsFloatingContainer = styled.div`
- position: absolute;
- left: 0;
- right: 0;
- color: var(--mb-color-text-primary);
-
- ${breakpointMaxSmall} {
- top: ${APP_BAR_HEIGHT};
- }
-
- ${breakpointMinSmall} {
- top: 42px;
- }
-`;
diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.tsx
index 860891ec3cc..28a2cc078b4 100644
--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.tsx
+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.tsx
@@ -1,3 +1,4 @@
+import cx from "classnames";
import type { LocationDescriptorObject } from "history";
import { useKBar } from "kbar";
import type {
@@ -20,24 +21,18 @@ import {
import type { SearchAwareLocation } from "metabase/common/search/types";
import { RecentsList } from "metabase/nav/components/search/RecentsList";
import { SearchResultsDropdown } from "metabase/nav/components/search/SearchResultsDropdown";
+import { APP_BAR_HEIGHT } from "metabase/nav/constants";
import { useDispatch, useSelector } from "metabase/redux";
import { push, withRouter } from "metabase/router";
import { getSetting } from "metabase/selectors/settings";
-import { Icon } from "metabase/ui";
+import { Box, Flex, Icon, UnstyledButton, rem } from "metabase/ui";
import { modelToUrl } from "metabase/urls";
import { isSmallScreen } from "metabase/utils/dom";
import { isWithinIframe } from "metabase/utils/iframe";
import type { SearchResult } from "metabase-types/api";
import { CommandPaletteTrigger } from "./CommandPaletteTrigger";
-import {
- CloseSearchButton,
- SearchBarRoot,
- SearchIcon,
- SearchInput,
- SearchInputContainer,
- SearchResultsFloatingContainer,
-} from "./SearchBar.styled";
+import S from "./SearchBar.module.css";
const ALLOWED_SEARCH_FOCUS_ELEMENTS = new Set(["BODY", "A"]);
@@ -201,11 +196,25 @@ function SearchBarView({
};
return (
- <SearchBarRoot ref={container}>
- <SearchInputContainer isActive={isActive} onClick={onInputContainerClick}>
- <SearchIcon name="search" isActive={isActive} />
- <SearchInput
- isActive={isActive}
+ <Box
+ ref={container}
+ w="100%"
+ maw={{ sm: rem(232) }}
+ pos={{ sm: "relative" }}
+ >
+ <Flex
+ className={cx(S.container, { [S.active]: isActive })}
+ align="center"
+ pos="relative"
+ flex="1 1 auto"
+ onClick={onInputContainerClick}
+ >
+ <Icon
+ name="search"
+ className={cx(S.searchIcon, { [S.active]: isActive })}
+ />
+ <input
+ className={cx(S.input, { [S.active]: isActive })}
value={searchText}
placeholder={t`Search` + "…"}
maxLength={200}
@@ -214,16 +223,30 @@ function SearchBarView({
ref={searchInput}
/>
{isSmallScreen() && isActive && (
- <CloseSearchButton onClick={handleClickOnClose}>
+ <UnstyledButton
+ className={S.closeButton}
+ display="flex"
+ w={rem(48)}
+ h="100%"
+ aria-label={t`Close search`}
+ onClick={handleClickOnClose}
+ >
<Icon name="close" />
- </CloseSearchButton>
+ </UnstyledButton>
)}
{!isSmallScreen() && !isWithinIframe() && isActive && (
<CommandPaletteTrigger onClick={handleCommandPaletteTriggerClick} />
)}
- </SearchInputContainer>
+ </Flex>
{isActive && isTypeaheadEnabled && (
- <SearchResultsFloatingContainer data-testid="search-results-floating-container">
+ <Box
+ pos="absolute"
+ left={0}
+ right={0}
+ top={{ base: APP_BAR_HEIGHT, sm: rem(42) }}
+ c="text-primary"
+ data-testid="search-results-floating-container"
+ >
{hasSearchText ? (
<SearchResultsDropdown
searchText={searchText}
@@ -234,9 +257,9 @@ function SearchBarView({
) : (
<RecentsList />
)}
- </SearchResultsFloatingContainer>
+ </Box>
)}
- </SearchBarRoot>
+ </Box>
);
}
diff --git a/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.module.css b/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.module.css
new file mode 100644
index 00000000000..54e5dbd99ca
--- /dev/null
+++ b/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.module.css
@@ -0,0 +1,7 @@
+.searchResultsList {
+ overflow: hidden;
+}
+
+.resultsContainer {
+ overflow-y: auto;
+}
diff --git a/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.styled.tsx b/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.styled.tsx
deleted file mode 100644
index b8850e807b1..00000000000
--- a/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.styled.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Stack } from "metabase/ui";
-
-export const EmptyStateContainer = styled.div`
- margin-top: 4rem;
- margin-bottom: 2rem;
-`;
-
-export const SearchResultsList = styled(Stack)`
- overflow: hidden;
-`;
-
-export const ResultsContainer = styled.ul`
- overflow-y: auto;
- padding: 0.5rem;
-`;
-
-export const ResultsFooter = styled.li`
- list-style-type: none;
-`;
diff --git a/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.tsx b/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.tsx
index 826167cc938..89d323e3b28 100644
--- a/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.tsx
+++ b/frontend/src/metabase/nav/components/search/SearchResults/SearchResults.tsx
@@ -1,3 +1,4 @@
+import type { ReactNode } from "react";
import { useEffect, useMemo, useState } from "react";
import { useDebounce } from "react-use";
import { t } from "ttag";
@@ -7,15 +8,9 @@ import { EmptyState } from "metabase/common/components/EmptyState";
import { SearchResult } from "metabase/common/components/SearchResult/SearchResult";
import { useListKeyboardNavigation } from "metabase/common/hooks/use-list-keyboard-navigation";
import type { SearchFilters } from "metabase/common/search/types";
-import {
- EmptyStateContainer,
- ResultsContainer,
- ResultsFooter,
- SearchResultsList,
-} from "metabase/nav/components/search/SearchResults/SearchResults.styled";
import { useDispatch } from "metabase/redux";
import { push } from "metabase/router";
-import { Loader } from "metabase/ui";
+import { Box, Loader, Stack, rem } from "metabase/ui";
import { modelToUrl } from "metabase/urls";
import {
DEFAULT_SEARCH_LIMIT,
@@ -29,6 +24,8 @@ import type {
SearchResponse as SearchResultsType,
} from "metabase-types/api";
+import S from "./SearchResults.module.css";
+
export type SearchResultsFooter =
| (({
metadata,
@@ -54,6 +51,18 @@ export const SearchLoadingSpinner = () => (
<Loader size="lg" label={t`Loading…`} />
);
+export const EmptyStateContainer = ({
+ children,
+ "data-testid": dataTestId,
+}: {
+ children: ReactNode;
+ "data-testid"?: string;
+}) => (
+ <Box mt={rem(64)} mb="xl" data-testid={dataTestId}>
+ {children}
+ </Box>
+);
+
export const SearchResults = ({
onEntitySelect,
forceEntitySelect = false,
@@ -132,7 +141,7 @@ export const SearchResults = ({
const { reset, getRef, cursorIndex } = useListKeyboardNavigation<
ItemType,
- HTMLLIElement
+ HTMLElement
>({
list: dropdownItemList,
onEnter: onEnterSelect,
@@ -148,8 +157,12 @@ export const SearchResults = ({
}
return hasResults ? (
- <SearchResultsList data-testid="search-results-list" gap={0}>
- <ResultsContainer>
+ <Stack
+ className={S.searchResultsList}
+ data-testid="search-results-list"
+ gap={0}
+ >
+ <Box component="ul" p="sm" className={S.resultsContainer}>
{list.map((item, index) => {
const isIndexedEntity = item.model === "indexed-entity";
const onClick =
@@ -173,16 +186,16 @@ export const SearchResults = ({
</li>
);
})}
- </ResultsContainer>
+ </Box>
{showFooter && (
- <ResultsFooter ref={getRef(footerComponent)}>
+ <Box ref={getRef(footerComponent)}>
{footerComponent({
metadata,
isSelected: cursorIndex === dropdownItemList.length - 1,
})}
- </ResultsFooter>
+ </Box>
)}
- </SearchResultsList>
+ </Stack>
) : (
<EmptyStateContainer data-testid="search-results-empty-state">
<EmptyState message={t`Didn't find anything`} icon="search" />
diff --git a/frontend/src/metabase/nav/components/search/SearchResults/index.ts b/frontend/src/metabase/nav/components/search/SearchResults/index.ts
index 79c3e1de483..92f50e14afc 100644
--- a/frontend/src/metabase/nav/components/search/SearchResults/index.ts
+++ b/frontend/src/metabase/nav/components/search/SearchResults/index.ts
@@ -1,3 +1,6 @@
-export { SearchResults, SearchLoadingSpinner } from "./SearchResults";
+export {
+ EmptyStateContainer,
+ SearchLoadingSpinner,
+ SearchResults,
+} from "./SearchResults";
export type { SearchResultsFooter } from "./SearchResults";
-export * from "./SearchResults.styled";
diff --git a/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.module.css b/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.module.css
new file mode 100644
index 00000000000..3dd51cbc824
--- /dev/null
+++ b/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.module.css
@@ -0,0 +1,16 @@
+.searchResultsContainer {
+ display: flex;
+ flex-direction: column;
+}
+
+.dropdownFooter {
+ border-top: 1px solid var(--mb-color-border-neutral);
+ transition: all 0.2s ease-in-out;
+}
+
+.dropdownFooter:hover,
+.dropdownFooterSelected {
+ color: var(--mb-color-core-brand);
+ background-color: var(--mb-color-background_surface-hover);
+ cursor: pointer;
+}
diff --git a/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.styled.tsx b/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.styled.tsx
deleted file mode 100644
index c4a3c5856d0..00000000000
--- a/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.styled.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { APP_BAR_HEIGHT } from "metabase/nav/constants";
-import {
- breakpointMaxSmall,
- breakpointMinSmall,
-} from "metabase/styled-components/theme";
-import type { GroupProps, PaperProps } from "metabase/ui";
-import { Group, Paper } from "metabase/ui";
-
-// Unjustified type cast. FIXME
-export const SearchResultsContainer = styled(Paper)<PaperProps>`
- display: flex;
- flex-direction: column;
-
- ${breakpointMaxSmall} {
- height: calc(100vh - ${APP_BAR_HEIGHT});
- }
-
- ${breakpointMinSmall} {
- max-height: 400px;
- }
-` as unknown as typeof Paper;
-
-const selectedStyles = css`
- color: var(--mb-color-core-brand);
- background-color: var(--mb-color-background_surface-hover);
- cursor: pointer;
- transition: all 0.2s ease-in-out;
-`;
-
-export const SearchDropdownFooter = styled(Group, {
- shouldForwardProp: (propName) => propName !== "isSelected",
-})<{ isSelected?: boolean } & GroupProps>`
- border-top: 1px solid var(--mb-color-border-neutral);
-
- ${({ isSelected }) => isSelected && selectedStyles}
- &:hover {
- ${selectedStyles}
- }
-`;
diff --git a/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.tsx b/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.tsx
index dec6c045f7e..1075195b06c 100644
--- a/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.tsx
+++ b/frontend/src/metabase/nav/components/search/SearchResultsDropdown/SearchResultsDropdown.tsx
@@ -1,14 +1,13 @@
+import cx from "classnames";
import { jt, t } from "ttag";
import type { SearchResultsFooter } from "metabase/nav/components/search/SearchResults";
import { SearchResults } from "metabase/nav/components/search/SearchResults";
-import { Icon, Text, rem } from "metabase/ui";
+import { APP_BAR_HEIGHT } from "metabase/nav/constants";
+import { Group, Icon, Paper, Text, rem } from "metabase/ui";
import type { SearchContext, SearchResult } from "metabase-types/api";
-import {
- SearchDropdownFooter,
- SearchResultsContainer,
-} from "./SearchResultsDropdown.styled";
+import S from "./SearchResultsDropdown.module.css";
import { MIN_RESULTS_FOR_FOOTER_TEXT } from "./constants";
export type SearchResultsDropdownProps = {
@@ -31,25 +30,31 @@ export const SearchResultsDropdown = ({
: t`View and filter results`;
return metadata.total > 0 ? (
- <SearchDropdownFooter
+ <Group
+ className={cx(S.dropdownFooter, {
+ [S.dropdownFooterSelected]: isSelected,
+ })}
+ role="button"
data-testid="search-dropdown-footer"
justify="space-between"
align="center"
px="lg"
py={rem(10)}
onClick={goToSearchApp}
- isSelected={isSelected}
>
<Text fw={700} size="sm" c="inherit">
{resultText}
</Text>
<Icon name="arrow_right" size={14} />
- </SearchDropdownFooter>
+ </Group>
) : null;
};
return (
- <SearchResultsContainer
+ <Paper
+ className={S.searchResultsContainer}
+ h={{ base: `calc(100vh - ${APP_BAR_HEIGHT})`, sm: "auto" }}
+ mah={{ sm: rem(400) }}
data-testid="search-bar-results-container"
withBorder
>
@@ -60,6 +65,6 @@ export const SearchResultsDropdown = ({
onFooterSelect={goToSearchApp}
context={context}
/>
- </SearchResultsContainer>
+ </Paper>
);
};