Class: Components::ColumnHeader
- Inherits:
-
Base
- Object
- Base
- Components::ColumnHeader
- Includes:
- Phlex::Rails::Helpers::Request
- Defined in:
- app/components/column_header.rb
Instance Method Summary collapse
- #before_template ⇒ Object
-
#initialize(label:, sort_param: nil, sort_option: nil, sort_default: false, sort_ascending: true) ⇒ ColumnHeader
constructor
A new instance of ColumnHeader.
- #view_template ⇒ Object
Constructor Details
#initialize(label:, sort_param: nil, sort_option: nil, sort_default: false, sort_ascending: true) ⇒ ColumnHeader
Returns a new instance of ColumnHeader.
4 5 6 7 8 9 10 |
# File 'app/components/column_header.rb', line 4 def initialize(label:, sort_param: nil, sort_option: nil, sort_default: false, sort_ascending: true) @label = label @sort_param_name = sort_param&.to_s @sort_option = sort_option&.to_s @sort_default = sort_default @sort_ascending = sort_ascending end |
Instance Method Details
#before_template ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/components/column_header.rb', line 12 def before_template if @sort_option @sort_param = request.params[@sort_param_name] @active_sort = @sort_param == @sort_option || (@sort_default && @sort_param.blank?) if @active_sort = { sort: @sort_ascending ? "ascending" : "descending" } end end end |
#view_template ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/components/column_header.rb', line 24 def view_template th aria: do if @sort_option if @active_sort span { @label } whitespace Icon(icon: "caret-down-fill", label: t("components.column_header.current_sort")) else a href: url_for(request.params.merge(@sort_param_name => @sort_option)), class: "link-body-emphasis link-underline link-underline-opacity-0", aria: {role: "button"} do span { @label } whitespace Icon(icon: "caret-down", label: t("components.column_header.sort_by")) end end else span { @label } end end end |