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

Remove the `attribute` type parameter #24

Closed upsiflu closed 1 year ago

upsiflu commented 1 year ago

Proposal A: Hide the attribute type parameter which affects the Link element rendering, and make it default to Html.Attribute msg

Proposal B: Introduce a type parameter linker analogous to wrapper, and in Layout, add a field link : linker -> html.

Proposal C: Replace the type parameter wrapper with a combined wrapper/linker that accepts either:

wrapOrLink : WrapperOrLinker -> List html -> List html
wrapOrLink wrapperOrLinker children =
    case wrapperOrLinker of
         Inserted -> ...
         ...
         Link attrs { url : String } -> [ a [ href url ] children ]
         Switch attrs { url : String, isChecked : Bool } -> [ Html.a ( Attr.href url :: Attr.aria-checked isChecked :: attrs ) children ]
         Node tag attrs -> Html.node tag attrs
         ...

The layout would connect Link and Switch via Link:

type alias Link.Elements attribute wrapper =
    { link : List attribute -> (\{ url : String } -> wrapper)
    , switch : List attribute -> (\{ url : String, isChecked : Bool }  -> wrapper)
    }
myElements =
    { link = Link, switch = Switch }

and then you's write `toggle []...

No! Instead,

type MyWrapper attribute label
= Inserted
| ...
| TextLink (List attribute) { label : String }
| ...

and then we

NO!

Here is correct:

We name it Style and then in layout, we say wrap : Style -> html -> html, link : Style -> {url, label} -> html, switch : Style -> {url, label, isChecked} -> html :-) :-) :-)

Disadvantage: The only use case where one would want to use a different attribute type to draw links than Html.Attribute Never is if you use elm-w3 (a package that makes Html nodes and attributes as strict as the w3c spec). In that case, each element (a and area are the only elements that allow hrefs) needs to have the same attribute type anyways. So instead, we force total composability around links, even when that would violate the w3 spec.

Advantage: Removing attribute simplifies the code

Discussion:

Implementation:

upsiflu commented 1 year ago

10587ff