Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

List Position Indicator (#1131)

Roman Pominov60dd4a918b05
diff --git a/packages/design-system/src/components/list-position-indicator.stories.tsx b/packages/design-system/src/components/list-position-indicator.stories.tsx
new file mode 100644
index 0000000000..2013c63abe
--- /dev/null
+++ b/packages/design-system/src/components/list-position-indicator.stories.tsx
@@ -0,0 +1,66 @@
+import { ListPositionIndicator } from "./list-position-indicator";
+import { StorySection, StoryGrid } from "./storybook";
+
+export default {
+ title: "Library/List Position Indicator",
+ parameters: {
+ // to make white outline visible
+ backgrounds: { default: "Maintenance Medium" },
+ },
+};
+
+export const Demo = () => (
+ <>
+ <StorySection title="Coordinates check">
+ <StoryGrid>
+ <div
+ style={{
+ background: "black",
+ position: "relative",
+ width: 250,
+ height: 30,
+ }}
+ >
+ <ListPositionIndicator x={0} y={0} length={200} />
+ </div>
+ <div
+ style={{
+ background: "black",
+ position: "relative",
+ width: 250,
+ height: 30,
+ }}
+ >
+ <ListPositionIndicator x={0} y={0} length={200} withNub />
+ </div>
+ </StoryGrid>
+ </StorySection>
+
+ <StorySection title="Length check">
+ <StoryGrid>
+ <div
+ style={{
+ background: "black",
+ position: "relative",
+ width: 200,
+ height: 30,
+ }}
+ >
+ <ListPositionIndicator x={0} y={0} length={200} />
+ </div>
+ <div
+ style={{
+ background: "black",
+ position: "relative",
+ width: 200,
+ height: 30,
+ }}
+ >
+ <ListPositionIndicator x={0} y={0} length={200} withNub />
+ </div>
+ </StoryGrid>
+ </StorySection>
+ </>
+);
+
+Demo.storyName = "List Position Indicator";
diff --git a/packages/design-system/src/components/list-position-indicator.tsx b/packages/design-system/src/components/list-position-indicator.tsx
new file mode 100644
index 0000000000..a361d36452
--- /dev/null
+++ b/packages/design-system/src/components/list-position-indicator.tsx
@@ -0,0 +1,88 @@
+/**
+ * Implementation of the "List Position Indicator" component from:
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=8%3A1883
+ */
+
+import { Box } from "./box";
+import { styled, theme } from "../stitches.config";
+
+const CIRCLE_SIZE = 8;
+const LINE_THICKNESS = 2;
+const OUTLINE_WIDTH = 1;
+
+// overlap the line with the circle by this much
+// to make sure they are connected
+const OVERLAP = 1;
+
+const CircleOutline = styled(Box, {
+ width: CIRCLE_SIZE + OUTLINE_WIDTH * 2,
+ height: CIRCLE_SIZE + OUTLINE_WIDTH * 2,
+ position: "absolute",
+ borderRadius: "50%",
+ pointerEvents: "none",
+ bc: theme.colors.borderContrast,
+});
+
+const Circle = styled(Box, {
+ width: CIRCLE_SIZE,
+ height: CIRCLE_SIZE,
+ position: "absolute",
+ border: `solid ${theme.colors.backgroundPrimary}`,
+ borderWidth: 2,
+ borderRadius: "50%",
+ pointerEvents: "none",
+});
+
+const Line = styled(Box, {
+ boxSizing: "content-box",
+ position: "absolute",
+ background: theme.colors.backgroundPrimary,
+ pointerEvents: "none",
+ outline: `solid ${theme.colors.borderContrast}`,
+ outlineWidth: OUTLINE_WIDTH,
+});
+
+export const ListPositionIndicator = ({
+ x,
+ y,
+ length,
+ withNub = false,
+}: {
+ x: number;
+ y: number;
+ length: number;
+ withNub?: boolean;
+}) =>
+ withNub ? (
+ <>
+ <CircleOutline
+ style={{
+ top: y - CIRCLE_SIZE / 2 - OUTLINE_WIDTH,
+ left: x - CIRCLE_SIZE / 2 - OUTLINE_WIDTH,
+ }}
+ />
+ <Line
+ style={{
+ top: y - LINE_THICKNESS / 2,
+ left: x + (CIRCLE_SIZE / 2 - OVERLAP),
+ width: length - (CIRCLE_SIZE / 2 - OVERLAP),
+ height: LINE_THICKNESS,
+ }}
+ />
+ <Circle
+ style={{
+ top: y - CIRCLE_SIZE / 2,
+ left: x - CIRCLE_SIZE / 2,
+ }}
+ />
+ </>
+ ) : (
+ <Line
+ style={{
+ top: y - LINE_THICKNESS / 2,
+ left: x,
+ width: length,
+ height: LINE_THICKNESS,
+ }}
+ />
+ );
diff --git a/packages/design-system/src/components/tree/placement-indicator.tsx b/packages/design-system/src/components/tree/placement-indicator.tsx
deleted file mode 100644
index 008b5a8784..0000000000
--- a/packages/design-system/src/components/tree/placement-indicator.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import { styled } from "../../stitches.config";
-import { Box } from "../box";
-import type { Placement } from "../primitives/dnd";
-import { theme } from "../../stitches.config";
-
-const CIRCLE_SIZE = 8;
-const LINE_THICKNESS = 2;
-const OUTLINE_WIDTH = 1;
-
-// overlap the line with the circle by this much
-// to make sure they are connected
-const OVERLAP = 1;
-
-const CircleOutline = styled(Box, {
- width: CIRCLE_SIZE + OUTLINE_WIDTH * 2,
- height: CIRCLE_SIZE + OUTLINE_WIDTH * 2,
- position: "absolute",
- borderRadius: "50%",
- pointerEvents: "none",
- bc: theme.colors.loContrast,
-});
-
-const Circle = styled(Box, {
- width: CIRCLE_SIZE,
- height: CIRCLE_SIZE,
- position: "absolute",
- border: `solid ${theme.colors.blue10}`,
- borderWidth: 2,
- borderRadius: "50%",
- pointerEvents: "none",
-});
-
-const Line = styled(Box, {
- boxSizing: "content-box",
- position: "absolute",
- background: theme.colors.blue10,
- pointerEvents: "none",
- outline: `solid ${theme.colors.loContrast}`,
- outlineWidth: OUTLINE_WIDTH,
-});
-
-export const PlacementIndicator = ({ placement }: { placement: Placement }) => (
- <>
- <CircleOutline
- style={{
- top: placement.y - CIRCLE_SIZE / 2 - OUTLINE_WIDTH,
- left: placement.x - CIRCLE_SIZE / 2 - OUTLINE_WIDTH,
- }}
- />
- <Line
- style={{
- top: placement.y - LINE_THICKNESS / 2,
- left: placement.x + (CIRCLE_SIZE / 2 - OVERLAP),
- width: placement.length - (CIRCLE_SIZE / 2 - OVERLAP),
- height: LINE_THICKNESS,
- }}
- />
- <Circle
- style={{
- top: placement.y - CIRCLE_SIZE / 2,
- left: placement.x - CIRCLE_SIZE / 2,
- }}
- />
- </>
-);
diff --git a/packages/design-system/src/components/tree/tree.tsx b/packages/design-system/src/components/tree/tree.tsx
index a1c98b6710..819aa8d4e8 100644
--- a/packages/design-system/src/components/tree/tree.tsx
+++ b/packages/design-system/src/components/tree/tree.tsx
@@ -1,8 +1,8 @@
import type { KeyboardEvent as ReactKeyboardEvent } from "react";
import { useState, useMemo, useRef, useCallback, useEffect } from "react";
import { createPortal } from "react-dom";
+import { ListPositionIndicator } from "../list-position-indicator";
import { TreeNode, INDENT, TreeItemRenderProps } from "./tree-node";
-import { PlacementIndicator } from "./placement-indicator";
import {
type DropTarget,
useHold,
@@ -291,7 +291,12 @@ export const Tree = <Data extends { id: string }>({
{shiftedDropTarget?.placement &&
createPortal(
- <PlacementIndicator placement={shiftedDropTarget.placement} />,
+ <ListPositionIndicator
+ x={shiftedDropTarget.placement.x}
+ y={shiftedDropTarget.placement.y}
+ length={shiftedDropTarget.placement.length}
+ withNub
+ />,
document.body
)}
</Box>
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index 1f3ab9683d..e8114abeaa 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -20,6 +20,7 @@ export * from "./components/switch";
export * from "./components/toolbar";
export * from "./components/two-rows-icon-button-container";
export * from "./components/small-icon-button";
+export * from "./components/list-position-indicator";
// Not aligned