Skip to content

Commit

Permalink
Fix build warning
Browse files Browse the repository at this point in the history
  • Loading branch information
bluzky committed Nov 16, 2024
1 parent 9098465 commit 0e791b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
19 changes: 17 additions & 2 deletions lib/salad_ui/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,23 @@ defmodule SaladUI.Helpers do
# => "background-color: red; color: white; font-size: 16px;"
```
"""
def style(css_map) do
Enum.map_join(css_map, "; ", fn {k, v} -> "#{k}: #{v}" end) <> ";"
def style(items) when is_list(items) do
{acc_map, acc_list} =
Enum.reduce(items, {%{}, []}, fn item, {acc_map, acc_list} ->
cond do
is_map(item) ->
{Map.merge(acc_map, item), acc_list}

is_binary(item) ->
{acc_map, [item | acc_list]}

true ->
{acc_map, [item | acc_list]}
end
end)

style = Enum.map_join(acc_map, "; ", fn {k, v} -> "#{k}: #{v}" end) <> ";"
Enum.join([style | acc_list], "; ")
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/salad_ui/sheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule SaladUI.Sheet do
"""
end

attr :id, :string, required: true, doc: "The id of the sheet"
attr :id, :string, default: nil, doc: "The id of the sheet, this is the target of sheet_trigger"
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
Expand Down
39 changes: 22 additions & 17 deletions lib/salad_ui/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule SaladUI.Sidebar do
@moduledoc false
use SaladUI, :component

import SaladUI.Button
import SaladUI.Input
import SaladUI.Separator
import SaladUI.Sheet
Expand All @@ -27,15 +26,13 @@ defmodule SaladUI.Sidebar do
~H"""
<div
style={
style(
Map.merge(
%{
"--sidebar-width": @sidebar_width,
"--sidebar-width-icon": @sidebar_width_icon
},
@style
)
)
style([
%{
"--sidebar-width": @sidebar_width,
"--sidebar-width-icon": @sidebar_width_icon
},
@style
])
}
class={
classes([
Expand All @@ -61,6 +58,7 @@ defmodule SaladUI.Sidebar do
attr :is_mobile, :boolean, default: false
attr :state, :string, values: ~w(expanded collapsed), default: "expanded"
attr(:class, :string, default: nil)
attr :style, :map, default: %{}
attr(:rest, :global)
slot(:inner_block, required: true)

Expand All @@ -81,16 +79,21 @@ defmodule SaladUI.Sidebar do
end

def sidebar(%{is_mobile: true} = assigns) do
assigns = assign(assigns, :sidebar_width_mobile, @sidebar_width_mobile)

~H"""
<.sheet>
<.sheet_content
data-sidebar="sidebar"
data-mobile="true"
class="w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
style={
style(%{
"--sidebar-width": @sidebar_width_mobile
})
style([
%{
"--sidebar-width": @sidebar_width_mobile
},
@style
])
}
side={@side}
>
Expand Down Expand Up @@ -520,7 +523,7 @@ defmodule SaladUI.Sidebar do
<.tooltip_trigger>
<%= @button %>
</.tooltip_trigger>
<.tooltip_content side="right" align="center" hidden={@state != "collapsed" || @is_mobile}>
<.tooltip_content side="right" hidden={@state != "collapsed" || @is_mobile}>
<%= render_slot(@tooltip) %>
</.tooltip_content>
</.tooltip>
Expand Down Expand Up @@ -613,9 +616,11 @@ defmodule SaladUI.Sidebar do
class="h-4 flex-1 max-w-[--skeleton-width]"
data-sidebar="menu-skeleton-text"
style={
style(%{
"--skeleton-width": @width
})
style([
%{
"--skeleton-width": @width
}
])
}
/>
</div>
Expand Down

0 comments on commit 0e791b6

Please sign in to comment.