Skip to content

Commit 3205764

Browse files
authored
Add breadcrumb to the documentation (#144)
1 parent 48bc8af commit 3205764

File tree

12 files changed

+293
-2
lines changed

12 files changed

+293
-2
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ GIT
1414

1515
GIT
1616
remote: https://github.com/ruby-ui/ruby_ui.git
17-
revision: 8909f0ecdd9ade28b01d76946e9d7438849b5856
17+
revision: 398415a462e170a1c9d7af06b588fa5f2b879465
1818
branch: main
1919
specs:
20-
ruby_ui (1.0.0.pre.alpha.4)
20+
ruby_ui (1.0.0.beta1)
2121

2222
GEM
2323
remote: https://rubygems.org/

app/components/ruby_ui/breadcrumb.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class Breadcrumb < Base
5+
def view_template(&)
6+
nav(**attrs, &)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
aria: {label: "breadcrumb"}
14+
}
15+
end
16+
end
17+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbEllipsis < Base
5+
def view_template(&)
6+
span(**attrs) do
7+
icon
8+
span(class: "sr-only") { "More" }
9+
end
10+
end
11+
12+
private
13+
14+
def icon
15+
svg(
16+
xmlns: "http://www.w3.org/2000/svg",
17+
class: "w-4 h-4",
18+
viewbox: "0 0 24 24",
19+
fill: "none",
20+
stroke: "currentColor",
21+
stroke_width: "2",
22+
stroke_linecap: "round",
23+
stroke_linejoin: "round"
24+
) do |s|
25+
s.circle(cx: "12", cy: "12", r: "1")
26+
s.circle(cx: "19", cy: "12", r: "1")
27+
s.circle(cx: "5", cy: "12", r: "1")
28+
end
29+
end
30+
31+
def default_attrs
32+
{
33+
aria: {hidden: true},
34+
class: "flex h-9 w-9 items-center justify-center",
35+
role: "presentation"
36+
}
37+
end
38+
end
39+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbItem < Base
5+
def view_template(&)
6+
li(**attrs, &)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
class: "inline-flex items-center gap-1.5"
14+
}
15+
end
16+
end
17+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbLink < Base
5+
def initialize(href: "#", **attrs)
6+
@href = href
7+
super(**attrs)
8+
end
9+
10+
def view_template(&)
11+
a(href: @href, **attrs, &)
12+
end
13+
14+
private
15+
16+
def default_attrs
17+
{
18+
class: "transition-colors hover:text-foreground"
19+
}
20+
end
21+
end
22+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbList < Base
5+
def view_template(&)
6+
ol(**attrs, &)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
class: "flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5"
14+
}
15+
end
16+
end
17+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbPage < Base
5+
def view_template(&)
6+
span(**attrs, &)
7+
end
8+
9+
private
10+
11+
def default_attrs
12+
{
13+
aria: {disabled: true, current: "page"},
14+
class: "font-normal text-foreground",
15+
role: "link"
16+
}
17+
end
18+
end
19+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module RubyUI
4+
class BreadcrumbSeparator < Base
5+
def view_template(&block)
6+
li(**attrs) do
7+
if block
8+
block.call
9+
else
10+
icon
11+
end
12+
end
13+
end
14+
15+
private
16+
17+
def icon
18+
svg(
19+
xmlns: "http://www.w3.org/2000/svg",
20+
class: "w-4 h-4",
21+
viewbox: "0 0 24 24",
22+
fill: "none",
23+
stroke: "currentColor",
24+
stroke_width: "2",
25+
stroke_linecap: "round",
26+
stroke_linejoin: "round"
27+
) { |s| s.path(d: "m9 18 6-6-6-6") }
28+
end
29+
30+
def default_attrs
31+
{
32+
aria: {hidden: true},
33+
class: "[&>svg]:w-3.5 [&>svg]:h-3.5",
34+
role: "presentation"
35+
}
36+
end
37+
end
38+
end

app/controllers/docs_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def badge
5858
render Docs::BadgeView.new
5959
end
6060

61+
def breadcrumb
62+
render Docs::BreadcrumbView.new
63+
end
64+
6165
def button
6266
render Docs::ButtonView.new
6367
end

app/views/components/shared/menu.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def components
6767
{name: "Aspect Ratio", path: helpers.docs_aspect_ratio_path},
6868
{name: "Avatar", path: helpers.docs_avatar_path},
6969
{name: "Badge", path: helpers.docs_badge_path},
70+
{name: "Breadcrumb", path: helpers.docs_breadcrumb_path, badge: "New"},
7071
{name: "Button", path: helpers.docs_button_path},
7172
{name: "Calendar", path: helpers.docs_calendar_path},
7273
{name: "Card", path: helpers.docs_card_path},

0 commit comments

Comments
 (0)