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.

fix: alignment UI dot hiding, stories, and unit tests

Oleg Isonen706a7254d48e
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx
index 67b4c0dcbb..52d329713d 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.stories.tsx
@@ -1,4 +1,4 @@
-import { Box, Flex, theme } from "@webstudio-is/design-system";
+import { Box, Flex, Text, theme } from "@webstudio-is/design-system";
import { AlignmentUi } from "./alignment-ui";
export default {
@@ -6,8 +6,15 @@ export default {
component: AlignmentUi,
};
-const alignItems = ["normal", "start", "center", "end", "stretch", "baseline"];
-const justifyContent = [
+const alignItemsValues = [
+ "normal",
+ "start",
+ "center",
+ "end",
+ "stretch",
+ "baseline",
+];
+const justifyContentValues = [
"normal",
"start",
"center",
@@ -16,60 +23,117 @@ const justifyContent = [
"space-around",
];
+const labelStyle = { fontSize: 10, fontFamily: "sans-serif" };
+
const CombinationGrid = ({
+ title,
isColumnDirection,
+ itemStretchWidth,
+ itemStretchHeight,
}: {
+ title: string;
isColumnDirection: boolean;
+ itemStretchWidth: (ai: string) => boolean;
+ itemStretchHeight: (ai: string) => boolean;
}) => (
- <Flex direction="column" gap="2">
- <Flex gap="2" align="center">
- <Box css={{ width: 70 }} />
- {justifyContent.map((jc) => (
- <Box
- key={jc}
- css={{
- width: 64,
- fontSize: 10,
- textAlign: "center",
- fontWeight: "bold",
- }}
- >
- {jc}
- </Box>
- ))}
- </Flex>
- {alignItems.map((ai) => (
- <Flex key={ai} gap="2" align="center">
- <Box css={{ fontSize: 10, width: 70, textAlign: "right" }}>{ai}</Box>
- {justifyContent.map((jc) => (
+ <Flex direction="column" gap="1">
+ <Text css={{ ...labelStyle, fontWeight: "bold", fontSize: 12 }}>
+ {title}
+ </Text>
+ <Flex direction="column" gap="2">
+ <Flex gap="2" align="center">
+ <Box css={{ width: 70 }} />
+ {justifyContentValues.map((jc) => (
<Box
key={jc}
css={{
width: 64,
- height: 62,
- color: theme.colors.foregroundFlexUiMain,
+ ...labelStyle,
+ textAlign: "center",
+ fontWeight: "bold",
}}
>
- <AlignmentUi
- justifyContent={jc}
- alignItems={ai}
- isColumnDirection={isColumnDirection}
- color="currentColor"
- itemStretchWidth={
- isColumnDirection && (ai === "stretch" || ai === "normal")
- }
- itemStretchHeight={
- !isColumnDirection && (ai === "stretch" || ai === "normal")
- }
- onSelect={() => {}}
- />
+ {jc}
</Box>
))}
</Flex>
- ))}
+ {alignItemsValues.map((ai) => (
+ <Flex key={ai} gap="2" align="center">
+ <Box css={{ ...labelStyle, width: 70, textAlign: "right" }}>{ai}</Box>
+ {justifyContentValues.map((jc) => (
+ <Box
+ key={jc}
+ css={{
+ width: 64,
+ height: 62,
+ color: theme.colors.foregroundFlexUiMain,
+ }}
+ >
+ <AlignmentUi
+ justifyContent={jc}
+ alignItems={ai}
+ isColumnDirection={isColumnDirection}
+ color="currentColor"
+ itemStretchWidth={itemStretchWidth(ai)}
+ itemStretchHeight={itemStretchHeight(ai)}
+ onSelect={() => {}}
+ />
+ </Box>
+ ))}
+ </Flex>
+ ))}
+ </Flex>
</Flex>
);
-export const FlexRow = () => <CombinationGrid isColumnDirection={false} />;
+// Flex: itemStretchWidth/Height are always false
+// (flex has no justify-items; stretch is purely from align-items)
+export const Flex_ = () => (
+ <Flex direction="column" gap="6">
+ <CombinationGrid
+ title="flex-direction: row"
+ isColumnDirection={false}
+ itemStretchWidth={() => false}
+ itemStretchHeight={() => false}
+ />
+ <CombinationGrid
+ title="flex-direction: column"
+ isColumnDirection={true}
+ itemStretchWidth={() => false}
+ itemStretchHeight={() => false}
+ />
+ </Flex>
+);
-export const FlexColumn = () => <CombinationGrid isColumnDirection={true} />;
+const isStretchOrNormal = (ai: string) => ai === "stretch" || ai === "normal";
+
+// Grid: justify-items controls item stretch independently
+// Show both justify-items: stretch (default) and justify-items: start (no stretch)
+export const Grid_ = () => (
+ <Flex direction="column" gap="6">
+ <CombinationGrid
+ title="grid-auto-flow: row, justify-items: stretch"
+ isColumnDirection={false}
+ itemStretchWidth={isStretchOrNormal}
+ itemStretchHeight={() => false}
+ />
+ <CombinationGrid
+ title="grid-auto-flow: row, justify-items: start"
+ isColumnDirection={false}
+ itemStretchWidth={() => false}
+ itemStretchHeight={() => false}
+ />
+ <CombinationGrid
+ title="grid-auto-flow: column, justify-items: stretch"
+ isColumnDirection={true}
+ itemStretchWidth={() => false}
+ itemStretchHeight={isStretchOrNormal}
+ />
+ <CombinationGrid
+ title="grid-auto-flow: column, justify-items: start"
+ isColumnDirection={true}
+ itemStretchWidth={() => false}
+ itemStretchHeight={() => false}
+ />
+ </Flex>
+);
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.test.ts b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.test.ts
new file mode 100644
index 0000000000..28cba3a3b3
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.test.ts
@@ -0,0 +1,434 @@
+import { describe, test, expect } from "vitest";
+import { shouldHideDot } from "./alignment-ui";
+
+const call = (overrides: Partial<Parameters<typeof shouldHideDot>[0]> = {}) =>
+ shouldHideDot({
+ x: 0,
+ y: 0,
+ justifyContent: "start",
+ alignItems: "start",
+ isColumnDirection: false,
+ itemStretchWidth: false,
+ itemStretchHeight: false,
+ ...overrides,
+ });
+
+describe("shouldHideDot", () => {
+ describe("row direction, non-stretched align-items", () => {
+ test("align-items: start hides dots only at y=0", () => {
+ expect(
+ call({ alignItems: "start", justifyContent: "start", x: 0, y: 0 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: "start", justifyContent: "start", x: 0, y: 1 })
+ ).toBe(false);
+ expect(
+ call({ alignItems: "start", justifyContent: "start", x: 0, y: 2 })
+ ).toBe(false);
+ });
+
+ test("align-items: center hides dots only at y=1", () => {
+ expect(
+ call({ alignItems: "center", justifyContent: "start", x: 0, y: 0 })
+ ).toBe(false);
+ expect(
+ call({ alignItems: "center", justifyContent: "start", x: 0, y: 1 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: "center", justifyContent: "start", x: 0, y: 2 })
+ ).toBe(false);
+ });
+
+ test("align-items: end hides dots only at y=2", () => {
+ expect(
+ call({ alignItems: "end", justifyContent: "start", x: 0, y: 0 })
+ ).toBe(false);
+ expect(
+ call({ alignItems: "end", justifyContent: "start", x: 0, y: 2 })
+ ).toBe(true);
+ });
+
+ test("align-items: baseline hides dots only at y=0", () => {
+ expect(
+ call({ alignItems: "baseline", justifyContent: "start", x: 0, y: 0 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: "baseline", justifyContent: "start", x: 0, y: 1 })
+ ).toBe(false);
+ });
+ });
+
+ describe("row direction, stretched cross-axis", () => {
+ // CSS align-items: stretch/normal stretches bars to full height
+ test.each(["stretch", "normal"])(
+ "align-items: %s hides at all y positions",
+ (ai) => {
+ expect(
+ call({ alignItems: ai, justifyContent: "start", x: 0, y: 0 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: ai, justifyContent: "start", x: 0, y: 1 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: ai, justifyContent: "start", x: 0, y: 2 })
+ ).toBe(true);
+ // but only at matching main-axis position
+ expect(
+ call({ alignItems: ai, justifyContent: "start", x: 1, y: 0 })
+ ).toBe(false);
+ }
+ );
+
+ // Explicit itemStretchHeight has same effect
+ test("itemStretchHeight=true hides at all y positions", () => {
+ expect(
+ call({
+ alignItems: "start",
+ itemStretchHeight: true,
+ justifyContent: "center",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ alignItems: "start",
+ itemStretchHeight: true,
+ justifyContent: "center",
+ x: 1,
+ y: 2,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ alignItems: "start",
+ itemStretchHeight: true,
+ justifyContent: "center",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(false);
+ });
+ });
+
+ describe("row direction, main-axis positions", () => {
+ const stretched = { alignItems: "stretch" };
+
+ test("justify-content: normal/start hides at x=0", () => {
+ expect(call({ ...stretched, justifyContent: "normal", x: 0 })).toBe(true);
+ expect(call({ ...stretched, justifyContent: "start", x: 0 })).toBe(true);
+ expect(call({ ...stretched, justifyContent: "start", x: 1 })).toBe(false);
+ expect(call({ ...stretched, justifyContent: "start", x: 2 })).toBe(false);
+ });
+
+ test("justify-content: center hides at x=1", () => {
+ expect(call({ ...stretched, justifyContent: "center", x: 1 })).toBe(true);
+ expect(call({ ...stretched, justifyContent: "center", x: 0 })).toBe(
+ false
+ );
+ });
+
+ test("justify-content: end hides at x=2", () => {
+ expect(call({ ...stretched, justifyContent: "end", x: 2 })).toBe(true);
+ expect(call({ ...stretched, justifyContent: "end", x: 1 })).toBe(false);
+ });
+
+ test("justify-content: space-between hides at all x positions", () => {
+ expect(
+ call({ ...stretched, justifyContent: "space-between", x: 0 })
+ ).toBe(true);
+ expect(
+ call({ ...stretched, justifyContent: "space-between", x: 1 })
+ ).toBe(true);
+ expect(
+ call({ ...stretched, justifyContent: "space-between", x: 2 })
+ ).toBe(true);
+ });
+
+ test("justify-content: space-around hides no dots", () => {
+ expect(call({ ...stretched, justifyContent: "space-around", x: 0 })).toBe(
+ false
+ );
+ expect(call({ ...stretched, justifyContent: "space-around", x: 1 })).toBe(
+ false
+ );
+ expect(call({ ...stretched, justifyContent: "space-around", x: 2 })).toBe(
+ false
+ );
+ });
+ });
+
+ describe("row direction, intersection check", () => {
+ test("align-items: start + justify-content: space-between hides row 0 only", () => {
+ expect(
+ call({
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 2,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(false);
+ expect(
+ call({
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 2,
+ y: 2,
+ })
+ ).toBe(false);
+ });
+
+ test("align-items: end + justify-content: center hides only (1,2)", () => {
+ expect(
+ call({ alignItems: "end", justifyContent: "center", x: 1, y: 2 })
+ ).toBe(true);
+ expect(
+ call({ alignItems: "end", justifyContent: "center", x: 0, y: 2 })
+ ).toBe(false);
+ expect(
+ call({ alignItems: "end", justifyContent: "center", x: 1, y: 0 })
+ ).toBe(false);
+ });
+ });
+
+ describe("column direction", () => {
+ const col = { isColumnDirection: true };
+
+ test("x maps to justify-content (main), y maps to align-items (cross) — same as row", () => {
+ // align-items: start → cross match at y=0
+ // justify-content: start → main match at x=0
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(false);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(false);
+ });
+
+ test("align-items: center matches y=1", () => {
+ expect(
+ call({
+ ...col,
+ alignItems: "center",
+ justifyContent: "end",
+ x: 2,
+ y: 1,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "center",
+ justifyContent: "end",
+ x: 2,
+ y: 0,
+ })
+ ).toBe(false);
+ });
+
+ test("align-items: stretch covers all y", () => {
+ expect(
+ call({
+ ...col,
+ alignItems: "stretch",
+ justifyContent: "start",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "stretch",
+ justifyContent: "start",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "stretch",
+ justifyContent: "start",
+ x: 0,
+ y: 2,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "stretch",
+ justifyContent: "start",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(false);
+ });
+
+ test("itemStretchWidth covers all y in column direction", () => {
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ itemStretchWidth: true,
+ justifyContent: "center",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ itemStretchWidth: true,
+ justifyContent: "center",
+ x: 1,
+ y: 2,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ itemStretchWidth: true,
+ justifyContent: "center",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(false);
+ });
+
+ test("space-between hides all x when cross matches", () => {
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 1,
+ y: 0,
+ })
+ ).toBe(true);
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 2,
+ y: 0,
+ })
+ ).toBe(true);
+ // cross doesn't match
+ expect(
+ call({
+ ...col,
+ alignItems: "start",
+ justifyContent: "space-between",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(false);
+ });
+ });
+
+ describe("stretch direction matters for itemStretch*", () => {
+ test("row: itemStretchWidth has no effect on cross-axis (y)", () => {
+ expect(
+ call({
+ isColumnDirection: false,
+ itemStretchWidth: true,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true); // matches anyway via alignItems
+ expect(
+ call({
+ isColumnDirection: false,
+ itemStretchWidth: true,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(false); // itemStretchWidth doesn't affect row cross-axis
+ });
+
+ test("column: itemStretchHeight has no effect on cross-axis (y)", () => {
+ expect(
+ call({
+ isColumnDirection: true,
+ itemStretchHeight: true,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 0,
+ })
+ ).toBe(true); // matches anyway via alignItems
+ expect(
+ call({
+ isColumnDirection: true,
+ itemStretchHeight: true,
+ alignItems: "start",
+ justifyContent: "start",
+ x: 0,
+ y: 1,
+ })
+ ).toBe(false); // itemStretchHeight doesn't affect column cross-axis
+ });
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx
index cb9918c699..b3304bfb45 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/alignment-ui.tsx
@@ -2,10 +2,26 @@ import { Box, Flex, Grid, IconButton } from "@webstudio-is/design-system";
import { DotIcon } from "@webstudio-is/icons";
import { theme } from "@webstudio-is/design-system";
-// Hide dots where flex/grid item lines overlap to avoid sub-pixel artifacts.
-// Lines have a cross-axis position (from alignItems) and main-axis positions
-// (from justifyContent). A dot is hidden when it sits at an intersection.
-const shouldHideDot = ({
+// Hide dots where indicator bars overlap to avoid sub-pixel artifacts.
+// Bars have a cross-axis position (from alignItems) and main-axis position
+// (from justifyContent). A dot is hidden when both axes match.
+//
+// x always maps to justify-content (main-axis position: 0=start, 1=center, 2=end)
+// y always maps to align-items (cross-axis position: 0=start, 1=center, 2=end)
+// The visual transposition for column direction is handled by the CSS grid swap.
+//
+// Cross-axis (y): CSS align-items controls bar position in the cross direction.
+// stretch/normal → bars span full cross-axis (CSS stretches flex items)
+// itemStretchWidth (column) / itemStretchHeight (row) → same visual effect
+// start/baseline/center/end → bars sit at one specific position
+//
+// Main-axis (x): CSS justify-content controls bar distribution.
+// normal/start → bars clustered at position 0
+// center → bars at position 1
+// end → bars at position 2
+// space-between → bars at positions 0, 1, 2
+// space-around → bars between positions, no dot overlap
+export const shouldHideDot = ({
x,
y,
justifyContent,
@@ -22,18 +38,21 @@ const shouldHideDot = ({
itemStretchWidth: boolean;
itemStretchHeight: boolean;
}) => {
- const crossAxis = isColumnDirection ? x : y;
- const mainAxis = isColumnDirection ? y : x;
+ // x always maps to justify-content (main-axis), y to align-items (cross-axis)
+ const crossAxis = y;
+ const mainAxis = x;
- // Determine if the dot's cross-axis position overlaps with lines
+ // Check if the dot's cross-axis position overlaps with bars.
+ // CSS align-items: stretch/normal makes bars span full cross-axis.
+ // Explicit itemStretch* does the same via min-width/height: 100%.
const isStretched =
- (isColumnDirection ? itemStretchWidth : itemStretchHeight) ||
alignItems === "stretch" ||
- alignItems === "normal";
+ alignItems === "normal" ||
+ (isColumnDirection ? itemStretchWidth : itemStretchHeight);
let crossMatch = false;
if (isStretched) {
- crossMatch = true; // lines span all cross-axis positions
+ crossMatch = true;
} else {
switch (alignItems) {
case "start":
@@ -53,7 +72,7 @@ const shouldHideDot = ({
return false;
}
- // Determine if the dot's main-axis position overlaps with lines
+ // Check if the dot's main-axis position overlaps with bars.
switch (justifyContent) {
case "normal":
case "start":
@@ -63,8 +82,8 @@ const shouldHideDot = ({
case "end":
return mainAxis === 2;
case "space-between":
- case "space-around":
return true;
+ // space-around: bars sit between dot positions, no overlap
}
return false;
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/flex-alignment.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/flex-alignment.stories.tsx
deleted file mode 100644
index 8906f9f7d4..0000000000
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/flex-alignment.stories.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-import { Box, Flex } from "@webstudio-is/design-system";
-import { FlexAlignment as FlexAlignmentComponent } from "./flex-alignment";
-
-export default {
- title: "Style Panel/Layout/Flex Alignment",
- component: FlexAlignmentComponent,
-};
-
-const alignItems = ["normal", "stretch", "baseline", "center", "start", "end"];
-const justifyContent = [
- "normal",
- "space-between",
- "space-around",
- "center",
- "start",
- "end",
-];
-
-export const FlexGrid = () => {
- return (
- <Flex>
- <Box
- css={{
- fontSize: 10,
- paddingTop: 200,
- paddingLeft: 6,
- fontWeight: "bold",
- writingMode: "vertical-lr",
- transform: "rotate(180deg)",
- }}
- >
- align-items
- </Box>
- <Flex direction="column" gap={2} css={{ color: "#000" }}>
- <Box css={{ fontSize: 10, paddingLeft: 200, fontWeight: "bold" }}>
- justify-content
- </Box>
- <Flex gap={2}>
- <Box css={{ fontSize: 10, writingMode: "vertical-lr" }}>&nbsp;</Box>
- {justifyContent.map((justifyContent) => (
- <Box key={justifyContent} css={{ width: 72, fontSize: 10 }}>
- {justifyContent}
- </Box>
- ))}
- </Flex>
- {alignItems.map((alignItems) => (
- <Flex key={alignItems} gap={2}>
- <Box
- css={{
- fontSize: 10,
- textAlign: "right",
- writingMode: "vertical-lr",
- transform: "rotate(180deg)",
- }}
- >
- {alignItems}
- </Box>
- {justifyContent.map((justifyContent) => (
- <Box key={justifyContent} css={{ position: "relative" }}>
- <FlexAlignmentComponent />
- </Box>
- ))}
- </Flex>
- ))}
- </Flex>
- </Flex>
- );
-};