Class: Pajamas::ButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/pajamas/button_component.rb

Constant Summary collapse

CATEGORY_OPTIONS =
[:primary, :secondary, :tertiary].freeze
VARIANT_OPTIONS =
[:default, :confirm, :danger, :link, :reset].freeze
SIZE_OPTIONS =
[:small, :medium].freeze
TYPE_OPTIONS =
[:button, :reset, :submit].freeze
TARGET_OPTIONS =
%w[_self _blank _parent _top].freeze
METHOD_OPTIONS =
[:get, :post, :put, :delete, :patch].freeze
CATEGORY_CLASSES =
{
  primary: '',
  secondary: 'secondary',
  tertiary: 'tertiary'
}.freeze
VARIANT_CLASSES =
{
  default: 'btn-default',
  confirm: 'btn-confirm',
  danger: 'btn-danger',
  link: 'btn-link',
  reset: 'btn-gl-reset'
}.freeze
NON_CATEGORY_VARIANTS =
[:link, :reset].freeze
SIZE_CLASSES =
{
  small: 'btn-sm',
  medium: 'btn-md'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(category: :primary, variant: :default, size: :medium, type: :button, disabled: false, loading: false, block: false, label: false, selected: false, icon: nil, href: nil, form: false, target: nil, method: nil, button_options: {}, button_text_classes: nil, icon_classes: nil) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.

Parameters:

  • category (Symbol) (defaults to: :primary)
  • variant (Symbol) (defaults to: :default)
  • size (Symbol) (defaults to: :medium)
  • type (Symbol) (defaults to: :button)
  • disabled (Boolean) (defaults to: false)
  • loading (Boolean) (defaults to: false)
  • block (Boolean) (defaults to: false)
  • label (Boolean) (defaults to: false)
  • selected (Boolean) (defaults to: false)
  • icon (String) (defaults to: nil)
  • href (String) (defaults to: nil)
  • form (Boolean) (defaults to: false)
  • target (String) (defaults to: nil)
  • method (Symbol) (defaults to: nil)
  • button_options (Hash) (defaults to: {})
  • button_text_classes (String) (defaults to: nil)
  • icon_classes (String) (defaults to: nil)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/components/pajamas/button_component.rb', line 54

def initialize(
  category: :primary,
  variant: :default,
  size: :medium,
  type: :button,
  disabled: false,
  loading: false,
  block: false,
  label: false,
  selected: false,
  icon: nil,
  href: nil,
  form: false,
  target: nil,
  method: nil,
  button_options: {},
  button_text_classes: nil,
  icon_classes: nil
)
  @category = filter_attribute(category.to_sym, CATEGORY_OPTIONS)
  @variant = filter_attribute(variant.to_sym, VARIANT_OPTIONS)
  @size = filter_attribute(size.to_sym, SIZE_OPTIONS)
  @type = filter_attribute(type.to_sym, TYPE_OPTIONS, default: :button)
  @disabled = disabled
  @loading = loading
  @block = block
  @label = label
  @selected = selected
  @icon = icon
  @href = href
  @form = form
  @target = filter_attribute(target, TARGET_OPTIONS)
  @method = filter_attribute(method, METHOD_OPTIONS)
  @button_options = button_options
  @button_text_classes = button_text_classes
  @icon_classes = icon_classes
end