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

+2-2
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

+17
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
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
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
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
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
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
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

+4
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

+1
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},

app/views/docs/breadcrumb_view.rb

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# frozen_string_literal: true
2+
3+
class Docs::BreadcrumbView < ApplicationView
4+
def view_template
5+
component = "Breadcrumb"
6+
7+
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
8+
render Docs::Header.new(title: "Breadcrumb", description: "Indicates the user's current location within a navigational hierarchy.")
9+
10+
Heading(level: 2) { "Usage" }
11+
12+
render Docs::VisualCodeExample.new(title: "Example", context: self) do
13+
<<~RUBY
14+
Breadcrumb do
15+
BreadcrumbList do
16+
BreadcrumbItem do
17+
BreadcrumbLink(href: "/") { "Home" }
18+
end
19+
BreadcrumbSeparator()
20+
BreadcrumbItem do
21+
BreadcrumbLink(href: "/docs/accordion") { "Components" }
22+
end
23+
BreadcrumbSeparator()
24+
BreadcrumbItem do
25+
BreadcrumbPage { "Breadcrumb" }
26+
end
27+
end
28+
end
29+
RUBY
30+
end
31+
32+
render Docs::VisualCodeExample.new(title: "With custom separator", context: self) do
33+
<<~RUBY
34+
Breadcrumb do
35+
BreadcrumbList do
36+
BreadcrumbItem do
37+
BreadcrumbLink(href: "/") { "Home" }
38+
end
39+
BreadcrumbSeparator { slash_icon }
40+
BreadcrumbItem do
41+
BreadcrumbLink(href: "/docs/accordion") { "Components" }
42+
end
43+
BreadcrumbSeparator { slash_icon }
44+
BreadcrumbItem do
45+
BreadcrumbPage { "Breadcrumb" }
46+
end
47+
end
48+
end
49+
RUBY
50+
end
51+
52+
render Docs::VisualCodeExample.new(title: "Collapsed", context: self) do
53+
<<~RUBY
54+
Breadcrumb do
55+
BreadcrumbList do
56+
BreadcrumbItem do
57+
BreadcrumbLink(href: "/") { "Home" }
58+
end
59+
BreadcrumbSeparator()
60+
BreadcrumbItem do
61+
BreadcrumbEllipsis()
62+
end
63+
BreadcrumbSeparator()
64+
BreadcrumbItem do
65+
BreadcrumbLink(href: "/docs/accordion") { "Components" }
66+
end
67+
BreadcrumbSeparator()
68+
BreadcrumbItem do
69+
BreadcrumbPage { "Breadcrumb" }
70+
end
71+
end
72+
end
73+
RUBY
74+
end
75+
76+
render Docs::VisualCodeExample.new(title: "With Link component", context: self) do
77+
<<~RUBY
78+
Breadcrumb do
79+
BreadcrumbList do
80+
BreadcrumbItem do
81+
BreadcrumbLink(href: "/") { "Home" }
82+
end
83+
BreadcrumbSeparator()
84+
BreadcrumbItem do
85+
Link(href: "/docs/accordion", class: "px-0") { "Components" }
86+
end
87+
BreadcrumbSeparator()
88+
BreadcrumbItem do
89+
BreadcrumbPage { "Breadcrumb" }
90+
end
91+
end
92+
end
93+
RUBY
94+
end
95+
96+
render Components::ComponentSetup::Tabs.new(component_name: component)
97+
98+
render Docs::ComponentsTable.new(component_files(component))
99+
end
100+
end
101+
102+
private
103+
104+
def slash_icon
105+
svg(
106+
xmlns: "http://www.w3.org/2000/svg",
107+
class: "w-4 h-4",
108+
viewbox: "0 0 24 24",
109+
fill: "none",
110+
stroke: "currentColor",
111+
stroke_width: "2",
112+
stroke_linecap: "round",
113+
stroke_linejoin: "round"
114+
) { |s| s.path(d: "M22 2 2 22") }
115+
end
116+
end

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
get "aspect_ratio", to: "docs#aspect_ratio", as: :docs_aspect_ratio
2121
get "avatar", to: "docs#avatar", as: :docs_avatar
2222
get "badge", to: "docs#badge", as: :docs_badge
23+
get "breadcrumb", to: "docs#breadcrumb", as: :docs_breadcrumb
2324
get "button", to: "docs#button", as: :docs_button
2425
get "card", to: "docs#card", as: :docs_card
2526
get "calendar", to: "docs#calendar", as: :docs_calendar

0 commit comments

Comments
 (0)