Class: DesignSystem::Components::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/design_system/components/grid.rb

Overview

This class provides a grid component.

Constant Summary collapse

WIDTHS =
{
  full: { class: 'full', fraction: Rational(1, 1) },
  half: { class: 'one-half', fraction: Rational(1, 2) },
  one_half: { class: 'one-half', fraction: Rational(1, 2) },
  two_thirds: { class: 'two-thirds', fraction: Rational(2, 3) },
  one_third: { class: 'one-third', fraction: Rational(1, 3) },
  three_quarters: { class: 'three-quarters', fraction: Rational(3, 4) },
  quarter: { class: 'one-quarter', fraction: Rational(1, 4) },
  one_quarter: { class: 'one-quarter', fraction: Rational(1, 4) }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrid

Returns a new instance of Grid.



20
21
22
# File 'lib/design_system/components/grid.rb', line 20

def initialize
  @columns = []
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



7
8
9
# File 'lib/design_system/components/grid.rb', line 7

def columns
  @columns
end

Instance Method Details

#add_column(width, options = {}, &block) ⇒ Object



24
25
26
# File 'lib/design_system/components/grid.rb', line 24

def add_column(width, options = {}, &block)
  @columns << { width:, options:, block: }
end

#validate_total_width!Object

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/design_system/components/grid.rb', line 28

def validate_total_width!
  total = columns.sum { |col| width_to_fraction(col[:width]) }
  raise ArgumentError, 'Total grid width exceeds 100%' if total > 1
end