MCPcopy
hub / github.com/react-grid-layout/react-grid-layout / snapToGrid

Function snapToGrid

src/core/constraints.ts:260–285  ·  view source on GitHub ↗
(
  stepX: number,
  stepY: number = stepX
)

Source from the content-addressed store, hash-verified

258 * ```
259 */
260export function snapToGrid(
261 stepX: number,
262 stepY: number = stepX
263): LayoutConstraint {
264 // Validate step values to prevent division by zero or invalid snapping
265 if (stepX <= 0 || stepY <= 0) {
266 throw new Error(
267 `snapToGrid: step values must be positive (got stepX=${stepX}, stepY=${stepY})`
268 );
269 }
270
271 return {
272 name: `snapToGrid(${stepX}, ${stepY})`,
273
274 constrainPosition(
275 _item: LayoutItem,
276 x: number,
277 y: number
278 ): { x: number; y: number } {
279 return {
280 x: Math.round(x / stepX) * stepX,
281 y: Math.round(y / stepY) * stepY
282 };
283 }
284 };
285}
286
287/**
288 * Create a minimum size constraint.

Callers 2

getCustomConstraintFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…