-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Progress component to the docs (#158)
- Loading branch information
1 parent
a717cc2
commit 194bfac
Showing
6 changed files
with
71 additions
and
1 deletion.
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class Progress < Base | ||
def initialize(value: 0, **attrs) | ||
@value = value.to_f.clamp(0, 100) | ||
|
||
super(**attrs) | ||
end | ||
|
||
def view_template | ||
div(**attrs) do | ||
div(**indicator_attrs) | ||
end | ||
end | ||
|
||
private | ||
|
||
def default_attrs | ||
{ | ||
role: "progressbar", | ||
aria_valuenow: @value, | ||
aria_valuemin: 0, | ||
aria_valuemax: 100, | ||
aria_valuetext: "#{@value}%", | ||
class: "relative h-2 overflow-hidden rounded-full bg-primary/20 [&>*]:bg-primary" | ||
} | ||
end | ||
|
||
def indicator_attrs | ||
{ | ||
class: "h-full w-full flex-1", | ||
style: "transform: translateX(-#{100 - @value}%)" | ||
} | ||
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class Docs::ProgressView < ApplicationView | ||
def view_template | ||
component = "Progress" | ||
|
||
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do | ||
render Docs::Header.new(title: "Progress", description: "Displays an indicator showing the completion progress of a task, typically displayed as a progress bar.") | ||
|
||
render Docs::VisualCodeExample.new(title: "Example", context: self) do | ||
<<~RUBY | ||
Progress(value: 50, class: "w-[60%]") | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "With custom indicator color", context: self) do | ||
<<~RUBY | ||
Progress(value: 35, class: "w-[60%] [&>*]:bg-success") | ||
RUBY | ||
end | ||
|
||
render Components::ComponentSetup::Tabs.new(component_name: component) | ||
|
||
render Docs::ComponentsTable.new(component_files(component)) | ||
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