diff --git a/assets/js/app.js b/assets/js/app.js index 14160ad39..7d16bfddd 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -27,6 +27,12 @@ window.addEventListener(`phx:update-value`, (e) => { el.value = e.detail.value }) +window.addEventListener(`phx:hide`, (e) => { + console.info(e) + let el = document.getElementById(e.detail.id) + el.style.display = 'none' +}) + const triggers = document.querySelectorAll('[data-dropdown-trigger]') for (const trigger of triggers) { diff --git a/lib/plausible_web/live/funnel_settings/form.ex b/lib/plausible_web/live/funnel_settings/form.ex index 7d8642d1d..e2ba53ee1 100644 --- a/lib/plausible_web/live/funnel_settings/form.ex +++ b/lib/plausible_web/live/funnel_settings/form.ex @@ -29,7 +29,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form do options={Enum.map(@goals, fn goal -> {goal.id, Plausible.Goal.display_name(goal)} end)} /> - + Add another step + + Add another step
diff --git a/lib/plausible_web/live/funnel_settings/input_picker.ex b/lib/plausible_web/live/funnel_settings/input_picker.ex index b5b418c85..606732b03 100644 --- a/lib/plausible_web/live/funnel_settings/input_picker.ex +++ b/lib/plausible_web/live/funnel_settings/input_picker.ex @@ -1,182 +1,205 @@ defmodule PlausibleWeb.Live.FunnelSettings.InputPicker do use Phoenix.LiveComponent + alias Phoenix.LiveView.JS - attr :placeholder, :string, default: "Select a Goal" + def update(assigns, socket) do + socket = + socket + |> assign(assigns) + |> assign(:candidate, 0) + |> assign_new(:display_value, fn -> "" end) + |> assign_new(:submit_value, fn -> "" end) + |> assign_new(:choices, fn -> assigns.options end) + + {:ok, socket} + end + + attr :placeholder, :string, default: "Select option" attr :id, :any, default: nil - attr :options, :list, default: [] - attr :choices, :list, default: nil - attr :show_picker?, :boolean, default: false - attr :value, :string, default: "" - attr :goal_id, :string, default: "" - attr :higlighted, :integer, default: nil + attr :options, :list, required: true - ## XXX handle phx-blur properly on tab def render(assigns) do ~H"""
- - - -
- -
- + + + <.dropdown_anchor id={@id}/> + +
- <.picker id={"picker-#{@id}"} :if={@show_picker?} options={@options} choices={@choices || @options} target={@myself} higlighted={@higlighted} /> + <.dropdown ref={@id} options={@options} choices={@choices} target={@myself} candidate={@candidate} />
""" end - attr :id, :any, default: nil + attr :id, :any, required: true + + def dropdown_anchor(assigns) do + ~H""" +
+ +
+ """ + end + + def open_dropdown(js \\ %JS{}, id) do + JS.show(js, to: "#dropdown-#{id}") + end + + def close_dropdown(js \\ %JS{}, id) do + JS.hide(js, to: "#dropdown-#{id}") + end + + attr :ref, :string, required: true attr :options, :list, default: [] attr :choices, :list, default: [] - attr :higlighted, :any + attr :candidate, :integer, required: true attr :target, :any - def picker(assigns) do + def dropdown(assigns) do ~H""" -