Class: NitroKit::AppShell

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

Constant Summary collapse

LAYOUTS =
%i[sidebar topbar hybrid].freeze
REGIONS =
%i[brand navigation topbar main].freeze

Constants inherited from Component

Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, layout: :sidebar, skip_link_label: I18n.t("nitro_kit.app_shell.skip_link"), open_navigation_label: I18n.t("nitro_kit.app_shell.open_navigation"), close_navigation_label: I18n.t("nitro_kit.app_shell.close_navigation"), navigation_dialog_label: I18n.t("nitro_kit.app_shell.navigation_dialog"), html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ AppShell

Returns a new instance of AppShell.



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
46
47
48
49
50
51
52
# File 'app/components/nitro_kit/app_shell.rb', line 12

def initialize(
  id:,
  layout: :sidebar,
  skip_link_label: I18n.t("nitro_kit.app_shell.skip_link"),
  open_navigation_label: I18n.t("nitro_kit.app_shell.open_navigation"),
  close_navigation_label: I18n.t("nitro_kit.app_shell.close_navigation"),
  navigation_dialog_label: I18n.t("nitro_kit.app_shell.navigation_dialog"),
  html: {},
  aria: {},
  data: {},
  desperately_need_a_class: nil
)
  @identifier = component_id(id)
  @layout = validate_choice!(:layout, layout, LAYOUTS)
  @skip_link_label = validate_label!(:skip_link_label, skip_link_label)
  @open_navigation_label = validate_label!(:open_navigation_label, open_navigation_label)
  @close_navigation_label = validate_label!(:close_navigation_label, close_navigation_label)
  @navigation_dialog_label = validate_label!(:navigation_dialog_label, navigation_dialog_label)
  @regions = REGIONS.to_h { |name| [ name, nil ] }
  @collecting = false

  super(
    component: :app_shell,
    attributes: {
      id: @identifier,
      data: {
        controller: "nk--app-shell",
        layout: @layout,
        state: "closed",
        action: "turbo:before-visit@document->nk--app-shell#closeForNavigation " \
          "turbo:morph@document->nk--app-shell#syncViewport",
        nk__app_shell_open_label_value: @open_navigation_label,
        nk__app_shell_close_label_value: @close_navigation_label
      }
    },
    html:,
    aria:,
    data:,
    desperately_need_a_class:
  )
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



54
55
56
# File 'app/components/nitro_kit/app_shell.rb', line 54

def identifier
  @identifier
end

#layoutObject (readonly)

Returns the value of attribute layout.



54
55
56
# File 'app/components/nitro_kit/app_shell.rb', line 54

def layout
  @layout
end

Instance Method Details

#brand(&content) ⇒ Object



68
69
70
# File 'app/components/nitro_kit/app_shell.rb', line 68

def brand(&content)
  add_region(:brand, content:)
end

#html_mainObject



5
# File 'app/components/nitro_kit/app_shell.rb', line 5

alias_method :html_main, :main

#main(&content) ⇒ Object



80
81
82
# File 'app/components/nitro_kit/app_shell.rb', line 80

def main(&content)
  add_region(:main, content:)
end


72
73
74
# File 'app/components/nitro_kit/app_shell.rb', line 72

def navigation(&content)
  add_region(:navigation, content:)
end

#topbar(&content) ⇒ Object



76
77
78
# File 'app/components/nitro_kit/app_shell.rb', line 76

def topbar(&content)
  add_region(:topbar, content:)
end

#view_template(&declarations) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/nitro_kit/app_shell.rb', line 56

def view_template(&declarations)
  collect_regions(&declarations)

  div(**root_attributes) do
    render_skip_link
    render_header
    render_sidebar
    render_dialog
    render_main
  end
end