Class: BetterUi::ButtonComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/better_ui/button_component.rb

Constant Summary collapse

SIZES =
{
  xs: { padding: "px-2 py-1", text: "text-xs", icon: "w-3 h-3", gap: "gap-1" },
  sm: { padding: "px-3 py-1.5", text: "text-sm", icon: "w-4 h-4", gap: "gap-1.5" },
  md: { padding: "px-4 py-2", text: "text-base", icon: "w-5 h-5", gap: "gap-2" },
  lg: { padding: "px-5 py-2.5", text: "text-lg", icon: "w-6 h-6", gap: "gap-2.5" },
  xl: { padding: "px-6 py-3", text: "text-xl", icon: "w-7 h-7", gap: "gap-3" }
}.freeze
STYLES =
%i[solid outline ghost soft].freeze
TYPES =
%i[button submit reset].freeze

Constants inherited from ApplicationComponent

ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED

Instance Method Summary collapse

Constructor Details

#initialize(variant: :primary, style: :solid, size: :md, show_loader: false, show_loader_on_click: false, disabled: false, type: :button, href: nil, target: nil, rel: nil, method: nil, container_classes: nil, **options) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/components/better_ui/button_component.rb', line 19

def initialize(
  variant: :primary,
  style: :solid,
  size: :md,
  show_loader: false,
  show_loader_on_click: false,
  disabled: false,
  type: :button,
  href: nil,
  target: nil,
  rel: nil,
  method: nil,
  container_classes: nil,
  **options
)
  @variant = validate_variant(variant)
  @style = validate_style(style)
  @size = validate_size(size)
  @show_loader = show_loader
  @show_loader_on_click = show_loader_on_click
  @disabled = disabled
  @type = validate_type(type) unless href
  @href = href
  @target = target
  @rel = compute_rel(target, rel)
  @method = method
  @container_classes = container_classes
  @options = options
end

Instance Method Details

#link?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/components/better_ui/button_component.rb', line 49

def link?
  @href.present?
end