Sha256: 75eb097d164c779e5af22d310c80bde58d1a24366b6d40c2763d79aadcafc562

Contents?: true

Size: 1.32 KB

Versions: 51

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Decidim
  # This cell renders a collapsible list of elements. Each element from the
  # `model` array will be rendered with the `:cell_name` cell.
  # `:cell_name` is optional, if not provided `card_for` helper is used.
  #
  # Available sizes:
  #  - any number between 1 and 12
  #  - default value is 3
  #
  # Example:
  #
  #    cell(
  #      "decidim/collapsible_list",
  #      my_list,
  #      cell_name: "my/cell",
  #      cell_options: { my: :options },
  #      hidden_elements_count_i18n_key: "my.custom.key",
  #      size: 4
  #    )
  class CollapsibleListCell < Decidim::ViewModel
    include Decidim::CardHelper

    private

    def list
      model
    end

    def cell_name
      options[:cell_name]
    end

    def cell_options
      options[:cell_options]
    end

    def size
      options[:size] || 3
    end

    def list_size_class
      "show-#{size}"
    end

    def list_class
      options[:list_class]
    end

    def collapsible?
      list.size > size
    end

    def hidden_elements_count
      return 0 unless collapsible?

      list.size - size
    end

    def hidden_elements_count_i18n_key
      options[:hidden_elements_count_i18n_key] || "decidim.collapsible_list.hidden_elements_count"
    end

    def seed
      @seed ||= Random.rand(9999)
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
decidim-core-0.23.3 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.23.2 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.23.1 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.23.1.rc1 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.23.0 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.22.0 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.21.0 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.20.1 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.20.0 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.19.1 app/cells/decidim/collapsible_list_cell.rb
decidim-core-0.19.0 app/cells/decidim/collapsible_list_cell.rb