Skip to content

Commit

Permalink
Merge pull request #76 from Munksgaard/fix-75
Browse files Browse the repository at this point in the history
use different styling options for clear_button and clear_tag_button
  • Loading branch information
maxmarcon authored Jul 14, 2024
2 parents ae285ff + 5283ed4 commit 32114c8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/live_select.ex
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ defmodule LiveSelect do
doc:
"Event to emit when the text input receives focus. The component id will be sent in the event's params"

@styling_options ~w(active_option_class available_option_class clear_button_class container_class container_extra_class dropdown_class dropdown_extra_class option_class option_extra_class text_input_class text_input_extra_class text_input_selected_class selected_option_class tag_class tag_extra_class tags_container_class tags_container_extra_class)a
@styling_options ~w(active_option_class available_option_class clear_button_class clear_button_extra_class clear_tag_button_class clear_tag_button_extra_class container_class container_extra_class dropdown_class dropdown_extra_class option_class option_extra_class text_input_class text_input_extra_class text_input_selected_class selected_option_class tag_class tag_extra_class tags_container_class tags_container_extra_class)a

for attr_name <- @styling_options do
Phoenix.Component.Declarative.__attr__!(
Expand Down
2 changes: 2 additions & 0 deletions lib/live_select/component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ defmodule LiveSelect.Component do
available_option_class: nil,
clear_button_class: nil,
clear_button_extra_class: nil,
clear_tag_button_class: nil,
clear_tag_button_extra_class: nil,
user_defined_options: false,
container_class: nil,
container_extra_class: nil,
Expand Down
7 changes: 6 additions & 1 deletion lib/live_select/component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
type="button"
data-idx={idx}
class={
class(@style, :clear_tag_button, @clear_button_class, @clear_button_extra_class)
class(
@style,
:clear_tag_button,
@clear_tag_button_class,
@clear_tag_button_extra_class
)
}
>
<%= if @clear_button == [] do %>
Expand Down
4 changes: 0 additions & 4 deletions lib/mix/tasks/dump_style_table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ defmodule Mix.Tasks.DumpStyleTable do
|> IO.write()
end

defp class_override_option(:clear_tag_button), do: class_override_option(:clear_button)

defp class_override_option(el) do
option_name = to_string(el) <> "_class"
if option_name in class_options(), do: option_name, else: ""
end

defp class_extend_option(:clear_tag_button), do: class_extend_option(:clear_button)

defp class_extend_option(el) do
option_name = to_string(el) <> "_extra_class"
if option_name in class_options(), do: option_name, else: ""
Expand Down
2 changes: 1 addition & 1 deletion styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following table shows the default styles for each element and the options yo
| *active_option* | active | bg-gray-600 text-white | active_option_class | |
| *available_option* | cursor-pointer | cursor-pointer hover:bg-gray-400 rounded | available_option_class | |
| *clear_button* | cursor-pointer hidden | cursor-pointer hidden | clear_button_class | clear_button_extra_class |
| *clear_tag_button* | cursor-pointer | cursor-pointer | clear_button_class | clear_button_extra_class |
| *clear_tag_button* | cursor-pointer | cursor-pointer | clear_tag_button_class | clear_tag_button_extra_class |
| *container* | dropdown dropdown-open | h-full relative text-black | container_class | container_extra_class |
| *dropdown* | bg-base-200 dropdown-content menu menu-compact p-1 rounded-box shadow w-full z-[1] | absolute bg-gray-100 inset-x-0 rounded-md shadow top-full z-50 | dropdown_class | dropdown_extra_class |
| *option* | | px-4 py-1 rounded | option_class | option_extra_class |
Expand Down
7 changes: 3 additions & 4 deletions test/live_select/component_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ defmodule LiveSelect.ComponentTest do
Keyword.values(
Keyword.drop(override_class_option(), [
:available_option,
:selected_option,
:clear_button,
:clear_tag_button
:selected_option
])
),
Keyword.values(extend_class_option())
Expand All @@ -512,7 +510,8 @@ defmodule LiveSelect.ComponentTest do
field: form[:input],
options: ["A", "B", "C"],
value: ["A", "B"],
mode: :tags,
allow_clear: @override_class == :clear_button_class,
mode: if(@override_class == :clear_button_class, do: :single, else: :tags),
hide_dropdown: false
]
|> Keyword.put(@override_class, "foo")
Expand Down
4 changes: 3 additions & 1 deletion test/support/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule LiveSelect.TestHelpers do
@override_class_option [
available_option: :available_option_class,
clear_button: :clear_button_class,
clear_tag_button: :clear_button_class,
clear_tag_button: :clear_tag_button_class,
container: :container_class,
dropdown: :dropdown_class,
option: :option_class,
Expand All @@ -54,6 +54,8 @@ defmodule LiveSelect.TestHelpers do
def override_class_option, do: @override_class_option

@extend_class_option [
clear_button: :clear_button_extra_class,
clear_tag_button: :clear_tag_button_extra_class,
container: :container_extra_class,
dropdown: :dropdown_extra_class,
option: :option_extra_class,
Expand Down

0 comments on commit 32114c8

Please sign in to comment.