# frozen_string_literal: true module Katalyst module Tables module Header module TypedColumns extend ActiveSupport::Concern # Renders a boolean column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a boolean column header # <% row.boolean :active %> # => Active # # @example Render a boolean column header with a custom label # <% row.boolean :active, label: "Published" %> # => Published # # @example Render a boolean column header with small width # <% row.boolean :active, width: :s %> # => Active # def boolean(method, **attributes, &) with_column(Header::BooleanComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a date column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a date column header # <% row.date :published_on %> # => Published on # # @example Render a date column header with a custom label # <% row.date :published_on, label: "Date" %> # => Date # # @example Render a boolean column header with small width # <% row.date :published_on, width: :s %> # => Published on # def date(method, **attributes, &) with_column(Header::DateComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a datetime column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a datetime column header # <% row.datetime :created_at %> # => Created at # # @example Render a datetime column header with a custom label # <% row.datetime :created_at, label: "Published at" %> # => Published at # # @example Render a boolean column header with small width # <% row.datetime :created_at, width: :s %> # => Created at # def datetime(method, **attributes, &) with_column(Header::DateTimeComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a number column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a number column header # <% row.number :comment_count %> # => Comments # # @example Render a number column header with a custom label # <% row.number :comment_count, label: "Comments" %> # => Comments # # @example Render a boolean column header with small width # <% row.number :comment_count, width: :s %> # => Comments # def number(method, **attributes, &) with_column(Header::NumberComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a currency column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a currency column header # <% row.currency :price %> # => Price # # @example Render a currency column header with a custom label # <% row.currency :price, label: "Amount($)" %> # => Amount($) # # @example Render a boolean column header with small width # <% row.currency :price, width: :s %> # => Price # def currency(method, **attributes, &) with_column(Header::CurrencyComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a rich text column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a rich text header # <% row.rich_text :content %> # => Content # # @example Render a rich text column header with a custom label # <% row.currency :content, label: "Content!" %> # => Content! # # @example Render a boolean column header with small width # <% row.currency :content, width: :s %> # => Content # def rich_text(method, **attributes, &) with_column(Header::RichTextComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a link column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a link column header # <% row.link :link %> # => Link # # @example Render a link column header with a custom label # <% row.link :link, label: "Post" %> # => Post # # @example Render a boolean column header with small width # <% row.link :link, width: :s %> # => Link # def link(method, **attributes, &) with_column(Header::LinkComponent.new(@table, method, link: @link_attributes, **attributes), &) end # Renders a attachment column header # @param method [Symbol] the method to call on the record to get the value # @param attributes [Hash] additional arguments are applied as html attributes to the th element # @option attributes [String] :label (nil) The label options to display in the header # @option attributes [Hash] :link ({}) The link options for the sorting link # @option attributes [String] :width (nil) The width of the column, can be +:xs+, +:s+, +:m+, +:l+ or nil # # @example Render a attachment column header # <% row.attachment :attachment %> # => Attachment # # @example Render a attachment column header with a custom label # <% row.attachment :attachment, label: "Document" %> # => Document # # @example Render a boolean column header with small width # <% row.attachment :attachment, width: :s %> # => Attachment # def attachment(method, **attributes, &) with_column(Header::AttachmentComponent.new(@table, method, link: @link_attributes, **attributes), &) end end end end end