Sha256: 7af974d637a310f208ed2f57b4d08306bf79b8021f00367b7d094e2f7685eb30

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module Coco
  module App
    module Elements
      class FormButton < Coco::Component
        include Concerns::WrapsComponent

        wraps_component :button do |args|
          Coco::App::Elements::Button.new(type: :submit, **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
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
coveragebook_components-0.7.2 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.7.1 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.7.0 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.5 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.4 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.3 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.2 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.1 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.6.0 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.7 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.6 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.5 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.4 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.3 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.2 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.1 app/components/coco/app/elements/form_button/form_button.rb
coveragebook_components-0.5.0 app/components/coco/app/elements/form_button/form_button.rb