forked from shibao/cannery
		
	add shading to table component
This commit is contained in:
		@@ -1,3 +1,6 @@
 | 
				
			|||||||
 | 
					# v0.6.1
 | 
				
			||||||
 | 
					- Add shading to table component
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# v0.6.0
 | 
					# v0.6.0
 | 
				
			||||||
- Update translations
 | 
					- Update translations
 | 
				
			||||||
- Display used-up date on used-up ammo
 | 
					- Display used-up date on used-up ammo
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ defmodule CanneryWeb.Components.TableComponent do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  use CanneryWeb, :live_component
 | 
					  use CanneryWeb, :live_component
 | 
				
			||||||
  alias Phoenix.LiveView.Socket
 | 
					  alias Phoenix.LiveView.Socket
 | 
				
			||||||
 | 
					  require Integer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @impl true
 | 
					  @impl true
 | 
				
			||||||
  @spec update(
 | 
					  @spec update(
 | 
				
			||||||
@@ -30,6 +31,8 @@ defmodule CanneryWeb.Components.TableComponent do
 | 
				
			|||||||
                required(:label) => String.t() | nil,
 | 
					                required(:label) => String.t() | nil,
 | 
				
			||||||
                required(:key) => atom() | nil,
 | 
					                required(:key) => atom() | nil,
 | 
				
			||||||
                optional(:class) => String.t(),
 | 
					                optional(:class) => String.t(),
 | 
				
			||||||
 | 
					                optional(:row_class) => String.t(),
 | 
				
			||||||
 | 
					                optional(:alternate_row_class) => String.t(),
 | 
				
			||||||
                optional(:sortable) => false
 | 
					                optional(:sortable) => false
 | 
				
			||||||
              }),
 | 
					              }),
 | 
				
			||||||
            required(:rows) =>
 | 
					            required(:rows) =>
 | 
				
			||||||
@@ -57,7 +60,7 @@ defmodule CanneryWeb.Components.TableComponent do
 | 
				
			|||||||
        :asc
 | 
					        :asc
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rows = rows |> Enum.sort_by(fn row -> row |> Map.get(initial_key) end, initial_sort_mode)
 | 
					    rows = rows |> sort_by_custom_sort_value_or_value(initial_key, initial_sort_mode)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    socket =
 | 
					    socket =
 | 
				
			||||||
      socket
 | 
					      socket
 | 
				
			||||||
@@ -68,6 +71,8 @@ defmodule CanneryWeb.Components.TableComponent do
 | 
				
			|||||||
        last_sort_key: initial_key,
 | 
					        last_sort_key: initial_key,
 | 
				
			||||||
        sort_mode: initial_sort_mode
 | 
					        sort_mode: initial_sort_mode
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
 | 
					      |> assign_new(:row_class, fn -> "bg-white" end)
 | 
				
			||||||
 | 
					      |> assign_new(:alternate_row_class, fn -> "bg-gray-200" end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {:ok, socket}
 | 
					    {:ok, socket}
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,8 +33,8 @@
 | 
				
			|||||||
      </tr>
 | 
					      </tr>
 | 
				
			||||||
    </thead>
 | 
					    </thead>
 | 
				
			||||||
    <tbody>
 | 
					    <tbody>
 | 
				
			||||||
      <%= for values <- @rows do %>
 | 
					      <%= for {values, i} <- @rows |> Enum.with_index() do %>
 | 
				
			||||||
        <tr>
 | 
					        <tr class={if i |> Integer.is_even(), do: @row_class, else: @alternate_row_class}>
 | 
				
			||||||
          <%= for %{key: key} = value <- @columns do %>
 | 
					          <%= for %{key: key} = value <- @columns do %>
 | 
				
			||||||
            <td class={"p-2 #{value[:class]}"}>
 | 
					            <td class={"p-2 #{value[:class]}"}>
 | 
				
			||||||
              <%= case values |> Map.get(key) do %>
 | 
					              <%= case values |> Map.get(key) do %>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -138,7 +138,7 @@ defmodule CanneryWeb.HomeLive do
 | 
				
			|||||||
            target="_blank"
 | 
					            target="_blank"
 | 
				
			||||||
            rel="noopener noreferrer"
 | 
					            rel="noopener noreferrer"
 | 
				
			||||||
          >
 | 
					          >
 | 
				
			||||||
            <p>0.6.0</p>
 | 
					            <p>0.6.1</p>
 | 
				
			||||||
            <i class="fas fa-md fa-info-circle"></i>
 | 
					            <i class="fas fa-md fa-info-circle"></i>
 | 
				
			||||||
          </.link>
 | 
					          </.link>
 | 
				
			||||||
        </li>
 | 
					        </li>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								mix.exs
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								mix.exs
									
									
									
									
									
								
							@@ -4,7 +4,7 @@ defmodule Cannery.MixProject do
 | 
				
			|||||||
  def project do
 | 
					  def project do
 | 
				
			||||||
    [
 | 
					    [
 | 
				
			||||||
      app: :cannery,
 | 
					      app: :cannery,
 | 
				
			||||||
      version: "0.6.0",
 | 
					      version: "0.6.1",
 | 
				
			||||||
      elixir: "1.14.1",
 | 
					      elixir: "1.14.1",
 | 
				
			||||||
      elixirc_paths: elixirc_paths(Mix.env()),
 | 
					      elixirc_paths: elixirc_paths(Mix.env()),
 | 
				
			||||||
      compilers: Mix.compilers(),
 | 
					      compilers: Mix.compilers(),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user