Class: LightningUiKit::ToggleComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- LightningUiKit::ToggleComponent
- Defined in:
- app/components/lightning_ui_kit/toggle_component.rb
Constant Summary collapse
- VARIANTS =
%i[default outline].freeze
- SIZES =
%i[default sm lg].freeze
Instance Attribute Summary collapse
-
#pressed ⇒ Object
readonly
Returns the value of attribute pressed.
Instance Method Summary collapse
- #classes ⇒ Object
- #data ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(pressed: false, variant: :default, size: :default, disabled: false, **options) ⇒ ToggleComponent
constructor
A new instance of ToggleComponent.
- #state ⇒ Object
Constructor Details
#initialize(pressed: false, variant: :default, size: :default, disabled: false, **options) ⇒ ToggleComponent
Returns a new instance of ToggleComponent.
5 6 7 8 9 10 11 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 5 def initialize(pressed: false, variant: :default, size: :default, disabled: false, **) @pressed = pressed @variant = VARIANTS.include?(variant) ? variant : :default @size = SIZES.include?(size) ? size : :default @disabled = disabled @options = end |
Instance Attribute Details
#pressed ⇒ Object (readonly)
Returns the value of attribute pressed.
30 31 32 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 30 def pressed @pressed end |
Instance Method Details
#classes ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 13 def classes base = "lui:inline-flex lui:items-center lui:justify-center lui:gap-2 lui:rounded-md lui:text-sm lui:font-medium lui:whitespace-nowrap lui:cursor-pointer lui:select-none lui:transition-colors " \ "lui:text-foreground-muted lui:hover:bg-surface-hover lui:hover:text-foreground " \ "lui:data-[state=on]:bg-surface-hover lui:data-[state=on]:text-foreground " \ "lui:focus-visible:outline-2 lui:focus-visible:outline-offset-2 lui:focus-visible:outline-focus " \ "lui:disabled:pointer-events-none lui:disabled:opacity-50" merge_classes([base, variant_classes, size_classes, @options[:class]].compact.join(" ")) end |
#data ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 32 def data { controller: "lui-toggle", lui_toggle_pressed_value: @pressed, action: "click->lui-toggle#toggle" }.merge(@options[:data] || {}) end |
#disabled? ⇒ Boolean
26 27 28 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 26 def disabled? @disabled end |
#state ⇒ Object
22 23 24 |
# File 'app/components/lightning_ui_kit/toggle_component.rb', line 22 def state @pressed ? "on" : "off" end |