Skip to content

Commit

Permalink
improve sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
bluzky committed Nov 15, 2024
1 parent ec27f8f commit aac3177
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions lib/salad_ui/collapsible.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ defmodule SaladUI.Collapsible do
Render trigger for collapsible component.
"""
attr(:class, :string, default: nil)
attr :as, :string, default: "button"
slot(:inner_block, required: true)

def collapsible_trigger(assigns) do
~H"""
<.dynamic as={@as}
<.dynamic tag="button"
onclick={exec_closest("phx-toggle-collapsible", ".collapsible-root")} class={@class}>
<%= render_slot(@inner_block) %>
</.dynamic>
Expand Down
18 changes: 12 additions & 6 deletions lib/salad_ui/helpers.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
defmodule SaladUI.Helpers do
@moduledoc false
import Phoenix.Component
use Phoenix.Component

import Phoenix.Component

@doc """
Prepare input assigns for use in a form. Extract required attribute from the Form.Field struct and update current assigns.
"""
Expand Down Expand Up @@ -226,7 +227,7 @@ defmodule SaladUI.Helpers do
"""
end

@doc """
@doc """
Generates a dynamically named HTML tag.
Raises an `ArgumentError` if the tag name is found to be unsafe HTML.
Expand All @@ -252,14 +253,19 @@ defmodule SaladUI.Helpers do
```
"""
def dynamic(%{as: name} = assigns) when is_function(name, 1) do
assigns = Map.delete(assigns, :as)
assigns = Map.delete(assigns, :as)
name.(assigns)
end

def dynamic(assigns) do
name = assigns[:as] || "div"
assigns = Map.delete(assigns, :as)
|> assign(:name, name)
name = assigns[:as] || assigns[:tag] || "div"

assigns =
assigns
|> Map.delete(:as)
|> Map.delete(:tag)
|> assign(:name, name)

dynamic_tag(assigns)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/salad_ui/sheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ defmodule SaladUI.Sheet do
attr :id, :string, required: true, doc: "The id of the sheet"
attr :class, :string, default: nil
attr :side, :string, default: "right", values: ~w(left right top bottom), doc: "The side of the sheet"
attr :rest, :global
slot :inner_block, required: true
slot :custom_close_btn, required: false

Expand All @@ -102,6 +103,7 @@ defmodule SaladUI.Sheet do
id={@id}
phx-show-sheet={show_sheet(@id, @side)}
phx-hide-sheet={hide_sheet(@id, @side)}
{@rest}
>
<.sheet_overlay />
<.focus_wrap
Expand Down
12 changes: 6 additions & 6 deletions lib/salad_ui/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ defmodule SaladUI.Sidebar do
data-mobile="true"
class="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
style={
%{
style(%{
"--sidebar-width": @sidebar_width_mobile
}
})
}
side={@side}
>
Expand Down Expand Up @@ -154,7 +154,7 @@ defmodule SaladUI.Sidebar do

def sidebar_trigger(assigns) do
~H"""
<.button
<.dynamic tag="button"
data-sidebar="trigger"
variant="ghost"
size="icon"
Expand All @@ -164,7 +164,7 @@ defmodule SaladUI.Sidebar do
>
<%= render_slot(@inner_block) %>
<span class="sr-only">Toggle Sidebar</span>
</.button>
</.dynamic>
"""
end

Expand Down Expand Up @@ -607,9 +607,9 @@ defmodule SaladUI.Sidebar do
class="h-4 flex-1 max-w-[--skeleton-width]"
data-sidebar="menu-skeleton-text"
style={
%{
style(%{
"--skeleton-width": @width
}
})
}
/>
</div>
Expand Down

0 comments on commit aac3177

Please sign in to comment.