Class: NitroKit::Component

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/nitro_kit/component.rb

Constant Summary collapse

COMPONENT_OWNED_DATA_ATTRIBUTES =

Data keys a component sets for itself through attributes:.

%w[
  state disabled required orientation presentation placement layout side field-type
].freeze
RESERVED_DATA_ATTRIBUTES =

Every data key Nitro owns. Applications may not pass any of them through data:.

(
  %w[nk slot variant size nk-escape enhanced] + COMPONENT_OWNED_DATA_ATTRIBUTES
).freeze
ADDITIVE_DATA_ATTRIBUTES =
%w[action controller].freeze
FORBIDDEN_ATTRIBUTES =
%w[class style].freeze

Instance Method Summary collapse

Constructor Details

#initialize(component:, attributes: {}, html: {}, aria: {}, data: {}, variant: nil, size: nil, desperately_need_a_class: nil) ⇒ Component

Returns a new instance of Component.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/nitro_kit/component.rb', line 18

def initialize(
  component:,
  attributes: {},
  html: {},
  aria: {},
  data: {},
  variant: nil,
  size: nil,
  desperately_need_a_class: nil
)
  @component_name = normalize_identity(component, name: "component")
  @attrs = owned_attributes(
    attributes:,
    html:,
    aria:,
    data:,
    owned_data: {
      nk: @component_name,
      variant: variant && normalize_identity(variant, name: "variant"),
      size: size && normalize_identity(size, name: "size")
    }.compact,
    desperately_need_a_class:
  )
end