Created
March 28, 2024 12:31
-
-
Save lubien/eb38a2d7e1d3a4f552e66fb95006fa69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mix.install([ | |
{:liveview_playground, "~> 0.1.1"} | |
]) | |
defmodule PageLive do | |
use LiveviewPlaygroundWeb, :live_view | |
def mount(_params, _session, socket) do | |
socket = assign(socket, tab: "home") | |
{:ok, socket} | |
end | |
def render(assigns) do | |
~H""" | |
<div> | |
<%= case @tab do %> | |
<% "home" -> %> | |
<p>You're on my personal page!</p> | |
<% "about" -> %> | |
<p>Hi, I'm a LiveView developer!</p> | |
<% "contact" -> %> | |
<p>Mail me to bot [at] company [dot] com</p> | |
<% end %> | |
</div> | |
<input :if={@tab != "home"} type="button" value="Open Home" phx-click="show_home" > | |
<input :if={@tab != "about"} type="button" value="Open About" phx-click="show_about" > | |
<input :if={@tab != "contact"} type="button" value="Open Contact" phx-click="show_contact" > | |
""" | |
end | |
def handle_event("show_home", _params, socket) do | |
socket = assign(socket, tab: "home") | |
{:noreply, socket} | |
end | |
def handle_event("show_about", _params, socket) do | |
socket = assign(socket, tab: "about") | |
{:noreply, socket} | |
end | |
def handle_event("show_contact", _params, socket) do | |
socket = assign(socket, tab: "contact") | |
{:noreply, socket} | |
end | |
end | |
LiveviewPlayground.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment