Socket
Book a DemoInstallSign in
Socket

react-drag-guide-lines-test

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

react-drag-guide-lines-test

Adds guide lines to react draggable components

1.0.0
unpublished
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

React drag lines Github

A React Library to enable draglines for perfect placement of draggable items

Usage

npm i -S react-drag-lines

Parent Component

Add the following import to your parent component

Parent import

import ReactDragAlign from 'react-drag-lines';

Parent code

instead of your parent you can wrap your draggable children with the following code

return (
  <ReactDragAlign styles={{...yourprops}}>
    {draggableComponents.map(item => <YourComponent {...props}>)}
  </ReactDragAlign>
)

Parent Props

TitleAbouttypeValuesDefault Values
emptyStateEmpty state component if there are no childrenReactNodeReactNodeundefined
showEmptyStateboolean to check if we need to show empty state or notbooleantrue, falsefalse
limitLimit the lines to the boundariesbooleantrue, falsefalse
stylesStyles for the wrapper, horizontal Lines and Vertical Linesstylesvaluesundefined
Styles

Styles required to pass from parent for different styles like backgroundColor, width or height

Type
{
  wrapper?: React.CSSProperties,
  xLineStyle?: React.CSSProperties,
  yLineStyle?: React.CSSProperties,
}
Default Values
{
  wrapper: { ...wrapperStyles },
  xLineStyle: { ...horizontalStyles },
  yLineStyle: { ...verticalStyles },
}

Child Component

import

import { IDragOperations } from 'react-drag-lines';

Props

to your props you can add a new Prop with IDragOperations

interface IChildProps {
  // your props
  dragOperations: IDragOperations
}

Child Code

add data-x and data-y props to your child props and use the functions of IDragOperations appropriately

const ChildComponent = (props: IChildProps) => {
  const {  dragOperations, ...rest } = props;

  // call this function when you end dragging
  const handleDragEnd = () => {
        // your code
        dragOperations?.onDragStop();
    };

    // call this function when you start dragging
    const handleDragStart = () => {
        // Your code
        dragOperations?.onDragStart();
    };

    // call this function when you are dragging
    const handleDragging = () => {
        // Your code
        // dragX - difference between current x position and previous x position
        // dragY - difference between current y position and previous y position
        dragOperations?.onDrag({ x: dragX, y: dragY });
    };

    return (
        <DragComponent
          // your props
          data-x={currentXPosition}
          data-y={currentYPosition}
        />
    );
}

export default ChildComponent;

Keywords

react

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.