Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
apps/phoenix_webcomponent/lib/phoenix_webcomponent/breadcrumb.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
defmodule Phoenix.WebComponent.Breadcrumb do | ||
@moduledoc """ | ||
render appbar | ||
""" | ||
use Phoenix.WebComponent, :html | ||
|
||
@doc """ | ||
Generates webcomponent breadcrumb | ||
## Example | ||
<.wc_breadcrumb> | ||
<:crumb>Menu1</:crumb> | ||
<:crumb>Menu2</:crumb> | ||
</.wc_breadcrumb> | ||
""" | ||
@doc type: :component | ||
attr(:id, :any, | ||
default: false, | ||
doc: """ | ||
html attribute id | ||
""" | ||
) | ||
|
||
attr(:class, :string, | ||
default: "", | ||
doc: """ | ||
html attribute class | ||
""" | ||
) | ||
|
||
slot(:icon, | ||
required: false, | ||
doc: """ | ||
Render Icon | ||
""" | ||
) | ||
|
||
slot(:crumb, | ||
required: true, | ||
doc: """ | ||
Render menu | ||
""" | ||
) do | ||
attr(:id, :any) | ||
attr(:class, :string) | ||
attr(:to, :string) | ||
end | ||
|
||
def wc_breadcrumb(assigns) do | ||
assigns = | ||
assigns | ||
|> assign_new(:id, fn -> false end) | ||
|> assign_new(:class, fn -> "" end) | ||
|
||
~H""" | ||
<div id={@id} class={[ | ||
"flex flex-row justify-start items-center gap-2", | ||
"w-full px-4", | ||
@class, | ||
]}> | ||
<%= if length(@icon) > 0 do %> | ||
<%= render_slot(@icon) %> | ||
<% else %> | ||
<Phoenix.WebComponent.Icons.wc_mdi name="home" class="w-4 h-4" /> | ||
<% end %> | ||
<%= for {crumb, i} <- Enum.with_index(@crumb) do %> | ||
<span class="flex flex-row"> | ||
<%= render_slot(crumb) %> | ||
</span> | ||
<%= if i + 1 < length(@crumb) do %> | ||
<span class="flex flex-row"> | ||
/ | ||
</span> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
""" | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
apps/phx_wc_storybook_web/lib/phx_wc_storybook_web/storybook/components/breadcrumb.story.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule PhxWCStorybookWeb.Storybook.Components.Breadcrumb do | ||
# :live_component or :page are also available | ||
use PhxLiveStorybook.Story, :component | ||
|
||
def function, do: &Phoenix.WebComponent.Breadcrumb.wc_breadcrumb/1 | ||
def description, do: "A breadcrumb element." | ||
|
||
def variations do | ||
[ | ||
%Variation{ | ||
id: :default, | ||
attributes: %{ | ||
class: "shadow" | ||
}, | ||
slots: [ | ||
""" | ||
<:crumb> | ||
<a href="/">Home</a> | ||
</:crumb> | ||
<:crumb> | ||
<button>Page</button> | ||
</:crumb> | ||
""" | ||
] | ||
}, | ||
%Variation{ | ||
id: :custom_icon, | ||
attributes: %{ | ||
class: "bg-white text-slate-600" | ||
}, | ||
slots: [ | ||
""" | ||
<:icon> | ||
<Phoenix.WebComponent.Icons.wc_mdi name="home-assistant" class="w-4 h-4" /> | ||
</:icon> | ||
""", | ||
""" | ||
<:crumb> | ||
<a href="/">Home</a> | ||
</:crumb> | ||
<:crumb> | ||
<button>Page</button> | ||
</:crumb> | ||
""" | ||
] | ||
} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
apps/phx_wc_storybook_web/lib/phx_wc_storybook_web/templates/page/bsi.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
apps/phx_wc_storybook_web/lib/phx_wc_storybook_web/templates/page/index.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
apps/phx_wc_storybook_web/lib/phx_wc_storybook_web/templates/page/mdi.html.heex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters