How to use the css-box-model.offset function in css-box-model

To help you get started, we’ve selected a few css-box-model examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atlassian / react-beautiful-dnd / test / unit / state / move-in-direction / move-to-next-place / moving-to-invisible-place / not-visible-in-viewport.spec.js View on Github external
destination: foreign,
          }),
        ).toBe(false);
        // going further - ensure it is not partially visible
        expect(
          isPartiallyVisible({
            target: inForeign.page.borderBox,
            viewport: scrolled.frame,
            withDroppableDisplacement: true,
            destination: foreign,
          }),
        ).toBe(false);

        // checking that if displaced then inForeign would be visible
        // using raw .displacedBy as we are scolling on
        const displaced: BoxModel = offset(
          inForeign.client,
          getDisplacedBy(axis, inHome.displaceBy).point,
        );
        expect(
          isPartiallyVisible({
            target: displaced.borderBox,
            viewport: scrolled.frame,
            withDroppableDisplacement: true,
            destination: foreign,
          }),
        ).toBe(true);
      });
github atlassian / react-beautiful-dnd / test / unit / state / move-in-direction / move-to-next-place / moving-to-invisible-place / not-visible-in-droppable.spec.js View on Github external
destination: scrolled,
          }),
        ).toBe(false);
        // going further - ensure it is not partially visible
        expect(
          isPartiallyVisible({
            target: inForeign.page.borderBox,
            viewport: viewport.frame,
            withDroppableDisplacement: true,
            destination: scrolled,
          }),
        ).toBe(false);

        // checking that if displaced then inForeign would be visible
        // using raw .displacedBy as we are scolling on
        const displaced: BoxModel = offset(
          inForeign.client,
          getDisplacedBy(axis, inHome.displaceBy).point,
        );
        expect(
          isPartiallyVisible({
            target: displaced.borderBox,
            viewport: viewport.frame,
            withDroppableDisplacement: true,
            destination: scrolled,
          }),
        ).toBe(true);
      });
github atlassian / react-beautiful-dnd / test / unit / state / publish-while-dragging / update-draggables / adjust-additions-for-scroll-change.spec.js View on Github external
const scrolled: DroppableDimension = scrollDroppable(
    scrollableHome,
    newScroll,
  );
  // validation
  expect(getFrame(scrolled).scroll.current).toEqual(scrollChange);
  // dimensions
  const added: DraggableDimension = getDraggableDimension({
    descriptor: {
      index: 0,
      id: 'added',
      droppableId: preset.home.descriptor.id,
      type: preset.home.descriptor.type,
    },
    // when collected this dimension would have been displaced by the scroll
    borderBox: offset(preset.inHome1.client, scrollDisplacement).borderBox,
    windowScroll: preset.windowScroll,
  });
  const unshifted: DraggableDimension = getDraggableDimension({
    descriptor: added.descriptor,
    // unshifted
    borderBox: preset.inHome1.client.borderBox,
    windowScroll: preset.windowScroll,
  });
  const published: Published = {
    ...empty,
    additions: [added],
    modified: [scrolled],
  };
  const original: CollectingState = state.collecting(
    preset.inHome1.descriptor.id,
  );
github atlassian / react-beautiful-dnd / src / state / get-center-from-impact / get-page-border-box-center / when-reordering.js View on Github external
const closestAfter: DraggableDimension =
      draggables[displaced[0].draggableId];
    // want to go before where it would be with the displacement

    // target is displaced and is already in it's starting position
    if (didStartDisplaced(closestAfter.descriptor.id, onLift)) {
      return goBefore({
        axis,
        moveRelativeTo: closestAfter.page,
        isMoving: draggablePage,
      });
    }

    // target has been displaced during the drag and it is not in its starting position
    // we need to account for the displacement
    const withDisplacement: BoxModel = offset(
      closestAfter.page,
      displacedBy.point,
    );

    return goBefore({
      axis,
      moveRelativeTo: withDisplacement,
      isMoving: draggablePage,
    });
  }

  // Nothing in list is displaced, we should go after the last item

  const last: DraggableDimension =
    insideDestination[insideDestination.length - 1];
github atlassian / react-beautiful-dnd / src / state / get-center-from-impact / get-page-border-box-center / when-reordering.js View on Github external
// Nothing in list is displaced, we should go after the last item

  const last: DraggableDimension =
    insideDestination[insideDestination.length - 1];

  // we can just go into our original position if the last item
  // is the dragging item
  if (last.descriptor.id === draggable.descriptor.id) {
    return draggablePage.borderBox.center;
  }

  if (didStartDisplaced(last.descriptor.id, onLift)) {
    // if the item started displaced and it is no longer displaced then
    // we need to go after it it's non-displaced position

    const page: BoxModel = offset(last.page, negate(onLift.displacedBy.point));
    return goAfter({
      axis,
      moveRelativeTo: page,
      isMoving: draggablePage,
    });
  }

  // item is in its resting spot. we can go straight after it
  return goAfter({
    axis,
    moveRelativeTo: last.page,
    isMoving: draggablePage,
  });
};
github atlassian / react-beautiful-dnd / test / unit / state / get-center-from-impact / get-page-border-box-center / reorder / nothing-displaced.spec.js View on Github external
index: preset.inHome4.descriptor.index,
              droppableId: preset.inHome4.descriptor.id,
            },
          },
        };
        const result: Position = getPageBorderBoxCenter({
          impact,
          afterCritical,
          draggable: preset.inHome1,
          draggables: preset.draggables,
          droppable: preset.home,
        });

        const expected: Position = goAfter({
          axis,
          moveRelativeTo: offset(
            preset.inHome4.page,
            negate(displacedBy.point),
          ),
          isMoving: preset.inHome1.page,
        });
        expect(result).toEqual(expected);
      });
    });
github atlassian / react-beautiful-dnd / test / unit / state / publish / util.js View on Github external
export const shift = ({
  draggable,
  change,
  newIndex,
}: ShiftArgs): DraggableDimension => {
  const client: BoxModel = offset(draggable.client, change);
  const page: BoxModel = withScroll(client, preset.windowScroll);

  const moved: DraggableDimension = {
    ...draggable,
    descriptor: {
      ...draggable.descriptor,
      index: newIndex,
    },
    placeholder: {
      ...draggable.placeholder,
      client,
    },
    client,
    page,
  };
github atlassian / react-beautiful-dnd / src / state / publish / get-draggable-map.js View on Github external
withAdditions.forEach((item: DraggableDimension) => {
      if (additionMap[item.descriptor.id]) {
        return;
      }

      const shift: Shift = toShift[item.descriptor.id];
      if (!shift) {
        return;
      }

      const client: BoxModel = offsetBox(item.client, shift.offset);
      const page: BoxModel = withScroll(client, initialWindowScroll);
      const index: number = item.descriptor.index + shift.indexChange;

      const moved: DraggableDimension = {
        ...item,
        descriptor: {
          ...item.descriptor,
          index,
        },
        placeholder: {
          ...item.placeholder,
          client,
        },
        client,
        page,
      };
github atlassian / react-beautiful-dnd / src / state / publish-while-dragging-in-virtual / offset-draggable.js View on Github external
export default ({
  draggable,
  offset,
  initialWindowScroll,
}: Args): DraggableDimension => {
  const client: BoxModel = offsetBox(draggable.client, offset);
  const page: BoxModel = withScroll(client, initialWindowScroll);

  const moved: DraggableDimension = {
    ...draggable,
    placeholder: {
      ...draggable.placeholder,
      client,
    },
    client,
    page,
  };

  return moved;
};
github atlassian / react-beautiful-dnd / src / state / publish / adjust-additions-for-scroll-changes.js View on Github external
(draggable: DraggableDimension): DraggableDimension => {
      const droppableId: DroppableId = draggable.descriptor.droppableId;
      const modified: DroppableDimension = modifiedMap[droppableId];
      const closest: ?Scrollable = modified.viewport.closestScrollable;

      invariant(closest);

      const droppableScrollChange: Position = closest.scroll.diff.value;

      const totalChange: Position = add(
        windowScrollChange,
        droppableScrollChange,
      );
      const client: BoxModel = offset(draggable.client, totalChange);
      const page: BoxModel = withScroll(client, viewport.scroll.initial);

      const moved: DraggableDimension = {
        ...draggable,
        placeholder: {
          ...draggable.placeholder,
          client,
        },
        client,
        page,
      };

      return moved;
    },
  );

css-box-model

Get accurate and well named css box model information about an Element 📦

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis