-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add breadcrumb to the documentation (#144)
- Loading branch information
1 parent
48bc8af
commit 3205764
Showing
12 changed files
with
293 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class Breadcrumb < Base | ||
def view_template(&) | ||
nav(**attrs, &) | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
aria: {label: "breadcrumb"} | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbEllipsis < Base | ||
def view_template(&) | ||
span(**attrs) do | ||
icon | ||
span(class: "sr-only") { "More" } | ||
end | ||
end | ||
|
||
private | ||
|
||
def icon | ||
svg( | ||
xmlns: "http://www.w3.org/2000/svg", | ||
class: "w-4 h-4", | ||
viewbox: "0 0 24 24", | ||
fill: "none", | ||
stroke: "currentColor", | ||
stroke_width: "2", | ||
stroke_linecap: "round", | ||
stroke_linejoin: "round" | ||
) do |s| | ||
s.circle(cx: "12", cy: "12", r: "1") | ||
s.circle(cx: "19", cy: "12", r: "1") | ||
s.circle(cx: "5", cy: "12", r: "1") | ||
end | ||
end | ||
|
||
def default_attrs | ||
{ | ||
aria: {hidden: true}, | ||
class: "flex h-9 w-9 items-center justify-center", | ||
role: "presentation" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbItem < Base | ||
def view_template(&) | ||
li(**attrs, &) | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
class: "inline-flex items-center gap-1.5" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbLink < Base | ||
def initialize(href: "#", **attrs) | ||
@href = href | ||
super(**attrs) | ||
end | ||
|
||
def view_template(&) | ||
a(href: @href, **attrs, &) | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
class: "transition-colors hover:text-foreground" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbList < Base | ||
def view_template(&) | ||
ol(**attrs, &) | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
class: "flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbPage < Base | ||
def view_template(&) | ||
span(**attrs, &) | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
aria: {disabled: true, current: "page"}, | ||
class: "font-normal text-foreground", | ||
role: "link" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class BreadcrumbSeparator < Base | ||
def view_template(&block) | ||
li(**attrs) do | ||
if block | ||
block.call | ||
else | ||
icon | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def icon | ||
svg( | ||
xmlns: "http://www.w3.org/2000/svg", | ||
class: "w-4 h-4", | ||
viewbox: "0 0 24 24", | ||
fill: "none", | ||
stroke: "currentColor", | ||
stroke_width: "2", | ||
stroke_linecap: "round", | ||
stroke_linejoin: "round" | ||
) { |s| s.path(d: "m9 18 6-6-6-6") } | ||
end | ||
|
||
def default_attrs | ||
{ | ||
aria: {hidden: true}, | ||
class: "[&>svg]:w-3.5 [&>svg]:h-3.5", | ||
role: "presentation" | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# frozen_string_literal: true | ||
|
||
class Docs::BreadcrumbView < ApplicationView | ||
def view_template | ||
component = "Breadcrumb" | ||
|
||
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do | ||
render Docs::Header.new(title: "Breadcrumb", description: "Indicates the user's current location within a navigational hierarchy.") | ||
|
||
Heading(level: 2) { "Usage" } | ||
|
||
render Docs::VisualCodeExample.new(title: "Example", context: self) do | ||
<<~RUBY | ||
Breadcrumb do | ||
BreadcrumbList do | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/") { "Home" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/docs/accordion") { "Components" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbPage { "Breadcrumb" } | ||
end | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "With custom separator", context: self) do | ||
<<~RUBY | ||
Breadcrumb do | ||
BreadcrumbList do | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/") { "Home" } | ||
end | ||
BreadcrumbSeparator { slash_icon } | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/docs/accordion") { "Components" } | ||
end | ||
BreadcrumbSeparator { slash_icon } | ||
BreadcrumbItem do | ||
BreadcrumbPage { "Breadcrumb" } | ||
end | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "Collapsed", context: self) do | ||
<<~RUBY | ||
Breadcrumb do | ||
BreadcrumbList do | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/") { "Home" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbEllipsis() | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/docs/accordion") { "Components" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbPage { "Breadcrumb" } | ||
end | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "With Link component", context: self) do | ||
<<~RUBY | ||
Breadcrumb do | ||
BreadcrumbList do | ||
BreadcrumbItem do | ||
BreadcrumbLink(href: "/") { "Home" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
Link(href: "/docs/accordion", class: "px-0") { "Components" } | ||
end | ||
BreadcrumbSeparator() | ||
BreadcrumbItem do | ||
BreadcrumbPage { "Breadcrumb" } | ||
end | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
render Components::ComponentSetup::Tabs.new(component_name: component) | ||
|
||
render Docs::ComponentsTable.new(component_files(component)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def slash_icon | ||
svg( | ||
xmlns: "http://www.w3.org/2000/svg", | ||
class: "w-4 h-4", | ||
viewbox: "0 0 24 24", | ||
fill: "none", | ||
stroke: "currentColor", | ||
stroke_width: "2", | ||
stroke_linecap: "round", | ||
stroke_linejoin: "round" | ||
) { |s| s.path(d: "M22 2 2 22") } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters