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

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
General::Components::Avatar::AvatarHelper, 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",
  white: "bg-white text-gray-900 border-gray-200",
  red: "bg-red-50 text-red-900 border-red-200",
  rose: "bg-rose-50 text-rose-900 border-rose-200",
  orange: "bg-orange-50 text-orange-900 border-orange-200",
  green: "bg-green-50 text-green-900 border-green-200",
  blue: "bg-blue-50 text-blue-900 border-blue-200",
  yellow: "bg-yellow-50 text-yellow-900 border-yellow-200",
  violet: "bg-violet-50 text-violet-900 border-violet-200"
}.freeze
{
  none: "",
  small: "shadow-sm",
  medium: "shadow-md",
  large: "shadow-lg"
}.freeze
{
  sm: 48,
  md: 64,
  lg: 72,
  xl: 80
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bui_avatar

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

#bui_icon

Constructor Details

#initialize(theme: :default, shadow: :small, border: false, actions: [], classes: nil, with_sidebar: false, sidebar_width: :md) ⇒ Component

Returns a new instance of Component.

Parameters:

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

    Tema colori (default, white, red, rose, orange, green, blue, yellow, violet), default :default

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

    Tipo di ombra (none, small, medium, large), default :small

  • border (Boolean) (defaults to: false)

    Se mostrare il bordo inferiore, default true

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

    Array di azioni/pulsanti a destra

  • classes (String) (defaults to: nil)

    Classi CSS aggiuntive

  • with_sidebar (Boolean) (defaults to: false)

    Se la navbar è affiancata a una sidebar, default false

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

    Larghezza della sidebar affiancata (:sm, :md, :lg, :xl), default :md



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/components/better_ui/application/navbar/component.rb', line 49

def initialize(
  theme: :default,
  shadow: :small,
  border: false,
  actions: [],
  classes: nil,
  with_sidebar: false,
  sidebar_width: :md
)
  @theme = theme.to_sym
  @shadow = shadow.to_sym
  @border = border
  @actions = actions || []
  @classes = classes
  @with_sidebar = with_sidebar
  @sidebar_width = sidebar_width.to_sym

  validate_params
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

#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

#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

Returns the value of attribute sidebar_width.



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

def sidebar_width
  @sidebar_width
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

#with_sidebarObject (readonly)

Returns the value of attribute with_sidebar.



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

def with_sidebar
  @with_sidebar
end

Instance Method Details

#container_classesObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/components/better_ui/application/navbar/component.rb', line 69

def container_classes
  base_classes = %w[h-[81px] px-6 py-4]
  
  # Width
  if with_sidebar
    sidebar_width_value = NAVBAR_SIDEBAR_WIDTH[@sidebar_width] || NAVBAR_SIDEBAR_WIDTH[:md]
    base_classes << "pl-#{sidebar_width_value}"
    base_classes << "ml-auto"
  else
    base_classes << "w-full"
  end

  # 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)


96
97
98
# File 'app/components/better_ui/application/navbar/component.rb', line 96

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