Skip to content

Commit 194bfac

Browse files
authored
Add Progress component to the docs (#158)
1 parent a717cc2 commit 194bfac

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ GIT
1414

1515
GIT
1616
remote: https://github.com/ruby-ui/ruby_ui.git
17-
revision: d29fac6edc255c352beb688c38e8365c1b277c4b
17+
revision: 500b8d98fbee73f15a3182feb4eca8e8e146d6b5
1818
branch: main
1919
specs:
2020
ruby_ui (1.0.0.beta1)

app/components/ruby_ui/progress.rb

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 RubyUI
4+
class Progress < Base
5+
def initialize(value: 0, **attrs)
6+
@value = value.to_f.clamp(0, 100)
7+
8+
super(**attrs)
9+
end
10+
11+
def view_template
12+
div(**attrs) do
13+
div(**indicator_attrs)
14+
end
15+
end
16+
17+
private
18+
19+
def default_attrs
20+
{
21+
role: "progressbar",
22+
aria_valuenow: @value,
23+
aria_valuemin: 0,
24+
aria_valuemax: 100,
25+
aria_valuetext: "#{@value}%",
26+
class: "relative h-2 overflow-hidden rounded-full bg-primary/20 [&>*]:bg-primary"
27+
}
28+
end
29+
30+
def indicator_attrs
31+
{
32+
class: "h-full w-full flex-1",
33+
style: "transform: translateX(-#{100 - @value}%)"
34+
}
35+
end
36+
end
37+
end

app/controllers/docs_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def popover
150150
render Docs::PopoverView.new
151151
end
152152

153+
def progress
154+
render Docs::ProgressView.new
155+
end
156+
153157
def radio_button
154158
render Docs::RadioButtonView.new
155159
end

app/views/components/shared/menu.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def components
9090
{name: "Masked Input", path: helpers.masked_input_path},
9191
{name: "Pagination", path: helpers.docs_pagination_path, badge: "New"},
9292
{name: "Popover", path: helpers.docs_popover_path},
93+
{name: "Progress", path: helpers.docs_progress_path, badge: "New"},
9394
{name: "Radio Button", path: helpers.docs_radio_button_path, badge: "New"},
9495
{name: "Select", path: helpers.docs_select_path, badge: "New"},
9596
{name: "Sheet", path: helpers.docs_sheet_path},

app/views/docs/progress_view.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
class Docs::ProgressView < ApplicationView
4+
def view_template
5+
component = "Progress"
6+
7+
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
8+
render Docs::Header.new(title: "Progress", description: "Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.")
9+
10+
render Docs::VisualCodeExample.new(title: "Example", context: self) do
11+
<<~RUBY
12+
Progress(value: 50, class: "w-[60%]")
13+
RUBY
14+
end
15+
16+
render Docs::VisualCodeExample.new(title: "With custom indicator color", context: self) do
17+
<<~RUBY
18+
Progress(value: 35, class: "w-[60%] [&>*]:bg-success")
19+
RUBY
20+
end
21+
22+
render Components::ComponentSetup::Tabs.new(component_name: component)
23+
24+
render Docs::ComponentsTable.new(component_files(component))
25+
end
26+
end
27+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
get "masked_input", to: "docs#masked_input", as: :masked_input
4444
get "pagination", to: "docs#pagination", as: :docs_pagination
4545
get "popover", to: "docs#popover", as: :docs_popover
46+
get "progress", to: "docs#progress", as: :docs_progress
4647
get "radio_button", to: "docs#radio_button", as: :docs_radio_button
4748
get "select", to: "docs#select", as: :docs_select
4849
get "sheet", to: "docs#sheet", as: :docs_sheet

0 commit comments

Comments
 (0)