Sha256: 17da42039ba5b6bd3daa1a959823025306a58b673d8591e204ceb1195f6d26d0

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Content
    module Editor
      class NewItemComponent < BaseComponent
        include ::Turbo::StreamsHelper

        with_collection_parameter :item

        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          dragstart->#{NEW_ITEM_CONTROLLER}#dragstart
        ACTIONS

        def initialize(item:, container: item.container)
          super(item:, container:)
        end

        def item_component(**)
          ItemComponent.new(item:, container:, **)
        end

        def row_component(**)
          RowComponent.new(item:, container:, **)
        end

        def label
          t("katalyst.content.editor.new_item.#{item_type}", default: item.model_name.human)
        end

        def item_type
          item.model_name.param_key
        end

        private

        def default_html_attributes
          {
            draggable: "true",
            role:      "listitem",
            data:      {
              item_type:,
              controller: NEW_ITEM_CONTROLLER,
              action:     ACTIONS,
            },
          }
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katalyst-content-2.3.2 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.3.1 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.3.0 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.2.0 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.1.4 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.1.3 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.1.2 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.1.1 app/components/katalyst/content/editor/new_item_component.rb
katalyst-content-2.1.0 app/components/katalyst/content/editor/new_item_component.rb