Sha256: b7e073fa4e976356d1a2bac1e106ebcacef55409a87f557ba5f476bc4837e247

Contents?: true

Size: 1.55 KB

Versions: 35

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module NfgUi
  module Bootstrap
    module Components
      # Bootstrap Carousel Slide / Carousel Item Component
      # https://getbootstrap.com/docs/4.1/components/carousel/#slides-only
      class CarouselItem < NfgUi::Bootstrap::Components::Base
        include Bootstrap::Utilities::Activatable

        def caption
          options.fetch(:caption, nil)
        end

        def component_family
          :carousel
        end

        def data
          return super unless interval
          super.merge!(interval: interval)
        end

        def image
          options.fetch(:image, nil)
        end

        # manually pass in an interval numerical value
        # which translates to miliseconds between carousel item
        # slide transitions.
        # ex: interval: 5000
        def interval
          options[:interval] || nil
        end

        def label
          options.fetch(:label, nil)
        end

        def render
          super do
            capture do
              concat(image_tag(image, class: 'd-block w-100')) if image
              if caption || label
                concat(NfgUi::Bootstrap::Components::CarouselCaption.new({ body: caption, label: label }, view_context).render)
              end
              concat(block_given? ? yield : body)
            end
          end
        end

        private

        def non_html_attribute_options
          super.push(:image,
                     :caption,
                     :label,
                     :interval)
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
nfg_ui-6.17.2 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.17.1 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.17.0 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.16.3 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.16.2 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.16.1 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-6.16.0 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-5.15.7 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-5.15.6 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-5.15.5 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-5.15.4 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-5.15.3 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.15.2 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.15.1 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.15.0 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.14.7 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.14.6.3 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.14.6.2 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.14.6.1 lib/nfg_ui/bootstrap/components/carousel_item.rb
nfg_ui-0.14.6 lib/nfg_ui/bootstrap/components/carousel_item.rb