Phoenix.WebComponent

release

Collection of helpers to generate and manipulate Web Component.

Although this project was originally extracted from Phoenix, it does not depend on Phoenix and can be used with any Plug application (or even without Plug).

See the docs for more information.

About at Web Component

Install

Add deps in mix.exs

    {:phoenix_webcomponent, "~> 2.0"},

Include in phoenix view helpers

 defp view_helpers do
    quote do
        # import all helper functions
        use Phoenix.WebComponent

        # or 
        use Phoenix.WebComponent, :alias
        ...
    end
end

Include javascript

import 'phoenix_webcomponent';

Use custom hook

import "phoenix_webcomponent";
const PhxWCHook = window.__PhxWCHook__;
const liveSocket = new LiveSocket("/live", Socket, {hooks: { PhxWCHook }});

Send custom events to live view:

<Element phx-wc-send-sync-content="load_content" phx-hook="PhxWCHook" />
<Element phx-wc-send-sync-content="load_content;loadAccepted" phx-hook="PhxWCHook" />

Receive live view event:

<Element phx-wc-receive-update_content="updateContent" phx-hook="PhxWCHook" />
<!-- equal  -->

<Element phx-wc-receive="update_content;updateContent" phx-hook="PhxWCHook" />

Import CSS

import "phoenix_webcomponent/priv/static/phoenix_webcomponent.css"

All helpers

Live Storybook

Live Storybook