|
| 1 | +defmodule LightningWeb.Dev.ReactLive do |
| 2 | + # Internal Development Page for viewing and working on React components. |
| 3 | + # Access this page at /dev/react |
| 4 | + @moduledoc false |
| 5 | + use LightningWeb, {:live_view, layout: {LightningWeb.Layouts, :blank}} |
| 6 | + |
| 7 | + import React |
| 8 | + |
| 9 | + @impl true |
| 10 | + def mount(_params, _session, socket) do |
| 11 | + socket = assign(socket, :baz, 0) |
| 12 | + {:ok, socket} |
| 13 | + end |
| 14 | + |
| 15 | + @impl true |
| 16 | + def handle_event("inc", _params, socket) do |
| 17 | + {:noreply, update(socket, :baz, &(&1 + 1))} |
| 18 | + end |
| 19 | + |
| 20 | + attr :foo, :integer |
| 21 | + slot :inner_block |
| 22 | + jsx("components/Foo.tsx") |
| 23 | + |
| 24 | + slot :before |
| 25 | + slot :inner_block, required: true |
| 26 | + slot :after, required: true |
| 27 | + jsx("components/Bar.tsx") |
| 28 | + |
| 29 | + attr :baz, :integer, default: 0 |
| 30 | + jsx("components/Baz.tsx") |
| 31 | + |
| 32 | + @impl true |
| 33 | + def render(assigns) do |
| 34 | + assigns = assign(assigns, foo: 42) |
| 35 | + |
| 36 | + ~H""" |
| 37 | + <.Foo foo={@foo}> |
| 38 | + <.Bar> |
| 39 | + <:before> |
| 40 | + <p style="color: blue">Bar before slot</p> |
| 41 | + </:before> |
| 42 | + <.Baz baz={@baz} /> |
| 43 | + <:after> |
| 44 | + <p style="color: red">Bar after slot</p> |
| 45 | + </:after> |
| 46 | + </.Bar> |
| 47 | + </.Foo> |
| 48 | + <button |
| 49 | + phx-click="inc" |
| 50 | + class="inline-flex justify-center items-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 phx-submit-loading:opacity-75 bg-primary-600 hover:bg-primary-700 text-white focus:ring-primary-500 disabled:bg-primary-300 rounded-md" |
| 51 | + > |
| 52 | + Increment |
| 53 | + </button> |
| 54 | + """ |
| 55 | + end |
| 56 | +end |
0 commit comments