Module: AdminSuite::ThemeHelper

Included in:
BaseHelper
Defined in:
app/helpers/admin_suite/theme_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_suite_themeObject



5
6
7
8
9
# File 'app/helpers/admin_suite/theme_helper.rb', line 5

def admin_suite_theme
  (AdminSuite.config.theme || {}).symbolize_keys
rescue StandardError
  {}
end

#admin_suite_theme_style_tagObject

Returns a <style> tag that scopes theme variables to AdminSuite.

This is the core of engine-build mode theming: UI classes stay static (no ‘bg-#…`), and color changes are driven by CSS variables.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/admin_suite/theme_helper.rb', line 23

def admin_suite_theme_style_tag
  theme = admin_suite_theme

  primary = theme[:primary]
  secondary = theme[:secondary]

  primary_name =
    if AdminSuite::ThemePalette.hex?(primary)
      nil
    else
      AdminSuite::ThemePalette.normalize_color(primary, default_name: :indigo)
    end

  secondary_name =
    if AdminSuite::ThemePalette.hex?(secondary)
      nil
    else
      AdminSuite::ThemePalette.normalize_color(secondary, default_name: :purple)
    end

  # Primary variables
  primary_600 = AdminSuite::ThemePalette.hex?(primary) ? primary : AdminSuite::ThemePalette.resolve(primary_name, 600, fallback: "#4f46e5")
  primary_700 = AdminSuite::ThemePalette.hex?(primary) ? primary : AdminSuite::ThemePalette.resolve(primary_name, 700, fallback: "#4338ca")

  # Sidebar gradient variables (dark shades)
  sidebar_from = AdminSuite::ThemePalette.resolve(primary_name || "indigo", 900, fallback: "#312e81")
  sidebar_via = AdminSuite::ThemePalette.resolve(primary_name || "indigo", 800, fallback: "#3730a3")
  sidebar_to =
    if AdminSuite::ThemePalette.hex?(secondary)
      secondary
    else
      AdminSuite::ThemePalette.resolve(secondary_name || "purple", 900, fallback: "#581c87")
    end

  css = <<~CSS
    body.admin-suite {
      --admin-suite-primary: #{primary_600};
      --admin-suite-primary-hover: #{primary_700};
      --admin-suite-sidebar-from: #{sidebar_from};
      --admin-suite-sidebar-via: #{sidebar_via};
      --admin-suite-sidebar-to: #{sidebar_to};
    }
  CSS

  (:style, css.html_safe)
end

#theme_badge_primary_classObject



86
87
88
# File 'app/helpers/admin_suite/theme_helper.rb', line 86

def theme_badge_primary_class
  "admin-suite-badge-primary"
end

#theme_btn_primary_classObject



78
79
80
# File 'app/helpers/admin_suite/theme_helper.rb', line 78

def theme_btn_primary_class
  "admin-suite-btn-primary"
end

#theme_btn_primary_small_classObject



82
83
84
# File 'app/helpers/admin_suite/theme_helper.rb', line 82

def theme_btn_primary_small_class
  "admin-suite-btn-primary admin-suite-btn-primary--sm"
end

#theme_focus_ring_classObject



90
91
92
# File 'app/helpers/admin_suite/theme_helper.rb', line 90

def theme_focus_ring_class
  "admin-suite-focus-ring"
end


70
71
72
# File 'app/helpers/admin_suite/theme_helper.rb', line 70

def theme_link_class
  "admin-suite-link"
end


74
75
76
# File 'app/helpers/admin_suite/theme_helper.rb', line 74

def theme_link_hover_text_class
  "admin-suite-link-hover"
end

#theme_primaryObject



11
12
13
# File 'app/helpers/admin_suite/theme_helper.rb', line 11

def theme_primary
  admin_suite_theme[:primary]
end

#theme_secondaryObject



15
16
17
# File 'app/helpers/admin_suite/theme_helper.rb', line 15

def theme_secondary
  admin_suite_theme[:secondary]
end

#theme_sidebar_gradient_classObject



94
95
96
97
# File 'app/helpers/admin_suite/theme_helper.rb', line 94

def theme_sidebar_gradient_class
  # Deprecated: gradient is now CSS-variable driven (see `admin_suite_theme_style_tag`).
  ""
end