Sha256: 59a03fa5918c1d351946c3f4b64221599ddeee86a6ef3a964cb7fb8d5bc5ff24

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

module UiBibz::Ui::Core::Buttons

  # Create a button group
  #
  # This element is an extend of UiBibz::Ui::Core::Component.
  #
  # ==== Attributes
  #
  # * +content+ - Content of element
  # * +options+ - Options of element
  # * +html_options+ - Html Options of element
  #
  # ==== Options
  #
  # You can add HTML attributes using the +html_options+.
  # You can pass arguments in options attribute:
  # * +status+ - status of element with +symbol+ value:
  #   (+:primary+, +:secondary+, +:info+, +:warning+, +:danger+)
  # * +size+ - Size of element with +symbol+ value:
  #   (+:xs+, +:sm+, +:lg+)
  # * +position+ - Position vertical or horizontal with +symbol+ value:
  #   (+:vertical+, +:horizontal+)
  #
  # ==== Signatures
  #
  #   UiBibz::Ui::Core::Buttons::ButtonGroup.new(options = nil, html_options = nil) do
  #     ...
  #   end
  #
  # ==== Examples
  #
  #   UiBibz::Ui::Core::Buttons::ButtonGroup.new(position: :vertical, size: :xs) do
  #     UiBibz::Ui::Core::Buttons.Button.new('test').render
  #     UiBibz::Ui::Core::Buttons.Button.new('test2').render
  #   end.render
  #
  # ==== Helper
  #
  #   button_group(content, options = {}, html_options = {})
  #
  #   button_group(options = {}, html_options = {}) do
  #     content
  #   end
  #
  class ButtonGroup < UiBibz::Ui::Core::Component

    # See UiBibz::Ui::Core::Component.initialize
    def initialize content = nil, options = nil, html_options = nil, &block
      super
    end

    # Render html tag
    def render
      content_tag :div, content, html_options
    end

  private

    def component_html_classes
      ["btn-#{ type }", size, position]
    end

    def component_html_options
      { role: type }
    end

    def type
      options[:type] || :group
    end

    def component_html_data
      add_html_data "toggle", "buttons"
    end

    def size
      "btn-group-#{ options[:size] }" if options[:size]
    end

    def position
      "btn-group-#{ options[:position] }" if options[:position]
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ui_bibz-2.0.0.alpha24 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha23 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha22 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha21 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha20 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha19 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha18 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha16 lib/ui_bibz/ui/core/buttons/button_group.rb
ui_bibz-2.0.0.alpha15 lib/ui_bibz/ui/core/buttons/button_group.rb