Class: Satis::Card::Component

Inherits:
ApplicationComponent show all
Defined in:
app/components/satis/card/component.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationComponent

#original_view_context

Instance Method Summary collapse

Methods inherited from ApplicationComponent

add_helper, #component_name

Constructor Details

#initialize(identifier = nil, icon: nil, title: nil, description: nil, menu: nil, content_padding: true, header_background_color: { dark: 'bg-gray-800', light: 'bg-white' }, custom_tabs_link: nil, scope: [], actions: [], key: nil, persist: true) ⇒ Component

Returns a new instance of Component.



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
# File 'app/components/satis/card/component.rb', line 13

def initialize(identifier = nil,
               icon: nil,
               title: nil,
               description: nil,
               menu: nil,
               content_padding: true,
               header_background_color: {
                 dark: 'bg-gray-800', light: 'bg-white'
               },
               custom_tabs_link: nil,
               scope: [],
               actions: [],
               key: nil,
               persist: true)
  super

  if identifier.blank?
    ActiveSupport::Deprecation.warn('Calling sts.card with the id parameter will become mandatory')
  end

  @identifier = identifier
  @title = title
  @title = @title.reject(&:blank?).compact.join(' ') if @title.is_a?(Array)
  @description = description
  @icon = icon
  @menu = menu
  @content_padding = content_padding
  @header_background_color = header_background_color
  @initial_actions = actions
  @persist = persist
  @key = key
  @custom_tabs_link = custom_tabs_link
  @scope = scope.present? ? scope : identifier
end

Instance Attribute Details

#content_paddingObject (readonly)

Returns the value of attribute content_padding.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def content_padding
  @content_padding
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def description
  @description
end

#header_background_colorObject (readonly)

Returns the value of attribute header_background_color.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def header_background_color
  @header_background_color
end

#iconObject (readonly)

Returns the value of attribute icon.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def icon
  @icon
end

#identifierObject (readonly)

Returns the value of attribute identifier.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def identifier
  @identifier
end

#initial_actionsObject (readonly)

Returns the value of attribute initial_actions.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def initial_actions
  @initial_actions
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def key
  @key
end

Returns the value of attribute menu.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def menu
  @menu
end

#persistObject (readonly)

Returns the value of attribute persist.



10
11
12
# File 'app/components/satis/card/component.rb', line 10

def persist
  @persist
end

#scope=(value) ⇒ Object (writeonly)

Sets the attribute scope

Parameters:

  • value

    the value to set the attribute scope to.



11
12
13
# File 'app/components/satis/card/component.rb', line 11

def scope=(value)
  @scope = value
end

Instance Method Details



63
64
65
66
67
68
# File 'app/components/satis/card/component.rb', line 63

def custom_tabs_link(&block)
  return @custom_tabs_link unless block_given?

  @custom_tabs_link = block.call
  # @custom_tabs_link_html = block.call.html_safe
end

#header?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/components/satis/card/component.rb', line 70

def header?
  icon.present? || title.present? || description.present? || menu
end

#titleObject

def key

return unless @persist

@key ||= identifier.to_s.parameterize.underscore if identifier.present?
@key ||=  strip_tags(@title)&.parameterize&.underscore

[controller_name, action_name, params[:id], @key, 'tab'].compact.join('_')

end



57
58
59
60
61
# File 'app/components/satis/card/component.rb', line 57

def title
  return @title if @title

  @title ||= ct('.title')
end