Skip to content

Commit

Permalink
use different styling options for clear_button and clear_tag_button
Browse files Browse the repository at this point in the history
Fixes: #75
  • Loading branch information
Munksgaard committed Jul 12, 2024
1 parent ae285ff commit 4c86c6b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 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_tag_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

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
2 changes: 1 addition & 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 Down

0 comments on commit 4c86c6b

Please sign in to comment.