Module: Baldur::UiHelper

Includes:
RenderHelper, UiHelperFeedback, UiHelperForms, UiHelperSidebar, UiHelperUnavailable
Included in:
Compatibility::UiAliases
Defined in:
app/helpers/baldur/ui_helper.rb

Constant Summary

Constants included from UiHelperFeedback

Baldur::UiHelperFeedback::FLASH_SNACKBAR_VARIANTS

Instance Method Summary collapse

Methods included from UiHelperForms

#ui_date_field_tag, #ui_menu_select_tag, #ui_mobile_field_tag, #ui_text_field_tag

Methods included from UiHelperUnavailable

#ui_dependency_dataset_name, #ui_unavailable_dependencies, #ui_unavailable_dependency_group_content, #ui_unavailable_dependency_groups, #ui_unavailable_explanation_content, #ui_unavailable_explanation_sections, #ui_unavailable_metric

Methods included from UiHelperSidebar

#ui_sidebar

Methods included from MarketingHelper

#ui_marketing_action_string, #ui_marketing_configured_brand, #ui_marketing_cta_banner, #ui_marketing_faq_section, #ui_marketing_features_section, #ui_marketing_footer, #ui_marketing_hero_section, #ui_marketing_pricing_tables, #ui_marketing_render_content, #ui_marketing_resolve_brand, #ui_marketing_testimonials_section, #ui_marketing_top_nav

Methods included from UiHelperFeedback

#snackbar_flash_payloads, #ui_alert, #ui_checkbox_tag, #ui_snackbar_stack, #ui_snackbar_turbo_stream

Instance Method Details

#ui_action_row(primary_button:, secondary_button: nil, extra_buttons: [], classes: nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/helpers/baldur/ui_helper.rb', line 26

def ui_action_row(primary_button:, secondary_button: nil, extra_buttons: [], classes: nil)
  buttons = []
  buttons << secondary_button if secondary_button.present?
  buttons.concat(Array(extra_buttons).compact)
  buttons << primary_button if primary_button.present?

  baldur_render 'baldur/components/action_row', buttons: buttons, class: classes
end

#ui_badge(text:, variant: :default, size: :sm, html_options: {}) ⇒ Object



205
206
207
# File 'app/helpers/baldur/ui_helper.rb', line 205

def ui_badge(text:, variant: :default, size: :sm, html_options: {})
  baldur_render 'baldur/components/badge', text: text, variant: variant, size: size, html_options: html_options
end

#ui_button(**options) ⇒ Object



18
19
20
# File 'app/helpers/baldur/ui_helper.rb', line 18

def ui_button(**options)
  baldur_render 'baldur/components/button', **options
end

#ui_card(title:, description: nil, badge: nil, icon: nil, actions: nil, variant: :default, classes: nil, body_class: nil, body: nil, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/baldur/ui_helper.rb', line 35

def ui_card(title:, description: nil, badge: nil, icon: nil, actions: nil, variant: :default, classes: nil,
            body_class: nil, body: nil, &block)
  body_content = body
  body_content = capture(&block) if block_given?
  baldur_render 'baldur/components/card',
                title: title,
                description: description,
                badge: badge,
                icon: icon,
                actions: actions,
                variant: variant,
                class: classes,
                body_class: body_class,
                body: body_content
end

#ui_chart_card(title: nil, description: nil, actions: nil, footer: nil, classes: nil, body: nil, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'app/helpers/baldur/ui_helper.rb', line 83

def ui_chart_card(title: nil, description: nil, actions: nil, footer: nil, classes: nil, body: nil, &block)
  body_content = body
  body_content = capture(&block) if block_given?
  baldur_render 'baldur/components/chart_card',
                title: title,
                description: description,
                actions: actions,
                footer: footer,
                class: classes,
                body: body_content
end

#ui_confirmation_modal(host_id:, dialog_id:, title:, description: nil, tone: :default, confirm_label: 'Confirm', cancel_label: 'Cancel', confirm_button_options: {}, cancel_button_options: {}, type_to_confirm: nil, body: nil, &block) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'app/helpers/baldur/ui_helper.rb', line 187

def ui_confirmation_modal(host_id:, dialog_id:, title:, description: nil, tone: :default, confirm_label: 'Confirm',
                          cancel_label: 'Cancel', confirm_button_options: {}, cancel_button_options: {}, type_to_confirm: nil, body: nil, &block)
  body = block_given? ? capture(&block) : body
  type_to_confirm = nil unless type_to_confirm.is_a?(Hash)
  baldur_render 'baldur/components/confirmation_modal',
                host_id: host_id,
                dialog_id: dialog_id,
                title: title,
                description: description,
                tone: tone,
                confirm_label: confirm_label,
                cancel_label: cancel_label,
                confirm_button_options: confirm_button_options,
                cancel_button_options: cancel_button_options,
                type_to_confirm: type_to_confirm,
                body: body
end

#ui_expandable_table_list(items) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/helpers/baldur/ui_helper.rb', line 115

def ui_expandable_table_list(items)
  values = Array(items).compact.map(&:to_s).map(&:strip).reject(&:blank?)
  return '' if values.empty?

  summary = values.join(', ')
  return ui_table_truncated_text(summary) if values.size <= 2

  (:div, class: 'table-disclosure', data: { controller: 'table-disclosure' }) do
    safe_join(
      [
        (
          :button,
          type: 'button',
          class: 'table-disclosure__trigger',
          aria: { expanded: 'false' },
          data: {
            action: 'click->table-disclosure#toggle',
            table_disclosure_target: 'trigger'
          }
        ) do
          safe_join(
            [
              (:span, "#{values.size} items", class: 'table-disclosure__summary', title: summary),
              (:span, 'Expand', class: 'table-disclosure__toggle table-disclosure__toggle--collapsed'),
              (:span, 'Collapse', class: 'table-disclosure__toggle table-disclosure__toggle--expanded')
            ]
          )
        end,
        (:div, class: 'table-disclosure__content', data: { table_disclosure_target: 'content' }) do
          safe_join(values.map { |value| (:div, value, class: 'table-disclosure__content-item') })
        end
      ]
    )
  end
end

#ui_hidden_field_tag(name, value = nil, options = {}) ⇒ Object



22
23
24
# File 'app/helpers/baldur/ui_helper.rb', line 22

def ui_hidden_field_tag(name, value = nil, options = {})
  hidden_field_tag(name, value, options)
end

#ui_icon(name, class_name: nil) ⇒ Object



11
12
13
14
15
16
# File 'app/helpers/baldur/ui_helper.rb', line 11

def ui_icon(name, class_name: nil)
  normalized_name = name.to_s.tr('_', '-')
  svg_options = LucideRails.default_options.merge('class' => class_name, 'aria-hidden' => 'true')

  (:svg, LucideRails::IconProvider.icon(normalized_name).html_safe, svg_options)
end

#ui_kpi(label:, value:, id: nil, caption: nil, trend: nil, variant: :default, caption_icon: nil, action: nil) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
# File 'app/helpers/baldur/ui_helper.rb', line 209

def ui_kpi(label:, value:, id: nil, caption: nil, trend: nil, variant: :default, caption_icon: nil, action: nil)
  baldur_render 'baldur/components/kpi',
                id: id,
                label: label,
                value: value,
                caption: caption,
                trend: trend,
                variant: variant,
                caption_icon: caption_icon,
                action: action
end

#ui_modal(id:, title:, description: nil, submit_label: 'Continue', close_label: 'Cancel', **options, &block) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
# File 'app/helpers/baldur/ui_helper.rb', line 166

def ui_modal(id:, title:, description: nil, submit_label: 'Continue', close_label: 'Cancel', **options, &block)
  body = block_given? ? capture(&block) : nil
  baldur_render 'baldur/components/modal',
                **{
                  id: id,
                  title: title,
                  description: description,
                  submit_label: submit_label,
                  close_label: close_label,
                  body: body
                }.merge(options)
end

#ui_modal_host(id:, classes: nil, &block) ⇒ Object



179
180
181
182
183
184
185
# File 'app/helpers/baldur/ui_helper.rb', line 179

def ui_modal_host(id:, classes: nil, &block)
  body = block_given? ? capture(&block) : nil
  baldur_render 'baldur/components/modal_host',
                id: id,
                classes: classes,
                body: body
end

#ui_pagination(current_page:, total_pages:, path_builder:, total_count: nil, per_page: nil, window: 2, rows_per_page_param: nil, rows_per_page_options: [], rows_per_page_selected: nil) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/helpers/baldur/ui_helper.rb', line 151

def ui_pagination(current_page:, total_pages:, path_builder:, total_count: nil, per_page: nil, window: 2,
                  rows_per_page_param: nil, rows_per_page_options: [], rows_per_page_selected: nil)
  baldur_render 'baldur/components/pagination',
                current_page: current_page.to_i,
                total_pages: total_pages.to_i,
                total_count: total_count,
                per_page: per_page,
                rows_per_page_param: rows_per_page_param,
                rows_per_page_options: Array(rows_per_page_options),
                rows_per_page_selected: rows_per_page_selected,
                path_builder: path_builder,
                pages: ui_pagination_pages(current_page: current_page.to_i, total_pages: total_pages.to_i,
                                           window: window.to_i)
end

#ui_pagination_pages(current_page:, total_pages:, window:) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'app/helpers/baldur/ui_helper.rb', line 248

def ui_pagination_pages(current_page:, total_pages:, window:)
  return [] if total_pages <= 1

  raw_pages = [1]
  raw_pages.concat(((current_page - window)..(current_page + window)).to_a)
  raw_pages << total_pages
  normalized = raw_pages.select { |page| page.between?(1, total_pages) }.uniq.sort

  pages = []
  normalized.each_with_index do |page, index|
    pages << page
    next_page = normalized[index + 1]
    pages << :gap if next_page && next_page - page > 1
  end
  pages
end

#ui_segmented_buttons(items:, aria_label: 'Tabs', classes: nil, id: nil, data: nil) ⇒ Object



221
222
223
224
225
226
227
228
# File 'app/helpers/baldur/ui_helper.rb', line 221

def ui_segmented_buttons(items:, aria_label: 'Tabs', classes: nil, id: nil, data: nil)
  baldur_render 'baldur/components/segmented_buttons',
                items: items,
                aria_label: aria_label,
                classes: classes,
                id: id,
                data: data
end

#ui_table(columns:, rows:, empty_state: 'No records yet', **options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/helpers/baldur/ui_helper.rb', line 51

def ui_table(columns:, rows:, empty_state: 'No records yet', **options)
  card_options = options.slice(:title, :title_meta, :description, :actions, :controls, :controls_position, :footer,
                               :classes)
  table_options = options.except(:title, :title_meta, :description, :actions, :controls, :controls_position,
                                 :footer, :classes)
  table_markup = baldur_render 'baldur/components/table',
                               **{
                                 columns: columns,
                                 rows: rows,
                                 empty_state: empty_state
                               }.merge(table_options)
  return table_markup if card_options.values.all?(&:blank?)

  ui_table_card(**card_options, body: table_markup)
end

#ui_table_card(title: nil, title_meta: nil, description: nil, actions: nil, controls: nil, controls_position: :row, footer: nil, classes: nil, body: nil, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/baldur/ui_helper.rb', line 67

def ui_table_card(title: nil, title_meta: nil, description: nil, actions: nil, controls: nil,
                  controls_position: :row, footer: nil, classes: nil, body: nil, &block)
  body_content = body
  body_content = capture(&block) if block_given?
  baldur_render 'baldur/components/table_card',
                title: title,
                title_meta: title_meta,
                description: description,
                actions: actions,
                controls: controls,
                controls_position: controls_position,
                footer: footer,
                class: classes,
                body: body_content
end


95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/helpers/baldur/ui_helper.rb', line 95

def ui_table_footer(current_page:, total_pages:, path_builder:, total_count: nil, per_page: nil,
                    rows_per_page_param: nil, rows_per_page_options: [], rows_per_page_selected: nil)
  baldur_render 'baldur/components/table_footer',
                current_page: current_page.to_i,
                total_pages: total_pages.to_i,
                total_count: total_count,
                per_page: per_page,
                rows_per_page_param: rows_per_page_param,
                rows_per_page_options: Array(rows_per_page_options),
                rows_per_page_selected: rows_per_page_selected,
                path_builder: path_builder
end

#ui_table_truncated_text(text, class_name: 'block truncate', title: nil) ⇒ Object



108
109
110
111
112
113
# File 'app/helpers/baldur/ui_helper.rb', line 108

def ui_table_truncated_text(text, class_name: 'block truncate', title: nil)
  value = text.to_s.strip
  return '' if value.blank?

  (:span, value, class: class_name, title: title.presence || value)
end

#ui_theme_toggle(aria_label: "Toggle theme", classes: nil) ⇒ Object



244
245
246
# File 'app/helpers/baldur/ui_helper.rb', line 244

def ui_theme_toggle(aria_label: "Toggle theme", classes: nil)
  baldur_render 'baldur/components/theme_toggle', aria_label: aria_label, classes: classes
end

#ui_tooltip(text:, content:, show_icon: true, icon: 'circle-help', variant: :link, wrapper_class: nil, trigger_class: nil, bubble_class: nil, inline: false) ⇒ Object



230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'app/helpers/baldur/ui_helper.rb', line 230

def ui_tooltip(text:, content:, show_icon: true, icon: 'circle-help', variant: :link, wrapper_class: nil,
               trigger_class: nil, bubble_class: nil, inline: false)
  baldur_render 'baldur/components/tooltip',
                text: text,
                content: content,
                show_icon: show_icon,
                icon: icon,
                variant: variant,
                wrapper_class: wrapper_class,
                trigger_class: trigger_class,
                bubble_class: bubble_class,
                inline: inline
end