Current section
41 Versions
Jump to
Current section
41 Versions
Compare versions
4
files changed
+166
additions
-172
deletions
| @@ -1,7 +1,7 @@ | |
| 1 1 | {<<"links">>, |
| 2 2 | [{<<"GitHub">>,<<"https://github.com/phcurado/daisy_ui_components">>}]}. |
| 3 3 | {<<"name">>,<<"daisy_ui_components">>}. |
| 4 | - {<<"version">>,<<"0.7.2">>}. |
| 4 | + {<<"version">>,<<"0.7.3">>}. |
| 5 5 | {<<"description">>,<<"DaisyUI component library for LiveView">>}. |
| 6 6 | {<<"elixir">>,<<"~> 1.14">>}. |
| 7 7 | {<<"app">>,<<"daisy_ui_components">>}. |
| @@ -1,163 +1,163 @@ | |
| 1 | - defmodule DaisyUIComponents.Sidebar do |
| 2 | - @moduledoc """ |
| 3 | - Sidebar component |
| 4 | - """ |
| 5 | - |
| 6 | - use DaisyUIComponents, :live_component |
| 7 | - |
| 8 | - import DaisyUIComponents.Button |
| 9 | - import DaisyUIComponents.Drawer |
| 10 | - import DaisyUIComponents.Icon |
| 11 | - import DaisyUIComponents.Menu |
| 12 | - |
| 13 | - attr :id, :string, required: true, doc: "identifier to toggle the sidebar" |
| 14 | - attr :class, :any, default: nil |
| 15 | - attr :open, :boolean, default: nil, doc: "Forces the sidebar to be open" |
| 16 | - attr :expanded, :boolean, default: false, doc: "Sidebar expand width" |
| 17 | - attr :rest, :global |
| 18 | - |
| 19 | - slot :content, required: true do |
| 20 | - attr :class, :any |
| 21 | - end |
| 22 | - |
| 23 | - slot :item do |
| 24 | - attr :path, :string |
| 25 | - attr :method, :any |
| 26 | - attr :active, :boolean |
| 27 | - attr :icon, :string |
| 28 | - end |
| 29 | - |
| 30 | - @doc """ |
| 31 | - Sidebar is a LiveComponent, it handles expanded and open states |
| 32 | - """ |
| 33 | - def sidebar(assigns) do |
| 34 | - ~H""" |
| 35 | - <.live_component |
| 36 | - module={__MODULE__} |
| 37 | - id={@id} |
| 38 | - class={@class} |
| 39 | - open={@open} |
| 40 | - expanded={@expanded} |
| 41 | - content={@content} |
| 42 | - item={@item} |
| 43 | - {@rest} |
| 44 | - /> |
| 45 | - """ |
| 46 | - end |
| 47 | - |
| 48 | - @impl true |
| 49 | - def render(assigns) do |
| 50 | - ~H""" |
| 51 | - <div> |
| 52 | - <.button |
| 53 | - phx-click={JS.toggle_class("lg:drawer-open", to: "##{@id}")} |
| 54 | - phx-target={@myself} |
| 55 | - shape="circle" |
| 56 | - size="xs" |
| 57 | - > |
| 58 | - <.icon :if={@expanded} name="hero-chevron-double-left" class="h-5 w-5" /> |
| 59 | - <.icon :if={!@expanded} name="hero-chevron-double-right" class="h-5 w-5" /> |
| 60 | - </.button> |
| 61 | - <.drawer id={@id} class={[@class]} selector_id={"#{@id}_selector"}> |
| 62 | - <:drawer_content :for={content <- @content} class={Map.get(content, :class)}> |
| 63 | - {render_slot(@content)} |
| 64 | - </:drawer_content> |
| 65 | - <:drawer_side class={["h-full absolute border-r", !@expanded && "sticky "]}> |
| 66 | - <div class="absolute top-0 right-0 z-10 will-change-unset transform-none"> |
| 67 | - <.button |
| 68 | - phx-click={JS.push("toggle_expand")} |
| 69 | - phx-target={@myself} |
| 70 | - shape="circle" |
| 71 | - size="xs" |
| 72 | - > |
| 73 | - <.icon :if={@expanded} name="hero-chevron-double-left" class="h-5 w-5" /> |
| 74 | - <.icon :if={!@expanded} name="hero-chevron-double-right" class="h-5 w-5" /> |
| 75 | - </.button> |
| 76 | - </div> |
| 77 | - <.drawer_items id={"#{@id}_items"} expanded={@expanded}> |
| 78 | - <.sidebar_item |
| 79 | - :for={item <- @item} |
| 80 | - path={item.path} |
| 81 | - icon={item.icon} |
| 82 | - expanded={@expanded} |
| 83 | - active={Map.get(item, :active)} |
| 84 | - method={Map.get(item, :method)} |
| 85 | - > |
| 86 | - {render_slot(item)} |
| 87 | - </.sidebar_item> |
| 88 | - </.drawer_items> |
| 89 | - </:drawer_side> |
| 90 | - </.drawer> |
| 91 | - </div> |
| 92 | - """ |
| 93 | - end |
| 94 | - |
| 95 | - ## Events |
| 96 | - @impl true |
| 97 | - def handle_event("toggle_expand", _params, socket) do |
| 98 | - socket = socket |> assign(:expanded, !socket.assigns.expanded) |
| 99 | - |
| 100 | - {:noreply, socket} |
| 101 | - end |
| 102 | - |
| 103 | - ## Internal Components |
| 104 | - |
| 105 | - attr :id, :any |
| 106 | - attr :expanded, :boolean, default: false |
| 107 | - slot :inner_block, required: true |
| 108 | - |
| 109 | - defp drawer_items(assigns) do |
| 110 | - ~H""" |
| 111 | - <.menu |
| 112 | - id={@id} |
| 113 | - class={[ |
| 114 | - "bg-base-100 text-base-content min-h-full", |
| 115 | - @expanded && "p-4 w-80", |
| 116 | - !@expanded && "w-20" |
| 117 | - ]} |
| 118 | - > |
| 119 | - {render_slot(@inner_block)} |
| 120 | - </.menu> |
| 121 | - """ |
| 122 | - end |
| 123 | - |
| 124 | - attr :path, :string, default: nil |
| 125 | - attr :method, :any, default: nil |
| 126 | - attr :active, :boolean, default: false |
| 127 | - attr :expanded, :boolean, default: false |
| 128 | - attr :icon, :string |
| 129 | - slot :inner_block, required: true |
| 130 | - |
| 131 | - def sidebar_item(assigns) do |
| 132 | - ~H""" |
| 133 | - <li> |
| 134 | - <.link_method |
| 135 | - class={!@expanded && "justify-center"} |
| 136 | - active={@active} |
| 137 | - path={@path} |
| 138 | - method={@method} |
| 139 | - expanded={@expanded} |
| 140 | - > |
| 141 | - <.icon :if={@icon} name={@icon} class="w-5 h-5 text-center" /> |
| 142 | - <span :if={@expanded}>{render_slot(@inner_block)}</span> |
| 143 | - </.link_method> |
| 144 | - </li> |
| 145 | - """ |
| 146 | - end |
| 147 | - |
| 148 | - defp link_method(%{method: nil} = assigns) do |
| 149 | - ~H""" |
| 150 | - <.link class={[@active && "active", @class]} navigate={@path}> |
| 151 | - {render_slot(@inner_block)} |
| 152 | - </.link> |
| 153 | - """ |
| 154 | - end |
| 155 | - |
| 156 | - defp link_method(assigns) do |
| 157 | - ~H""" |
| 158 | - <.link class={[@active && "active", @class]} href={@path} method={@method}> |
| 159 | - {render_slot(@inner_block)} |
| 160 | - </.link> |
| 161 | - """ |
| 162 | - end |
| 163 | - end |
| 1 | + # defmodule DaisyUIComponents.Sidebar do |
| 2 | + # @moduledoc """ |
| 3 | + # Sidebar component |
| 4 | + # """ |
| 5 | + # |
| 6 | + # use DaisyUIComponents, :live_component |
| 7 | + # |
| 8 | + # import DaisyUIComponents.Button |
| 9 | + # import DaisyUIComponents.Drawer |
| 10 | + # import DaisyUIComponents.Icon |
| 11 | + # import DaisyUIComponents.Menu |
| 12 | + # |
| 13 | + # attr :id, :string, required: true, doc: "identifier to toggle the sidebar" |
| 14 | + # attr :class, :any, default: nil |
| 15 | + # attr :open, :boolean, default: nil, doc: "Forces the sidebar to be open" |
| 16 | + # attr :expanded, :boolean, default: false, doc: "Sidebar expand width" |
| 17 | + # attr :rest, :global |
| 18 | + # |
| 19 | + # slot :content, required: true do |
| 20 | + # attr :class, :any |
| 21 | + # end |
| 22 | + # |
| 23 | + # slot :item do |
| 24 | + # attr :path, :string |
| 25 | + # attr :method, :any |
| 26 | + # attr :active, :boolean |
| 27 | + # attr :icon, :string |
| 28 | + # end |
| 29 | + # |
| 30 | + # @doc """ |
| 31 | + # Sidebar is a LiveComponent, it handles expanded and open states |
| 32 | + # """ |
| 33 | + # def sidebar(assigns) do |
| 34 | + # ~H""" |
| 35 | + # <.live_component |
| 36 | + # module={__MODULE__} |
| 37 | + # id={@id} |
| 38 | + # class={@class} |
| 39 | + # open={@open} |
| 40 | + # expanded={@expanded} |
| 41 | + # content={@content} |
| 42 | + # item={@item} |
| 43 | + # {@rest} |
| 44 | + # /> |
| 45 | + # """ |
| 46 | + # end |
| 47 | + # |
| 48 | + # @impl true |
| 49 | + # def render(assigns) do |
| 50 | + # ~H""" |
| 51 | + # <div> |
| 52 | + # <.button |
| 53 | + # phx-click={JS.toggle_class("lg:drawer-open", to: "##{@id}")} |
| 54 | + # phx-target={@myself} |
| 55 | + # shape="circle" |
| 56 | + # size="xs" |
| 57 | + # > |
| 58 | + # <.icon :if={@expanded} name="hero-chevron-double-left" class="h-5 w-5" /> |
| 59 | + # <.icon :if={!@expanded} name="hero-chevron-double-right" class="h-5 w-5" /> |
| 60 | + # </.button> |
| 61 | + # <.drawer id={@id} class={[@class]} selector_id={"#{@id}_selector"}> |
| 62 | + # <:drawer_content :for={content <- @content} class={Map.get(content, :class)}> |
| 63 | + # {render_slot(@content)} |
| 64 | + # </:drawer_content> |
| 65 | + # <:drawer_side class={["h-full absolute border-r", !@expanded && "sticky "]}> |
| 66 | + # <div class="absolute top-0 right-0 z-10 will-change-unset transform-none"> |
| 67 | + # <.button |
| 68 | + # phx-click={JS.push("toggle_expand")} |
| 69 | + # phx-target={@myself} |
| 70 | + # shape="circle" |
| 71 | + # size="xs" |
| 72 | + # > |
| 73 | + # <.icon :if={@expanded} name="hero-chevron-double-left" class="h-5 w-5" /> |
| 74 | + # <.icon :if={!@expanded} name="hero-chevron-double-right" class="h-5 w-5" /> |
| 75 | + # </.button> |
| 76 | + # </div> |
| 77 | + # <.drawer_items id={"#{@id}_items"} expanded={@expanded}> |
| 78 | + # <.sidebar_item |
| 79 | + # :for={item <- @item} |
| 80 | + # path={item.path} |
| 81 | + # icon={item.icon} |
| 82 | + # expanded={@expanded} |
| 83 | + # active={Map.get(item, :active)} |
| 84 | + # method={Map.get(item, :method)} |
| 85 | + # > |
| 86 | + # {render_slot(item)} |
| 87 | + # </.sidebar_item> |
| 88 | + # </.drawer_items> |
| 89 | + # </:drawer_side> |
| 90 | + # </.drawer> |
| 91 | + # </div> |
| 92 | + # """ |
| 93 | + # end |
| 94 | + # |
| 95 | + # ## Events |
| 96 | + # @impl true |
| 97 | + # def handle_event("toggle_expand", _params, socket) do |
| 98 | + # socket = socket |> assign(:expanded, !socket.assigns.expanded) |
| 99 | + # |
| 100 | + # {:noreply, socket} |
| 101 | + # end |
| 102 | + # |
| 103 | + # ## Internal Components |
| 104 | + # |
| 105 | + # attr :id, :any |
| 106 | + # attr :expanded, :boolean, default: false |
| 107 | + # slot :inner_block, required: true |
| 108 | + # |
| 109 | + # defp drawer_items(assigns) do |
| 110 | + # ~H""" |
| 111 | + # <.menu |
| 112 | + # id={@id} |
| 113 | + # class={[ |
| 114 | + # "bg-base-100 text-base-content min-h-full", |
| 115 | + # @expanded && "p-4 w-80", |
| 116 | + # !@expanded && "w-20" |
| 117 | + # ]} |
| 118 | + # > |
| 119 | + # {render_slot(@inner_block)} |
| 120 | + # </.menu> |
| 121 | + # """ |
| 122 | + # end |
| 123 | + # |
| 124 | + # attr :path, :string, default: nil |
| 125 | + # attr :method, :any, default: nil |
| 126 | + # attr :active, :boolean, default: false |
| 127 | + # attr :expanded, :boolean, default: false |
| 128 | + # attr :icon, :string |
| 129 | + # slot :inner_block, required: true |
| 130 | + # |
| 131 | + # def sidebar_item(assigns) do |
| 132 | + # ~H""" |
| 133 | + # <li> |
| 134 | + # <.link_method |
| 135 | + # class={!@expanded && "justify-center"} |
| 136 | + # active={@active} |
| 137 | + # path={@path} |
| 138 | + # method={@method} |
| 139 | + # expanded={@expanded} |
| 140 | + # > |
| 141 | + # <.icon :if={@icon} name={@icon} class="w-5 h-5 text-center" /> |
| 142 | + # <span :if={@expanded}>{render_slot(@inner_block)}</span> |
| 143 | + # </.link_method> |
| 144 | + # </li> |
| 145 | + # """ |
| 146 | + # end |
| 147 | + # |
| 148 | + # defp link_method(%{method: nil} = assigns) do |
| 149 | + # ~H""" |
| 150 | + # <.link class={[@active && "active", @class]} navigate={@path}> |
| 151 | + # {render_slot(@inner_block)} |
| 152 | + # </.link> |
| 153 | + # """ |
| 154 | + # end |
| 155 | + # |
| 156 | + # defp link_method(assigns) do |
| 157 | + # ~H""" |
| 158 | + # <.link class={[@active && "active", @class]} href={@path} method={@method}> |
| 159 | + # {render_slot(@inner_block)} |
| 160 | + # </.link> |
| 161 | + # """ |
| 162 | + # end |
| 163 | + # end |
| @@ -27,8 +27,6 @@ defmodule DaisyUIComponents.Swap do | |
| 27 27 | attr :name, :string, required: true |
| 28 28 | end |
| 29 29 | |
| 30 | - slot :inner_block |
| 31 | - |
| 32 30 | def swap(assigns) do |
| 33 31 | assigns = |
| 34 32 | assigns |
| @@ -36,11 +34,7 @@ defmodule DaisyUIComponents.Swap do | |
| 36 34 | |
| 37 35 | ~H""" |
| 38 36 | <label class={@class} {@rest}> |
| 39 | - <%= if render?(@inner_block) do %> |
| 40 | - {render_slot(@inner_block)} |
| 41 | - <% else %> |
| 42 | - <input class="hidden" type="checkbox" /> |
| 43 | - <% end %> |
| 37 | + <input type="checkbox" /> |
| 44 38 | <.swap_mode |
| 45 39 | :for={swap_on <- @swap_on} |
| 46 40 | type={Map.get(swap_on, :type, "label")} |
| @@ -2,7 +2,7 @@ defmodule DaisyUIComponents.MixProject do | |
| 2 2 | use Mix.Project |
| 3 3 | |
| 4 4 | @source_url "https://github.com/phcurado/daisy_ui_components" |
| 5 | - @version "0.7.2" |
| 5 | + @version "0.7.3" |
| 6 6 | |
| 7 7 | def project do |
| 8 8 | [ |