This commit is contained in:
Chris McCord 2022-05-13 14:52:19 -04:00
parent f1908151f9
commit 433a2f7faf
5 changed files with 199 additions and 108 deletions

View file

@ -1,5 +1,6 @@
// See the Tailwind configuration guide for advanced usage // See the Tailwind configuration guide for advanced usage
// https://tailwindcss.com/docs/configuration // https://tailwindcss.com/docs/configuration
module.exports = { module.exports = {
content: [ content: [
'./js/**/*.js', './js/**/*.js',

View file

@ -1,6 +1,5 @@
defmodule LiveBeatsWeb.LiveHelpers do defmodule LiveBeatsWeb.LiveHelpers do
import Phoenix.LiveView use Phoenix.Component
import Phoenix.LiveView.Helpers
alias LiveBeatsWeb.Router.Helpers, as: Routes alias LiveBeatsWeb.Router.Helpers, as: Routes
alias Phoenix.LiveView.JS alias Phoenix.LiveView.JS
@ -35,9 +34,21 @@ defmodule LiveBeatsWeb.LiveHelpers do
> >
<div class="flex"> <div class="flex">
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-red-800" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" aria-hidden="true"> <svg
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> class="animate-spin -ml-1 mr-3 h-5 w-5 text-red-800"
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path> xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
aria-hidden="true"
>
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4">
</circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
>
</path>
</svg> </svg>
</div> </div>
<div class="ml-3"> <div class="ml-3">
@ -50,21 +61,30 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
attr :flash, :map
attr :kiny, :atom
def flash(%{kind: :error} = assigns) do def flash(%{kind: :error} = assigns) do
~H""" ~H"""
<%= if live_flash(@flash, @kind) do %> <%= if live_flash(@flash, @kind) do %>
<div <div
id="flash" id="flash"
class="rounded-md bg-red-50 p-4 fixed top-1 right-1 w-96 fade-in-scale z-50" class="rounded-md bg-red-50 p-4 fixed top-1 right-1 w-96 fade-in-scale z-50"
phx-click={JS.push("lv:clear-flash") |> JS.remove_class("fade-in-scale", to: "#flash") |> hide("#flash")} phx-click={
JS.push("lv:clear-flash")
|> JS.remove_class("fade-in-scale", to: "#flash")
|> hide("#flash")
}
phx-hook="Flash" phx-hook="Flash"
> >
<div class="flex justify-between items-center space-x-3 text-red-700"> <div class="flex justify-between items-center space-x-3 text-red-700">
<.icon name={:exclamation_circle} class="w-5 w-5"/> <.icon name={:exclamation_circle} class="w-5 w-5" />
<p class="flex-1 text-sm font-medium" role="alert"> <p class="flex-1 text-sm font-medium" role="alert">
<%= live_flash(@flash, @kind) %> <%= live_flash(@flash, @kind) %>
</p> </p>
<button type="button" class="inline-flex bg-red-50 rounded-md p-1.5 text-red-500 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-red-50 focus:ring-red-600"> <button
type="button"
class="inline-flex bg-red-50 rounded-md p-1.5 text-red-500 hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-red-50 focus:ring-red-600"
>
<.icon name={:x} class="w-4 h-4" /> <.icon name={:x} class="w-4 h-4" />
</button> </button>
</div> </div>
@ -84,11 +104,14 @@ defmodule LiveBeatsWeb.LiveHelpers do
phx-hook="Flash" phx-hook="Flash"
> >
<div class="flex justify-between items-center space-x-3 text-green-700"> <div class="flex justify-between items-center space-x-3 text-green-700">
<.icon name={:check_circle} class="w-5 h-5"/> <.icon name={:check_circle} class="w-5 h-5" />
<p class="flex-1 text-sm font-medium" role="alert"> <p class="flex-1 text-sm font-medium" role="alert">
<%= live_flash(@flash, @kind) %> <%= live_flash(@flash, @kind) %>
</p> </p>
<button type="button" class="inline-flex bg-green-50 rounded-md p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-green-50 focus:ring-green-600"> <button
type="button"
class="inline-flex bg-green-50 rounded-md p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-green-50 focus:ring-green-600"
>
<.icon name={:x} class="w-4 h-4" /> <.icon name={:x} class="w-4 h-4" />
</button> </button>
</div> </div>
@ -99,54 +122,73 @@ defmodule LiveBeatsWeb.LiveHelpers do
def spinner(assigns) do def spinner(assigns) do
~H""" ~H"""
<svg class="inline-block animate-spin h-2.5 w-2.5 text-gray-400" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" aria-hidden="true"> <svg
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle> class="inline-block animate-spin h-2.5 w-2.5 text-gray-400"
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path> xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
aria-hidden="true"
>
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4">
</circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
>
</path>
</svg> </svg>
""" """
end end
attr :name, :atom, required: true
attr :outlined, :boolean, default: false
attr :rest, :global, default: %{class: "w-4 h-4 inline-block"}
def icon(assigns) do def icon(assigns) do
assigns = assigns = assign_new(assigns, :"aria-hidden", fn -> !Map.has_key?(assigns, :"aria-label") end)
assigns
|> assign_new(:outlined, fn -> false end)
|> assign_new(:class, fn -> "w-4 h-4 inline-block" end)
|> assign_new(:"aria-hidden", fn -> !Map.has_key?(assigns, :"aria-label") end)
~H""" ~H"""
<%= if @outlined do %> <%= if @outlined do %>
<%= apply(Heroicons.Outline, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> <%= apply(Heroicons.Outline, @name, [Map.to_list(@rest)]) %>
<% else %> <% else %>
<%= apply(Heroicons.Solid, @name, [assigns_to_attributes(assigns, [:outlined, :name])]) %> <%= apply(Heroicons.Solid, @name, [Map.to_list(@rest)]) %>
<% end %> <% end %>
""" """
end end
attr :navigate, :string
attr :patch, :string
attr :href, :string, default: nil
attr :replace, :string, default: false
attr :rest, :global
def link(%{navigate: _to} = assigns) do def link(%{navigate: _to} = assigns) do
assigns = assign_new(assigns, :class, fn -> nil end) assigns = assign_new(assigns, :class, fn -> nil end)
~H""" ~H"""
<a href={@navigate} data-phx-link="redirect" data-phx-link-state="push" class={@class}> <a href={@navigate} data-phx-link="redirect" data-phx-link-state="push" {@rest}>
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
</a> </a>
""" """
end end
def link(%{patch: to} = assigns) do def link(%{patch: _to} = assigns) do
opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, to)
assigns = assign(assigns, :opts, opts)
~H""" ~H"""
<%= live_patch @opts do %><%= render_slot(@inner_block) %><% end %> <a
href={@patch}
data-phx-link="patch"
data-phx-link-state={if @replace, do: "replace", else: "push"}
{@rest}
>
<%= render_slot(@inner_block) %>
</a>
""" """
end end
def link(%{} = assigns) do def link(%{} = assigns) do
opts = assigns |> assigns_to_attributes() |> Keyword.put(:to, assigns[:href] || "#")
assigns = assign(assigns, :opts, opts)
~H""" ~H"""
<%= Phoenix.HTML.Link.link @opts do %><%= render_slot(@inner_block) %><% end %> <a href={@href || "#"} {@rest}>
<%= render_slot(@inner_block) %>
</a>
""" """
end end
@ -171,13 +213,13 @@ defmodule LiveBeatsWeb.LiveHelpers do
<:link navigate={Routes.settings_path(LiveBeatsWeb.Endpoint, :edit)}Settings</:link> <:link navigate={Routes.settings_path(LiveBeatsWeb.Endpoint, :edit)}Settings</:link>
</.dropdown> </.dropdown>
""" """
attr :id, :string, required: true
attr :ok, :string, required: true
attr :img, :list, default: []
attr :title, :list, default: []
attr :subtitle, :list, default: []
attr :link, :list, default: []
def dropdown(assigns) do def dropdown(assigns) do
assigns =
assigns
|> assign_new(:img, fn -> nil end)
|> assign_new(:title, fn -> nil end)
|> assign_new(:subtitle, fn -> nil end)
~H""" ~H"""
<!-- User account dropdown --> <!-- User account dropdown -->
<div class="px-3 mt-6 relative inline-block text-left"> <div class="px-3 mt-6 relative inline-block text-left">
@ -194,19 +236,32 @@ defmodule LiveBeatsWeb.LiveHelpers do
<span class="flex w-full justify-between items-center"> <span class="flex w-full justify-between items-center">
<span class="flex min-w-0 items-center justify-between space-x-3"> <span class="flex min-w-0 items-center justify-between space-x-3">
<%= for img <- @img do %> <%= for img <- @img do %>
<img class="w-10 h-10 bg-gray-300 rounded-full flex-shrink-0" alt="" {assigns_to_attributes(img)}/> <img
class="w-10 h-10 bg-gray-300 rounded-full flex-shrink-0"
alt=""
{assigns_to_attributes(img)}
/>
<% end %> <% end %>
<span class="flex-1 flex flex-col min-w-0"> <span class="flex-1 flex flex-col min-w-0">
<span class="text-gray-900 text-sm font-medium truncate"><%= render_slot(@title) %></span> <span class="text-gray-900 text-sm font-medium truncate">
<%= render_slot(@title) %>
</span>
<span class="text-gray-500 text-sm truncate"><%= render_slot(@subtitle) %></span> <span class="text-gray-500 text-sm truncate"><%= render_slot(@subtitle) %></span>
</span> </span>
</span> </span>
<svg class="flex-shrink-0 h-5 w-5 text-gray-400 group-hover:text-gray-500" <svg
xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" class="flex-shrink-0 h-5 w-5 text-gray-400 group-hover:text-gray-500"
fill="currentColor" aria-hidden="true"> xmlns="http://www.w3.org/2000/svg"
<path fill-rule="evenodd" viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path
fill-rule="evenodd"
d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z"
clip-rule="evenodd"></path> clip-rule="evenodd"
>
</path>
</svg> </svg>
</span> </span>
</button> </button>
@ -223,8 +278,11 @@ defmodule LiveBeatsWeb.LiveHelpers do
<.link <.link
tabindex="-1" tabindex="-1"
role="menuitem" role="menuitem"
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-purple-500" {link} class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-purple-500"
><%= render_slot(link) %></.link> {link}
>
<%= render_slot(link) %>
</.link>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -333,30 +391,45 @@ defmodule LiveBeatsWeb.LiveHelpers do
|> JS.dispatch("click", to: "##{id} [data-modal-return]") |> JS.dispatch("click", to: "##{id} [data-modal-return]")
end end
def modal(assigns) do attr :id, :string, required: true
assigns = attr :show, :boolean, default: false
assigns attr :patch, :string, default: nil
|> assign_new(:show, fn -> false end) attr :navigate, :string, default: nil
|> assign_new(:patch, fn -> nil end) attr :on_cancel, JS, default: %JS{}
|> assign_new(:navigate, fn -> nil end) attr :on_confirm, JS, default: %JS{}
|> assign_new(:on_cancel, fn -> %JS{} end)
|> assign_new(:on_confirm, fn -> %JS{} end)
# slots # slots
|> assign_new(:title, fn -> [] end) attr :title, :list, default: []
|> assign_new(:confirm, fn -> [] end) attr :confirm, :list, default: []
|> assign_new(:cancel, fn -> [] end) attr :cancel, :list, default: []
|> assign_rest(~w(id show patch navigate on_cancel on_confirm title confirm cancel)a) attr :rest, :global
def modal(assigns) do
~H""" ~H"""
<div id={@id} class={"fixed z-10 inset-0 overflow-y-auto #{if @show, do: "fade-in", else: "hidden"}"} {@rest}> <div
id={@id}
class={"fixed z-10 inset-0 overflow-y-auto #{if @show, do: "fade-in", else: "hidden"}"}
{@rest}
>
<.focus_wrap id={"#{@id}-focus-wrap"} content={"##{@id}-container"}> <.focus_wrap id={"#{@id}-focus-wrap"} content={"##{@id}-container"}>
<div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0" aria-labelledby={"#{@id}-title"} aria-describedby={"#{@id}-description"} role="dialog" aria-modal="true" tabindex="0"> <div
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true"></div> class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span> aria-labelledby={"#{@id}-title"}
aria-describedby={"#{@id}-description"}
role="dialog"
aria-modal="true"
tabindex="0"
>
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true">
</div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">
&#8203;
</span>
<div <div
id={"#{@id}-container"} id={"#{@id}-container"}
class={"#{if @show, do: "fade-in-scale", else: "hidden"} sticky inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform sm:my-8 sm:align-middle sm:max-w-xl sm:w-full sm:p-6"} class={
phx-window-keydown={hide_modal(@on_cancel, @id)} phx-key="escape" "#{if @show, do: "fade-in-scale", else: "hidden"} sticky inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform sm:my-8 sm:align-middle sm:max-w-xl sm:w-full sm:p-6"
}
phx-window-keydown={hide_modal(@on_cancel, @id)}
phx-key="escape"
phx-click-away={hide_modal(@on_cancel, @id)} phx-click-away={hide_modal(@on_cancel, @id)}
> >
<%= if @patch do %> <%= if @patch do %>
@ -366,16 +439,16 @@ defmodule LiveBeatsWeb.LiveHelpers do
<.link navigate={@navigate} data-modal-return class="hidden"></.link> <.link navigate={@navigate} data-modal-return class="hidden"></.link>
<% end %> <% end %>
<div class="sm:flex sm:items-start"> <div class="sm:flex sm:items-start">
<div class={"mx-auto flex-shrink-0 flex items-center justify-center h-8 w-8 rounded-full bg-purple-100 sm:mx-0"}> <div class="mx-auto flex-shrink-0 flex items-center justify-center h-8 w-8 rounded-full bg-purple-100 sm:mx-0">
<!-- Heroicon name: outline/plus --> <!-- Heroicon name: outline/plus -->
<.icon name={:information_circle} outlined class="h-6 w-6 text-purple-600"/> <.icon name={:information_circle} outlined class="h-6 w-6 text-purple-600" />
</div> </div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left w-full mr-12"> <div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left w-full mr-12">
<h3 class="text-lg leading-6 font-medium text-gray-900" id={"#{@id}-title"}> <h3 class="text-lg leading-6 font-medium text-gray-900" id={"#{@id}-title"}>
<%= render_slot(@title) %> <%= render_slot(@title) %>
</h3> </h3>
<div class="mt-2"> <div class="mt-2">
<p id={"#{@id}-content"} class={"text-sm text-gray-500"}> <p id={"#{@id}-content"} class="text-sm text-gray-500">
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
</p> </p>
</div> </div>
@ -410,6 +483,8 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
attr :id, :string, required: true
attr :content, :string
def focus_wrap(assigns) do def focus_wrap(assigns) do
~H""" ~H"""
<div id={@id} phx-hook="FocusWrap" data-content={@content}> <div id={@id} phx-hook="FocusWrap" data-content={@content}>
@ -420,29 +495,33 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
attr :id, :string, required: true
attr :min, :integer, default: 0
attr :max, :integer, default: 100
attr :value, :integer
def progress_bar(assigns) do def progress_bar(assigns) do
assigns = assigns = assign_new(assigns, :value, fn -> assigns[:min] || 0 end)
assigns
|> assign_new(:min, fn -> 0 end)
|> assign_new(:max, fn -> 100 end)
|> assign_new(:value, fn -> assigns[:min] || 0 end)
~H""" ~H"""
<div id={"#{@id}-container"} class="bg-gray-200 flex-auto dark:bg-black rounded-full overflow-hidden" phx-update="ignore"> <div
id={"#{@id}-container"}
class="bg-gray-200 flex-auto dark:bg-black rounded-full overflow-hidden"
phx-update="ignore"
>
<div <div
id={@id} id={@id}
class="bg-lime-500 dark:bg-lime-400 h-1.5 w-0" class="bg-lime-500 dark:bg-lime-400 h-1.5 w-0"
data-min={@min} data-min={@min}
data-max={@max} data-max={@max}
data-val={@value}> data-val={@value}
>
</div> </div>
</div> </div>
""" """
end end
attr :actions, :list, default: []
def title_bar(assigns) do def title_bar(assigns) do
assigns = assign_new(assigns, :actions, fn -> [] end)
~H""" ~H"""
<!-- Page title & actions --> <!-- Page title & actions -->
<div class="border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8 sm:h-16"> <div class="border-b border-gray-200 px-4 py-4 sm:flex sm:items-center sm:justify-between sm:px-6 lg:px-8 sm:h-16">
@ -460,13 +539,14 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
attr :patch, :string
attr :primary, :boolean, default: false
attr :rest, :global
def button(%{patch: _} = assigns) do def button(%{patch: _} = assigns) do
assigns = assign_new(assigns, :primary, fn -> false end)
~H""" ~H"""
<%= if @primary do %> <%= if @primary do %>
<%= live_patch [to: @patch, class: "order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3"] ++ <%= live_patch [to: @patch, class: "order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3"] ++
assigns_to_attributes(assigns, [:primary, :patch]) do %> Map.to_list(@rest) do %>
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
<% end %> <% end %>
<% else %> <% else %>
@ -479,24 +559,31 @@ defmodule LiveBeatsWeb.LiveHelpers do
end end
def button(%{} = assigns) do def button(%{} = assigns) do
assigns =
assigns
|> assign_new(:primary, fn -> false end)
|> assign(:rest, assigns_to_attributes(assigns))
~H""" ~H"""
<%= if @primary do %> <%= if @primary do %>
<button type="button" class="order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3" {@rest}> <button
type="button"
class="order-0 inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-purple-600 hover:bg-purple-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-1 sm:ml-3"
{@rest}
>
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
</button> </button>
<% else %> <% else %>
<button type="button" class="order-1 inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-0 sm:ml-0 lg:ml-3" {@rest}> <button
type="button"
class="order-1 inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-500 sm:order-0 sm:ml-0 lg:ml-3"
{@rest}
>
<%= render_slot(@inner_block) %> <%= render_slot(@inner_block) %>
</button> </button>
<% end %> <% end %>
""" """
end end
attr :row_id, :any, default: false
attr :rows, :list, required: true
# slots
attr :col, :list, required: true
def table(assigns) do def table(assigns) do
assigns = assigns =
assigns assigns
@ -510,8 +597,7 @@ defmodule LiveBeatsWeb.LiveHelpers do
<thead> <thead>
<tr class="border-t border-gray-200"> <tr class="border-t border-gray-200">
<%= for col <- @col do %> <%= for col <- @col do %>
<th <th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<span class="lg:pl-2"><%= col.label %></span> <span class="lg:pl-2"><%= col.label %></span>
</th> </th>
<% end %> <% end %>
@ -521,7 +607,9 @@ defmodule LiveBeatsWeb.LiveHelpers do
<%= for {row, i} <- Enum.with_index(@rows) do %> <%= for {row, i} <- Enum.with_index(@rows) do %>
<tr id={@row_id && @row_id.(row)} class="hover:bg-gray-50"> <tr id={@row_id && @row_id.(row)} class="hover:bg-gray-50">
<%= for col <- @col do %> <%= for col <- @col do %>
<td class={"px-6 py-3 whitespace-nowrap text-sm font-medium text-gray-900 #{if i == 0, do: "max-w-0 w-full"} #{col[:class]}"}> <td class={
"px-6 py-3 whitespace-nowrap text-sm font-medium text-gray-900 #{if i == 0, do: "max-w-0 w-full"} #{col[:class]}"
}>
<div class="flex items-center space-x-3 lg:pl-2"> <div class="flex items-center space-x-3 lg:pl-2">
<%= render_slot(col, row) %> <%= render_slot(col, row) %>
</div> </div>
@ -536,13 +624,16 @@ defmodule LiveBeatsWeb.LiveHelpers do
""" """
end end
attr :id, :any, required: true
attr :module, :atom, required: true
attr :row_id, :any, default: false
attr :rows, :list, required: true
attr :owns_profile?, :boolean, default: false
attr :active_id, :any, default: nil
# slots
attr :col, :list
def live_table(assigns) do def live_table(assigns) do
assigns = assigns = assign(assigns, :col, for(col <- assigns.col, col[:if] != false, do: col))
assigns
|> assign_new(:row_id, fn -> false end)
|> assign_new(:active_id, fn -> nil end)
|> assign_new(:owns_profile?, fn -> assigns.owns_profile? end)
|> assign(:col, for(col <- assigns.col, col[:if] != false, do: col))
~H""" ~H"""
<div class="hidden mt-8 sm:block"> <div class="hidden mt-8 sm:block">
@ -551,8 +642,7 @@ defmodule LiveBeatsWeb.LiveHelpers do
<thead> <thead>
<tr class="border-t border-gray-200"> <tr class="border-t border-gray-200">
<%= for col <- @col do %> <%= for col <- @col do %>
<th <th class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
class="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
<span class="lg:pl-2"><%= col.label %></span> <span class="lg:pl-2"><%= col.label %></span>
</th> </th>
<% end %> <% end %>
@ -563,10 +653,12 @@ defmodule LiveBeatsWeb.LiveHelpers do
<.live_component <.live_component
module={@module} module={@module}
id={@row_id.(row)} id={@row_id.(row)}
row={row} col={@col} row={row}
col={@col}
index={i} index={i}
active_id={@active_id} active_id={@active_id}
class="hover:bg-gray-50", class="hover:bg-gray-50"
,
owns_profile?={@owns_profile?} owns_profile?={@owns_profile?}
/> />
<% end %> <% end %>
@ -595,8 +687,4 @@ defmodule LiveBeatsWeb.LiveHelpers do
|> JS.dispatch("js:focus-closest", to: to) |> JS.dispatch("js:focus-closest", to: to)
|> hide(to) |> hide(to)
end end
defp assign_rest(assigns, exclude) do
assign(assigns, :rest, assigns_to_attributes(assigns, exclude))
end
end end

View file

@ -1,5 +1,6 @@
defmodule LiveBeatsWeb.LayoutView do defmodule LiveBeatsWeb.LayoutView do
use LiveBeatsWeb, :view use LiveBeatsWeb, :view
use Phoenix.Component
# Phoenix LiveDashboard is available only in development by default, # Phoenix LiveDashboard is available only in development by default,
# so we instruct Elixir to not warn if the dashboard route is missing. # so we instruct Elixir to not warn if the dashboard route is missing.
@ -69,7 +70,7 @@ defmodule LiveBeatsWeb.LayoutView do
def sidebar_account_dropdown(assigns) do def sidebar_account_dropdown(assigns) do
~H""" ~H"""
<.dropdown id={@id}> <.dropdown id={@id} foo="bar">
<:img src={@current_user.avatar_url}/> <:img src={@current_user.avatar_url}/>
<:title><%= @current_user.name %></:title> <:title><%= @current_user.name %></:title>
<:subtitle>@<%= @current_user.username %></:subtitle> <:subtitle>@<%= @current_user.username %></:subtitle>

View file

@ -7,7 +7,7 @@ defmodule LiveBeats.MixProject do
version: "0.1.0", version: "0.1.0",
elixir: "~> 1.12", elixir: "~> 1.12",
elixirc_paths: elixirc_paths(Mix.env()), elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:gettext] ++ Mix.compilers(), compilers: [:gettext, :phoenix_live_view] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod, start_permanent: Mix.env() == :prod,
aliases: aliases(), aliases: aliases(),
deps: deps() deps: deps()
@ -40,7 +40,8 @@ defmodule LiveBeats.MixProject do
{:postgrex, ">= 0.0.0"}, {:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.0"}, {:phoenix_html, "~> 3.0"},
{:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, github: "phoenixframework/phoenix_live_view", override: true}, # {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", override: true},
{:phoenix_live_view, path: "~/oss/phoenix_live_view", override: true},
{:floki, ">= 0.30.0", only: :test}, {:floki, ">= 0.30.0", only: :test},
{:phoenix_live_dashboard, "~> 0.6"}, {:phoenix_live_dashboard, "~> 0.6"},
{:esbuild, "~> 0.2", runtime: Mix.env() == :dev}, {:esbuild, "~> 0.2", runtime: Mix.env() == :dev},

View file

@ -22,12 +22,12 @@
"libcluster": {:hex, :libcluster, "3.3.1", "e7a4875cd1290cee7a693d6bd46076863e9e433708b01339783de6eff5b7f0aa", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "b575ca63c1cd84e01f3fa0fc45e6eb945c1ee7ae8d441d33def999075e9e5398"}, "libcluster": {:hex, :libcluster, "3.3.1", "e7a4875cd1290cee7a693d6bd46076863e9e433708b01339783de6eff5b7f0aa", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "b575ca63c1cd84e01f3fa0fc45e6eb945c1ee7ae8d441d33def999075e9e5398"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mint": {:hex, :mint, "1.3.0", "396b3301102f7b775e103da5a20494b25753aed818d6d6f0ad222a3a018c3600", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "a9aac960562e43ca69a77e5176576abfa78b8398cec5543dd4fb4ab0131d5c1e"}, "mint": {:hex, :mint, "1.3.0", "396b3301102f7b775e103da5a20494b25753aed818d6d6f0ad222a3a018c3600", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "a9aac960562e43ca69a77e5176576abfa78b8398cec5543dd4fb4ab0131d5c1e"},
"phoenix": {:git, "https://github.com/phoenixframework/phoenix.git", "ae2fb6bddd64fc7e3908ee6dd632f608254f532e", []}, "phoenix": {:git, "https://github.com/phoenixframework/phoenix.git", "c5bb03eee8ad802c125c92202ebec4e15c35c3e8", []},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.2", "0769470265eb13af01b5001b29cb935f4710d6adaa1ffc18417a570a337a2f0f", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "5bc6c6b38a2ca8b5020b442322fcee6afd5e641637a0b1fb059d4bd89bc58e7b"}, "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.2", "0769470265eb13af01b5001b29cb935f4710d6adaa1ffc18417a570a337a2f0f", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "5bc6c6b38a2ca8b5020b442322fcee6afd5e641637a0b1fb059d4bd89bc58e7b"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
"phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "1ae64fb69b0951f2f67f01d369ec9a4006060001", []}, "phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "e24527536890be2f0565c4a6d122a89e819df58e", []},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
"phoenix_view": {:hex, :phoenix_view, "1.0.0", "fea71ecaaed71178b26dd65c401607de5ec22e2e9ef141389c721b3f3d4d8011", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "82be3e2516f5633220246e2e58181282c71640dab7afc04f70ad94253025db0c"}, "phoenix_view": {:hex, :phoenix_view, "1.0.0", "fea71ecaaed71178b26dd65c401607de5ec22e2e9ef141389c721b3f3d4d8011", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "82be3e2516f5633220246e2e58181282c71640dab7afc04f70ad94253025db0c"},
"plug": {:hex, :plug, "1.13.4", "addb6e125347226e3b11489e23d22a60f7ab74786befb86c14f94fb5f23ca9a4", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "06114c1f2a334212fe3ae567dbb3b1d29fd492c1a09783d52f3d489c1a6f4cf2"}, "plug": {:hex, :plug, "1.13.4", "addb6e125347226e3b11489e23d22a60f7ab74786befb86c14f94fb5f23ca9a4", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "06114c1f2a334212fe3ae567dbb3b1d29fd492c1a09783d52f3d489c1a6f4cf2"},