Sha256: 8efe6a6fc862c248b785c2993f1d230399ce8e2f3f9c7bc9ce89530df5c61bd2

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Navigation
    module Editor
      class StatusBarComponent < BaseComponent
        ACTIONS = <<~ACTIONS.gsub(/\s+/, " ").freeze
          navigation:change@document->#{STATUS_BAR_CONTROLLER}#change
          turbo:morph-element->#{STATUS_BAR_CONTROLLER}#morph
        ACTIONS

        attr_reader :container

        def call
          tag.div(**html_attributes) do
            concat status(:published, last_update: l(menu.updated_at, format: :short))
            concat status(:draft)
            concat status(:dirty)
            concat actions
          end
        end

        def status(state, **)
          tag.span(t("views.katalyst.navigation.editor.#{state}_html", **),
                   class: "status-text",
                   data:  { state => "" })
        end

        def actions
          tag.menu do
            concat action(:discard, class: "button button--text")
            concat action(:revert, class: "button button--text") if menu.state == :draft
            concat action(:save, class: "button button--secondary")
            concat action(:publish, class: "button button--primary")
          end
        end

        def action(action, **)
          tag.li do
            button_tag(t("views.katalyst.navigation.editor.#{action}"),
                       name:  "commit",
                       value: action,
                       form:  menu_form_id,
                       **)
          end
        end

        private

        def default_html_attributes
          {
            data: {
              controller: STATUS_BAR_CONTROLLER,
              action:     ACTIONS,
              state:      menu.state,
            },
          }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katalyst-navigation-1.8.4 app/components/katalyst/navigation/editor/status_bar_component.rb
katalyst-navigation-1.8.3 app/components/katalyst/navigation/editor/status_bar_component.rb
katalyst-navigation-1.8.2 app/components/katalyst/navigation/editor/status_bar_component.rb