Class: DesignSystem::Components::Grid
- Inherits:
-
Object
- Object
- DesignSystem::Components::Grid
- 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
-
#columns ⇒ Object
Returns the value of attribute columns.
Instance Method Summary collapse
- #add_column(width, options = {}, &block) ⇒ Object
-
#initialize ⇒ Grid
constructor
A new instance of Grid.
- #validate_total_width! ⇒ Object
Constructor Details
#initialize ⇒ Grid
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
#columns ⇒ Object
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, = {}, &block) @columns << { width:, options:, block: } end |
#validate_total_width! ⇒ Object
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 |