-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathbase_component.rb
More file actions
45 lines (36 loc) · 1.25 KB
/
base_component.rb
File metadata and controls
45 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
require "view_component/version"
require "view_component/translatable"
module SolidusAdmin
# BaseComponent is the base class for all components in Solidus Admin.
class BaseComponent < ViewComponent::Base
include SolidusAdmin::ComponentsHelper
include SolidusAdmin::StimulusHelper
include SolidusAdmin::VoidElementsHelper
include SolidusAdmin::SolidusFormHelper
include Turbo::FramesHelper
def icon_tag(name, **attrs)
render component("ui/icon").new(name:, **attrs)
end
def missing_translation(key, options)
keys = I18n.normalize_keys(options[:locale] || I18n.locale, key, options[:scope])
logger.debug " [#{self.class}] Missing translation: #{keys.join(".")}"
if (options[:locale] || I18n.default_locale) != :en
t(key, **options, locale: :en)
else
"translation missing: #{keys.join(".")}"
end
end
def self.i18n_scope
@i18n_scope ||= name.underscore.tr("/", ".")
end
def self.stimulus_id
@stimulus_id ||= name.underscore
.sub(/^solidus_admin\/(.*)\/component$/, '\1')
.gsub("/", "--")
.tr("_", "-")
end
delegate :stimulus_id, to: :class
delegate :search_filter_params, to: :helpers
end
end