Skip to content

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

chore: make bookmark button look the same as other action buttons (#64951)

Uladzimir Havenchyk6ec03b098ec0
diff --git a/frontend/src/metabase/collections/components/CollectionHeader/CollectionBookmark.tsx b/frontend/src/metabase/collections/components/CollectionHeader/CollectionBookmark.tsx
index 7ef1697278c..c7e40aaa2a7 100644
--- a/frontend/src/metabase/collections/components/CollectionHeader/CollectionBookmark.tsx
+++ b/frontend/src/metabase/collections/components/CollectionHeader/CollectionBookmark.tsx
@@ -1,7 +1,7 @@
import { useCallback } from "react";
import { isRootCollection } from "metabase/collections/utils";
-import BookmarkToggle from "metabase/common/components/BookmarkToggle";
+import { BookmarkToggle } from "metabase/common/components/BookmarkToggle";
import type { Collection } from "metabase-types/api";
export interface CollectionBookmarkProps {
diff --git a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.module.css b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.module.css
new file mode 100644
index 00000000000..ed4c6acd511
--- /dev/null
+++ b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.module.css
@@ -0,0 +1,33 @@
+@keyframes expand {
+ 50% {
+ transform: scale(1.3);
+ }
+}
+
+@keyframes shrink {
+ 50% {
+ transform: scale(0.8);
+ }
+}
+
+.actionIconBookmarked {
+ color: var(--mb-color-brand);
+}
+
+.icon {
+ animation-duration: 0.3s;
+ animation-timing-function: linear;
+ animation-play-state: paused;
+}
+
+.iconAnimating {
+ animation-play-state: running;
+}
+
+.iconAnimatingBookmarked {
+ animation-name: expand;
+}
+
+.iconAnimatingUnbookmarked {
+ animation-name: shrink;
+}
diff --git a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.stories.tsx b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.stories.tsx
index 106cdf60681..f6d66983f0b 100644
--- a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.stories.tsx
+++ b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.stories.tsx
@@ -1,7 +1,7 @@
import { useArgs } from "@storybook/preview-api";
import type { StoryFn } from "@storybook/react";
-import BookmarkToggle from "./BookmarkToggle";
+import { BookmarkToggle } from "./BookmarkToggle";
export default {
title: "Components/BookmarkToggle",
diff --git a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.styled.tsx b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.styled.tsx
deleted file mode 100644
index 66c36872b02..00000000000
--- a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.styled.tsx
+++ /dev/null
@@ -1,70 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import { keyframes } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-import { forwardRef } from "react";
-
-import { doNotForwardProps } from "metabase/common/utils/doNotForwardProps";
-import { Icon } from "metabase/ui";
-import { color } from "metabase/ui/utils/colors";
-
-import Button, { type ButtonProps } from "../Button";
-
-const expandKeyframes = keyframes`
- 50% {
- transform: scale(1.3);
- }
-`;
-
-const shrinkKeyframes = keyframes`
- 50% {
- transform: scale(0.8);
- }
-`;
-
-interface BookmarkIconProps {
- isBookmarked: boolean;
- isAnimating: boolean;
- onAnimationEnd: () => void;
-}
-
-export const BookmarkIcon = styled(
- Icon,
- doNotForwardProps("isBookmarked", "isAnimating"),
-)<BookmarkIconProps>`
- color: ${(props) => (props.isBookmarked ? color("brand") : "")};
- animation-name: ${(props) =>
- props.isBookmarked ? expandKeyframes : shrinkKeyframes};
- animation-play-state: ${(props) =>
- props.isAnimating ? "running" : "paused"};
- animation-duration: 0.3s;
- animation-timing-function: linear;
-`;
-
-const BaseBookmarkButton = forwardRef<HTMLButtonElement, ButtonProps>(
- function BookmarkButton(props, ref) {
- return (
- <Button
- {...props}
- ref={ref}
- onlyIcon={props.onlyIcon ?? true}
- iconSize={props.iconSize ?? 16}
- />
- );
- },
-);
-
-export const BookmarkButton = styled(BaseBookmarkButton)`
- padding: 0.25rem 0.5rem;
- height: 2rem;
- width: 2rem;
-
- &:hover {
- color: var(--mb-color-brand);
- background-color: var(--mb-color-bg-medium);
- }
-
- svg {
- vertical-align: middle;
- }
-`;
diff --git a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.tsx b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.tsx
index 591c78d7a51..7ec09a40bc8 100644
--- a/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.tsx
+++ b/frontend/src/metabase/common/components/BookmarkToggle/BookmarkToggle.tsx
@@ -1,10 +1,11 @@
+import cx from "classnames";
import type { HTMLAttributes, Ref } from "react";
import { forwardRef, useCallback, useState } from "react";
import { t } from "ttag";
-import { Tooltip } from "metabase/ui";
+import { ActionIcon, Icon, Tooltip } from "metabase/ui";
-import { BookmarkButton, BookmarkIcon } from "./BookmarkToggle.styled";
+import S from "./BookmarkToggle.module.css";
export interface BookmarkToggleProps extends HTMLAttributes<HTMLButtonElement> {
isBookmarked: boolean;
@@ -44,22 +45,27 @@ const BookmarkToggle = forwardRef(function BookmarkToggle(
return (
<Tooltip label={label} position={tooltipPlacement}>
- <BookmarkButton
+ <ActionIcon
{...props}
aria-label={label}
ref={ref}
onClick={handleClick}
+ variant="viewHeader"
+ size="2rem"
>
- <BookmarkIcon
+ <Icon
name={iconName}
- isBookmarked={isBookmarked}
- isAnimating={isAnimating}
+ className={cx(S.icon, {
+ [S.iconAnimating]: isAnimating,
+ [S.actionIconBookmarked]: isBookmarked,
+ [S.iconAnimatingBookmarked]: isAnimating && isBookmarked,
+ [S.iconAnimatingUnbookmarked]: isAnimating && !isBookmarked,
+ })}
onAnimationEnd={handleAnimationEnd}
/>
- </BookmarkButton>
+ </ActionIcon>
</Tooltip>
);
});
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default BookmarkToggle;
+export { BookmarkToggle };
diff --git a/frontend/src/metabase/common/components/BookmarkToggle/index.ts b/frontend/src/metabase/common/components/BookmarkToggle/index.ts
index 9cbd038c40c..06d9bbdc3c8 100644
--- a/frontend/src/metabase/common/components/BookmarkToggle/index.ts
+++ b/frontend/src/metabase/common/components/BookmarkToggle/index.ts
@@ -1,2 +1 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./BookmarkToggle";
+export * from "./BookmarkToggle";
diff --git a/frontend/src/metabase/dashboard/components/DashboardBookmark.tsx b/frontend/src/metabase/dashboard/components/DashboardBookmark.tsx
index a846c53cef0..f85721fe00e 100644
--- a/frontend/src/metabase/dashboard/components/DashboardBookmark.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardBookmark.tsx
@@ -1,4 +1,4 @@
-import BookmarkToggle from "metabase/common/components/BookmarkToggle";
+import { BookmarkToggle } from "metabase/common/components/BookmarkToggle";
import { useBookmarkListQuery } from "metabase/common/hooks";
import { useDashboardContext } from "metabase/dashboard/context/context";
import Bookmark from "metabase/entities/bookmarks";
diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.tsx
index ceb803a565a..7ccd9963792 100644
--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.tsx
+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/QuestionActions/QuestionActions.tsx
@@ -2,7 +2,7 @@ import type { ChangeEvent } from "react";
import { useRef, useState } from "react";
import { t } from "ttag";
-import BookmarkToggle from "metabase/common/components/BookmarkToggle";
+import { BookmarkToggle } from "metabase/common/components/BookmarkToggle";
import { ToolbarButton } from "metabase/common/components/ToolbarButton";
import { UploadInput } from "metabase/common/components/upload";
import { useDispatch } from "metabase/lib/redux";
@@ -105,7 +105,6 @@ export const QuestionActions = ({
{!question.isArchived() && (
<Box className={ViewTitleHeaderS.ViewHeaderIconButtonContainer}>
<BookmarkToggle
- className={ViewTitleHeaderS.ViewHeaderIconButton}
onCreateBookmark={onToggleBookmark}
onDeleteBookmark={onToggleBookmark}
isBookmarked={isBookmarked}