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, collapsible: false, collapsed: false, height: nil, min_height: nil, max_height: nil, padding: nil, compact: false) ⇒ Component

Returns a new instance of Component.



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
55
56
57
58
59
60
61
# File 'app/components/satis/card/component.rb', line 14

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,
               collapsible: false,
               collapsed: false,
               height: nil,
               min_height: nil,
               max_height: nil,
               padding: nil,
               compact: false)
  super

  if identifier.blank?
    Satis::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
  @collapsible = collapsible
  @collapsed = collapsed
  @height = height
  @min_height = min_height
  @max_height = max_height
  @padding = padding
  @compact = compact
end

Instance Attribute Details

#collapsedObject (readonly)

Returns the value of attribute collapsed.



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

def collapsed
  @collapsed
end

#collapsibleObject (readonly)

Returns the value of attribute collapsible.



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

def collapsible
  @collapsible
end

#compactObject (readonly)

Returns the value of attribute compact.



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

def compact
  @compact
end

#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

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
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

#max_heightObject (readonly)

Returns the value of attribute max_height.



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

def max_height
  @max_height
end

Returns the value of attribute menu.



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

def menu
  @menu
end

#min_heightObject (readonly)

Returns the value of attribute min_height.



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

def min_height
  @min_height
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
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.



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

def scope=(value)
  @scope = value
end

Instance Method Details

#content_classesObject



97
98
99
100
101
102
103
104
105
# File 'app/components/satis/card/component.rb', line 97

def content_classes
  classes = []
  if padding
    classes << padding
  elsif content_padding
    classes << (compact ? 'px-4 py-3' : 'px-6 py-6')
  end
  classes.join(' ')
end

#content_styleObject



89
90
91
92
93
94
95
# File 'app/components/satis/card/component.rb', line 89

def content_style
  styles = []
  styles << "height: #{height}" if height
  styles << "min-height: #{min_height}" if min_height
  styles << "max-height: #{max_height}; overflow-y: auto" if max_height
  styles.join('; ')
end


78
79
80
81
82
83
# File 'app/components/satis/card/component.rb', line 78

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)


85
86
87
# File 'app/components/satis/card/component.rb', line 85

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

#header_classesObject



107
108
109
110
111
# File 'app/components/satis/card/component.rb', line 107

def header_classes
  base = tabs? ? '' : 'border-b border-gray-200'
  base += ' sts-card__header--compact' if compact
  base
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



72
73
74
75
76
# File 'app/components/satis/card/component.rb', line 72

def title
  return @title if @title

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

#title_classesObject



113
114
115
116
117
118
119
# File 'app/components/satis/card/component.rb', line 113

def title_classes
  if compact
    'text-sm leading-5 font-medium text-gray-900 dark:text-white'
  else
    'text-lg leading-6 font-medium text-gray-900 dark:text-white'
  end
end