File: settings_block_component.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (49 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

module Layouts
  class SettingsBlockComponent < ViewComponent::Base
    # @param [String] heading
    # @param [String] description
    # @param [String] id
    # @param [String] testid
    # @param [Boolean] expanded
    # @param [Hash] button_options
    def initialize(
      heading, description: nil, id: nil, testid: nil, expanded: nil, button_options: {},
      css_class: nil)
      @heading = heading
      @description = description
      @id = id
      @testid = testid
      @expanded = expanded
      @button_options = button_options
      @css_class = css_class
    end

    renders_one :heading
    renders_one :description
    renders_one :callout
    renders_one :body

    private

    def section_classes
      classes = %w[settings no-animate]
      classes.push('expanded') if @expanded
      classes.push(@css_class) if @css_class
      classes.join(' ')
    end

    def title_classes
      %w[gl-heading-2 gl-cursor-pointer !gl-mb-2 js-settings-toggle js-settings-toggle-trigger-only]
    end

    def button_text
      @expanded ? _('Collapse') : _('Expand')
    end

    def aria_label
      @expanded ? "#{_('Collapse')} #{@heading}" : "#{_('Expand')} #{@heading}"
    end
  end
end