Git Product home page Git Product logo

elm-dnd's Introduction

elm-dnd

This library allows you to build great UI with drag-and-drop simple.
It is abstracting you from mouse events and other low-level stuff.
You can operate high-level things such as draggable and droppable areas.

The idea of package API is you should be able to wrap elements with draggable dragMeta to add an ability to drag it.
The dragging object will get some meta information.
Also, you could wrap another element with droppable dropMeta,
so if you drop element over that element, the message YourOnDropMessage dragMeta dropMeta will be invoked.

At first, you need to initialize draggable state and function.
DnD.init helper returns initModel, subscription, draggable and droppable functions for your message wrapper and onDrop message.

type Msg
    = NoOp
    ..
    | OnDrop String Int
    | DnDMsg (DnD.Msg String Int)


type alias Model =
    { ...
    , draggable : DnD.Draggable String Int
    }


dnd = DnD.init DnDMsg OnDrop


model =
    { ...
    , draggable : dnd.model
    }

Subscriptions allow you to get drop event.

subscriptions : Model -> Sub Msg
subscriptions model =
    dnd.subscriptions model.draggable

View wrapper for draggable object, you could drag object wrapped by this helper

draggable
    : (Html.Attribute Msg)
    -> List (Html Msg)
    -> Html Msg
draggable =  dnd.draggable dragMeta

View helper for droppable area, you could drop object to this area, after that your on OnDrop message will be invoked.

droppable
  : (Html.Attribute Msg)
  -> List (Html Msg)
  -> Html Msg
droppable = dnd.droppable dropMeta

You can find simple examples here.
For more complex example check Chess Board.

elm-dnd's People

Contributors

giulioungaretti avatar ir4y avatar norpan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.