Sha256: 29d62fc796fde43a049e2878f66d4d0533e4fe3c1073817ecafa2792830ec418

Contents?: true

Size: 826 Bytes

Versions: 108

Compression:

Stored size: 826 Bytes

Contents

# frozen_string_literal: true

module Primer
  # Conditionally renders a `Primer::BaseComponent` around the given content. If the given condition
  # is true, a `Primer::BaseComponent` will render around the content. If the condition is false, only
  # the content is rendered.
  class ConditionalWrapper < Primer::Component
    # @param condition [Boolean] Whether or not to wrap the content in a `Primer::BaseComponent`.
    # @param base_component_arguments [Hash] The arguments to pass to `Primer::BaseComponent`.
    def initialize(condition:, **base_component_arguments)
      @condition = condition
      @base_component_arguments = base_component_arguments
    end

    def call
      return content unless @condition

      BaseComponent.new(**@base_component_arguments).render_in(self) { content }
    end
  end
end

Version data entries

108 entries across 108 versions & 2 rubygems

Version Path
primer_view_components-0.22.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.21.1 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.25.0 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.24.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.21.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.20.1 app/components/primer/conditional_wrapper.rb
primer_view_components-0.20.0 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.23.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.19.0 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.22.2 app/components/primer/conditional_wrapper.rb
primer_view_components-0.18.2 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.22.1 app/components/primer/conditional_wrapper.rb
primer_view_components-0.18.1 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.22.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.18.0 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.21.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.17.0 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.20.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.16.1 app/components/primer/conditional_wrapper.rb
primer_view_components-0.16.0 app/components/primer/conditional_wrapper.rb