npm package: @stevorated/dnd
Description: A simple unopinionated Drag and drop component. we do the draggin', you do everything else.
Latest version: 0.0.4

# @stevorated/dnd

A simple unopinionated Drag and drop component. we do the draggin', you do everything else.

## Installation

```
npm i @stevorated/dnd
```
or 

```
yarn add @stevorated/dnd
```

## Props

| Prop          | Type                                                         | Required? | Notes/Example                                                                                                         |
|---------------|--------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------|
| data          | (Record & { id: string })[]                                  | required  | data, should contain an id field of type string, other properties are up to you and are exposed in renderItem's props |
| renderItem    | (props:Record<string, string> & { id: string }) => ReactNode | required  | render function to create the drag item component                                                                     |
| className     | string                                                       | optional  | style root container div                                                                                              |
| dragCardClass | string                                                       | optional  | style card while being dragged                                                                                        |
| cardClass     | string                                                       | optional  | style card container                                                                                                  |
| onDrop        | (items: Record & { id: string })[]) => void;                 | optional  | callback function to handle things like updating your server                                                          |
| ...rest       | HTMLAttributes<HTMLDivElement>                               | optional  | other HTML properties to the root container div like style for instance.                                              |

## Example

```
import { Dnd } from '@stevorated/dnd';

import './index.scss';
import styles from './styles.module.scss';

const data = [
  {
    id: '1',
    title: 'What is Lorem Ipsum?',
    subtitle: 'Lorem Ipsum is simply dummy',
  },
  {
    id: '2',
    title: 'Why do we use it?',
    subtitle: 'The point of using at its layout',
  },
  {
    id: '3',
    title: 'Where does it come from?',
    subtitle: 'Contrary to popular belief',
  },
  {
    id: '4',
    title: 'Where can I get some?',
    subtitle: 'There are many variations',
  },
  {
    id: '5',
    title: 'Morbi sagittis tellus a efficitur',
    subtitle: 'Etiam mollis eros eget mi.',
  },
];

function ExampleItem(item: { id: string; title: string; subtitle: string }) {
  return (
    <>
      <div className={`${styles.imgContainer}`}>
        <img src="/card.svg" alt="" />
      </div>
      <div className={`${styles.box}`}>
        <h4>{item.subtitle}</h4>
        <h2>{item.title}</h2>
      </div>
    </>
  );
}

function Example() {
  return (
    <>
      <Dnd
        onDrop={async items => {
          // eslint-disable-next-line no-console
          console.log({ items });
        }}
        data={data}
        renderItem={ExampleItem}
        className="container"
        cardClass="card"
        dragCardClass="drag"
      />
    </>
  );
}

export default Example;

```


And add styles files just for the looks 👀 👗

`styles.module.scss`

```

.imgContainer {
    width: 90px;
    height: 100%;
    background: #bfdbfe;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    pointer-events: none;

    img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
    }
}

.box {
    flex: 1;
    padding: 0 10px;

    h4 {
        font-size: 0.8rem;
        text-transform: uppercase;
        font-weight: 400;
        color: #797979
    }

    h2 {
        font-size: 1rem;
        text-transform: capitalize;
        font-weight: 600;
        color: #444
    }
}

```

`index.scss`
```

* {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
  margin: 0;
  padding: 0;
}

body {
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #e1eeff;
  padding: 15px;
}

.card {
  width: 100%;
  height: 80px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px;
  box-shadow: 2px 20px 30px rgba(0, 0, 0, 0.08);
}

.container {
  max-width: 450px;
  width: 100%;
  padding: 30px 20px;
  display: flex;
  gap: 15px;
  flex-direction: column;
  background: #fefbdf;
  border-radius: 10px;
}

.drag {
  box-shadow: 2px 20px 30px rgba(0, 0, 0, 0.2);
}

```

## Issues

- none for the time. if you find something feel free to contact me on github.

## License
Copyright © 2024 <stevorated (Shirel Garber)>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.