From 0e791b6247c56ca604e15de6314531757adea160 Mon Sep 17 00:00:00 2001 From: Dzung Nguyen Date: Sat, 16 Nov 2024 12:40:58 +0700 Subject: [PATCH] Fix build warning --- lib/salad_ui/helpers.ex | 19 +++++++++++++++++-- lib/salad_ui/sheet.ex | 2 +- lib/salad_ui/sidebar.ex | 39 ++++++++++++++++++++++----------------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/lib/salad_ui/helpers.ex b/lib/salad_ui/helpers.ex index bbe2841..07d9972 100644 --- a/lib/salad_ui/helpers.ex +++ b/lib/salad_ui/helpers.ex @@ -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 """ diff --git a/lib/salad_ui/sheet.ex b/lib/salad_ui/sheet.ex index 2faf1fb..28c59ea 100644 --- a/lib/salad_ui/sheet.ex +++ b/lib/salad_ui/sheet.ex @@ -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 diff --git a/lib/salad_ui/sidebar.ex b/lib/salad_ui/sidebar.ex index 1c57bfd..7f85aaa 100644 --- a/lib/salad_ui/sidebar.ex +++ b/lib/salad_ui/sidebar.ex @@ -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 @@ -27,15 +26,13 @@ defmodule SaladUI.Sidebar do ~H"""
<.sheet_content @@ -88,9 +88,12 @@ 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 - }) + style([ + %{ + "--sidebar-width": @sidebar_width_mobile + }, + @style + ]) } side={@side} > @@ -520,7 +523,7 @@ defmodule SaladUI.Sidebar do <.tooltip_trigger> <%= @button %> - <.tooltip_content side="right" align="center" hidden={@state != "collapsed" || @is_mobile}> + <.tooltip_content side="right" hidden={@state != "collapsed" || @is_mobile}> <%= render_slot(@tooltip) %> @@ -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 + } + ]) } />