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 segment form and revision icons off Emotion (#83448)

Andrei Chernykh6e674681c39c
diff --git a/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.module.css b/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.module.css
new file mode 100644
index 00000000000..f10c0af6784
--- /dev/null
+++ b/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.module.css
@@ -0,0 +1,3 @@
+.error:not(:focus) {
+ border-color: var(--mb-color-feedback-negative);
+}
diff --git a/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.styled.tsx b/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.styled.tsx
deleted file mode 100644
index 769624aabb9..00000000000
--- a/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.styled.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { color } from "metabase/ui/utils/colors";
-
-interface FormInputRootProps {
- touched?: boolean;
- error?: string | boolean;
-}
-
-export const FormInputRoot = styled.input<FormInputRootProps>`
- width: 100%;
-
- &:not(:focus) {
- border-color: ${(props) =>
- props.touched && props.error && color("feedback-negative")};
- }
-`;
diff --git a/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.tsx b/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.tsx
index fb9b43f6d85..fcde57c3f68 100644
--- a/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.tsx
+++ b/frontend/src/metabase/admin/datamodel/components/FormInput/FormInput.tsx
@@ -3,8 +3,9 @@ import type { InputHTMLAttributes, Ref } from "react";
import { forwardRef } from "react";
import CS from "metabase/css/core/index.css";
+import { Box } from "metabase/ui";
-import { FormInputRoot } from "./FormInput.styled";
+import S from "./FormInput.module.css";
interface FormInputProps extends InputHTMLAttributes<HTMLInputElement> {
touched?: boolean;
@@ -16,14 +17,14 @@ const FormInput = forwardRef(function FormInput(
ref: Ref<HTMLInputElement>,
) {
return (
- <FormInputRoot
+ <Box
+ component="input"
{...props}
value={props.value ?? ""}
ref={ref}
- className={cx(CS.input, className)}
+ className={cx(CS.input, { [S.error]: touched && error }, className)}
type="text"
- touched={touched}
- error={error}
+ w="100%"
/>
);
});
diff --git a/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.styled.tsx b/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.styled.tsx
deleted file mode 100644
index b5fc15c6716..00000000000
--- a/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.styled.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-export const FormLabelRoot = styled.div`
- margin-bottom: 2rem;
-`;
-
-export const FormLabelContent = styled.div`
- max-width: 36rem;
-`;
-
-export const FormLabelTitle = styled.label`
- font-size: 0.72rem;
- font-weight: bold;
- text-transform: uppercase;
- letter-spacing: 0.06em;
-`;
-
-export const FormLabelDescription = styled.p`
- margin-top: 0.5rem;
- margin-bottom: 1rem;
-`;
diff --git a/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.tsx b/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.tsx
index 6769cc9656c..3101fd000da 100644
--- a/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.tsx
+++ b/frontend/src/metabase/admin/datamodel/components/FormLabel/FormLabel.tsx
@@ -6,12 +6,7 @@ import type {
} from "react";
import { forwardRef } from "react";
-import {
- FormLabelContent,
- FormLabelDescription,
- FormLabelRoot,
- FormLabelTitle,
-} from "./FormLabel.styled";
+import { Box } from "metabase/ui";
interface FormLabelProps extends HTMLAttributes<HTMLDivElement> {
htmlFor?: LabelHTMLAttributes<HTMLLabelElement>["htmlFor"];
@@ -25,15 +20,28 @@ const FormLabel = forwardRef(function FormLabel(
ref: Ref<HTMLDivElement>,
) {
return (
- <FormLabelRoot {...props} ref={ref}>
- <FormLabelContent>
- {title && <FormLabelTitle htmlFor={htmlFor}>{title}</FormLabelTitle>}
+ <Box {...props} ref={ref} mb="xxl">
+ <Box maw="36rem">
+ {title && (
+ <Box
+ component="label"
+ htmlFor={htmlFor}
+ fz="sm"
+ fw="bold"
+ tt="uppercase"
+ lts="0.06em"
+ >
+ {title}
+ </Box>
+ )}
{description && (
- <FormLabelDescription>{description}</FormLabelDescription>
+ <Box component="p" mt="sm" mb="lg">
+ {description}
+ </Box>
)}
- </FormLabelContent>
+ </Box>
{children}
- </FormLabelRoot>
+ </Box>
);
});
diff --git a/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.module.css b/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.module.css
new file mode 100644
index 00000000000..f10c0af6784
--- /dev/null
+++ b/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.module.css
@@ -0,0 +1,3 @@
+.error:not(:focus) {
+ border-color: var(--mb-color-feedback-negative);
+}
diff --git a/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.styled.tsx b/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.styled.tsx
deleted file mode 100644
index f5c8c5cd1f4..00000000000
--- a/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.styled.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { color } from "metabase/ui/utils/colors";
-
-interface FormTextAreaRootProps {
- touched?: boolean;
- error?: string | boolean;
-}
-
-export const FormTextAreaRoot = styled.textarea<FormTextAreaRootProps>`
- width: 100%;
-
- &:not(:focus) {
- border-color: ${(props) =>
- props.touched && props.error && color("feedback-negative")};
- }
-`;
diff --git a/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.tsx b/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.tsx
index 4704fc85e12..b5303266fcb 100644
--- a/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.tsx
+++ b/frontend/src/metabase/admin/datamodel/components/FormTextArea/FormTextArea.tsx
@@ -3,8 +3,9 @@ import type { Ref, TextareaHTMLAttributes } from "react";
import { forwardRef } from "react";
import CS from "metabase/css/core/index.css";
+import { Box } from "metabase/ui";
-import { FormTextAreaRoot } from "./FormTextArea.styled";
+import S from "./FormTextArea.module.css";
interface FormTextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
touched?: boolean;
@@ -16,12 +17,12 @@ const FormTextArea = forwardRef(function FormTextArea(
ref: Ref<HTMLTextAreaElement>,
) {
return (
- <FormTextAreaRoot
+ <Box
+ component="textarea"
{...props}
ref={ref}
- className={cx(CS.input, className)}
- touched={touched}
- error={error}
+ className={cx(CS.input, { [S.error]: touched && error }, className)}
+ w="100%"
/>
);
});
diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.module.css b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.module.css
new file mode 100644
index 00000000000..c2a11783df5
--- /dev/null
+++ b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.module.css
@@ -0,0 +1,6 @@
+.form {
+ width: 100%;
+ height: 100%;
+ overflow: auto;
+ background-color: var(--mb-color-background_page-primary);
+}
diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.styled.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.styled.tsx
deleted file mode 100644
index a5cdd6ee887..00000000000
--- a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.styled.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import {
- breakpointMinMedium,
- breakpointMinSmall,
-} from "metabase/styled-components/theme";
-
-export const FormRoot = styled.form`
- width: 100%;
- height: 100%;
- overflow: auto;
- background-color: var(--mb-color-background_page-primary);
-`;
-
-export const FormSection = styled.div`
- margin: 0 auto;
- padding: 0 1em;
-
- ${breakpointMinSmall} {
- padding-left: 1.75rem;
- padding-right: 1.75rem;
- }
-
- ${breakpointMinMedium} {
- padding-left: 2.625rem;
- padding-right: 2.625rem;
- }
-`;
-
-export const FormBody = styled(FormSection)`
- padding-top: 2rem;
- padding-bottom: 2rem;
-`;
-
-export const FormBodyContent = styled.div`
- max-width: 36rem;
-`;
-
-export const FormFooter = styled.div`
- padding-top: 2rem;
- padding-bottom: 2rem;
- border-top: 1px solid var(--mb-color-border-neutral);
-`;
-
-export const FormFooterContent = styled.div`
- display: flex;
- align-items: center;
-`;
diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx
index df8b56204b8..8a76763f178 100644
--- a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx
+++ b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx
@@ -6,6 +6,7 @@ import { t } from "ttag";
import { skipToken, useGetTableQuery } from "metabase/api";
import { FieldSet } from "metabase/common/components/FieldSet";
import { Link } from "metabase/common/components/Link";
+import CS from "metabase/css/core/index.css";
import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";
import { useSelector, useStore } from "metabase/redux";
import type { State } from "metabase/redux/store";
@@ -14,7 +15,7 @@ import {
getSegmentQuery,
getSegmentQueryDefinition,
} from "metabase/segments";
-import { Alert, Button } from "metabase/ui";
+import { Alert, Box, Button } from "metabase/ui";
import * as Lib from "metabase-lib";
import type { DatasetQuery, Segment, TableId } from "metabase-types/api";
@@ -22,14 +23,9 @@ import FormInput from "../FormInput";
import FormLabel from "../FormLabel";
import FormTextArea from "../FormTextArea";
-import {
- FormBody,
- FormBodyContent,
- FormFooter,
- FormFooterContent,
- FormRoot,
- FormSection,
-} from "./SegmentForm.styled";
+import S from "./SegmentForm.module.css";
+
+const SECTION_PADDING_X = { base: "md", sm: "1.75rem", md: "xxxl" };
export interface SegmentFormProps {
segment?: Segment;
@@ -58,6 +54,9 @@ export const SegmentForm = ({
});
const definitionProps = getFieldProps("definition");
const tableIdProps = getFieldProps("table_id");
+ const nameMeta = getFieldMeta("name");
+ const descriptionMeta = getFieldMeta("description");
+ const revisionMessageMeta = getFieldMeta("revision_message");
const editorQuery = useSelector((state) =>
getSegmentQuery(state, definitionProps.value, tableIdProps.value),
);
@@ -75,8 +74,8 @@ export const SegmentForm = ({
}, [dirty, onIsDirtyChange]);
return (
- <FormRoot onSubmit={handleSubmit}>
- <FormBody>
+ <Box component="form" className={S.form} onSubmit={handleSubmit}>
+ <Box px={SECTION_PADDING_X} py="xxl">
{isReadOnly && (
<Alert
size="compact"
@@ -105,7 +104,7 @@ export const SegmentForm = ({
readOnly={isReadOnly}
/>
</FormLabel>
- <FormBodyContent>
+ <Box maw="36rem">
<FormLabel
htmlFor="name"
title={t`Name Your Segment`}
@@ -113,7 +112,8 @@ export const SegmentForm = ({
>
<FormInput
{...getFieldProps("name")}
- {...getFieldMeta("name")}
+ touched={nameMeta.touched}
+ error={nameMeta.error}
id="name"
placeholder={t`Something descriptive but not too long`}
readOnly={isReadOnly}
@@ -126,7 +126,8 @@ export const SegmentForm = ({
>
<FormTextArea
{...getFieldProps("description")}
- {...getFieldMeta("description")}
+ touched={descriptionMeta.touched}
+ error={descriptionMeta.error}
id="description"
placeholder={t`This is a good place to be more specific about less obvious segment rules`}
readOnly={isReadOnly}
@@ -140,26 +141,23 @@ export const SegmentForm = ({
>
<FormTextArea
{...getFieldProps("revision_message")}
- {...getFieldMeta("revision_message")}
+ touched={revisionMessageMeta.touched}
+ error={revisionMessageMeta.error}
id="revision_message"
placeholder={t`This will show up in the revision history for this segment to help everyone remember why things changed`}
/>
</FormLabel>
- <FormFooterContent>
- <SegmentFormActions isValid={isValid} />
- </FormFooterContent>
+ <SegmentFormActions isValid={isValid} />
</FieldSet>
)}
- </FormBodyContent>
- </FormBody>
+ </Box>
+ </Box>
{isNew && !isReadOnly && (
- <FormFooter>
- <FormSection>
- <SegmentFormActions isValid={isValid} />
- </FormSection>
- </FormFooter>
+ <Box className={CS.borderTop} px={SECTION_PADDING_X} py="xxl">
+ <SegmentFormActions isValid={isValid} />
+ </Box>
)}
- </FormRoot>
+ </Box>
);
};
diff --git a/frontend/src/metabase/segments/components/revisions/RevisionDiff.styled.tsx b/frontend/src/metabase/segments/components/revisions/RevisionDiff.styled.tsx
deleted file mode 100644
index c34b333749e..00000000000
--- a/frontend/src/metabase/segments/components/revisions/RevisionDiff.styled.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Icon } from "metabase/ui";
-
-export const EditIcon = styled(Icon)`
- color: var(--mb-color-core-brand);
-`;
-
-export const ErrorIcon = styled(Icon)`
- color: var(--mb-color-feedback-negative);
-`;
-
-export const SuccessIcon = styled(Icon)`
- color: var(--mb-color-core-summarize);
-`;
diff --git a/frontend/src/metabase/segments/components/revisions/RevisionDiffIcon.tsx b/frontend/src/metabase/segments/components/revisions/RevisionDiffIcon.tsx
index 40705163b83..0b21dbb2ed9 100644
--- a/frontend/src/metabase/segments/components/revisions/RevisionDiffIcon.tsx
+++ b/frontend/src/metabase/segments/components/revisions/RevisionDiffIcon.tsx
@@ -1,7 +1,6 @@
+import { Icon } from "metabase/ui";
import type { FieldDiff } from "metabase-types/api";
-import { EditIcon, ErrorIcon, SuccessIcon } from "./RevisionDiff.styled";
-
interface Props {
diff: FieldDiff;
}
@@ -10,13 +9,13 @@ export function RevisionDiffIcon({ diff }: Props) {
const { before, after } = diff;
if (before != null && after != null) {
- return <EditIcon name="pencil" size={16} />;
+ return <Icon name="pencil" size={16} c="core-brand" />;
}
if (before != null) {
- return <ErrorIcon name="add" size={16} />;
+ return <Icon name="add" size={16} c="feedback-negative" />;
}
// TODO: "minus" icon
- return <SuccessIcon name="add" size={16} />;
+ return <Icon name="add" size={16} c="core-summarize" />;
}