Class: Global::Sidebar

Inherits:
Components::Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::CurrentPage, Phlex::Rails::Helpers::LinkTo
Defined in:
app/components/databasium/global/sidebar.rb

Constant Summary collapse

PAGES =
[
  { icon: "list-bullet", path: :records_path, text: "Records" },
  { icon: "arrow-path", path: :migrations_path, text: "Migrations" },
  { icon: "cube", path: :new_model_path, text: "Models" },
  { icon: "table-cells", path: :schemas_path, text: "Schema" }
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(sidebar: nil) ⇒ Sidebar

Returns a new instance of Sidebar.



13
14
15
# File 'app/components/databasium/global/sidebar.rb', line 13

def initialize(sidebar: nil)
  @sidebar = sidebar
end

Instance Method Details

#view_templateObject



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
# File 'app/components/databasium/global/sidebar.rb', line 17

def view_template
  div(
    class: "flex flex-col bg-panel border-r-2 border-r-border py-2 px-3 w-80",
    data: {
      layout_target: "sidebar"
    }
  ) do
    div(class: "flex flex-col gap-2 pb-6") do
      PAGES.each do |page|
        path = databasium.send(page[:path])
        link_to(
          path,
          class:
            class_names(
              "text-main-text hover:text-hover flex items-center gap-2 py-2 px-3 border border-border rounded-lg",
              "bg-accent shadow-accent" => current_page?(path)
            )
        ) do
          heroicon(page[:icon], variant: :outline, options: { class: "w-6 h-6" })
          span(class: "ml-2") { page[:text] }
        end
      end
    end
    raw @sidebar
  end
end