CustomizableButtonComponent

InfoGenerateCreated ByPackages

This code defines a Ruby class called `ButtonComponent` that inherits from `ApplicationComponent`. This class is designed to generate customizable button components for a web application. The buttons can be modified in terms of color, size, and additional functionalities through various options.

Key attributes and functionalities include:

1. **Attributes:**
- `color`: Specifies the color of the button (e.g., btn-primary, btn-secondary).
- `size`: Specifies the size of the button (e.g., btn-lg, btn-md).
- `misc`: An array of additional CSS classes that can be applied to the button (e.g., btn-link, btn-outline).
- `text`: The text to be displayed on the button, defaulting to

# frozen_string_literal: true

# This component can be modified by various options for color, size, and additional functionalities:
# Colors: btn-neutral, btn-primary, btn-secondary, btn-accent, btn-info, btn-success, btn-warning, btn-error, btn-ghost
# Sizes: btn-lg, btn-md, btn-sm, btn-xs
# Misc: btn-link, btn-outline, btn-active, btn-disabled, glass, no-animation, btn-block, btn-circle, btn-square, btn-wide

class ButtonComponent < ApplicationComponent
  attr_reader :color, :size, :misc, :text

  def initialize(color: nil, size: nil, misc: [], text: "Button")
    @color = color
    @size = size
    @misc = misc
    @text = text
  end

  def template
    classes = ["btn"]
    classes << color if color
    classes << size if size
    classes.concat(misc)

    button(class: classes.join(" ")) { text }
  end
end