Sha256: a996b4ff400d9aa023732e9eeeec5b942460d696f3d0376e0ecec8e121e4ced6

Contents?: true

Size: 939 Bytes

Versions: 12

Compression:

Stored size: 939 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
      @trim = !!@base_component_arguments.delete(:trim)
    end

    def call
      unless @condition
        return @trim ? trimmed_content : content
      end

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

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.52.2 app/components/primer/conditional_wrapper.rb
primer_view_components-0.36.4 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.52.1 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.52.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.36.3 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.51.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.36.2 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.50.1 app/components/primer/conditional_wrapper.rb
openproject-primer_view_components-0.50.0 app/components/primer/conditional_wrapper.rb
primer_view_components-0.36.1 app/components/primer/conditional_wrapper.rb
primer_view_components-0.36.0 app/components/primer/conditional_wrapper.rb