Sha256: 2f2cebf7035f22aa638dbc2643ca1e12de18d0b2d23c83e72451fab5ba8a17cf

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Formtastic
  module Inputs
    class BlazeToggleInput < Formtastic::Inputs::BooleanInput
      include Formtastic::Inputs::Base

      # def to_html
      #   input_wrapping do
      #     # hidden_field_html <<
      #     label_html <<
      #     builder.check_box( method, input_html_options )
      #     # label_with_nested_checkbox
      #   end
      # end

      def to_html
        input_wrapping do
          toggle_label <<
            hidden_field_html <<
            toggle_checkbox
        end
      end

      def toggle_label
        builder.label(
          method,
          label_text
        )
      end

      def toggle_checkbox
        builder.label(
          method,
          label_with_embedded_checkbox,
          label_html_options
        )
      end

      def label_html_options
        classes = input_html_options[:simple_checkbox] ? [] : ['c-toggle', input_html_options[:toggle_class]]
        super.merge(for: input_html_options[:id], class: classes - ['label'])
      end

      def label_with_embedded_checkbox
        check_box_html << "" << (input_html_options[:simple_checkbox] ? '' : toggle_html)  # << label_text
      end

      def toggle_html
        template.content_tag(
          :div,
          Formtastic::Util.html_safe(template.content_tag(:div, '', class: 'c-toggle__handle')),
          class: 'c-toggle__track'
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin_blaze_theme-0.6.0 lib/formtastic/inputs/blaze_toggle_input.rb
activeadmin_blaze_theme-0.5.16 lib/formtastic/inputs/blaze_toggle_input.rb