Class: Satis::Card::Component
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Satis::Card::Component
- Defined in:
- app/components/satis/card/component.rb
Instance Attribute Summary collapse
-
#collapsed ⇒ Object
readonly
Returns the value of attribute collapsed.
-
#collapsible ⇒ Object
readonly
Returns the value of attribute collapsible.
-
#compact ⇒ Object
readonly
Returns the value of attribute compact.
-
#content_padding ⇒ Object
readonly
Returns the value of attribute content_padding.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#header_background_color ⇒ Object
readonly
Returns the value of attribute header_background_color.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#initial_actions ⇒ Object
readonly
Returns the value of attribute initial_actions.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#max_height ⇒ Object
readonly
Returns the value of attribute max_height.
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
-
#min_height ⇒ Object
readonly
Returns the value of attribute min_height.
-
#padding ⇒ Object
readonly
Returns the value of attribute padding.
-
#persist ⇒ Object
readonly
Returns the value of attribute persist.
-
#scope ⇒ Object
writeonly
Sets the attribute scope.
Attributes inherited from ApplicationComponent
Instance Method Summary collapse
- #content_classes ⇒ Object
- #content_style ⇒ Object
- #custom_tabs_link(&block) ⇒ Object
- #header? ⇒ Boolean
- #header_classes ⇒ Object
-
#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
constructor
A new instance of Component.
-
#title ⇒ Object
def key return unless @persist.
- #title_classes ⇒ Object
Methods inherited from ApplicationComponent
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 = @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
#collapsed ⇒ Object (readonly)
Returns the value of attribute collapsed.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def collapsed @collapsed end |
#collapsible ⇒ Object (readonly)
Returns the value of attribute collapsible.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def collapsible @collapsible end |
#compact ⇒ Object (readonly)
Returns the value of attribute compact.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def compact @compact end |
#content_padding ⇒ Object (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 |
#description ⇒ Object (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_color ⇒ Object (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 |
#height ⇒ Object (readonly)
Returns the value of attribute height.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def height @height end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def icon @icon end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def identifier @identifier end |
#initial_actions ⇒ Object (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 |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def key @key end |
#max_height ⇒ Object (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 |
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def @menu end |
#min_height ⇒ Object (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 |
#padding ⇒ Object (readonly)
Returns the value of attribute padding.
10 11 12 |
# File 'app/components/satis/card/component.rb', line 10 def padding @padding end |
#persist ⇒ Object (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
12 13 14 |
# File 'app/components/satis/card/component.rb', line 12 def scope=(value) @scope = value end |
Instance Method Details
#content_classes ⇒ Object
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_style ⇒ Object
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 |
#custom_tabs_link(&block) ⇒ Object
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
85 86 87 |
# File 'app/components/satis/card/component.rb', line 85 def header? icon.present? || title.present? || description.present? || end |
#header_classes ⇒ Object
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 |
#title ⇒ Object
def key
return unless @persist
@key ||= identifier.to_s.parameterize.underscore if identifier.present?
@key ||= (@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_classes ⇒ Object
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 |