Skip to content

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

chore: replace more deprecated buttons with mantine buttons (#76051)

Uladzimir Havenchyk3f54ca2ce3ee
diff --git a/frontend/src/metabase/common/components/ViewButton/ViewButton.module.css b/frontend/src/metabase/common/components/ViewButton/ViewButton.module.css
index c75bb92e0c2..cb1706915cc 100644
--- a/frontend/src/metabase/common/components/ViewButton/ViewButton.module.css
+++ b/frontend/src/metabase/common/components/ViewButton/ViewButton.module.css
@@ -1,15 +1,26 @@
.ViewButton {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.5rem;
+ padding: 0.5rem 0.75rem;
+ font-weight: bold;
+ border: none;
+ border-radius: var(--default-button-border-radius);
background-color: color-mix(
in srgb,
var(--view-button-color) 20%,
transparent
);
color: var(--view-button-color);
- border: none;
transition:
background 300ms linear,
border 300ms linear;
+ @media screen and (--breakpoint-min-lg) {
+ padding: 0.75rem 1rem;
+ }
+
&:hover {
background-color: color-mix(
in srgb,
@@ -18,6 +29,15 @@
);
}
+ &.medium {
+ padding: 0.5rem 0.75rem;
+ font-size: 0.8rem;
+ }
+
+ &.onlyIcon {
+ padding: 0.5rem;
+ }
+
&.active {
background-color: var(--view-button-color);
color: var(--mb-color-text-primary-inverse);
@@ -31,3 +51,9 @@
}
}
}
+
+.label {
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+}
diff --git a/frontend/src/metabase/common/components/ViewButton/ViewButton.tsx b/frontend/src/metabase/common/components/ViewButton/ViewButton.tsx
index 4adcf091248..bfcdbda84a7 100644
--- a/frontend/src/metabase/common/components/ViewButton/ViewButton.tsx
+++ b/frontend/src/metabase/common/components/ViewButton/ViewButton.tsx
@@ -1,28 +1,64 @@
import cx from "classnames";
-import type { CSSProperties } from "react";
+import type { CSSProperties, ComponentPropsWithoutRef } from "react";
-import { Button, type ButtonProps } from "metabase/common/components/Button";
+import CS from "metabase/css/core/index.css";
+import { Icon, UnstyledButton } from "metabase/ui";
+import type { IconName } from "metabase-types/api";
import S from "./ViewButton.module.css";
-interface Props extends ButtonProps {
+interface Props extends ComponentPropsWithoutRef<"button"> {
color?: string;
active?: boolean;
+ medium?: boolean;
+ onlyIcon?: boolean;
+ icon?: IconName;
+ iconSize?: number;
+ labelBreakpoint?: "sm";
}
// NOTE: some of this is duplicated from NotebookCell.jsx
-export const ViewButton = ({ className, active, color, ...props }: Props) => {
+export const ViewButton = ({
+ className,
+ active,
+ color,
+ medium,
+ onlyIcon,
+ icon,
+ iconSize = 16,
+ labelBreakpoint,
+ children,
+ ...props
+}: Props) => {
return (
- <Button
- classNames={{
- root: cx(S.ViewButton, { [S.active]: active }, className),
- }}
+ <UnstyledButton
+ className={cx(
+ S.ViewButton,
+ {
+ [S.active]: active,
+ [S.medium]: medium,
+ [S.onlyIcon]: onlyIcon,
+ },
+ className,
+ )}
style={
{
"--view-button-color": color ?? "var(--mb-color-core-brand)",
} as CSSProperties
}
{...props}
- />
+ >
+ {icon && <Icon name={icon} size={iconSize} />}
+ {children && (
+ <span
+ className={cx(
+ S.label,
+ labelBreakpoint === "sm" && [CS.hide, CS.smShow],
+ )}
+ >
+ {children}
+ </span>
+ )}
+ </UnstyledButton>
);
};
diff --git a/frontend/src/metabase/css/query_builder.module.css b/frontend/src/metabase/css/query_builder.module.css
index c0df0e88954..bb28074a669 100644
--- a/frontend/src/metabase/css/query_builder.module.css
+++ b/frontend/src/metabase/css/query_builder.module.css
@@ -256,37 +256,6 @@
padding-right: 10px;
}
-/* VISUALIZATION SETTINGS */
-
-.RunButton {
- opacity: 1;
- transition:
- transform 0.25s,
- opacity 0.25s;
-}
-
-.RunButton.RunButtonCircular {
- padding: 0.25rem 1.5rem;
- border: none;
-
- .RunButtonIcon {
- transform: translateX(2px);
- }
-}
-
-.RunButton.RunButtonHidden {
- transform: translateY(-20px);
- opacity: 0;
-}
-
-@media (prefers-reduced-motion) {
- .RunButton,
- .RunButton.RunButtonCircular,
- .RunButton.RunButtonHidden {
- transition-duration: 10ms;
- }
-}
-
/* DATA REFERENCE */
.ObjectJSON {
diff --git a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ViewTitleHeaderRightSide/ViewTitleHeaderRightSide.tsx b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ViewTitleHeaderRightSide/ViewTitleHeaderRightSide.tsx
index 57e5f15a502..1b693ae0806 100644
--- a/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ViewTitleHeaderRightSide/ViewTitleHeaderRightSide.tsx
+++ b/frontend/src/metabase/query_builder/components/view/ViewHeader/components/ViewTitleHeaderRightSide/ViewTitleHeaderRightSide.tsx
@@ -215,7 +215,6 @@ export function ViewTitleHeaderRightSide({
)}
iconSize={16}
onlyIcon
- medium
isRunning={isRunning}
isDirty={isResultDirty}
onRun={() => runQuestionQuery({ ignoreCache: true })}
diff --git a/frontend/src/metabase/querying/components/QueryVisualization/RunButton.module.css b/frontend/src/metabase/querying/components/QueryVisualization/RunButton.module.css
new file mode 100644
index 00000000000..26165ee366c
--- /dev/null
+++ b/frontend/src/metabase/querying/components/QueryVisualization/RunButton.module.css
@@ -0,0 +1,71 @@
+.root {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ padding: 0.5rem 0.75rem;
+ font-weight: bold;
+ border: 1px solid var(--mb-color-border);
+ border-radius: var(--default-button-border-radius);
+ opacity: 1;
+ transition:
+ transform 0.25s,
+ opacity 0.25s,
+ color 200ms linear,
+ border-color 200ms linear,
+ background-color 200ms linear;
+
+ @media screen and (--breakpoint-min-lg) {
+ padding: 0.75rem 1rem;
+ }
+
+ &:hover {
+ color: var(--mb-color-text-brand);
+ background: var(--mb-color-background-secondary);
+ }
+}
+
+.primary {
+ color: var(--mb-color-text-primary-inverse);
+ background: var(--mb-color-core-brand);
+ border-color: var(--mb-color-core-brand);
+
+ &:hover {
+ color: var(--mb-color-text-primary-inverse);
+ border-color: var(--mb-color-core-brand);
+ background-color: var(--mb-color-core-brand-hover);
+ }
+}
+
+.white {
+ background-color: var(--mb-color-background-primary);
+ color: var(--mb-color-text-primary);
+ border-color: var(--mb-color-border);
+}
+
+.onlyIcon {
+ padding: 0;
+ border: none;
+ background: transparent;
+ color: var(--mb-color-text-primary);
+}
+
+.circular {
+ padding: 0.25rem 1.5rem;
+ border: none;
+ border-radius: 99px;
+
+ .icon {
+ transform: translateX(2px);
+ }
+}
+
+.hidden {
+ transform: translateY(-20px);
+ opacity: 0;
+}
+
+@media (prefers-reduced-motion) {
+ .root {
+ transition-duration: 10ms;
+ }
+}
diff --git a/frontend/src/metabase/querying/components/QueryVisualization/RunButton.tsx b/frontend/src/metabase/querying/components/QueryVisualization/RunButton.tsx
index 249253366af..5e8c51a2aa3 100644
--- a/frontend/src/metabase/querying/components/QueryVisualization/RunButton.tsx
+++ b/frontend/src/metabase/querying/components/QueryVisualization/RunButton.tsx
@@ -3,16 +3,15 @@ import type { Ref } from "react";
import { forwardRef } from "react";
import { t } from "ttag";
-import { Button } from "metabase/common/components/Button";
-import CS from "metabase/css/core/index.css";
-import QueryBuilderS from "metabase/css/query_builder.module.css";
+import { Icon, UnstyledButton } from "metabase/ui";
+
+import S from "./RunButton.module.css";
export interface RunButtonProps {
className?: string;
isRunning: boolean;
isDirty: boolean;
circular?: boolean;
- medium?: boolean;
hidden?: boolean;
disabled?: boolean;
onlyIcon?: boolean;
@@ -30,6 +29,8 @@ export const RunButton = forwardRef(function RunButton(
className,
circular,
hidden,
+ onlyIcon,
+ iconSize = 16,
...props
}: RunButtonProps,
ref: Ref<HTMLButtonElement>,
@@ -38,24 +39,22 @@ export const RunButton = forwardRef(function RunButton(
const ariaLabel = getButtonLabel(isRunning, isDirty);
return (
- <Button
+ <UnstyledButton
{...props}
ref={ref}
- className={cx(className, QueryBuilderS.RunButton, {
- [QueryBuilderS.RunButtonHidden]: hidden,
- [QueryBuilderS.RunButtonCircular]: circular,
- [CS.circular]: circular,
+ className={cx(S.root, className, {
+ [S.primary]: isDirty,
+ [S.white]: !isDirty,
+ [S.onlyIcon]: onlyIcon,
+ [S.circular]: circular,
+ [S.hidden]: hidden,
})}
- classNames={{
- icon: QueryBuilderS.RunButtonIcon,
- }}
- icon={icon}
- primary={isDirty}
- white={!isDirty}
data-testid="run-button"
aria-label={ariaLabel}
onClick={isRunning ? onCancel : onRun}
- />
+ >
+ <Icon className={S.icon} name={icon} size={iconSize} />
+ </UnstyledButton>
);
});
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.module.css b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.module.css
index dd32f0e1ee5..56b1192e0e4 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.module.css
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.module.css
@@ -1,5 +1,10 @@
.ColorButton {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
border: none;
+ font-weight: bold;
+ border-radius: var(--default-button-border-radius);
transition: background 300ms;
color: var(--notebook-action-button-color);
background-color: color-mix(
@@ -8,6 +13,18 @@
transparent 80%
);
+ &.large {
+ padding: 0.5rem 0.75rem;
+
+ @media screen and (--breakpoint-min-lg) {
+ padding: 0.75rem 1rem;
+ }
+ }
+
+ &.small {
+ padding: 0.5rem;
+ }
+
&.secondary {
color: var(--mb-color-text-secondary);
background-color: var(--mb-color-notebook-step-bg);
@@ -26,3 +43,10 @@
color: color-mix(in srgb, var(--notebook-action-button-color), black 11.5%);
}
}
+
+.label {
+ margin-top: 0.5rem;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+}
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.tsx
index 88cb0eeebc4..2e0803b359a 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookActionButton/NotebookActionButton.tsx
@@ -1,8 +1,7 @@
import cx from "classnames";
import type { CSSProperties } from "react";
-import { Button } from "metabase/common/components/Button";
-import { Tooltip } from "metabase/ui";
+import { Flex, Icon, Tooltip, UnstyledButton } from "metabase/ui";
import type { ColorName } from "metabase/ui/colors/types";
import type { IconName } from "metabase-types/api";
@@ -31,18 +30,16 @@ export function NotebookActionButton({
const label = large ? title : undefined;
const button = (
- <Button
+ <UnstyledButton
className={cx(
S.ColorButton,
{
[S.secondary]: secondary,
+ [S.large]: large,
+ [S.small]: !large,
},
className,
)}
- icon={icon}
- small={!large}
- iconVertical={large}
- iconSize={large ? 20 : 16}
aria-label={label}
onClick={onClick}
style={
@@ -52,8 +49,15 @@ export function NotebookActionButton({
}
{...props}
>
- {label}
- </Button>
+ {large ? (
+ <Flex direction="column" align="center" miw="60px">
+ {icon && <Icon name={icon} size={20} />}
+ {label && <span className={S.label}>{label}</span>}
+ </Flex>
+ ) : (
+ icon && <Icon name={icon} size={16} />
+ )}
+ </UnstyledButton>
);
return large ? button : <Tooltip label={title}>{button}</Tooltip>;
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
index 35285bff718..7df57e2e5e7 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx
@@ -63,7 +63,9 @@ export function NotebookStep({
[CS.mr1]: !isLastStep || (isLastStep && !hasLargeActionButtons),
})}
large={hasLargeActionButtons}
- {...stepUi}
+ icon={stepUi.icon}
+ color={stepUi.color}
+ secondary={stepUi.secondary}
title={title}
aria-label={title}
onClick={() => action.action({ openStep })}
diff --git a/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.module.css b/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.module.css
new file mode 100644
index 00000000000..c30b379e1de
--- /dev/null
+++ b/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.module.css
@@ -0,0 +1,5 @@
+.archiveButton {
+ &:hover {
+ background-color: transparent;
+ }
+}
diff --git a/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.tsx b/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.tsx
index c3586ad1612..744df502b91 100644
--- a/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.tsx
+++ b/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormArchiveButton.tsx
@@ -1,6 +1,8 @@
import type { MouseEvent, ReactNode } from "react";
-import { ArchiveButton } from "./FormDangerButton.styled";
+import { Button } from "metabase/ui";
+
+import S from "./FormArchiveButton.module.css";
export interface FormArchiveButtonProps {
children?: ReactNode;
@@ -12,9 +14,16 @@ const FormArchiveButton = ({
onClick,
}: FormArchiveButtonProps): JSX.Element => {
return (
- <ArchiveButton type="button" borderless onClick={onClick}>
+ <Button
+ className={S.archiveButton}
+ type="button"
+ variant="subtle"
+ color="danger"
+ px={0}
+ onClick={onClick}
+ >
{children}
- </ArchiveButton>
+ </Button>
);
};
diff --git a/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormDangerButton.styled.tsx b/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormDangerButton.styled.tsx
deleted file mode 100644
index fe03a249455..00000000000
--- a/frontend/src/metabase/timelines/common/components/FormArchiveButton/FormDangerButton.styled.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Button } from "metabase/common/components/Button/Button";
-
-export const ArchiveButton = styled(Button)`
- color: var(--mb-color-danger);
- padding-left: 0;
- padding-right: 0;
-
- &:hover {
- color: var(--mb-color-danger);
- background-color: transparent;
- }
-`;