Class: BetterUi::General::Table::ThComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Table::ThComponent
- Defined in:
- app/components/better_ui/general/table/th_component.rb
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#sort_direction ⇒ Object
readonly
Returns the value of attribute sort_direction.
-
#sortable ⇒ Object
readonly
Returns the value of attribute sortable.
-
#sorted ⇒ Object
readonly
Returns the value of attribute sorted.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(theme: :default, sortable: false, sorted: false, sort_direction: :asc, scope: "col", **html_options) ⇒ ThComponent
constructor
A new instance of ThComponent.
- #sort_icon ⇒ Object
- #th_attributes ⇒ Object
- #th_classes ⇒ Object
Constructor Details
#initialize(theme: :default, sortable: false, sorted: false, sort_direction: :asc, scope: "col", **html_options) ⇒ ThComponent
Returns a new instance of ThComponent.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/components/better_ui/general/table/th_component.rb', line 7 def initialize( theme: :default, sortable: false, sorted: false, sort_direction: :asc, scope: "col", ** ) @theme = theme.to_sym @sortable = !!sortable @sorted = !!sorted @sort_direction = sort_direction.to_sym @scope = scope @html_options = end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'app/components/better_ui/general/table/th_component.rb', line 5 def scope @scope end |
#sort_direction ⇒ Object (readonly)
Returns the value of attribute sort_direction.
5 6 7 |
# File 'app/components/better_ui/general/table/th_component.rb', line 5 def sort_direction @sort_direction end |
#sortable ⇒ Object (readonly)
Returns the value of attribute sortable.
5 6 7 |
# File 'app/components/better_ui/general/table/th_component.rb', line 5 def sortable @sortable end |
#sorted ⇒ Object (readonly)
Returns the value of attribute sorted.
5 6 7 |
# File 'app/components/better_ui/general/table/th_component.rb', line 5 def sorted @sorted end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
5 6 7 |
# File 'app/components/better_ui/general/table/th_component.rb', line 5 def theme @theme end |
Instance Method Details
#sort_icon ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/components/better_ui/general/table/th_component.rb', line 39 def sort_icon return unless @sortable if @sorted @sort_direction == :asc ? "↑" : "↓" else "↕" end end |
#th_attributes ⇒ Object
32 33 34 35 36 37 |
# File 'app/components/better_ui/general/table/th_component.rb', line 32 def th_attributes attrs = @html_options.except(:class) attrs[:class] = th_classes attrs[:scope] = @scope attrs end |
#th_classes ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/components/better_ui/general/table/th_component.rb', line 23 def th_classes [ "px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider", @sortable ? "cursor-pointer hover:bg-gray-200" : nil, @sorted ? "bg-gray-200" : nil, @html_options[:class] ].compact.join(" ") end |