Class: Keystone::Ui::OptionCardComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/option_card_component.rb

Constant Summary collapse

BASE_CLASSES =
"inline-flex items-center gap-2 px-3 py-2 rounded-lg border-2 transition cursor-pointer"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, selected: false, input_data: {}, label_data: {}) ⇒ OptionCardComponent

Returns a new instance of OptionCardComponent.



10
11
12
13
14
15
16
# File 'app/components/keystone/ui/option_card_component.rb', line 10

def initialize(name:, value:, selected: false, input_data: {}, label_data: {})
  @name = name
  @value = value
  @selected = selected
  @input_data = input_data
  @label_data = label_data
end

Instance Attribute Details

#input_dataObject (readonly)

Returns the value of attribute input_data.



8
9
10
# File 'app/components/keystone/ui/option_card_component.rb', line 8

def input_data
  @input_data
end

#label_dataObject (readonly)

Returns the value of attribute label_data.



8
9
10
# File 'app/components/keystone/ui/option_card_component.rb', line 8

def label_data
  @label_data
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'app/components/keystone/ui/option_card_component.rb', line 8

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'app/components/keystone/ui/option_card_component.rb', line 8

def value
  @value
end

Instance Method Details

#classesObject



22
23
24
25
# File 'app/components/keystone/ui/option_card_component.rb', line 22

def classes
  border = selected? ? "border-accent-500" : "border-transparent"
  "#{BASE_CLASSES} #{border}"
end

#selected?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/components/keystone/ui/option_card_component.rb', line 18

def selected?
  @selected
end