Module: Baldur::UiHelper
- Includes:
- RenderHelper, UiHelperFeedback, UiHelperForms, UiHelperUnavailable
- Included in:
- Compatibility::UiAliases
- Defined in:
- app/helpers/baldur/ui_helper.rb
Instance Method Summary collapse
- #ui_action_row(primary_button:, secondary_button: nil, extra_buttons: [], classes: nil) ⇒ Object
- #ui_badge(text:, variant: :default, size: :sm, html_options: {}) ⇒ Object
- #ui_button(**options) ⇒ Object
- #ui_card(title:, description: nil, badge: nil, icon: nil, actions: nil, variant: :default, classes: nil, body_class: nil, body: nil, &block) ⇒ Object
- #ui_chart_card(title: nil, description: nil, actions: nil, footer: nil, classes: nil, body: nil, &block) ⇒ Object
- #ui_expandable_table_list(items) ⇒ Object
- #ui_icon(name, class_name: nil) ⇒ Object
- #ui_kpi(id: nil, label:, value:, caption: nil, trend: nil, variant: :default, caption_icon: nil, action: nil) ⇒ Object
- #ui_modal(id:, title:, description: nil, submit_label: "Continue", close_label: "Cancel", **options, &block) ⇒ Object
- #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
- #ui_pagination_pages(current_page:, total_pages:, window:) ⇒ Object
- #ui_segmented_buttons(items:, aria_label: "Tabs", classes: nil) ⇒ Object
- #ui_table(columns:, rows:, empty_state: "No records yet", **options) ⇒ Object
- #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
- #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) ⇒ Object
- #ui_table_truncated_text(text, class_name: "block truncate", title: nil) ⇒ Object
- #ui_tooltip(text:, content:, show_icon: true, icon: "circle-help", variant: :link, wrapper_class: nil, trigger_class: nil, bubble_class: nil, inline: false) ⇒ Object
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 UiHelperFeedback
#ui_alert, #ui_checkbox_tag, #ui_snackbar_stack
Instance Method Details
#ui_action_row(primary_button:, secondary_button: nil, extra_buttons: [], classes: nil) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/helpers/baldur/ui_helper.rb', line 21 def ui_action_row(primary_button:, secondary_button: nil, extra_buttons: [], classes: nil) = [] << if .present? .concat(Array().compact) << if .present? baldur_render "baldur/components/action_row", buttons: , class: classes end |
#ui_badge(text:, variant: :default, size: :sm, html_options: {}) ⇒ Object
167 168 169 |
# File 'app/helpers/baldur/ui_helper.rb', line 167 def ui_badge(text:, variant: :default, size: :sm, html_options: {}) baldur_render "baldur/components/badge", text: text, variant: variant, size: size, html_options: end |
#ui_button(**options) ⇒ Object
17 18 19 |
# File 'app/helpers/baldur/ui_helper.rb', line 17 def (**) baldur_render "baldur/components/button", ** end |
#ui_card(title:, description: nil, badge: nil, icon: nil, actions: nil, variant: :default, classes: nil, body_class: nil, body: nil, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/baldur/ui_helper.rb', line 30 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
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/baldur/ui_helper.rb', line 74 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: , class: classes, body: body_content end |
#ui_expandable_table_list(items) ⇒ Object
105 106 107 108 109 110 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 |
# File 'app/helpers/baldur/ui_helper.rb', line 105 def (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 content_tag(:div, class: "table-disclosure", data: { controller: "table-disclosure" }) do safe_join( [ content_tag( :button, type: "button", class: "table-disclosure__trigger", aria: { expanded: "false" }, data: { action: "click->table-disclosure#toggle", table_disclosure_target: "trigger" } ) do safe_join( [ content_tag(:span, "#{values.size} items", class: "table-disclosure__summary", title: summary), content_tag(:span, "Expand", class: "table-disclosure__toggle table-disclosure__toggle--collapsed"), content_tag(:span, "Collapse", class: "table-disclosure__toggle table-disclosure__toggle--expanded") ] ) end, content_tag(:div, class: "table-disclosure__content", data: { table_disclosure_target: "content" }) do safe_join(values.map { |value| content_tag(:div, value, class: "table-disclosure__content-item") }) end ] ) end end |
#ui_icon(name, class_name: nil) ⇒ Object
10 11 12 13 14 15 |
# File 'app/helpers/baldur/ui_helper.rb', line 10 def ui_icon(name, class_name: nil) normalized_name = name.to_s.tr("_", "-") = LucideRails..merge("class" => class_name, "aria-hidden" => "true") content_tag(:svg, LucideRails::IconProvider.icon(normalized_name).html_safe, ) end |
#ui_kpi(id: nil, label:, value:, caption: nil, trend: nil, variant: :default, caption_icon: nil, action: nil) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/helpers/baldur/ui_helper.rb', line 171 def ui_kpi(id: nil, label:, value:, 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
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/helpers/baldur/ui_helper.rb', line 154 def ui_modal(id:, title:, description: nil, submit_label: "Continue", close_label: "Cancel", **, &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() 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
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/baldur/ui_helper.rb', line 141 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_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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'app/helpers/baldur/ui_helper.rb', line 200 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
183 184 185 |
# File 'app/helpers/baldur/ui_helper.rb', line 183 def (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
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/baldur/ui_helper.rb', line 45 def ui_table(columns:, rows:, empty_state: "No records yet", **) = .slice(:title, :title_meta, :description, :actions, :controls, :controls_position, :footer, :classes) = .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() return table_markup if .values.all?(&:blank?) ui_table_card(**, 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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/helpers/baldur/ui_helper.rb', line 59 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: , description: description, actions: actions, controls: controls, controls_position: controls_position, footer: , class: classes, body: body_content end |
#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) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/baldur/ui_helper.rb', line 86 def (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_selected: rows_per_page_selected, path_builder: path_builder end |
#ui_table_truncated_text(text, class_name: "block truncate", title: nil) ⇒ Object
98 99 100 101 102 103 |
# File 'app/helpers/baldur/ui_helper.rb', line 98 def ui_table_truncated_text(text, class_name: "block truncate", title: nil) value = text.to_s.strip return "—" if value.blank? content_tag(:span, value, class: class_name, title: (title.presence || value)) 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
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/helpers/baldur/ui_helper.rb', line 187 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 |