forked from primer/view_components
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflex_layout.rb
More file actions
50 lines (43 loc) · 1.69 KB
/
Copy pathflex_layout.rb
File metadata and controls
50 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
module Primer
module OpenProject
# A layouting component used to arrange multiple components next / below each other
class FlexLayout < Primer::Component
status :open_project
renders_many :rows, lambda { |**system_arguments, &block|
child_component(system_arguments, &block)
}
renders_many :columns, lambda { |**system_arguments, &block|
child_component(system_arguments, &block)
}
# boxes are used when direction is set to row or column based on responsive breakpoints
renders_many :boxes, lambda { |**system_arguments, &block|
child_component(system_arguments, &block)
}
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(**system_arguments)
@system_arguments = deny_tag_argument(**system_arguments) || {}
@system_arguments[:display] = :flex
end
private
def render?
# no slot provided
return false if rows.empty? && columns.empty? && boxes.empty?
if [rows, columns, boxes].one? { |arr| !arr.empty? }
# only rows or columns or boxes are used
true
elsif [rows, columns, boxes].many? { |arr| !arr.empty? }
# rows, columns and boxes are used together, which is not allowed
raise ArgumentError, "You can't mix row, column and box slots"
end
end
def child_component(system_arguments, &block)
if system_arguments[:flex_layout] == true
Primer::OpenProject::FlexLayout.new(**system_arguments.except(:flex_layout), &block)
else
Primer::Box.new(**system_arguments || {})
end
end
end
end
end