Skip to content

Commit f3da8af

Browse files
authored
Merge pull request #265 from BalajiR/icon-support-to-breadcrumb-link
Add icon support to breadcrumb link
2 parents 2ce9051 + 3599c6e commit f3da8af

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

assets/default.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@
692692
.pc-breadcrumbs__separator-chevron__icon {
693693
@apply w-6 h-6;
694694
}
695+
.pc-breadcrumb-icon {
696+
@apply w-6 h-6 shrink-0;
697+
}
695698

696699
/* Avatars */
697700

lib/petal_components/breadcrumbs.ex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule PetalComponents.Breadcrumbs do
22
use Phoenix.Component
3-
alias PetalComponents.Link
3+
alias PetalComponents.{Icon, Link}
44

55
attr(:separator, :string, default: "slash", values: ["slash", "chevron"])
66
attr(:class, :string, default: "", doc: "Parent div CSS class")
@@ -15,6 +15,7 @@ defmodule PetalComponents.Breadcrumbs do
1515
# link_class="!text-blue-500 text-sm font-semibold"
1616
# links={[
1717
# %{ label: "Link 1", to: "/" },
18+
# %{ to: "/", icon: :home, icon_class="text-blue-500" },
1819
# %{ label: "Link 1", to: "/", link_type: "patch|a|redirect" }
1920
# ]}
2021
# />
@@ -31,7 +32,14 @@ defmodule PetalComponents.Breadcrumbs do
3132
to={link.to}
3233
class={get_breadcrumb_classes(@link_class)}
3334
>
34-
<%= link.label %>
35+
<div class="flex items-center gap-2">
36+
<%= if link[:icon] do %>
37+
<Icon.icon name={link[:icon]} class={get_icon_classes(link[:icon_class])} />
38+
<% end %>
39+
<%= if link[:label] do %>
40+
<%= link.label %>
41+
<% end %>
42+
</div>
3543
</Link.a>
3644
<% end %>
3745
</div>
@@ -54,4 +62,7 @@ defmodule PetalComponents.Breadcrumbs do
5462

5563
defp get_breadcrumb_classes(user_classes),
5664
do: "pc-breadcrumb #{user_classes}"
65+
66+
defp get_icon_classes(icon_classes),
67+
do: "pc-breadcrumb-icon #{icon_classes}"
5768
end

test/petal/breadcrumbs_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule PetalComponents.BreadcrumbsTest do
1010
<.breadcrumbs
1111
class="text-md"
1212
links={[
13-
%{label: "Link 1", to: "/"}
13+
%{label: "Link 1", to: "/", icon: :home}
1414
]}
1515
/>
1616
""")
@@ -19,6 +19,7 @@ defmodule PetalComponents.BreadcrumbsTest do
1919
assert html =~ "<a"
2020
assert html =~ "href"
2121
assert html =~ "text-md"
22+
assert html =~ "<svg"
2223
end
2324

2425
test "breadcrumb_patch" do

0 commit comments

Comments
 (0)