Skip to content

Instantly share code, notes, and snippets.

@janwirth
Last active November 14, 2022 12:06
Show Gist options
  • Save janwirth/9ac1cf6ec4cf0fa81b75a0eb4dea0018 to your computer and use it in GitHub Desktop.
Save janwirth/9ac1cf6ec4cf0fa81b75a0eb4dea0018 to your computer and use it in GitHub Desktop.
awesome-custom-elements

A collection of usable, lightweight custom elements

Some catalogues

Comments below are draftpad

@janwirth
Copy link
Author

janwirth commented Jul 7, 2022

Redefining custom elements
https://gist.github.com/janwirth/60797dd30c0b472dad5761e53423790a

Using proxies to abduct an element of elm's VDOM for things like portals
https://gist.github.com/janwirth/6f1c3cb2723ef2eed578c1d695447533

Note: one can use defineGetter to create reactive properties.

@janwirth
Copy link
Author

janwirth commented Jul 7, 2022

Very popular framework: https://stenciljs.com/

@janwirth
Copy link
Author

janwirth commented Jul 7, 2022

Draft of a spec:

{-| Render the datepicker custom element -}
viewElement : String -> Html.Styled.Html String
viewElement value =
    let
        root =
            Html.Styled.node "elm-element-provider" [ Html.Styled.Attributes.attribute "info" info ] [ inputEl ]

        info =
            "{\"name\":\"DatePicker_\", \"date_value\": [\"down\", \"up\"]}"

        inputEl =
            Html.Styled.node "date-picker_"
                [ Html.Styled.Attributes.attribute "date_value" value
                , Ev.on "date_value" (Decode.field "detail" Decode.string)
                ]
                []
    in
    root```

@janwirth
Copy link
Author

janwirth commented Jul 7, 2022

Why react does not embrace custom elements
facebook/react#5052

  • react has a "one-way data flow, non-imperative"
  • custom elements have no SSR support

@janwirth
Copy link
Author

janwirth commented Jul 7, 2022

@janwirth
Copy link
Author

janwirth commented Jul 18, 2022

Wheel picker:
https://ellie-app.com/j5kZnwCGhz4a1

(updated version in go-outreach / gearbag codebase)

@janwirth
Copy link
Author

janwirth commented Jul 21, 2022

@janwirth
Copy link
Author

@janwirth
Copy link
Author

@janwirth
Copy link
Author

Fetching data / hooks with custom elements

https://ellie-app.com/jDDr5jYsYW7a1

@janwirth
Copy link
Author

janwirth commented Nov 9, 2022

Quoting @billstclair from the elm slack.

In using TweetDeck recently, I noticed that it responds properly to my Mac settings, entering Dark mode at night and going back to Light mode during the day. I didn’t know before now that there was an HTML DOM API for that, so I found it, and created a custom-element to send those notifications to Elm.
An example is at mammudeck.com/watch-color-scheme.html (change your system color scheme and watch the example window change).
To get it to work in your own application, you need two files:
The CustomElement.WatchColorScheme module.
watch-color-scheme.js, which must be loaded in the head section of your index.html.
Then you add a watchColorScheme element to your view method, with an onChange attribute, and a Msg to handle the changes.
This commit shows those two, plus the other files necessary for the example (and a lower-level example, which tests the JS in JS, without Elm).
I have not yet integrated this into the Mammudeck application. Soon.
I also haven’t tested the code on Windows or Linux, or in any non-Chromium browsers (I did Brave and Chrome on my M2 MacBook Air). If you do so, and it doesn’t work, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment