-
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.
Co-authored-by: Seth Horsley <[email protected]>
- Loading branch information
1 parent
3ee3442
commit 81e90a3
Showing
7 changed files
with
72 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
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyUI | ||
class Switch < Base | ||
def initialize(include_hidden: true, checked_value: "1", unchecked_value: "0", **attrs) | ||
@include_hidden = include_hidden | ||
@checked_value = checked_value | ||
@unchecked_value = unchecked_value | ||
super(**attrs) | ||
end | ||
|
||
def view_template | ||
label( | ||
role: "switch", | ||
class: "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background has-[:disabled]:cursor-not-allowed has-[:disabled]:opacity-50 bg-input has-[:checked]:bg-primary" | ||
) do | ||
input(type: "hidden", name: attrs[:name], value: @unchecked_value) if @include_hidden | ||
input(**attrs.merge(type: "checkbox", class: "hidden peer", value: @checked_value)) | ||
|
||
span(class: "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform translate-x-0 peer-checked:translate-x-5 ") | ||
end | ||
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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class Docs::SwitchView < ApplicationView | ||
def view_template | ||
component = "Switch" | ||
|
||
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do | ||
render Docs::Header.new(title: "Switch", description: "A control that allows the user to toggle between checked and not checked.") | ||
|
||
Heading(level: 2) { "Usage" } | ||
|
||
render Docs::VisualCodeExample.new(title: "Default", context: self) do | ||
<<~RUBY | ||
Switch(name: "switch") | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "Checked", context: self) do | ||
<<~RUBY | ||
Switch(name: "switch", checked: true) | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "Disabled", context: self) do | ||
<<~RUBY | ||
Switch(name: "switch", disabled: true) | ||
RUBY | ||
end | ||
|
||
render Docs::VisualCodeExample.new(title: "With flag include_hidden false", context: self) do | ||
<<~RUBY | ||
# Supports the creation of a hidden input to be used in forms inspired by the Ruby on Rails implementation of check_box. Default is true. | ||
Switch(name: "switch", include_hidden: false) | ||
RUBY | ||
end | ||
|
||
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