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

Instance Method Details

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



22
23
24
25
26
27
28
29
# File 'app/helpers/baldur/ui_helper.rb', line 22

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



201
202
203
# File 'app/helpers/baldur/ui_helper.rb', line 201

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/baldur/ui_helper.rb', line 31

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



79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/baldur/ui_helper.rb', line 79

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



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/helpers/baldur/ui_helper.rb', line 183

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



111
112
113
114
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
# File 'app/helpers/baldur/ui_helper.rb', line 111

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_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



205
206
207
208
209
210
211
212
213
214
215
# File 'app/helpers/baldur/ui_helper.rb', line 205

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



162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/helpers/baldur/ui_helper.rb', line 162

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



175
176
177
178
179
180
181
# File 'app/helpers/baldur/ui_helper.rb', line 175

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



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/helpers/baldur/ui_helper.rb', line 147

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



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/helpers/baldur/ui_helper.rb', line 239

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) ⇒ Object



217
218
219
# File 'app/helpers/baldur/ui_helper.rb', line 217

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

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/baldur/ui_helper.rb', line 47

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/helpers/baldur/ui_helper.rb', line 63

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


91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/baldur/ui_helper.rb', line 91

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



104
105
106
107
108
109
# File 'app/helpers/baldur/ui_helper.rb', line 104

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



235
236
237
# File 'app/helpers/baldur/ui_helper.rb', line 235

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



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

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