Sha256: 437a0c89dd10a702571cfa953eefcfdbb1fc9732d601a6a04fc868796ed4dd34

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Coco
  class ButtonTo < Coco::Component
    include Concerns::WrapsComponent
    include Concerns::AcceptsOptions

    accepts_option :fit, from: [:auto, :full]

    wraps_component :button do |args|
      Coco::Button.new(
        type: :submit,
        fit: get_option_value(:fit) || :auto,
        **args
      )
    end

    %i[confirmation].each do |slot_name|
      renders_one slot_name, ->(**kwargs, &block) do
        button.send("with_#{slot_name}".to_sym, **kwargs, &block)
      end
    end

    attr_reader :method, :turbo

    def initialize(form: nil, params: nil, method: :post, action: nil, href: nil, turbo: false, **kwargs)
      @form_args = form.to_h
      @action = action || href
      @method = method
      @params = params.to_h
      @turbo = turbo
    end

    def params
      to_form_params(@params)
    end

    def form_args
      {
        url: action,
        method: method,
        data: {
          turbo: ("false" if !turbo)
        }
      }.deep_merge(@form_args)
    end

    def action
      @action.is_a?(String) ? @action : helpers.url_for(@action)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
coveragebook_components-0.12.2 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.12.1 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.12.0 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.11.0 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/shared/button_to/button_to.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/shared/button_to/button_to.rb