diff --git a/lib/livebook_web/components/form_components.ex b/lib/livebook_web/components/form_components.ex index f0abaa7b6..abb7c6bdd 100644 --- a/lib/livebook_web/components/form_components.ex +++ b/lib/livebook_web/components/form_components.ex @@ -216,6 +216,45 @@ defmodule LivebookWeb.FormComponents do """ end + @doc """ + Renders checkbox input with label and error messages. + """ + attr :id, :any, default: nil + attr :name, :any + attr :label, :string, default: nil + attr :value, :any + attr :errors, :list, default: [] + attr :field, Phoenix.HTML.FormField, doc: "a form field struct retrieved from the form" + + attr :disabled, :boolean, default: false + attr :checked_value, :string, default: "true" + attr :unchecked_value, :string, default: "false" + + attr :rest, :global + + def checkbox_field(assigns) do + assigns = assigns_from_field(assigns) + + ~H""" +
+ + <.error :for={msg <- @errors}><%= msg %> +
+ """ + end + @doc """ Renders radio inputs with label and error messages. """ diff --git a/lib/livebook_web/live/session_live/app_info_component.ex b/lib/livebook_web/live/session_live/app_info_component.ex index 1001195de..5d29d0a37 100644 --- a/lib/livebook_web/live/session_live/app_info_component.ex +++ b/lib/livebook_web/live/session_live/app_info_component.ex @@ -71,18 +71,20 @@ defmodule LivebookWeb.SessionLive.AppInfoComponent do >
<.text_field field={f[:slug]} label="Slug" spellcheck="false" phx-debounce="blur" /> - <.switch_field - field={f[:access_type]} - label="Password-protected" - checked_value="protected" - unchecked_value="public" - /> - <%= if Ecto.Changeset.get_field(@changeset, :access_type) == :protected do %> - <.password_field field={f[:password]} spellcheck="false" phx-debounce="blur" /> - <% end %> - <.switch_field field={f[:show_source]} label="Show source" /> +
+ <.checkbox_field + field={f[:access_type]} + label="Password-protected" + checked_value="protected" + unchecked_value="public" + /> + <%= if Ecto.Changeset.get_field(@changeset, :access_type) == :protected do %> + <.password_field field={f[:password]} spellcheck="false" phx-debounce="blur" /> + <% end %> +
+ <.checkbox_field field={f[:show_source]} label="Show source" />
-
+