pokemon-couture/lib/pokemon_couture_web/live/components/clothes_component.ex

43 lines
819 B
Elixir
Raw Normal View History

2021-09-13 14:36:14 +02:00
defmodule PokemonCoutureWeb.Components.ClothesComponent do
use Phoenix.LiveComponent
def mount(socket) do
socket =
socket
|> assign(active: true)
{:ok, socket}
end
def render(assigns) do
~L"""
<tr>
<td><%= @clothes.name %></td>
<td><%= @clothes.color %></td>
<td><%= @clothes.game %></td>
<td>
<button
phx-click="toggle-active"
phx-target="<%= @myself %>"
>
<%= if @active do %>
Got it
<% else %>
X
<% end %>
</button>
<!-- here be acquire buton -->
</td>
</tr>
"""
end
def handle_event("toggle-active", _value, socket) do
socket =
socket
|> assign(:active, not socket.assigns.active)
{:noreply, socket}
end
end