Class: NitroKit::Alert

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/alert.rb

Constant Summary collapse

VARIANTS =
%i[default warning error success]

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(variant: :default, **attrs) ⇒ Alert

Returns a new instance of Alert.



7
8
9
10
11
12
13
14
15
# File 'app/components/nitro_kit/alert.rb', line 7

def initialize(variant: :default, **attrs)
  @variant = variant

  super(
    attrs,
    role: "alert",
    class: [ base_class, variant_class ]
  )
end

Instance Attribute Details

#variantObject (readonly)

Returns the value of attribute variant.



17
18
19
# File 'app/components/nitro_kit/alert.rb', line 17

def variant
  @variant
end

Instance Method Details

#description(text = nil, **attrs, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'app/components/nitro_kit/alert.rb', line 33

def description(text = nil, **attrs, &block)
  builder do
    div(**mattr(attrs, class: description_class)) do
      text_or_block(text, &block)
    end
  end
end

#title(text = nil, **attrs, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'app/components/nitro_kit/alert.rb', line 25

def title(text = nil, **attrs, &block)
  builder do
    h5(**mattr(attrs, class: title_class)) do
      text_or_block(text, &block)
    end
  end
end

#view_templateObject



19
20
21
22
23
# File 'app/components/nitro_kit/alert.rb', line 19

def view_template
  div(**attrs) do
    yield
  end
end