File: action_card_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 (54 lines) | stat: -rw-r--r-- 1,197 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
50
51
52
53
54
# frozen_string_literal: true

module Onboarding
  class ActionCardComponent < Onboarding::Component
    VARIANT_OPTIONS = [:default, :success, :promo].freeze

    # @param [String] title
    # @param [String] description
    # @param [String] icon
    # @param [String] href
    # @param [Symbol] variant
    # @param [Hash] html_options
    # @param [Hash] link_options

    def initialize(
      title: nil,
      description: nil,
      icon: nil,
      href: nil,
      variant: :default,
      link_options: {},
      **html_options
    )
      @title = title
      @description = description
      @icon = icon.to_s
      @href = href
      @variant = filter_attribute(variant.to_sym, VARIANT_OPTIONS, default: :default)
      @html_options = html_options
      @link_options = link_options
    end

    private

    delegate :sprite_icon, to: :helpers
    renders_one :this_is_text

    def card_classes
      ["action-card", "action-card-#{@variant}"]
    end

    def card_icon
      @variant == :success ? 'check' : @icon
    end

    def link?
      @href.present?
    end

    def html_options
      format_options(options: @html_options, css_classes: card_classes)
    end
  end
end