Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2018 05:33
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
defmodule DemoWeb.ImageView do
use Phoenix.LiveView
def render(assigns) do
<form phx-change="update">
<input type="range" min="10" max="630" name="width" value="<%= @width %>" />
<%= @width %>px
White <%= radio_tag(name: :bg, value: "white", checked: @bg) %>
Black <%= radio_tag(name: :bg, value: "black", checked: @bg) %>
Blue <%= radio_tag(name: :bg, value: "blue", checked: @bg) %>
<img src="/images/phx.png" width="<%= @width %>" style="background: <%= @bg %>;" />
def radio_tag(assigns) do
<input type="radio" name="<%= @name %>" value="<%= @value %>"
<%= if @value == @checked, do: "checked" %> />
def mount(_session, socket) do
{:ok, assign(socket, width: 100, bg: "white")}
def handle_event("update", %{"width" => width, "bg" => bg}, socket) do
{:noreply, assign(socket, width: String.to_integer(width), bg: bg)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment