Class: Fluxbit::TableComponent

Inherits:
Component
  • Object
show all
Includes:
Config::TableComponent
Defined in:
app/components/fluxbit/table_component.rb

Overview

The ‘Fluxbit::TableComponent` is a customizable alert component that extends `Fluxbit::Component`. It provides various options to display alert messages with different styles, icons, and behaviors such as close functionality and animations.

Example usage:

= render Fluxbit::TableComponent.new(
  striped: true,
  bordered: true,
  hover: true,
  shadow: true,
  wrapper_html: { class: "my-custom-wrapper" },
  thead_html: { class: "my-custom-thead" },
  tbody_html: { class: "my-custom-tbody" },
  tr_html: { class: "my-custom-tr" }
) do |table|
  table.with_header do |header|
    header.with_column "Column 1"
    header.with_column "Column 2"
  end

  table.with_row do |row|
    row.with_cell "Data 1"
    row.with_cell "Data 2"
  end
end

Constant Summary

Constants inherited from Component

Component::ComponentObj

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ Fluxbit::TableComponent

Initializes the table component with the given properties.

Examples:

= render Fluxbit::TableComponent.new(
  striped: true,
  bordered: true,
  hover: true,
  shadow: true,
  thead_html: { class: "my-custom-thead" },
  tbody_html: { class: "my-custom-tbody" },
  tr_html: { class: "my-custom-tr" }
) do |table|
  table.with_header do |header|
    header.with_column "Column 1"
    header.with_column "Column 2"
  end

  table.with_row do |row|
    row.with_cell "Data 1"
    row.with_cell "Data 2"
  end
end

Parameters:

  • props (Hash)

    The properties to customize the table.

Options Hash (**props):

  • :striped (Boolean) — default: false

    Determines if the table rows should be striped.

  • :bordered (Boolean) — default: false

    Determines if the table should have borders.

  • :hover (Boolean) — default: false

    Determines if the table rows should highlight on hover.

  • :shadow (Boolean) — default: false

    Determines if the table should have a shadow effect.

  • :thead_html (Hash)

    Additional HTML attributes for the table header.

  • :tbody_html (Hash)

    Additional HTML attributes for the table body.

  • :tr_html (Hash)

    Additional HTML attributes for the table rows.

  • :cells_html (Hash)

    Additional HTML attributes for the table cells.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'app/components/fluxbit/table_component.rb', line 116

def initialize(**props)
  super
  @props = props
  @striped = options @props.delete(:striped), default: @@striped
  @bordered = options @props.delete(:bordered), default: @@bordered
  @hover = options @props.delete(:hover), default: @@hover
  @shadow = options @props.delete(:shadow), default: @@shadow
  @only_rows = options @props.delete(:only_rows), default: false

  # Wrapper HTML
  @wrapper_html = @props.delete(:wrapper_html) || {}
  add(class: styles[:wrapper][:base], to: @wrapper_html)
  add(class: styles[:wrapper][:shadow], to: @wrapper_html) if @shadow

  # Head HTML
  @thead_html = @props.delete(:thead_html) || {}
  # add(class: styles[:head][:base], to: @thead_html)

  # Body HTML
  @tbody_html = @props.delete(:tbody_html) || {}
  add(class: styles[:body][:base], to: @tbody_html)

  # Row HTML
  @tr_html = @props.delete(:tr_html) || {}
  add(class: styles[:body][:base], to: @tbody_html)

  # Footer HTML
  @tfoot_html = @props.delete(:tfoot_html) || {}
  add(class: styles[:footer][:base], to: @tfoot_html)

  # Table HTML
  add(class: styles[:root][:base], to: @props)
end

Instance Method Details

#callObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'app/components/fluxbit/table_component.rb', line 150

def call
  return safe_join(rows) if @only_rows && rows?

  # Wrapper
  capture do
    # Table
    concat(tag.div(**@wrapper_html) do
      concat(tag.table(**@props) do
        # header
        concat(
          tag.thead(**@thead_html) do
            concat(safe_join headers)
          end
        ) if headers?

        # body
        concat(
          tag.tbody(**@tbody_html) do
            if content.present?
              content
            else
              concat(safe_join(rows)) if rows?
            end
          end
        )

        # Footer
        concat(
          tag.tfoot(**@tfoot_html) do
            concat(footer)
          end
        ) if footer?
      end)
    end)
  end
end