Skip to content

Commit 32114c8

Browse files
authored
Merge pull request #76 from Munksgaard/fix-75
use different styling options for clear_button and clear_tag_button
2 parents ae285ff + 5283ed4 commit 32114c8

File tree

7 files changed

+16
-12
lines changed

7 files changed

+16
-12
lines changed

lib/live_select.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ defmodule LiveSelect do
437437
doc:
438438
"Event to emit when the text input receives focus. The component id will be sent in the event's params"
439439

440-
@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
440+
@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
441441

442442
for attr_name <- @styling_options do
443443
Phoenix.Component.Declarative.__attr__!(

lib/live_select/component.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule LiveSelect.Component do
1616
available_option_class: nil,
1717
clear_button_class: nil,
1818
clear_button_extra_class: nil,
19+
clear_tag_button_class: nil,
20+
clear_tag_button_extra_class: nil,
1921
user_defined_options: false,
2022
container_class: nil,
2123
container_extra_class: nil,

lib/live_select/component.html.heex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
type="button"
2525
data-idx={idx}
2626
class={
27-
class(@style, :clear_tag_button, @clear_button_class, @clear_button_extra_class)
27+
class(
28+
@style,
29+
:clear_tag_button,
30+
@clear_tag_button_class,
31+
@clear_tag_button_extra_class
32+
)
2833
}
2934
>
3035
<%= if @clear_button == [] do %>

lib/mix/tasks/dump_style_table.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ defmodule Mix.Tasks.DumpStyleTable do
3535
|> IO.write()
3636
end
3737

38-
defp class_override_option(:clear_tag_button), do: class_override_option(:clear_button)
39-
4038
defp class_override_option(el) do
4139
option_name = to_string(el) <> "_class"
4240
if option_name in class_options(), do: option_name, else: ""
4341
end
4442

45-
defp class_extend_option(:clear_tag_button), do: class_extend_option(:clear_button)
46-
4743
defp class_extend_option(el) do
4844
option_name = to_string(el) <> "_extra_class"
4945
if option_name in class_options(), do: option_name, else: ""

styling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The following table shows the default styles for each element and the options yo
6262
| *active_option* | active | bg-gray-600 text-white | active_option_class | |
6363
| *available_option* | cursor-pointer | cursor-pointer hover:bg-gray-400 rounded | available_option_class | |
6464
| *clear_button* | cursor-pointer hidden | cursor-pointer hidden | clear_button_class | clear_button_extra_class |
65-
| *clear_tag_button* | cursor-pointer | cursor-pointer | clear_button_class | clear_button_extra_class |
65+
| *clear_tag_button* | cursor-pointer | cursor-pointer | clear_tag_button_class | clear_tag_button_extra_class |
6666
| *container* | dropdown dropdown-open | h-full relative text-black | container_class | container_extra_class |
6767
| *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 |
6868
| *option* | | px-4 py-1 rounded | option_class | option_extra_class |

test/live_select/component_test.exs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,7 @@ defmodule LiveSelect.ComponentTest do
492492
Keyword.values(
493493
Keyword.drop(override_class_option(), [
494494
:available_option,
495-
:selected_option,
496-
:clear_button,
497-
:clear_tag_button
495+
:selected_option
498496
])
499497
),
500498
Keyword.values(extend_class_option())
@@ -512,7 +510,8 @@ defmodule LiveSelect.ComponentTest do
512510
field: form[:input],
513511
options: ["A", "B", "C"],
514512
value: ["A", "B"],
515-
mode: :tags,
513+
allow_clear: @override_class == :clear_button_class,
514+
mode: if(@override_class == :clear_button_class, do: :single, else: :tags),
516515
hide_dropdown: false
517516
]
518517
|> Keyword.put(@override_class, "foo")

test/support/helpers.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule LiveSelect.TestHelpers do
4242
@override_class_option [
4343
available_option: :available_option_class,
4444
clear_button: :clear_button_class,
45-
clear_tag_button: :clear_button_class,
45+
clear_tag_button: :clear_tag_button_class,
4646
container: :container_class,
4747
dropdown: :dropdown_class,
4848
option: :option_class,
@@ -54,6 +54,8 @@ defmodule LiveSelect.TestHelpers do
5454
def override_class_option, do: @override_class_option
5555

5656
@extend_class_option [
57+
clear_button: :clear_button_extra_class,
58+
clear_tag_button: :clear_tag_button_extra_class,
5759
container: :container_extra_class,
5860
dropdown: :dropdown_extra_class,
5961
option: :option_extra_class,

0 commit comments

Comments
 (0)