|
| 1 | +defmodule ErrorTracker.Web.CoreComponents do |
| 2 | + @moduledoc false |
| 3 | + use Phoenix.Component |
| 4 | + |
| 5 | + @doc """ |
| 6 | + Renders a button. |
| 7 | +
|
| 8 | + ## Examples |
| 9 | +
|
| 10 | + <.button>Send!</.button> |
| 11 | + <.button phx-click="go" class="ml-2">Send!</.button> |
| 12 | + """ |
| 13 | + attr :type, :string, default: nil |
| 14 | + attr :class, :string, default: nil |
| 15 | + attr :rest, :global, include: ~w(disabled form name value href patch navigate) |
| 16 | + |
| 17 | + slot :inner_block, required: true |
| 18 | + |
| 19 | + def button(assigns = %{type: "link"}) do |
| 20 | + ~H""" |
| 21 | + <.link |
| 22 | + class={[ |
| 23 | + "phx-submit-loading:opacity-75 rounded-lg bg-zinc-600 hover:bg-zinc-400 py-[11.5px] px-3", |
| 24 | + "text-sm font-semibold leading-6 text-white active:text-white/80", |
| 25 | + @class |
| 26 | + ]} |
| 27 | + {@rest} |
| 28 | + > |
| 29 | + <%= render_slot(@inner_block) %> |
| 30 | + </.link> |
| 31 | + """ |
| 32 | + end |
| 33 | + |
| 34 | + def button(assigns) do |
| 35 | + ~H""" |
| 36 | + <button |
| 37 | + type={@type} |
| 38 | + class={[ |
| 39 | + "phx-submit-loading:opacity-75 rounded-lg bg-zinc-600 hover:bg-zinc-400 py-2 px-3", |
| 40 | + "text-sm font-semibold leading-6 text-white active:text-white/80", |
| 41 | + @class |
| 42 | + ]} |
| 43 | + {@rest} |
| 44 | + > |
| 45 | + <%= render_slot(@inner_block) %> |
| 46 | + </button> |
| 47 | + """ |
| 48 | + end |
| 49 | + |
| 50 | + @doc """ |
| 51 | + Renders a badge. |
| 52 | +
|
| 53 | + ## Examples |
| 54 | +
|
| 55 | + <.badge>Info</.badge> |
| 56 | + <.badge color={:red}>Error</.badge> |
| 57 | + """ |
| 58 | + attr :color, :atom, default: :blue |
| 59 | + attr :rest, :global |
| 60 | + |
| 61 | + slot :inner_block, required: true |
| 62 | + |
| 63 | + def badge(assigns) do |
| 64 | + color_class = |
| 65 | + case assigns.color do |
| 66 | + :blue -> "bg-blue-900 text-blue-300" |
| 67 | + :gray -> "bg-gray-700 text-gray-300" |
| 68 | + :red -> "bg-red-900 text-red-300" |
| 69 | + :green -> "bg-green-900 text-green-300" |
| 70 | + :yellow -> "bg-yellow-900 text-yellow-300" |
| 71 | + :indigo -> "bg-indigo-900 text-indigo-300" |
| 72 | + :purple -> "bg-purple-900 text-purple-300" |
| 73 | + :pink -> "bg-pink-900 text-pink-300" |
| 74 | + end |
| 75 | + |
| 76 | + assigns = Map.put(assigns, :color_class, color_class) |
| 77 | + |
| 78 | + ~H""" |
| 79 | + <span class={["text-sm font-medium me-2 px-2.5 py-1.5 rounded", @color_class]} {@rest}> |
| 80 | + <%= render_slot(@inner_block) %> |
| 81 | + </span> |
| 82 | + """ |
| 83 | + end |
| 84 | + |
| 85 | + attr :page, :integer, required: true |
| 86 | + attr :total_pages, :integer, required: true |
| 87 | + attr :event_previous, :string, default: "prev-page" |
| 88 | + attr :event_next, :string, default: "next-page" |
| 89 | + |
| 90 | + def pagination(assigns) do |
| 91 | + ~H""" |
| 92 | + <div class="mt-10 w-full flex"> |
| 93 | + <button |
| 94 | + :if={@page > 1} |
| 95 | + class="flex items-center justify-center px-4 h-10 text-base font-medium text-gray-400 bg-gray-800 border border-gray-700 rounded-lg hover:bg-gray-700 hover:text-white" |
| 96 | + phx-click={@event_previous} |
| 97 | + > |
| 98 | + Previous page |
| 99 | + </button> |
| 100 | + <button |
| 101 | + :if={@page < @total_pages} |
| 102 | + class="flex items-center justify-center px-4 h-10 text-base font-medium text-gray-400 bg-gray-800 border border-gray-700 rounded-lg hover:bg-gray-700 hover:text-white" |
| 103 | + phx-click={@event_next} |
| 104 | + > |
| 105 | + Next page |
| 106 | + </button> |
| 107 | + </div> |
| 108 | + """ |
| 109 | + end |
| 110 | + |
| 111 | + attr :title, :string |
| 112 | + attr :title_class, :string, default: nil |
| 113 | + attr :rest, :global |
| 114 | + |
| 115 | + slot :inner_block, required: true |
| 116 | + |
| 117 | + def section(assigns) do |
| 118 | + ~H""" |
| 119 | + <div> |
| 120 | + <h2 :if={assigns[:title]} class={["text-sm font-bold mb-2 uppercase", @title_class]}> |
| 121 | + <%= @title %> |
| 122 | + </h2> |
| 123 | + <%= render_slot(@inner_block) %> |
| 124 | + </div> |
| 125 | + """ |
| 126 | + end |
| 127 | +end |
0 commit comments