GithubHelp home page GithubHelp logo

avh4 / elm-debug-controls Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 4.0 732 KB

Easily build interactive UIs for complex data structures

Home Page: https://avh4.github.io/elm-debug-controls/

License: BSD 3-Clause "New" or "Revised" License

Elm 99.54% Nix 0.46%

elm-debug-controls's Introduction

Build Status Latest Version

elm-debug-controls

This package helps you easily build interactive UIs for complex data structures. The resulting controls are not meant for building end-user UIs, but they are useful for quickly building debugging consoles, documentation, and style guides.

Demo

https://avh4.github.io/elm-debug-controls/

Usage

Suppose we have an Elm data structure like the following and want to create a simple debugging tool to experiment with different values:

import Time

type alias UploadRequest =
    { path : String
    , mode : WriteMode
    , autorename : Bool
    , clientModified : Maybe Time.Posix
    , mute : Bool
    , content : String
    }

type WriteMode
    = Add
    | Overwrite
    | Update String

Using elm-debug-controls, we can quickly create an interactive UI to create UploadRequest values:

elm install avh4/elm-debug-controls
import Debug.Control exposing (bool, choice, field, map, record, string, value)

type alias Model =
    { ...
    , uploadRequest : Debug.Control.Control UploadRequest
    }

init : Model
init =
    { ...
    , uploadRequest =
        record UploadRequest
            |> field "path" (string "/demo.txt")
            |> field "mode"
                (choice
                    [ ( "Add", value Add )
                    , ( "Overwrite", value Overwrite )
                    , ( "Update rev", map Update <| string "123abcdef" )
                    ]
                )
            |> field "autorename" (bool False)
            |> field "clientModified"
                (maybe False <| date Time.utc <| Time.millisToPosix 0)
            |> field "mute" (bool False)
            |> field "content" (string "HELLO.")
    }

Now we can hook the control up to our view:

type Msg
    = ...
    | ChangeUploadRequest (Debug.Control.Control UploadRequest)

update : Msg -> Model -> Model
update msg model =
    case msg of
        ...
        ChangeUploadRequest uploadRequest ->
            { model | uploadRequest = uploadRequest }

view : Model -> Html Msg
view model =
    ...
    Debug.Control.view ChangeUploadRequest model.uploadRequest

We now have an interactive UI that looks like this:

Screen capture of the interactive UI

Finally, we can use the UploadResponse value elsewhere in our program with:

Debug.Control.currentValue model.uploadRequest

elm-debug-controls's People

Contributors

avh4 avatar brianhicks avatar tesk9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

elm-debug-controls's Issues

Lists of Controls?

Great project!

https://avh4.github.io/elm-debug-controls/ demonstrates how to create, view, and interact with (click on and change) a UploadRequest, but how would one create and view a List UploadRequest? It would be great to be able to have a list of N UploadRequests all of which are interactive. That's what I am trying to do with my own model. I have a record like:

type alias Record = {
  name: String,
  notes: List String,
  things: List Thing
}

type alias Thing = {
  one: String,
  two: Int
}

It's not clear to me from the documentation and code how do to this. I saw that there is a "list" Control, but that doesn't do what I am trying to do, and I haven't been able to figure out exactly how to do it. I'm having a bit of a hard time wrapping my head around exactly how all of this works -- I'm a good developer with functional experience so a lot of it makes sense, but the overall approach is translucent to me currently (though, I can see that it is very cool).

Thank you!

Control.float

It would be great to have something like

Control.float : { min : Float, max : Float } -> Float -> Control Float

implemented as a slider (in my case, I'd like to make some debug UIs for experimenting with different elm-3d-scene parameter values). Control.int could be implemented similarly (with a step size of 1 set on the underlying HTML slider). Happy to submit a PR if that would be helpful!

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.