upsiflu / less-ui

Write your views across several screen regions, and hide all Ui state in the Url.
https://package.elm-lang.org/packages/upsiflu/less-ui/latest
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

Smarter Regions! #56

Open upsiflu opened 10 months ago

upsiflu commented 10 months ago

Example:

Given my model of

type alias Paragraph =
    { name : String, body : Markdown, shape : Shape }

type Shape
    = OneColumn
    | TwoColumns 

I want to offer editing controls.

module Shape

view : Shape -> Ui
view shape =
  inRegion Control
    (case shape of
       OneColumn -> button [onClick (makeTwoColumns shape)] ["One Column (switch)"]
       TwoColumns -> button [onClick (makeOneColumn shape)] ["Two Columns (switch)"]
    )
    ++ inRegion Scene (css shape)
module Parapgraph

view paragraph =
    Shape.view paragraph.shape
    ++ Ui.node "p" [ id paragraph.name ] [ Markdown.render paragraph.body ]
    ++ Markdown.editor paragraph.body

As of v1.0, toggle indiscriminately toggles its descendants. In an earlier draft, toggle would only affect Control, which makes it more suitable for such nested Uis.