Skip to content

Commit

Permalink
feat: Add Breadcrumb component.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSMLG-BOT committed Feb 18, 2023
1 parent bbe9482 commit 72b1812
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 38 deletions.
2 changes: 2 additions & 0 deletions apps/phoenix_webcomponent/lib/phoenix_webcomponent.ex
Expand Up @@ -44,6 +44,7 @@ defmodule Phoenix.WebComponent do
alias Phoenix.WebComponent.Link
alias Phoenix.WebComponent.Actionbar
alias Phoenix.WebComponent.Appbar
alias Phoenix.WebComponent.Breadcrumb
alias Phoenix.WebComponent.Card
alias Phoenix.WebComponent.LeftMenu
alias Phoenix.WebComponent.Markdown
Expand All @@ -68,6 +69,7 @@ defmodule Phoenix.WebComponent do
import Phoenix.WebComponent.Link
import Phoenix.WebComponent.Actionbar
import Phoenix.WebComponent.Appbar
import Phoenix.WebComponent.Breadcrumb
import Phoenix.WebComponent.Card
import Phoenix.WebComponent.LeftMenu
import Phoenix.WebComponent.Markdown
Expand Down
79 changes: 79 additions & 0 deletions apps/phoenix_webcomponent/lib/phoenix_webcomponent/breadcrumb.ex
@@ -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
@@ -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
Expand Up @@ -5,43 +5,46 @@
class="w-48 h-[calc(100vh-56px)] bg-slate-100"
active={assigns[:active_menu]}
>
<:title class="text-slate-400 font-bold">
WebComponent
</:title>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Hooks</:title>
<:menu id="phx-wc-hook" to={"/"}>
<.wc_mdi name={"webhook"} class="w-4 h-4" />
PhxWCHook
</:menu>
</.wc_left_menu_group>
</:menu>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Icons</:title>
<:menu id="mdi" to={"/mdi"}>
<.wc_mdi name={"material-design"} class="w-4 h-4" />
MD Icon
</:menu>
<:menu id="bsi" to={"/bsi"}>
<.wc_bsi name={"bootstrap"} class="w-4 h-4" />
BS Icon
</:menu>
</.wc_left_menu_group>
</:menu>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Components</:title>
<:menu id="table" to="/storybook/components/actionbar"><.wc_bsi name={"tools"} class="w-4 h-4" />Actionbar</:menu>
<:menu id="card" to="/storybook/components/card"><.wc_mdi name={"card"} class="w-4 h-4" />Card</:menu>
<:menu id="left_menu" to="/storybook/components/left_menu"><.wc_bsi name={"layout-sidebar"} class="w-4 h-4" />Left Menu</:menu>
<:menu id="markdown" to="/storybook/components/markdown"><.wc_bsi name={"markdown"} class="w-4 h-4" />Markdown</:menu>
<:menu id="modal" to="/storybook/components/modal"><.wc_bsi name={"chat-square"} class="w-4 h-4" />Modal</:menu>
<:menu id="pagination" to="/storybook/components/pagination"><.wc_mdi name={"book-open-page-variant-outline"} class="w-4 h-4" />Pagination</:menu>
<:menu id="table" to="/storybook/components/table"><.wc_mdi name={"table"} class="w-4 h-4" />Table</:menu>
</.wc_left_menu_group>
</:menu>
<:title class="text-slate-400 font-bold">
WebComponent
</:title>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Hooks</:title>
<:menu id="phx-wc-hook" to={"/"}>
<.wc_mdi name={"webhook"} class="w-4 h-4" />
PhxWCHook
</:menu>
</.wc_left_menu_group>
</:menu>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Icons</:title>
<:menu id="mdi" to={"/mdi"}>
<.wc_mdi name={"material-design"} class="w-4 h-4" />
MD Icon
</:menu>
<:menu id="bsi" to={"/bsi"}>
<.wc_bsi name={"bootstrap"} class="w-4 h-4" />
BS Icon
</:menu>
</.wc_left_menu_group>
</:menu>
<:menu>
<.wc_left_menu_group active={assigns[:active_menu]}>
<:title>Components</:title>
<:menu id="actionbar" to="/storybook/components/actionbar"><.wc_bsi name={"tools"} class="w-4 h-4" />Actionbar</:menu>
<:menu id="breadcrumb" to="/storybook/components/breadcrumb"><.wc_bsi name={"segmented-nav"} class="w-4 h-4" />Breadcrumb</:menu>
<:menu id="card" to="/storybook/components/card"><.wc_bsi name={"card-text"} class="w-4 h-4" />Card</:menu>
<:menu id="left_menu" to="/storybook/components/left_menu"><.wc_bsi name={"layout-sidebar"} class="w-4 h-4" />Left Menu</:menu>
<:menu id="markdown" to="/storybook/components/markdown"><.wc_bsi name={"markdown"} class="w-4 h-4" />Markdown</:menu>
<:menu id="modal" to="/storybook/components/modal"><.wc_bsi name={"chat-square"} class="w-4 h-4" />Modal</:menu>
<:menu id="pagination" to="/storybook/components/pagination"><.wc_mdi name={"book-open-page-variant-outline"} class="w-4 h-4" />Pagination</:menu>
<:menu id="table" to="/storybook/components/table"><.wc_mdi name={"table"} class="w-4 h-4" />Table</:menu>
</.wc_left_menu_group>
</:menu>
</.wc_left_menu>
<div class="flex flex-col flex-auto">
<%= @inner_content %>
</div>
</main>
@@ -1,3 +1,7 @@
<.wc_breadcrumb class="bg-white h-6 text-slate-400">
<:crumb>Icon</:crumb>
<:crumb>Bootstrap Icon</:crumb>
</.wc_breadcrumb>
<.wc_card class="w-[100%_!important] h-[calc(100vh-56px-2em)_!important] overflow-auto">
<:title class="flex flex-row justify-center items-center">
<span class="text-4xl text-blue-600 hover:text-blue-400">
Expand Down
@@ -1,4 +1,7 @@

<.wc_breadcrumb class="bg-white h-6 text-slate-400">
<:crumb>Hooks</:crumb>
<:crumb>PhxWCHook</:crumb>
</.wc_breadcrumb>
<.wc_card class="w-[100%_!important] h-[calc(100vh-56px-2em)_!important] overflow-auto">
<:title class="flex flex-row justify-center items-center">
<span class="text-4xl text-blue-600 hover:text-blue-400">
Expand Down
@@ -1,3 +1,7 @@
<.wc_breadcrumb class="bg-white h-6 text-slate-400">
<:crumb>Icon</:crumb>
<:crumb>Material Design Icon</:crumb>
</.wc_breadcrumb>
<.wc_card class="w-[100%_!important] h-[calc(100vh-56px-2em)_!important] overflow-auto">
<:title class="flex flex-row justify-center items-center">
<span class="text-4xl text-blue-600 hover:text-blue-400">
Expand Down

0 comments on commit 72b1812

Please sign in to comment.