From 5e6033e261b33073f263836f83d2b30b91d1b149 Mon Sep 17 00:00:00 2001 From: Vinicius Brasil Date: Thu, 30 Nov 2023 15:02:36 -0300 Subject: [PATCH] Move input range bubble to JavaScript (#3569) * Move input range bubble to JavaScript This commit switches the input range bubble on the choose plan page from LiveView to JavaScript. The reason for this change is the input range is a regular HTML input rendered by the browser, not LV, therefore bubble was not in sync when sliding the input. * Apply suggestions from code review --- lib/plausible_web/live/choose_plan.ex | 49 +++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.ex index 53922907d..f6fb0b3cc 100644 --- a/lib/plausible_web/live/choose_plan.ex +++ b/lib/plausible_web/live/choose_plan.ex @@ -231,47 +231,62 @@ defmodule PlausibleWeb.Live.ChoosePlan do end defp slider(assigns) do - selected_index = - Enum.find_index(assigns.available_volumes, &(&1 == assigns.selected_volume)) || - length(assigns.available_volumes) + slider_labels = + Enum.map( + assigns.available_volumes ++ [:enterprise], + &format_volume(&1, assigns.available_volumes) + ) - slider_percentage = selected_index / length(assigns.available_volumes) * 100 - bubble_position = "left: calc(#{slider_percentage}% + #{13.87 - slider_percentage * 0.26}px)" - - assigns = - assigns - |> assign(:selected_index, selected_index) - |> assign(:bubble_position, bubble_position) + assigns = assign(assigns, :slider_labels, slider_labels) ~H"""
- <%= format_volume(List.first(@available_volumes), @available_volumes) %> + <%= List.first(@slider_labels) %>
- <%= format_volume(@selected_volume, @available_volumes) %> - + phx-update="ignore" + />
- <%= format_volume(List.last(@available_volumes), @available_volumes) <> "+" %> + <%= List.last(@slider_labels) %>
+ + """ end