Skip to content

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

Migrate copy components off EmotionCSS and replace CopyWidget with CopyTextInput (#75425)

Andrei Chernykhf8873d9ae93f
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/InlineActionSettings.tsx b/frontend/src/metabase/actions/containers/ActionCreator/InlineActionSettings.tsx
index 82b51e2ea3f..832430d7e30 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/InlineActionSettings.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/InlineActionSettings.tsx
@@ -7,7 +7,7 @@ import {
useDeleteActionPublicLinkMutation,
} from "metabase/api";
import { ConfirmModal } from "metabase/common/components/ConfirmModal";
-import { CopyWidget } from "metabase/common/components/CopyWidget";
+import { CopyTextInput } from "metabase/common/components/CopyTextInput";
import { FormField } from "metabase/common/components/FormField";
import { SidebarContent } from "metabase/common/components/SidebarContent";
import { TextArea } from "metabase/common/components/TextArea";
@@ -130,7 +130,7 @@ const InlineActionSettings = ({
)}
{action?.public_uuid && hasSharingPermission && (
<CopyWidgetContainer>
- <CopyWidget
+ <CopyTextInput
value={Urls.publicAction(siteUrl, action.public_uuid)}
aria-label={t`Public action form URL`}
/>
diff --git a/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.module.css b/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.module.css
new file mode 100644
index 00000000000..462bfdd7ab5
--- /dev/null
+++ b/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.module.css
@@ -0,0 +1,10 @@
+.input {
+ height: 3rem;
+ min-height: 3rem;
+ /* 8px block, 16px inline-start; extra inline-end leaves room for the copy button */
+ padding: var(--mantine-spacing-sm) 2.5rem var(--mantine-spacing-sm)
+ var(--mantine-spacing-md);
+ border: none;
+ border-radius: var(--mantine-radius-md);
+ background-color: var(--mb-color-background-secondary);
+}
diff --git a/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.styled.tsx b/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.styled.tsx
deleted file mode 100644
index 6dd04717299..00000000000
--- a/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.styled.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-
-export const CopyWidgetButton = styled(CopyButton)`
- position: absolute;
- top: 0;
- bottom: 0;
- right: 0;
- display: flex;
- align-items: center;
- padding: 0.5rem 0.75rem;
- border-top-right-radius: 4px;
- border-bottom-right-radius: 4px;
- color: var(--mb-color-brand);
- outline: none;
- cursor: pointer;
-
- &:hover {
- color: var(--mb-color-text-primary-inverse);
- background-color: var(--mb-color-brand);
- }
-`;
diff --git a/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.tsx b/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.tsx
index 2bbf3b4cc0a..56b1434afb2 100644
--- a/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.tsx
+++ b/frontend/src/metabase/common/components/CopyTextInput/CopyTextInput.tsx
@@ -1,10 +1,12 @@
+import cx from "classnames";
import type { Ref } from "react";
import { forwardRef } from "react";
+import { t } from "ttag";
import type { TextInputProps } from "metabase/ui";
-import { TextInput } from "metabase/ui";
+import { ActionIcon, CopyButton, Icon, TextInput, Tooltip } from "metabase/ui";
-import { CopyWidgetButton } from "./CopyTextInput.styled";
+import S from "./CopyTextInput.module.css";
const defaultProps = {
readOnly: true,
@@ -12,16 +14,44 @@ const defaultProps = {
};
export const CopyTextInput = forwardRef(function CopyTextInput(
- props: TextInputProps & { value: string },
+ {
+ classNames,
+ onClick,
+ readOnly,
+ ...props
+ }: TextInputProps & { value: string },
ref: Ref<HTMLInputElement>,
) {
+ const isReadOnly = readOnly ?? defaultProps.readOnly;
+
return (
<TextInput
{...defaultProps}
{...props}
ref={ref}
- rightSection={<CopyWidgetButton value={props.value} />}
- rightSectionWidth={40}
+ readOnly={isReadOnly}
+ onClick={(e) => {
+ if (isReadOnly) {
+ e.currentTarget.setSelectionRange(0, e.currentTarget.value.length);
+ }
+ onClick?.(e);
+ }}
+ classNames={{
+ ...classNames,
+ input: cx(S.input, (classNames as Record<string, string>)?.input),
+ }}
+ rightSectionPointerEvents="all"
+ rightSection={
+ <CopyButton value={props.value} timeout={2000}>
+ {({ copied, copy }) => (
+ <Tooltip label={t`Copied!`} opened={copied}>
+ <ActionIcon variant="subtle" aria-label={t`Copy`} onClick={copy}>
+ <Icon name="copy" />
+ </ActionIcon>
+ </Tooltip>
+ )}
+ </CopyButton>
+ }
/>
);
});
diff --git a/frontend/src/metabase/common/components/CopyWidget/CopyWidget.styled.tsx b/frontend/src/metabase/common/components/CopyWidget/CopyWidget.styled.tsx
deleted file mode 100644
index 2a8c5598fd5..00000000000
--- a/frontend/src/metabase/common/components/CopyWidget/CopyWidget.styled.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { CopyButton } from "metabase/common/components/CopyButton";
-
-export const CopyWidgetButton = styled(CopyButton)`
- position: absolute;
- top: 0;
- bottom: 0;
- right: 0;
- display: flex;
- align-items: center;
- padding: 0.5rem;
- border-left: 1px solid var(--mb-color-border);
- border-top-right-radius: 0.5rem;
- border-bottom-right-radius: 0.5rem;
- color: var(--mb-color-brand);
- outline: none;
-
- &:hover {
- color: var(--mb-color-text-primary-inverse);
- background-color: var(--mb-color-brand);
- }
-`;
diff --git a/frontend/src/metabase/common/components/CopyWidget/CopyWidget.tsx b/frontend/src/metabase/common/components/CopyWidget/CopyWidget.tsx
deleted file mode 100644
index 4212bedf0da..00000000000
--- a/frontend/src/metabase/common/components/CopyWidget/CopyWidget.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import cx from "classnames";
-import type { CSSProperties, ChangeEvent, InputHTMLAttributes } from "react";
-
-import FormS from "metabase/css/components/form.module.css";
-import CS from "metabase/css/core/index.css";
-
-import { CopyWidgetButton } from "./CopyWidget.styled";
-
-interface CopyWidgetProps extends Omit<
- InputHTMLAttributes<HTMLInputElement>,
- "onChange" | "style"
-> {
- value: string;
- onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
- style?: CSSProperties;
-}
-
-export const CopyWidget = ({
- value,
- onChange,
- style,
- ...props
-}: CopyWidgetProps) => {
- return (
- <div className={cx(CS.flex, CS.relative)} style={style}>
- <input
- className={cx(FormS.FormInput, CS.flexFull, {
- [FormS.noFocus]: !onChange,
- })}
- style={{
- paddingRight: 40,
- }}
- onClick={
- !onChange
- ? (e) => {
- e.currentTarget.setSelectionRange(
- 0,
- e.currentTarget.value.length,
- );
- }
- : undefined
- }
- value={value}
- onChange={onChange}
- readOnly={!!value && !onChange}
- {...props}
- />
- <CopyWidgetButton value={value} />
- </div>
- );
-};
diff --git a/frontend/src/metabase/common/components/CopyWidget/index.tsx b/frontend/src/metabase/common/components/CopyWidget/index.tsx
deleted file mode 100644
index 8e0add12a50..00000000000
--- a/frontend/src/metabase/common/components/CopyWidget/index.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { CopyWidget } from "./CopyWidget";