diff --git a/lib/surface_bootstrap/dropdown.ex b/lib/surface_bootstrap/dropdown.ex index 8ad0e88..b7bc465 100644 --- a/lib/surface_bootstrap/dropdown.ex +++ b/lib/surface_bootstrap/dropdown.ex @@ -26,8 +26,8 @@ defmodule SurfaceBootstrap.DropDown do @doc "ID of dropdown, required to work" prop id, :string, required: true - @doc "Label of dropdown link/button" - prop label, :string, required: true + @doc "Label of dropdown link/button. Use button_content to provide inner content." + prop label, :string @doc """ If prop `split` is set to `true`, wrapper type is automatically set to `btn_group`. @@ -51,6 +51,15 @@ defmodule SurfaceBootstrap.DropDown do prop button_size, :string, values: ~w(small normal large), default: "normal" + @doc "Custom class for the dropdown button" + prop button_class, :css_class, default: [] + + @doc "Custom class for the wrapper" + prop wrapper_class, :css_class, default: [] + + @doc "Custom class for the dropdown menu" + prop menu_class, :css_class, default: [] + @doc """ Show dropdown with a separate arrow to click on (split view)? Defaults false. If set to true will automatically set `@wrapper = "btn_group"` and `@button = true`. @@ -63,6 +72,8 @@ defmodule SurfaceBootstrap.DropDown do @doc "Show dropdown as active" prop active, :boolean + slot button_content + slot dropdown_items slot default @@ -86,11 +97,11 @@ defmodule SurfaceBootstrap.DropDown do id={@id} :hook="DropDown" class={ - dropdown: @wrapper == "dropdown" && !@direction, + [dropdown: @wrapper == "dropdown" && !@direction, dropup: @direction == "up", dropend: @direction == "right", dropstart: @direction == "left", - "btn-group": @wrapper == "btn_group" || @split == true + "btn-group": @wrapper == "btn_group" || @split == true] ++ @wrapper_class } :attrs={ "data-bsnclass": "show" @@ -107,12 +118,12 @@ defmodule SurfaceBootstrap.DropDown do id={@id} :hook="DropDown" class={ - "nav-item", + ["nav-item", dropdown: !@direction, dropup: @direction == "up", dropend: @direction == "right", dropstart: @direction == "left", - "btn-group": @wrapper == "btn_group" || @split == true + "btn-group": @wrapper == "btn_group" || @split == true] ++ @wrapper_class } :attrs={ "data-bsnclass": "show" @@ -151,17 +162,19 @@ defmodule SurfaceBootstrap.DropDown do "dropdown"} class={ - "dropdown-toggle": !@split, + ["dropdown-toggle": !@split, "nav-link": @wrapper == "nav_item", active: @active, btn: @button, "btn-#{@color}": @button && @color, "btn-lg": @button && @button_size == "large", - "btn-sm": @button && @button_size == "small" + "btn-sm": @button && @button_size == "small"] ++ @button_class } href={!@split && "#"} > - {@label} + <#slot name="button_content"> + {@label} + """ end @@ -193,8 +206,8 @@ defmodule SurfaceBootstrap.DropDown do ~F"""
{#for {_item, index} <- Enum.with_index(@dropdown_items)} -
  • - <#slot name="dropdown_items" index={index} /> -
  • + <#slot name="dropdown_items" index={index} /> {/for} """ diff --git a/lib/surface_bootstrap/dropdown/item.ex b/lib/surface_bootstrap/dropdown/item.ex index 91100c5..62e7974 100644 --- a/lib/surface_bootstrap/dropdown/item.ex +++ b/lib/surface_bootstrap/dropdown/item.ex @@ -12,6 +12,18 @@ defmodule SurfaceBootstrap.DropDown.Item do - `` - `` """ - use Surface.Component, slot: "dropdown_items" + + @doc "Classes to propagate to the li." + prop class, :css_class, default: [] + + slot default + + def render(assigns) do + ~F""" +
  • + <#slot /> +
  • + """ + end end diff --git a/priv/catalogue/navbar/example01.ex b/priv/catalogue/navbar/example01.ex index 0fb3444..5106c7a 100644 --- a/priv/catalogue/navbar/example01.ex +++ b/priv/catalogue/navbar/example01.ex @@ -51,8 +51,11 @@ defmodule SurfaceBootstrap.Catalogue.NavBar.Example01 do - - + + <:button_content> + John Doe + + Edit profile