Class: BetterUi::Application::Navbar::Component

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
General::Components::Avatar::AvatarHelper, General::Components::Breadcrumb::BreadcrumbHelper, General::Components::Icon::IconHelper
Defined in:
app/components/better_ui/application/navbar/component.rb

Constant Summary collapse

{
  default: "bg-white text-gray-900 border-gray-200",
  dark: "bg-gray-900 text-white border-gray-700",
  light: "bg-gray-50 text-gray-900 border-gray-100"
}
{
  sm: "h-12",
  md: "h-16",
  lg: "h-20"
}
{
  top: "",
  fixed_top: "fixed top-0 left-0 right-0 z-50",
  sticky_top: "sticky top-0 z-40"
}
{
  none: "",
  sm: "shadow-sm",
  md: "shadow-md",
  lg: "shadow-lg",
  xl: "shadow-xl"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from General::Components::Breadcrumb::BreadcrumbHelper

#bui_breadcrumb

Methods included from General::Components::Avatar::AvatarHelper

#bui_avatar

Methods included from General::Components::Icon::IconHelper

#bui_icon

Constructor Details

#initialize(theme: :default, position: :top, height: :md, shadow: :sm, border: true, brand: {}, breadcrumb: {}, navigation_items: [], actions: [], classes: nil) ⇒ Component

Returns a new instance of Component.

Parameters:

  • theme (Symbol) (defaults to: :default)

    Tema colori (:default, :dark, :light), default :default

  • position (Symbol) (defaults to: :top)

    Posizione della navbar (:top, :fixed_top, :sticky_top), default :top

  • height (Symbol) (defaults to: :md)

    Altezza della navbar (:sm, :md, :lg), default :md

  • shadow (Symbol) (defaults to: :sm)

    Tipo di ombra (:none, :sm, :md, :lg, :xl), default :sm

  • border (Boolean) (defaults to: true)

    Se mostrare il bordo inferiore, default true

  • brand (Hash) (defaults to: {})

    Configurazione brand (logo, title, href)

  • breadcrumb (Hash) (defaults to: {})

    Configurazione breadcrumb (items, separator, theme)

  • navigation_items (Array) (defaults to: [])

    Array di elementi di navigazione centrali

  • actions (Array) (defaults to: [])

    Array di azioni/pulsanti a destra

  • classes (String) (defaults to: nil)

    Classi CSS aggiuntive



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/components/better_ui/application/navbar/component.rb', line 53

def initialize(
  theme: :default,
  position: :top,
  height: :md,
  shadow: :sm,
  border: true,
  brand: {},
  breadcrumb: {},
  navigation_items: [],
  actions: [],
  classes: nil
)
  @theme = theme.to_sym
  @position = position.to_sym
  @height = height.to_sym
  @shadow = shadow.to_sym
  @border = border
  @brand = brand || {}
  @breadcrumb = breadcrumb || {}
  @navigation_items = navigation_items || []
  @actions = actions || []
  @classes = classes
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def actions
  @actions
end

#borderObject (readonly)

Returns the value of attribute border.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def border
  @border
end

#brandObject (readonly)

Returns the value of attribute brand.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def brand
  @brand
end

Returns the value of attribute breadcrumb.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def breadcrumb
  @breadcrumb
end

#classesObject (readonly)

Returns the value of attribute classes.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def classes
  @classes
end

#heightObject (readonly)

Returns the value of attribute height.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def height
  @height
end

Returns the value of attribute navigation_items.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def navigation_items
  @navigation_items
end

#positionObject (readonly)

Returns the value of attribute position.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def position
  @position
end

#shadowObject (readonly)

Returns the value of attribute shadow.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def shadow
  @shadow
end

#themeObject (readonly)

Returns the value of attribute theme.



11
12
13
# File 'app/components/better_ui/application/navbar/component.rb', line 11

def theme
  @theme
end

Instance Method Details

#container_classesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/components/better_ui/application/navbar/component.rb', line 77

def container_classes
  base_classes = %w[w-full flex items-center justify-between px-4 sm:px-6 lg:px-8]
  
  # Posizione
  base_classes.concat(position_classes.split) if position != :top
  
  # Altezza
  base_classes << height_class
  
  # Tema
  base_classes.concat(theme_classes.split)
  
  # Shadow
  base_classes << shadow_class if shadow != :none
  
  # Border
  base_classes << "border-b" if border
  
  # Classi aggiuntive
  base_classes << classes if classes.present?
  
  base_classes.compact.join(" ")
end

#has_actions?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/components/better_ui/application/navbar/component.rb', line 113

def has_actions?
  actions.present? && actions.any?
end

#has_brand?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'app/components/better_ui/application/navbar/component.rb', line 101

def has_brand?
  brand.present? && (brand[:title].present? || brand[:logo].present?)
end

#has_breadcrumb?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/components/better_ui/application/navbar/component.rb', line 105

def has_breadcrumb?
  breadcrumb.present? && breadcrumb[:items].present? && breadcrumb[:items].any?
end

#has_navigation?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/components/better_ui/application/navbar/component.rb', line 109

def has_navigation?
  navigation_items.present? && navigation_items.any?
end

#render_breadcrumbObject



117
118
119
120
121
122
123
124
125
126
# File 'app/components/better_ui/application/navbar/component.rb', line 117

def render_breadcrumb
  return unless has_breadcrumb?
  
  bui_breadcrumb(
    items: breadcrumb[:items],
    separator: breadcrumb[:separator] || :chevron,
    theme: breadcrumb[:theme] || theme,
    size: :small
  )
end