Module: MatViews::Admin::UiHelper
- Defined in:
- app/helpers/mat_views/admin/ui_helper.rb
Overview
MatViews::Admin::UiHelper
View helper methods for the MatViews admin UI.
Responsibilities:
-
Provides consistent button, link, drawer, badge, and icon components.
-
Wraps standard Rails helpers (‘link_to`, `button_to`, `button_tag`, etc.) with MatViews-specific styling and Stimulus integration.
-
Defines inline SVG icon snippets for use across the admin dashboard.
Key Components:
-
Buttons: #mv_button_link, #mv_button_to, #mv_drawer_link, #mv_drawer_action_button
-
Links: #mv_link_to
-
Badges: #mv_badge
-
Icons: #mv_icon with private ‘svg_icon_*` methods
-
Translations: #mv_t
Instance Method Summary collapse
-
#mv_badge(status, text) ⇒ String
Renders a badge element styled by status.
-
#mv_button_classes(variant, size) ⇒ String
Builds CSS classes for a MatViews-styled button.
-
#mv_button_link(href, opts = {}) { ... } ⇒ String
Renders a styled link button.
-
#mv_button_to(href, opts = {}) { ... } ⇒ String
Renders a styled ‘button_to` element.
-
#mv_cancel_button(opts = {}) { ... } ⇒ String
Renders a styled cancel button.
-
#mv_drawer_action_button(label, action, tooltip = nil, tooltip_placement = nil, args_org = {}) { ... } ⇒ String
Renders a drawer action button with optional tooltip.
-
#mv_drawer_link(drawer_url, drawer_title, args = {}) { ... } ⇒ String
Renders a button link that opens a drawer via Stimulus.
-
#mv_icon(name, size: 16, class_name: nil) ⇒ String
Renders an inline SVG icon.
-
#mv_link_to(text = nil, url = nil, args_orig = nil) { ... } ⇒ String
Renders a styled external or internal link, with optional tooltip.
-
#mv_submit_button(opts = {}) { ... } ⇒ String
Renders a styled submit button.
-
#mv_t(key, **args) ⇒ String
Shortcut for translating keys under the ‘mat_views` namespace.
-
#mv_tab_link(tab_name, args_org = {}) { ... } ⇒ String
Renders a tab link for the tabs component.
Instance Method Details
#mv_badge(status, text) ⇒ String
Renders a badge element styled by status.
168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 168 def mv_badge(status, text) klass = case status.to_s.downcase when 'success' then 'mv-badge mv-badge--success' when 'running' then 'mv-badge mv-badge--running' when 'failed' then 'mv-badge mv-badge--failed' else 'mv-badge' end content_tag(:span, text, class: klass) end |
#mv_button_classes(variant, size) ⇒ String
Builds CSS classes for a MatViews-styled button.
33 34 35 36 37 38 39 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 33 def (variant, size) [ 'mv-btn', "mv-btn--#{variant}", "mv-btn--#{size}" ].join(' ') end |
#mv_button_link(href, opts = {}) { ... } ⇒ String
Renders a styled link button.
47 48 49 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 47 def (href, opts = {}, &) link_to capture(&), href, **(assign_test_id(opts)) end |
#mv_button_to(href, opts = {}) { ... } ⇒ String
Renders a styled ‘button_to` element.
70 71 72 73 74 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 70 def (href, opts = {}, &) href, **(assign_test_id(opts)) do capture(&) end end |
#mv_cancel_button(opts = {}) { ... } ⇒ String
Renders a styled cancel button.
217 218 219 220 221 222 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 217 def (opts = {}, &) opts = (assign_test_id(opts)) opts[:type] = 'button' opts.delete(:method) (capture(&), **opts) end |
#mv_drawer_action_button(label, action, tooltip = nil, tooltip_placement = nil, args_org = {}) { ... } ⇒ String
Renders a drawer action button with optional tooltip.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 85 def (label, action, tooltip = nil, tooltip_placement = nil, args_org = {}, &) args = assign_test_id(args_org) data = { action: "drawer##{action}" } data = data.merge(args[:data] || {}) if tooltip data[:controller] = 'tooltip' data[:'tooltip-text-value'] = tooltip data[:'tooltip-placement'] = tooltip_placement || 'top' end args[:data] = data (type: 'button', class: 'mv-drawer-action', 'aria-label': label, **args, &) end |
#mv_drawer_link(drawer_url, drawer_title, args = {}) { ... } ⇒ String
Renders a button link that opens a drawer via Stimulus.
58 59 60 61 62 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 58 def mv_drawer_link(drawer_url, drawer_title, args = {}, &) data = { action: 'click->drawer#open', drawer_title: drawer_title, drawer_url: drawer_url } args[:data] = (args[:data] || {}).merge(data) '#', assign_test_id(args), & end |
#mv_icon(name, size: 16, class_name: nil) ⇒ String
Renders an inline SVG icon.
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 184 def mv_icon(name, size: 16, class_name: nil) icon_method_name = :"svg_icon_#{name}" content_tag :svg, class: ['mv-icon', class_name].compact.join(' '), xmlns: 'http://www.w3.org/2000/svg', width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '2', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true' do respond_to?(icon_method_name, true) ? raw(send(icon_method_name)) : ''.html_safe end end |
#mv_link_to(text = nil, url = nil, args_orig = nil) { ... } ⇒ String
Renders a styled external or internal link, with optional tooltip.
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 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 107 def mv_link_to(text = nil, url = nil, args_orig = nil, &block) args = assign_test_id(args_orig || {}) if block_given? args = assign_test_id(url || {}) url = text end tooltip = args.fetch(:tooltip, nil) is_blank = args.fetch(:is_blank, true) underline = args.fetch(:underline, true) args_to_apply = args.except(:tooltip, :is_blank) if is_blank args_to_apply[:target] = '_blank' args_to_apply[:rel] = 'noopener noreferrer' end args_to_apply[:class] = 'underline' if underline if tooltip args_to_apply[:'data-controller'] = 'tooltip' args_to_apply[:'data-tooltip-text-value'] = tooltip end if block_given? link_to url, args_to_apply do capture(&block) end else link_to text, url, **args_to_apply end end |
#mv_submit_button(opts = {}) { ... } ⇒ String
Renders a styled submit button.
204 205 206 207 208 209 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 204 def (opts = {}, &) opts = (assign_test_id(opts)) opts[:type] = 'submit' opts.delete(:method) (capture(&), **opts) end |
#mv_t(key, **args) ⇒ String
Shortcut for translating keys under the ‘mat_views` namespace.
159 160 161 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 159 def mv_t(key, **args) I18n.t("mat_views.#{key}", **args) end |
#mv_tab_link(tab_name, args_org = {}) { ... } ⇒ String
Renders a tab link for the tabs component.
144 145 146 147 148 149 150 151 152 |
# File 'app/helpers/mat_views/admin/ui_helper.rb', line 144 def mv_tab_link(tab_name, args_org = {}, &) args = assign_test_id(args_org) classes = ['mv-tab'] selected = args.delete(:selected) classes << (selected ? 'mv-tab--on' : '') args[:class] = [args[:class], classes.compact.join(' ')].compact.join(' ').strip args[:data] = args.fetch(:data, {}).merge({ action: 'click->tabs#show', 'tabs-target': 'link', name: tab_name }) link_to '#', **args, & end |