Module: KozenetUi::ComponentHelper

Includes:
IconHelper
Defined in:
app/helpers/kozenet_ui/component_helper.rb

Overview

Helper methods for rendering Kozenet UI components in views

Constant Summary collapse

KOZENET_UI_STYLESHEETS =
[
  "kozenet_ui/tokens",
  "kozenet_ui/fonts",
  "kozenet_ui/base",
  "kozenet_ui/components/button",
  "kozenet_ui/components/header",
  "kozenet_ui/components/avatar",
  "kozenet_ui/components/badge",
  "kozenet_ui/components/utilities"
].freeze

Instance Method Summary collapse

Methods included from IconHelper

#kozenet_ui_icon

Instance Method Details

#kozenet_ui_config_tagObject



65
66
67
# File 'app/helpers/kozenet_ui/component_helper.rb', line 65

def kozenet_ui_config_tag
  tag.meta name: "kozenet-ui-stimulus-prefix", content: KozenetUi.configuration.stimulus_prefix
end

#kozenet_ui_head_tags(stylesheets: true, javascript: true) ⇒ Object

Include runtime tags once in the application layout.

Stylesheets are loaded directly so Propshaft/Sprockets can emit digested asset URLs in production. Apps can pass stylesheets: false when bundling Kozenet UI CSS with their own build pipeline.



55
56
57
58
59
60
61
62
63
# File 'app/helpers/kozenet_ui/component_helper.rb', line 55

def kozenet_ui_head_tags(stylesheets: true, javascript: true)
  tags = []
  tags << kozenet_ui_stylesheet_tag if stylesheets
  tags << kozenet_ui_config_tag
  tags << kozenet_ui_theme_variables_tag
  tags << kozenet_ui_javascript_tag if javascript

  safe_join(tags, "\n")
end

#kozenet_ui_javascript_tagObject

Include theme JavaScript



46
47
48
# File 'app/helpers/kozenet_ui/component_helper.rb', line 46

def kozenet_ui_javascript_tag
  javascript_include_tag "kozenet_ui/index", type: "module", "data-turbo-track": "reload"
end

#kozenet_ui_stylesheet_tagObject

Include theme styles in layout



41
42
43
# File 'app/helpers/kozenet_ui/component_helper.rb', line 41

def kozenet_ui_stylesheet_tag
  stylesheet_link_tag(*KOZENET_UI_STYLESHEETS, "data-turbo-track": "reload")
end

#kozenet_ui_theme_variables_tagObject

Inject inline theme variables (CSP-compliant)



70
71
72
# File 'app/helpers/kozenet_ui/component_helper.rb', line 70

def kozenet_ui_theme_variables_tag
  (:style, build_theme_css, nonce: content_security_policy_nonce)
end

#kz_avatar(**options, &block) ⇒ Object

Render a Kozenet UI avatar



36
37
38
# File 'app/helpers/kozenet_ui/component_helper.rb', line 36

def kz_avatar(**options, &block)
  render(KozenetUi::AvatarComponent.new(**options), &block)
end

#kz_badge(**options, &block) ⇒ Object

Render a Kozenet UI badge



31
32
33
# File 'app/helpers/kozenet_ui/component_helper.rb', line 31

def kz_badge(**options, &block)
  render(KozenetUi::BadgeComponent.new(**options), &block)
end

#kz_button(**options, &block) ⇒ Object

Render a Kozenet UI button



21
22
23
# File 'app/helpers/kozenet_ui/component_helper.rb', line 21

def kz_button(**options, &block)
  render(KozenetUi::ButtonComponent.new(**options), &block)
end

#kz_header(**options, &block) ⇒ Object

Render a Kozenet UI header



26
27
28
# File 'app/helpers/kozenet_ui/component_helper.rb', line 26

def kz_header(**options, &block)
  render(KozenetUi::HeaderComponent.new(**options), &block)
end