Class: BetterUi::General::Grid::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Grid::Component
- Defined in:
- app/components/better_ui/general/grid/component.rb
Constant Summary collapse
- GRID_BASE_CLASSES =
Classi base grid
"grid"
- VALID_GRID_COLS =
Valori supportati per validazione
(1..12).to_a + [:auto, :none].freeze
- VALID_GRID_ROWS =
(1..6).to_a + [:auto, :none].freeze
- VALID_BREAKPOINTS =
[:sm, :md, :lg, :xl].freeze
- GRID_GAP =
Gap (spaziatura)
{ none: 'gap-0', small: 'gap-2', medium: 'gap-4', large: 'gap-6' }.freeze
- GRID_FLOW =
Flow (direzione)
{ row: 'grid-flow-row', col: 'grid-flow-col', row_dense: 'grid-flow-row-dense', col_dense: 'grid-flow-col-dense' }.freeze
- GRID_ALIGN_ITEMS =
Align items
{ start: 'items-start', center: 'items-center', end: 'items-end', stretch: 'items-stretch' }.freeze
- GRID_JUSTIFY_ITEMS =
Justify items
{ start: 'justify-items-start', center: 'justify-items-center', end: 'justify-items-end', stretch: 'justify-items-stretch' }.freeze
Instance Attribute Summary collapse
-
#align_items ⇒ Object
readonly
Returns the value of attribute align_items.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#cols ⇒ Object
readonly
Returns the value of attribute cols.
-
#flow ⇒ Object
readonly
Returns the value of attribute flow.
-
#gap ⇒ Object
readonly
Returns the value of attribute gap.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#justify_items ⇒ Object
readonly
Returns the value of attribute justify_items.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #combined_classes ⇒ Object
- #grid_attributes ⇒ Object
-
#initialize(cols: 1, rows: nil, gap: :medium, flow: :row, align_items: nil, justify_items: nil, classes: '', id: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(cols: 1, rows: nil, gap: :medium, flow: :row, align_items: nil, justify_items: nil, classes: '', id: nil, **html_options) ⇒ Component
Returns a new instance of Component.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/components/better_ui/general/grid/component.rb', line 40 def initialize( cols: 1, rows: nil, gap: :medium, flow: :row, align_items: nil, justify_items: nil, classes: '', id: nil, ** ) @cols = normalize_grid_cols_with_defaults(cols) @rows = normalize_grid_rows_with_defaults(rows) if rows @gap = normalize_grid_gap_with_defaults(gap) @flow = flow.to_sym @align_items = align_items&.to_sym @justify_items = justify_items&.to_sym @classes = classes @id = id @html_options = validate_grid_params end |
Instance Attribute Details
#align_items ⇒ Object (readonly)
Returns the value of attribute align_items.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def align_items @align_items end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def classes @classes end |
#cols ⇒ Object (readonly)
Returns the value of attribute cols.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def cols @cols end |
#flow ⇒ Object (readonly)
Returns the value of attribute flow.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def flow @flow end |
#gap ⇒ Object (readonly)
Returns the value of attribute gap.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def gap @gap end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def @html_options end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def id @id end |
#justify_items ⇒ Object (readonly)
Returns the value of attribute justify_items.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def justify_items @justify_items end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
7 8 9 |
# File 'app/components/better_ui/general/grid/component.rb', line 7 def rows @rows end |
Instance Method Details
#combined_classes ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/components/better_ui/general/grid/component.rb', line 64 def combined_classes [ GRID_BASE_CLASSES, generate_cols_classes, generate_rows_classes, generate_gap_classes, GRID_FLOW[@flow], @align_items ? GRID_ALIGN_ITEMS[@align_items] : nil, @justify_items ? GRID_JUSTIFY_ITEMS[@justify_items] : nil, @classes, @html_options[:class] ].compact.join(" ") end |
#grid_attributes ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/components/better_ui/general/grid/component.rb', line 78 def grid_attributes attrs = { class: combined_classes, id: @id } @html_options.except(:class).each do |key, value| attrs[key] = value end attrs end |