Skip to content

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

Migrate Pinned items off Emotion (#83131)

Andrei Chernykh51ec37c506da
diff --git a/frontend/src/metabase/collections/components/PinnedItemsGrid/PinnedItemsGrid.tsx b/frontend/src/metabase/collections/components/PinnedItemsGrid/PinnedItemsGrid.tsx
index 30909173f58..3b0a1d97e6c 100644
--- a/frontend/src/metabase/collections/components/PinnedItemsGrid/PinnedItemsGrid.tsx
+++ b/frontend/src/metabase/collections/components/PinnedItemsGrid/PinnedItemsGrid.tsx
@@ -76,7 +76,7 @@ export function PinnedItemsGrid({
if (sortedItems.length === 0) {
return (
- <Box mb={rem(48)} pos="relative">
+ <Box h={rem(16)} pos="relative">
<PinDropZone variant="pin" empty />
</Box>
);
diff --git a/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.module.css b/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.module.css
new file mode 100644
index 00000000000..dffcee68e17
--- /dev/null
+++ b/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.module.css
@@ -0,0 +1,39 @@
+/* DropArea positions its own root, hence the !important; its children stay droppable. */
+.dropTarget {
+ position: absolute !important;
+ top: 0;
+ bottom: 0;
+ left: calc(-1 * var(--mantine-spacing-lg));
+ right: calc(-1 * var(--mantine-spacing-lg));
+ pointer-events: none;
+
+ > * {
+ pointer-events: all;
+ }
+}
+
+.indicator {
+ position: absolute;
+ inset: 0;
+ z-index: 1;
+ border-left: 4px solid var(--mb-color-background_page-tertiary);
+}
+
+.hovered {
+ border-left-color: var(--mb-color-core-brand);
+}
+
+/* Hangs from the container's bottom edge, which meets the items table. */
+.emptyTarget {
+ position: absolute;
+ left: var(--mantine-spacing-lg);
+ right: var(--mantine-spacing-lg);
+ bottom: var(--mantine-spacing-sm);
+ z-index: 1;
+ border: 1px dashed var(--mb-color-core-brand);
+ transition: background-color 0.2s;
+}
+
+.emptyTargetHovered {
+ background-color: var(--mb-color-background_surface-brand-subtle);
+}
diff --git a/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.styled.tsx b/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.styled.tsx
deleted file mode 100644
index cfbdeabf2b9..00000000000
--- a/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.styled.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-
-import { PinDropTarget } from "metabase/common/components/dnd/PinDropTarget";
-
-type PinDropTargetProps = {
- variant: "pin" | "unpin";
- pinIndex: number | null;
- hideUntilDrag: boolean;
-};
-
-export type PinDropTargetRenderArgs = PinDropTargetProps & {
- hovered: boolean;
- highlighted: boolean;
- empty?: boolean;
-};
-
-export const StyledPinDropTarget = styled(PinDropTarget)<PinDropTargetProps>`
- position: absolute !important;
- top: 0;
- bottom: 0;
- left: -1rem;
- right: -1rem;
- pointer-events: none;
- background-color: transparent !important;
-
- * {
- pointer-events: all;
- background-color: transparent !important;
- }
-`;
-
-export const PinDropTargetIndicator = styled.div<PinDropTargetRenderArgs>`
- z-index: 1;
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- border-left: ${(props) =>
- `4px solid ${
- props.hovered
- ? "var(--mb-color-core-brand)"
- : "var(--mb-color-background_page-tertiary)"
- }`};
- display: ${(props) => !(props.hovered || props.highlighted) && "none"};
- min-height: 2rem;
- transform: ${(props) => props.empty && "translateY(-1rem)"};
-`;
diff --git a/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.tsx b/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.tsx
index de0ab851c17..dded1b7e365 100644
--- a/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.tsx
+++ b/frontend/src/metabase/common/collections/components/PinDropZone/PinDropZone.tsx
@@ -1,26 +1,60 @@
-import type { PinDropTargetRenderArgs } from "./PinDropZone.styled";
-import {
- PinDropTargetIndicator,
- StyledPinDropTarget,
-} from "./PinDropZone.styled";
+import cx from "classnames";
+import { t } from "ttag";
+
+import { PinDropTarget } from "metabase/common/components/dnd/PinDropTarget";
+import { Box, Flex, Icon, rem } from "metabase/ui";
+
+import S from "./PinDropZone.module.css";
type PinDropZoneProps = {
variant: "pin" | "unpin";
empty?: boolean;
};
-function PinDropZone({ variant, empty, ...props }: PinDropZoneProps) {
+type PinDropTargetRenderArgs = {
+ hovered: boolean;
+ highlighted: boolean;
+};
+
+function PinDropZone({ variant, empty }: PinDropZoneProps) {
return (
- <StyledPinDropTarget
+ <PinDropTarget
+ className={S.dropTarget}
variant={variant}
pinIndex={variant === "pin" ? 1 : null}
hideUntilDrag
- {...props}
>
- {(args: PinDropTargetRenderArgs) => (
- <PinDropTargetIndicator empty={empty} {...args} />
- )}
- </StyledPinDropTarget>
+ {({ hovered, highlighted }: PinDropTargetRenderArgs) => {
+ if (!hovered && !highlighted) {
+ return null;
+ }
+
+ if (empty) {
+ return (
+ <Flex
+ className={cx(S.emptyTarget, { [S.emptyTargetHovered]: hovered })}
+ mih={rem(32)}
+ align="center"
+ justify="center"
+ gap="sm"
+ bdrs="sm"
+ c="core-brand"
+ fw="bold"
+ >
+ <Icon name="pin" />
+ {t`Drag here to pin`}
+ </Flex>
+ );
+ }
+
+ return (
+ <Box
+ className={cx(S.indicator, { [S.hovered]: hovered })}
+ mih={rem(32)}
+ />
+ );
+ }}
+ </PinDropTarget>
);
}