Module: RailsAdminNext::Icons
- Defined in:
- lib/rails_admin_next/icons.rb
Overview
Inline-SVG icon registry. RailsAdminNext renders its icons as inline <svg>
(see IconsHelper#rails_admin_icon) instead of a Font Awesome icon font,
so the engine ships no web fonts and no icon CSS framework.
Icons are referenced by a logical name (e.g. :edit, :delete, :list).
The glyph path data below matches Font Awesome Free 6.1.1 (solid), so the
rendered icons stay visually familiar.
Action#link_icon and Model#navigation_icon take a logical name. A legacy
Font Awesome class string is also resolved best-effort and warns via
RailsAdminNext.deprecator.
Constant Summary collapse
- GLYPHS =
Logical name => { view_box:, path: } (Font Awesome Free 6.1.1 solid).
{ dashboard: {view_box: "0 0 576 512", path: "M575.8 255.5C575.8 273.5 560.8 287.6 543.8 287.6H511.8L512.5 447.7C512.5 450.5 512.3 453.1 512 455.8V472C512 494.1 494.1 512 472 512H456C454.9 512 453.8 511.1 452.7 511.9C451.3 511.1 449.9 512 448.5 512H392C369.9 512 352 494.1 352 472V384C352 366.3 337.7 352 320 352H256C238.3 352 224 366.3 224 384V472C224 494.1 206.1 512 184 512H128.1C126.6 512 125.1 511.9 123.6 511.8C122.4 511.9 121.2 512 120 512H104C81.91 512 64 494.1 64 472V360C64 359.1 64.03 358.1 64.09 357.2V287.6H32.05C14.02 287.6 0 273.5 0 255.5C0 246.5 3.004 238.5 10.01 231.5L266.4 8.016C273.4 1.002 281.4 0 288.4 0C295.4 0 303.4 2.004 309.5 7.014L564.8 231.5C572.8 238.5 576.9 246.5 575.8 255.5L575.8 255.5z"}, list: {view_box: "0 0 512 512", path: "M0 96C0 60.65 28.65 32 64 32H448C483.3 32 512 60.65 512 96V416C512 451.3 483.3 480 448 480H64C28.65 480 0 451.3 0 416V96zM64 160H128V96H64V160zM448 96H192V160H448V96zM64 288H128V224H64V288zM448 224H192V288H448V224zM64 416H128V352H64V416zM448 352H192V416H448V352z"}, show: {view_box: "0 0 512 512", path: "M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 128c17.67 0 32 14.33 32 32c0 17.67-14.33 32-32 32S224 177.7 224 160C224 142.3 238.3 128 256 128zM296 384h-80C202.8 384 192 373.3 192 360s10.75-24 24-24h16v-64H224c-13.25 0-24-10.75-24-24S210.8 224 224 224h32c13.25 0 24 10.75 24 24v88h16c13.25 0 24 10.75 24 24S309.3 384 296 384z"}, new: {view_box: "0 0 448 512", path: "M432 256c0 17.69-14.33 32.01-32 32.01H256v144c0 17.69-14.33 31.99-32 31.99s-32-14.3-32-31.99v-144H48c-17.67 0-32-14.32-32-32.01s14.33-31.99 32-31.99H192v-144c0-17.69 14.33-32.01 32-32.01s32 14.32 32 32.01v144h144C417.7 224 432 238.3 432 256z"}, edit: {view_box: "0 0 512 512", path: "M421.7 220.3L188.5 453.4L154.6 419.5L158.1 416H112C103.2 416 96 408.8 96 400V353.9L92.51 357.4C87.78 362.2 84.31 368 82.42 374.4L59.44 452.6L137.6 429.6C143.1 427.7 149.8 424.2 154.6 419.5L188.5 453.4C178.1 463.8 165.2 471.5 151.1 475.6L30.77 511C22.35 513.5 13.24 511.2 7.03 504.1C.8198 498.8-1.502 489.7 .976 481.2L36.37 360.9C40.53 346.8 48.16 333.9 58.57 323.5L291.7 90.34L421.7 220.3zM492.7 58.75C517.7 83.74 517.7 124.3 492.7 149.3L444.3 197.7L314.3 67.72L362.7 19.32C387.7-5.678 428.3-5.678 453.3 19.32L492.7 58.75z"}, delete: {view_box: "0 0 320 512", path: "M310.6 361.4c12.5 12.5 12.5 32.75 0 45.25C304.4 412.9 296.2 416 288 416s-16.38-3.125-22.62-9.375L160 301.3L54.63 406.6C48.38 412.9 40.19 416 32 416S15.63 412.9 9.375 406.6c-12.5-12.5-12.5-32.75 0-45.25l105.4-105.4L9.375 150.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0L160 210.8l105.4-105.4c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25l-105.4 105.4L310.6 361.4z"}, export: {view_box: "0 0 576 512", path: "M192 312C192 298.8 202.8 288 216 288H384V160H256c-17.67 0-32-14.33-32-32L224 0H48C21.49 0 0 21.49 0 48v416C0 490.5 21.49 512 48 512h288c26.51 0 48-21.49 48-48v-128H216C202.8 336 192 325.3 192 312zM256 0v128h128L256 0zM568.1 295l-80-80c-9.375-9.375-24.56-9.375-33.94 0s-9.375 24.56 0 33.94L494.1 288H384v48h110.1l-39.03 39.03C450.3 379.7 448 385.8 448 392s2.344 12.28 7.031 16.97c9.375 9.375 24.56 9.375 33.94 0l80-80C578.3 319.6 578.3 304.4 568.1 295z"}, history: {view_box: "0 0 448 512", path: "M448 336v-288C448 21.49 426.5 0 400 0H96C42.98 0 0 42.98 0 96v320c0 53.02 42.98 96 96 96h320c17.67 0 32-14.33 32-31.1c0-11.72-6.607-21.52-16-27.1v-81.36C441.8 362.8 448 350.2 448 336zM143.1 128h192C344.8 128 352 135.2 352 144C352 152.8 344.8 160 336 160H143.1C135.2 160 128 152.8 128 144C128 135.2 135.2 128 143.1 128zM143.1 192h192C344.8 192 352 199.2 352 208C352 216.8 344.8 224 336 224H143.1C135.2 224 128 216.8 128 208C128 199.2 135.2 192 143.1 192zM384 448H96c-17.67 0-32-14.33-32-32c0-17.67 14.33-32 32-32h288V448z"}, show_in_app: {view_box: "0 0 576 512", path: "M279.6 160.4C282.4 160.1 285.2 160 288 160C341 160 384 202.1 384 256C384 309 341 352 288 352C234.1 352 192 309 192 256C192 253.2 192.1 250.4 192.4 247.6C201.7 252.1 212.5 256 224 256C259.3 256 288 227.3 288 192C288 180.5 284.1 169.7 279.6 160.4zM480.6 112.6C527.4 156 558.7 207.1 573.5 243.7C576.8 251.6 576.8 260.4 573.5 268.3C558.7 304 527.4 355.1 480.6 399.4C433.5 443.2 368.8 480 288 480C207.2 480 142.5 443.2 95.42 399.4C48.62 355.1 17.34 304 2.461 268.3C-.8205 260.4-.8205 251.6 2.461 243.7C17.34 207.1 48.62 156 95.42 112.6C142.5 68.84 207.2 32 288 32C368.8 32 433.5 68.84 480.6 112.6V112.6zM288 112C208.5 112 144 176.5 144 256C144 335.5 208.5 400 288 400C367.5 400 432 335.5 432 256C432 176.5 367.5 112 288 112z"}, bulk_delete: {view_box: "0 0 320 512", path: "M204.3 32.01H96c-52.94 0-96 43.06-96 96c0 17.67 14.31 31.1 32 31.1s32-14.32 32-31.1c0-17.64 14.34-32 32-32h108.3C232.8 96.01 256 119.2 256 147.8c0 19.72-10.97 37.47-30.5 47.33L127.8 252.4C117.1 258.2 112 268.7 112 280v40c0 17.67 14.31 31.99 32 31.99s32-14.32 32-31.99V298.3L256 251.3c39.47-19.75 64-59.42 64-103.5C320 83.95 268.1 32.01 204.3 32.01zM144 400c-22.09 0-40 17.91-40 40s17.91 39.1 40 39.1s40-17.9 40-39.1S166.1 400 144 400z"}, collapse: {view_box: "0 0 448 512", path: "M224 416c-8.188 0-16.38-3.125-22.62-9.375l-192-192c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0L224 338.8l169.4-169.4c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25l-192 192C240.4 412.9 232.2 416 224 416z"}, expand: {view_box: "0 0 320 512", path: "M96 480c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L242.8 256L73.38 86.63c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l192 192c12.5 12.5 12.5 32.75 0 45.25l-192 192C112.4 476.9 104.2 480 96 480z"}, calendar: {view_box: "0 0 448 512", path: "M96 32C96 14.33 110.3 0 128 0C145.7 0 160 14.33 160 32V64H288V32C288 14.33 302.3 0 320 0C337.7 0 352 14.33 352 32V64H400C426.5 64 448 85.49 448 112V160H0V112C0 85.49 21.49 64 48 64H96V32zM448 464C448 490.5 426.5 512 400 512H48C21.49 512 0 490.5 0 464V192H448V464z"}, check: {view_box: "0 0 448 512", path: "M438.6 105.4C451.1 117.9 451.1 138.1 438.6 150.6L182.6 406.6C170.1 419.1 149.9 419.1 137.4 406.6L9.372 278.6C-3.124 266.1-3.124 245.9 9.372 233.4C21.87 220.9 42.13 220.9 54.63 233.4L159.1 338.7L393.4 105.4C405.9 92.88 426.1 92.88 438.6 105.4H438.6z"}, minus: {view_box: "0 0 448 512", path: "M400 288h-352c-17.69 0-32-14.32-32-32.01s14.31-31.99 32-31.99h352c17.69 0 32 14.3 32 31.99S417.7 288 400 288z"}, refresh: {view_box: "0 0 512 512", path: "M464 16c-17.67 0-32 14.31-32 32v74.09C392.1 66.52 327.4 32 256 32C161.5 32 78.59 92.34 49.58 182.2c-5.438 16.81 3.797 34.88 20.61 40.28c16.89 5.5 34.88-3.812 40.3-20.59C130.9 138.5 189.4 96 256 96c50.5 0 96.26 24.55 124.4 64H336c-17.67 0-32 14.31-32 32s14.33 32 32 32h128c17.67 0 32-14.31 32-32V48C496 30.31 481.7 16 464 16zM441.8 289.6c-16.92-5.438-34.88 3.812-40.3 20.59C381.1 373.5 322.6 416 256 416c-50.5 0-96.25-24.55-124.4-64H176c17.67 0 32-14.31 32-32s-14.33-32-32-32h-128c-17.67 0-32 14.31-32 32v144c0 17.69 14.33 32 32 32s32-14.31 32-32v-74.09C119.9 445.5 184.6 480 255.1 480c94.45 0 177.4-60.34 206.4-150.2C467.9 313 458.6 294.1 441.8 289.6z"}, trash: {view_box: "0 0 448 512", path: "M135.2 17.69C140.6 6.848 151.7 0 163.8 0H284.2C296.3 0 307.4 6.848 312.8 17.69L320 32H416C433.7 32 448 46.33 448 64C448 81.67 433.7 96 416 96H32C14.33 96 0 81.67 0 64C0 46.33 14.33 32 32 32H128L135.2 17.69zM394.8 466.1C393.2 492.3 372.3 512 346.9 512H101.1C75.75 512 54.77 492.3 53.19 466.1L31.1 128H416L394.8 466.1z"}, move_right: {view_box: "0 0 512 512", path: "M256 0C114.6 0 0 114.6 0 256c0 141.4 114.6 256 256 256s256-114.6 256-256C512 114.6 397.4 0 256 0zM358.6 278.6l-112 112c-12.5 12.5-32.75 12.5-45.25 0s-12.5-32.75 0-45.25L290.8 256L201.4 166.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l112 112C364.9 239.6 368 247.8 368 256S364.9 272.4 358.6 278.6z"}, move_left: {view_box: "0 0 512 512", path: "M256 0C114.6 0 0 114.6 0 256c0 141.4 114.6 256 256 256s256-114.6 256-256C512 114.6 397.4 0 256 0zM310.6 345.4c12.5 12.5 12.5 32.75 0 45.25s-32.75 12.5-45.25 0l-112-112C147.1 272.4 144 264.2 144 256s3.125-16.38 9.375-22.62l112-112c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25L221.3 256L310.6 345.4z"}, move_up: {view_box: "0 0 512 512", path: "M256 0C114.6 0 0 114.6 0 256c0 141.4 114.6 256 256 256s256-114.6 256-256C512 114.6 397.4 0 256 0zM390.6 310.6c-12.5 12.5-32.75 12.5-45.25 0L256 221.3L166.6 310.6c-12.5 12.5-32.75 12.5-45.25 0s-12.5-32.75 0-45.25l112-112C239.6 147.1 247.8 144 256 144s16.38 3.125 22.62 9.375l112 112C403.1 277.9 403.1 298.1 390.6 310.6z"}, move_down: {view_box: "0 0 512 512", path: "M256 0C114.6 0 0 114.6 0 256c0 141.4 114.6 256 256 256s256-114.6 256-256C512 114.6 397.4 0 256 0zM390.6 246.6l-112 112C272.4 364.9 264.2 368 256 368s-16.38-3.125-22.62-9.375l-112-112c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0L256 290.8l89.38-89.38c12.5-12.5 32.75-12.5 45.25 0S403.1 234.1 390.6 246.6z"} }.freeze
- ALIASES =
Synonyms => canonical glyph name. Lets host config and call sites use the name that reads best (e.g.
:cancelfor the X glyph on a cancel button). { add: :new, book: :history, cancel: :delete, chevron_circle_down: :move_down, chevron_circle_left: :move_left, chevron_circle_right: :move_right, chevron_circle_up: :move_up, chevron_down: :collapse, chevron_right: :expand, close: :delete, eye: :show_in_app, help: :bulk_delete, home: :dashboard, info: :show, info_circle: :show, pencil: :edit, plus: :new, question: :bulk_delete, reload: :refresh, sort_asc: :move_up, sort_desc: :move_down, sync: :refresh, th_list: :list, times: :delete, view: :show_in_app, xmark: :delete }.freeze
- LEGACY_FA =
Font Awesome glyph token (v5 and v6 names) => canonical logical name, used to gracefully resolve legacy
'fas fa-…'values a host may still pass. { "arrows-rotate" => :refresh, "book" => :history, "calendar" => :calendar, "check" => :check, "chevron-circle-down" => :move_down, "chevron-circle-left" => :move_left, "chevron-circle-right" => :move_right, "chevron-circle-up" => :move_up, "chevron-down" => :collapse, "chevron-right" => :expand, "circle-chevron-down" => :move_down, "circle-chevron-left" => :move_left, "circle-chevron-right" => :move_right, "circle-chevron-up" => :move_up, "circle-info" => :show, "close" => :delete, "edit" => :edit, "eye" => :show_in_app, "file-export" => :export, "home" => :dashboard, "house" => :dashboard, "info-circle" => :show, "list" => :list, "minus" => :minus, "pencil" => :edit, "pencil-alt" => :edit, "plus" => :new, "question" => :bulk_delete, "sync" => :refresh, "table-list" => :list, "th-list" => :list, "times" => :delete, "trash" => :trash, "trash-alt" => :trash, "xmark" => :delete }.freeze
Class Method Summary collapse
-
.canonical(name) ⇒ Object
Resolve a logical name (or alias) to its canonical glyph key, or nil.
-
.fa_class?(value) ⇒ Boolean
Does this value look like a (legacy) Font Awesome class string?.
-
.from_fa_class(value) ⇒ Object
Best-effort canonical name for a legacy
'fas fa-…'string, or nil. -
.svg(name, **html_options) ⇒ Object
Build an inline
<svg>markup string for a logical icon name (see GLYPHS), or nil if the name is unknown.
Class Method Details
.canonical(name) ⇒ Object
Resolve a logical name (or alias) to its canonical glyph key, or nil.
125 126 127 128 129 130 |
# File 'lib/rails_admin_next/icons.rb', line 125 def self.canonical(name) key = name.to_sym return key if GLYPHS.key?(key) ALIASES[key] end |
.fa_class?(value) ⇒ Boolean
Does this value look like a (legacy) Font Awesome class string?
133 134 135 |
# File 'lib/rails_admin_next/icons.rb', line 133 def self.fa_class?(value) value.is_a?(String) && value.match?(/\bfa[a-z]?\b|\bfa-[a-z]/) end |
.from_fa_class(value) ⇒ Object
Best-effort canonical name for a legacy 'fas fa-…' string, or nil. Scans
every fa-… token so sizing modifiers (e.g. fa-fw) don't mask the glyph.
139 140 141 |
# File 'lib/rails_admin_next/icons.rb', line 139 def self.from_fa_class(value) value.to_s.scan(/fa-([a-z0-9-]+)/).flatten.lazy.filter_map { |token| LEGACY_FA[token] }.first end |
.svg(name, **html_options) ⇒ Object
Build an inline <svg> markup string for a logical icon name (see GLYPHS),
or nil if the name is unknown. A legacy Font Awesome class string is resolved
best-effort and warns via RailsAdminNext.deprecator. The single source of
truth for icon markup, shared by IconsHelper (views) and field types (lib).
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rails_admin_next/icons.rb', line 97 def self.svg(name, **) return if name.nil? if fa_class?(name) RailsAdminNext.deprecator.warn( "RailsAdminNext icons now use logical names; #{name.inspect} is a Font Awesome class string. " \ "Font Awesome is no longer shipped — pass a logical name (see RailsAdminNext::Icons::GLYPHS)." ) name = from_fa_class(name) end key = name && canonical(name) glyph = key && GLYPHS[key] return unless glyph classes = ["rails-admin-icon", .delete(:class)].compact.join(" ") attributes = { "viewBox" => glyph[:view_box], "aria-hidden" => "true", "focusable" => "false", "data-icon" => key.to_s, "class" => classes }.merge(.transform_keys(&:to_s)) rendered = attributes.map { |attr, value| %(#{CGI.escapeHTML(attr.to_s)}="#{CGI.escapeHTML(value.to_s)}") }.join(" ") %(<svg #{rendered}><path d="#{CGI.escapeHTML(glyph[:path])}"/></svg>) end |