improve components
This commit is contained in:
		| @@ -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> | ||||||
|   | |||||||
| @@ -135,4 +135,25 @@ defmodule CanneryWeb.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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user