Class: Layout::GridComponent

Inherits:
SparkComponents::Component
  • Object
show all
Defined in:
app/components/spark/layout/grid_component.rb

Constant Summary collapse

COLUMN =
[1,2,3,4,6,12].freeze
GUTTER =
i[small base medium large xl].freeze

Instance Method Summary collapse

Instance Method Details

#after_initObject



13
14
15
16
17
# File 'app/components/spark/layout/grid_component.rb', line 13

def after_init
  raise "Grids do not support both cols and span. Set `span` (default span for colums), or `cols` (the number of columns per row)" if span && cols
  @gutter ||= :base if gutter_match
  @span = 12 / @cols if @cols
end

#before_renderObject



19
20
21
22
23
24
25
26
# File 'app/components/spark/layout/grid_component.rb', line 19

def before_render
  base_class "spark-grid"

  add_class(join_class("gutter-#{gutter}")) if gutter
  add_class(join_class("gutter-#{gutter}-match")) if gutter && gutter_match
  data_attr column_min: min
  add_class join_class("no-wrap") unless wrap
end

#renderObject



28
29
30
31
32
33
34
35
36
# File 'app/components/spark/layout/grid_component.rb', line 28

def render
  (:div, tag_attrs) do
    concat (:div, class: join_class(:columns)) {
      columns.each { |column|
        concat column
      }
    }
  end
end