Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use different styling options for clear_button and clear_tag_button #76

Merged
merged 4 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 Expand Up @@ -565,7 +564,7 @@
)

assert Floki.attribute(component, selectors()[@element], "class") == [
get_in(expected_class(), [@style || default_style(), @element]) || ""

Check warning on line 567 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 567 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result
]
end

Expand Down Expand Up @@ -628,7 +627,7 @@
)

assert Floki.attribute(component, selectors()[@element], "class") == [
((get_in(expected_class(), [@style || default_style(), @element]) || "") <>

Check warning on line 630 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 630 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result
" foo")
|> String.trim()
]
Expand All @@ -650,7 +649,7 @@
)

assert Floki.attribute(component, selectors()[@element], "class") == [
((get_in(expected_class(), [@style || default_style(), @element]) || "") <>

Check warning on line 652 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 652 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result
" foo goo")
|> String.trim()
]
Expand All @@ -660,7 +659,7 @@
%{form: form} do
option = extend_class_option()[@element]

base_classes = get_in(expected_class(), [@style || default_style(), @element])

Check warning on line 662 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 662 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result

if base_classes do
class_to_remove = String.split(base_classes) |> List.first()
Expand Down Expand Up @@ -702,9 +701,9 @@
)

expected_class =
(get_in(expected_class(), [@style || default_style(), :text_input]) || "") <>

Check warning on line 704 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 704 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result
" " <>
(get_in(expected_class(), [@style || default_style(), :text_input_selected]) || "")

Check warning on line 706 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 706 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result

assert Floki.attribute(component, selectors()[:text_input], "class") == [
String.trim(expected_class)
Expand All @@ -725,7 +724,7 @@
)

expected_class =
(get_in(expected_class(), [@style || default_style(), :text_input]) || "") <>

Check warning on line 727 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result

Check warning on line 727 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.15.0 otp 26.0

this check/guard will always yield the same result
" foo"

assert Floki.attribute(component, selectors()[:text_input], "class") == [
Expand All @@ -749,7 +748,7 @@
assert_selected_option_class(
component,
2,
get_in(expected_class(), [@style || default_style(), :selected_option]) || ""

Check warning on line 751 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result
)
end

Expand Down Expand Up @@ -790,7 +789,7 @@
assert_available_option_class(
component,
2,
get_in(expected_class(), [@style || default_style(), :available_option]) || ""

Check warning on line 792 in test/live_select/component_test.exs

View workflow job for this annotation

GitHub Actions / Build and test with elixir 1.14.0 otp 25.0

this check/guard will always yield the same result
)
end

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
Loading