okonomi_ui_kit 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,158 +0,0 @@
1
- module OkonomiUiKit
2
- module TableHelper
3
- def table(**options, &block)
4
- builder = TableBuilder.new(self)
5
-
6
- render 'okonomi/tables/table', builder: builder, options: options, &block
7
- end
8
-
9
- class TableBuilder
10
- include ActionView::Helpers::TagHelper
11
- include ActionView::Helpers::CaptureHelper
12
-
13
- def initialize(template)
14
- @template = template
15
- @current_row_cells = []
16
- @in_header = false
17
- @in_body = false
18
- end
19
-
20
- def head(&block)
21
- @in_header = true
22
- @in_body = false
23
- result = tag.thead(&block)
24
- @in_header = false
25
- result
26
- end
27
-
28
- def body(&block)
29
- @in_header = false
30
- @in_body = true
31
- result = tag.tbody(class: "divide-y divide-gray-200 bg-white", &block)
32
- @in_body = false
33
- result
34
- end
35
-
36
- def tr(&block)
37
- @current_row_cells = []
38
-
39
- # Collect all cells first
40
- yield if block_given?
41
-
42
- # Now render each cell with proper first/last detection
43
- rendered_cells = @current_row_cells.map.with_index do |cell, index|
44
- is_first = index == 0
45
- is_last = index == @current_row_cells.length - 1
46
-
47
- if cell[:type] == :th
48
- render_th(cell, is_first, is_last)
49
- else
50
- render_td(cell, is_first, is_last)
51
- end
52
- end
53
-
54
- result = tag.tr do
55
- @template.safe_join(rendered_cells)
56
- end
57
-
58
- @current_row_cells = []
59
- result
60
- end
61
-
62
- def th(scope: "col", align: :left, **options, &block)
63
- content = capture(&block) if block_given?
64
-
65
- # Store cell data for later processing in tr
66
- cell = { type: :th, scope: scope, align: align, options: options, content: content }
67
- @current_row_cells << cell
68
-
69
- # Return empty string for now, actual rendering happens in tr
70
- ""
71
- end
72
-
73
- def td(align: :left, **options, &block)
74
- content = capture(&block) if block_given?
75
-
76
- # Store cell data for later processing in tr
77
- cell = { type: :td, align: align, options: options, content: content }
78
- @current_row_cells << cell
79
-
80
- # Return empty string for now, actual rendering happens in tr
81
- ""
82
- end
83
-
84
-
85
- def empty_state(title: "No records found", icon: "heroicons/outline/document", colspan: nil, &block)
86
- content = if block_given?
87
- capture(&block)
88
- else
89
- tag.div(class: "text-center py-8") do
90
- icon_content = @template.svg_icon(icon, class: "mx-auto h-12 w-12 text-gray-400")
91
-
92
- icon_content + tag.p(title, class: "mt-2 text-sm font-medium text-gray-900") +
93
- tag.p("Get started by creating a new record.", class: "mt-1 text-sm text-gray-500")
94
- end
95
- end
96
-
97
- tr do
98
- td(colspan: colspan, class: "text-center py-8 text-gray-500") do
99
- content
100
- end
101
- end
102
- end
103
-
104
- private
105
-
106
- def tag
107
- @template.tag
108
- end
109
-
110
- def capture(*args, &block)
111
- @template.capture(*args, &block)
112
- end
113
-
114
- def render_th(cell, is_first, is_last)
115
- align_class = alignment_class(cell[:align])
116
-
117
- if is_first
118
- full_class = "py-3.5 pr-3 #{align_class} text-sm font-semibold text-gray-900 #{cell[:options][:class] || ""}".strip
119
- elsif is_last
120
- full_class = "relative py-3.5 #{align_class} text-sm font-semibold text-gray-900 #{cell[:options][:class] || ""}".strip
121
- else
122
- full_class = "pl-3 pr-3 py-3.5 #{align_class} text-sm font-semibold text-gray-900 #{cell[:options][:class] || ""}".strip
123
- end
124
-
125
- options = cell[:options].except(:class)
126
- tag.th(cell[:content], scope: cell[:scope], class: full_class, **options)
127
- end
128
-
129
- def render_td(cell, is_first, is_last)
130
- align_class = alignment_class(cell[:align])
131
-
132
- if is_first
133
- full_class = "py-4 pr-3 #{align_class} text-sm font-medium whitespace-nowrap text-gray-900 #{cell[:options][:class] || ""}".strip
134
- elsif is_last
135
- full_class = "relative py-4 #{align_class} text-sm font-medium whitespace-nowrap #{cell[:options][:class] || ""}".strip
136
- else
137
- full_class = "pl-3 pr-3 py-4 #{align_class} text-sm whitespace-nowrap text-gray-500 #{cell[:options][:class] || ""}".strip
138
- end
139
-
140
- options = cell[:options].except(:class)
141
- tag.td(cell[:content], class: full_class, **options)
142
- end
143
-
144
- def alignment_class(align)
145
- case align.to_sym
146
- when :left
147
- "text-left"
148
- when :center
149
- "text-center"
150
- when :right
151
- "text-right"
152
- else
153
- "text-left"
154
- end
155
- end
156
- end
157
- end
158
- end