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.

765 B
Raw Blame
import { groupBreakpoints } from "@webstudio-is/project-build/runtime";
import { $selectedBreakpointId } from "../nano-states";
import { $breakpoints } from "~/shared/sync/data-stores";
import { setCanvasWidth } from "~/builder/shared/calc-canvas-width";

/**
 * Order number starts with 1 and covers all existing breakpoints
 */
export const selectBreakpointByOrder = (orderNumber: number) => {
  const breakpoints = $breakpoints.get();
  const index = orderNumber - 1;
  const grouped = groupBreakpoints(Array.from(breakpoints.values()));
  const allBreakpoints = [...grouped.widthBased, ...grouped.custom];
  const breakpoint = allBreakpoints.at(index);
  if (breakpoint) {
    $selectedBreakpointId.set(breakpoint.id);
    setCanvasWidth(breakpoint.id);
  }
};