improve components
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
shibao 2023-03-23 00:22:04 -04:00
parent 5a41d8b3e7
commit cb049cb178
2 changed files with 23 additions and 2 deletions

View File

@ -1,4 +1,4 @@
<label for={@id || @action} class="inline-flex relative items-center cursor-pointer"> <label for={@id || @action} class="relative inline-flex items-center cursor-pointer">
<input <input
id={@id || @action} id={@id || @action}
type="checkbox" type="checkbox"
@ -23,7 +23,7 @@
</div> </div>
<span <span
id={"#{@id || @action}-label"} id={"#{@id || @action}-label"}
class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300" class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300 whitespace-nowrap"
> >
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
</span> </span>

View File

@ -135,4 +135,25 @@ defmodule MemexWeb.Components.TableComponent do
sort_mode sort_mode
) )
end end
@doc """
Conditionally composes elements into the columns list, supports maps and
lists. Works tail to front in order for efficiency
iex> []
...> |> maybe_compose_columns(%{label: "Column 3"}, true)
...> |> maybe_compose_columns(%{label: "Column 2"}, false)
...> |> maybe_compose_columns(%{label: "Column 1"})
[%{label: "Column 1"}, %{label: "Column 3"}]
"""
@spec maybe_compose_columns(list(), element_to_add :: list() | map()) :: list()
@spec maybe_compose_columns(list(), element_to_add :: list() | map(), boolean()) :: list()
def maybe_compose_columns(columns, element_or_elements, add? \\ true)
def maybe_compose_columns(columns, elements, true) when is_list(elements),
do: Enum.concat(elements, columns)
def maybe_compose_columns(columns, element, true) when is_map(element), do: [element | columns]
def maybe_compose_columns(columns, _element_or_elements, false), do: columns
end end