Class: BetterUi::General::Input::Toggle::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Input::Toggle::Component
- Defined in:
- app/components/better_ui/general/input/toggle/component.rb
Constant Summary collapse
- TOGGLE_THEME =
Costanti con classi Tailwind dirette
{ default: 'peer-checked:bg-gray-800', white: 'peer-checked:bg-white border peer-checked:border-gray-900', red: 'peer-checked:bg-red-600', rose: 'peer-checked:bg-rose-600', orange: 'peer-checked:bg-orange-600', green: 'peer-checked:bg-green-600', blue: 'peer-checked:bg-blue-600', yellow: 'peer-checked:bg-yellow-600', violet: 'peer-checked:bg-violet-600' }.freeze
- TOGGLE_TRACK_SIZE =
{ small: 'w-9 h-5', medium: 'w-11 h-6', large: 'w-14 h-7' }.freeze
- TOGGLE_THUMB_SIZE =
{ small: 'w-4 h-4', medium: 'w-5 h-5', large: 'w-6 h-6' }.freeze
- TOGGLE_THUMB_POSITION =
{ small: 'peer-checked:translate-x-4', medium: 'peer-checked:translate-x-5', large: 'peer-checked:translate-x-7' }.freeze
- TOGGLE_BASE_TRACK =
'relative bg-gray-300 rounded-full transition-colors duration-200 ease-in-out'.freeze
- TOGGLE_BASE_THUMB =
'bg-white rounded-full shadow-sm transform transition-transform duration-200 ease-in-out absolute top-0.5 left-0.5'.freeze
- TOGGLE_LABEL_GAP =
{ small: 'gap-2', medium: 'gap-2.5', large: 'gap-3' }.freeze
- TOGGLE_LABEL_TEXT =
{ small: 'text-sm', medium: 'text-base', large: 'text-lg' }.freeze
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#label_position ⇒ Object
readonly
Returns the value of attribute label_position.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name:, value: '1', checked: false, required: false, disabled: false, label: nil, label_position: :right, theme: :default, size: :medium, form: nil, classes: '', **options) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(name:, value: '1', checked: false, required: false, disabled: false, label: nil, label_position: :right, theme: :default, size: :medium, form: nil, classes: '', **options) ⇒ Component
Returns a new instance of Component.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 70 def initialize(name:, value: '1', checked: false, required: false, disabled: false, label: nil, label_position: :right, theme: :default, size: :medium, form: nil, classes: '', **) @name = name @value = value @checked = checked @required = required @disabled = disabled @label = label @label_position = label_position.to_sym @theme = theme.to_sym @size = size.to_sym @form = form @classes = classes = validate_params end |
Instance Attribute Details
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def checked @checked end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def classes @classes end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def disabled @disabled end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def form @form end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def label @label end |
#label_position ⇒ Object (readonly)
Returns the value of attribute label_position.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def label_position @label_position end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def required @required end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def size @size end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def theme @theme end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
54 55 56 |
# File 'app/components/better_ui/general/input/toggle/component.rb', line 54 def value @value end |