Skip to content

Commit 2d4e442

Browse files
authored
Merge pull request #77 from substancelab/koppen/breadcrumb-item-namespace
Move BreadcrumbItem to Flowbite::Breadcrumb namespace
2 parents a62d834 + bd9fa34 commit 2d4e442

File tree

11 files changed

+153
-147
lines changed

11 files changed

+153
-147
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77

88
### Added
99

10-
* Breadcrumb component, including Flowbite::BreadcrumbItem with Flowbite::BreadcrumbItem::First and Flowbite::BreadcrumbItem::Current variants.
10+
* Breadcrumb component, including Flowbite::Breadcrumb::Item with Flowbite::Breadcrumb::Item::First and Flowbite::Breadcrumb::Item::Current variants.
1111
* DateTime input field components.
1212
* Toast component.
1313
* Ruby 4.0 support (no changes).

app/components/flowbite/breadcrumb.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ module Flowbite
55
#
66
# See https://flowbite.com/docs/components/breadcrumb/
77
#
8-
# Use {Flowbite::Breadcrumb} and the child {Flowbite::BreadcrumbItem} components to create and indicate a series of page structure and URLs to help the user navigate through the website.
8+
# Use {Flowbite::Breadcrumb} and the child {Flowbite::Breadcrumb::Item} components to create and indicate a series of page structure and URLs to help the user navigate through the website.
99
#
1010
# Breadcrumbs consist of the following components:
1111
#
1212
# - {Flowbite::Breadcrumb}: Container for breadcrumb items.
1313
# - {Flowbite::Breadcrumb::HomeIcon}: Home icon for the first breadcrumb item.
1414
# - {Flowbite::Breadcrumb::SeparatorIcon}: Separator between breadcrumb items.
15-
# - {Flowbite::BreadcrumbItem}: An individual breadcrumb item.
16-
# - {Flowbite::BreadcrumbItem::Current}: An invidual breadcrumb item without a link, usually used for the current page in the breadcrumb trail.
17-
# - {Flowbite::BreadcrumbItem::First}: An individual breadcrumb item with a home icon on it.
15+
# - {Flowbite::Breadcrumb::Item}: An individual breadcrumb item.
16+
# - {Flowbite::Breadcrumb::Item::Current}: An invidual breadcrumb item without a link, usually used for the current page in the breadcrumb trail.
17+
# - {Flowbite::Breadcrumb::Item::First}: An individual breadcrumb item with a home icon on it.
1818
#
19-
# @viewcomponent_slot [Flowbite::BreadcrumbItem] items The items of the
20-
# breadcrumb trail. Use {Flowbite::BreadcrumbItem::First} for the first
21-
# item to get a home icon, and {Flowbite::BreadcrumbItem::Current} for the
19+
# @viewcomponent_slot [Flowbite::Breadcrumb::Item] items The items of the
20+
# breadcrumb trail. Use {Flowbite::Breadcrumb::Item::First} for the first
21+
# item to get a home icon, and {Flowbite::Breadcrumb::Item::Current} for the
2222
# last item to render it without a link.
2323
#
2424
# @lookbook_embed BreadcrumbPreview
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
module Flowbite
4+
class Breadcrumb
5+
# Base class for rendering a breadcrumb item (middle items in the breadcrumb trail).
6+
#
7+
# @param href [String] The URL for the breadcrumb link.
8+
# @param options [Hash] Additional HTML attributes to pass to the link element.
9+
#
10+
# @example Middle item
11+
# <%= render Flowbite::Breadcrumb::Item.new(href: "/projects") { "Projects" } %>
12+
class Item < ViewComponent::Base
13+
attr_reader :href, :options
14+
15+
def initialize(href:, **options)
16+
super()
17+
@href = href
18+
@options = options
19+
end
20+
21+
def call
22+
content_tag(:li, item_options) do
23+
content_tag(:div, class: "flex items-center") do
24+
concat(render(prefix_icon)) if prefix_icon
25+
concat(render_link)
26+
end
27+
end
28+
end
29+
30+
protected
31+
32+
def item_options
33+
{}
34+
end
35+
36+
def prefix_icon
37+
Flowbite::Breadcrumb::SeparatorIcon.new
38+
end
39+
40+
def render_link
41+
link_options = {class: link_classes}.merge(options)
42+
content_tag(:a, content, href: href, **link_options)
43+
end
44+
45+
def link_classes
46+
["ms-1", "text-sm", "font-medium", "text-body", "hover:text-fg-brand"]
47+
end
48+
end
49+
end
50+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
module Flowbite
4+
class Breadcrumb
5+
class Item
6+
# Renders the current page breadcrumb item.
7+
# Current items are rendered as non-interactive spans with different styling.
8+
#
9+
# @param options [Hash] Additional HTML attributes to pass to the span element.
10+
#
11+
# @example Current page item
12+
# <%= render Flowbite::Breadcrumb::Item::Current.new { "Current Page" } %>
13+
class Current < Item
14+
def initialize(**options)
15+
super(href: nil, **options)
16+
end
17+
18+
protected
19+
20+
def item_options
21+
{"aria-current": "page"}
22+
end
23+
24+
def render_link
25+
link_options = {class: link_classes}.merge(options)
26+
content_tag(:span, content, **link_options)
27+
end
28+
29+
def link_classes
30+
["ms-1", "text-sm", "font-medium", "text-body-subtle"]
31+
end
32+
end
33+
end
34+
end
35+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
module Flowbite
4+
class Breadcrumb
5+
class Item
6+
# Renders the first breadcrumb item (typically home).
7+
# First items don't show a separator icon.
8+
#
9+
# @param href [String] The URL for the breadcrumb link.
10+
# @param options [Hash] Additional HTML attributes to pass to the link element.
11+
#
12+
# @example First item
13+
# <%= render Flowbite::Breadcrumb::Item::First.new(href: "/") { "Home" } %>
14+
class First < Item
15+
protected
16+
17+
def item_options
18+
{class: "inline-flex items-center"}
19+
end
20+
21+
def link_classes
22+
["text-sm", "font-medium", "inline-flex", "items-center", "text-body", "hover:text-fg-brand"]
23+
end
24+
25+
def prefix_icon
26+
nil
27+
end
28+
29+
def render_link
30+
icon = render(Flowbite::Breadcrumb::HomeIcon.new)
31+
link_options = {class: link_classes}.merge(options)
32+
content_tag(:a, safe_join([icon, content]), href: href, **link_options)
33+
end
34+
end
35+
end
36+
end
37+
end

app/components/flowbite/breadcrumb/separator_icon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Flowbite
44
class Breadcrumb
55
# Renders a breadcrumb separator icon.
66
#
7-
# This is automatically used by BreadcrumbItem components, but can be
7+
# This is automatically used by Breadcrumb::Item components, but can be
88
# used standalone if needed.
99
#
1010
# @example Standalone usage

app/components/flowbite/breadcrumb_item.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

app/components/flowbite/breadcrumb_item/current.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/components/flowbite/breadcrumb_item/first.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

demo/test/components/previews/breadcrumb_preview.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ class BreadcrumbPreview < Lookbook::Preview
66
def default
77
render(Flowbite::Breadcrumb.new) do |breadcrumb|
88
breadcrumb.with_item do
9-
render_to_string(Flowbite::BreadcrumbItem::First.new(href: "/").with_content("Home"))
9+
render_to_string(Flowbite::Breadcrumb::Item::First.new(href: "/").with_content("Home"))
1010
end
1111
breadcrumb.with_item do
12-
render_to_string(Flowbite::BreadcrumbItem.new(href: "/projects").with_content("Projects"))
12+
render_to_string(Flowbite::Breadcrumb::Item.new(href: "/projects").with_content("Projects"))
1313
end
1414
breadcrumb.with_item do
15-
render_to_string(Flowbite::BreadcrumbItem::Current.new.with_content("Current Page"))
15+
render_to_string(Flowbite::Breadcrumb::Item::Current.new.with_content("Current Page"))
1616
end
1717
end
1818
end

0 commit comments

Comments
 (0)