defmodule Moon.Components.TextInput.TextInputPassword do @moduledoc false use Moon.StatefulComponent alias Moon.Components.TextInput.Container alias Moon.Components.TextInput.Password alias Moon.Components.TextInput.Utils alias Moon.Components.TextInput.ShowPassword alias Moon.Components.ErrorTag data(password_shown, :boolean, default: false) data(password, :string, default: "") prop(field, :atom) prop(class, :css_class) slot(default) slot(left_icon_slot) slot(right_icon_slot) data(disabled, :boolean, from_context: {Moon.Components.TextInput, :disabled}) data(size, :string, from_context: {Moon.Components.TextInput, :size}) data(is_error, :boolean, from_context: {Moon.Components.TextInput, :is_error}) data(background_color, :string, from_context: {Moon.Components.TextInput, :background_color}) data(label, :string, from_context: {Moon.Components.TextInput, :label}) data(use_error_tag, :boolean, from_context: {Moon.Components.TextInput, :use_error_tag}) data(show_password_text, :string, from_context: {Moon.Components.TextInput, :show_password_text} ) data(has_left_icon, :boolean, from_context: {Moon.Components.TextInput, :has_left_icon}) def render(assigns) do ~F""" {#if @size == "xl"}
{@show_password_text}
<#slot {@left_icon_slot} />
<#slot {@right_icon_slot} />
<#slot />
{#else}
{@show_password_text}
<#slot {@left_icon_slot} />
<#slot {@right_icon_slot} />
<#slot />
{/if}
""" end def handle_event("toggle_password_visibility", _, socket) do {:noreply, assign(socket, password_shown: !socket.assigns.password_shown)} end def handle_event("on_keyup", params, socket) do {:noreply, assign(socket, password: params["value"])} end defp get_type(password_shown) do if password_shown do "text" else "password" end end end