Class: BetterUi::Application::Sidebar::Component

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
General::Components::Avatar::AvatarHelper, General::Components::Button::ButtonHelper, General::Components::Dropdown::DropdownHelper, General::Components::Dropdown::ItemHelper, General::Components::Icon::IconHelper
Defined in:
app/components/better_ui/application/sidebar/component.rb

Constant Summary collapse

{
  sm: "w-48",
  md: "w-64",
  lg: "w-72",
  xl: "w-80"
}
{
  default: "bg-white text-gray-900",
  dark: "bg-gray-900 text-white",
  light: "bg-white text-gray-900"
}
{
  none: "",
  sm: "shadow-sm",
  md: "shadow-md",
  lg: "shadow-lg",
  xl: "shadow-xl"
}
{
  left: "border-r border-gray-200",
  right: "border-l border-gray-200"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from General::Components::Dropdown::ItemHelper

#bui_dropdown_item

Methods included from General::Components::Dropdown::DropdownHelper

#bui_dropdown

Methods included from General::Components::Button::ButtonHelper

#bui_button

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

#bui_avatar

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

#bui_icon

Constructor Details

#initialize(width: :md, position: :left, theme: :default, shadow: :lg, border: true, header: {}, footer: {}, navigation_sections: [], collapsible: true, classes: nil) ⇒ Component

Returns a new instance of Component.

Parameters:

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

    Larghezza della sidebar (:sm, :md, :lg, :xl), default :md (w-64)

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

    Posizione della sidebar (:left, :right), default :left

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

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

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

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

  • border (Boolean) (defaults to: true)

    Se mostrare il bordo destro/sinistro, default true

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

    Configurazione header (logo, title, subtitle)

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

    Configurazione footer (content, user_info, user_dropdown)

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

    Array di sezioni di navigazione

  • collapsible (Boolean) (defaults to: true)

    Se abilitare sezioni collassabili, default true

  • classes (String) (defaults to: nil)

    Classi CSS aggiuntive



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

def initialize(
  width: :md,
  position: :left,
  theme: :default,
  shadow: :lg,
  border: true,
  header: {},
  footer: {},
  navigation_sections: [],
  collapsible: true,
  classes: nil
)
  @width = width.to_sym
  @position = position.to_sym
  @theme = theme.to_sym
  @shadow = shadow.to_sym
  @border = border
  @header = header || {}
  @footer = footer || {}
  @navigation_sections = navigation_sections || []
  @collapsible = collapsible
  @classes = classes
end

Instance Attribute Details

#borderObject (readonly)

Returns the value of attribute border.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def border
  @border
end

#classesObject (readonly)

Returns the value of attribute classes.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def classes
  @classes
end

#collapsibleObject (readonly)

Returns the value of attribute collapsible.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def collapsible
  @collapsible
end

Returns the value of attribute footer.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def footer
  @footer
end

#headerObject (readonly)

Returns the value of attribute header.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def header
  @header
end

Returns the value of attribute navigation_sections.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def navigation_sections
  @navigation_sections
end

#positionObject (readonly)

Returns the value of attribute position.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def position
  @position
end

#shadowObject (readonly)

Returns the value of attribute shadow.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def shadow
  @shadow
end

#themeObject (readonly)

Returns the value of attribute theme.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def theme
  @theme
end

#widthObject (readonly)

Returns the value of attribute width.



13
14
15
# File 'app/components/better_ui/application/sidebar/component.rb', line 13

def width
  @width
end

Instance Method Details

#container_classesObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/components/better_ui/application/sidebar/component.rb', line 91

def container_classes
  base_classes = %w[flex flex-col h-full]

  # Tema
  base_classes.concat(theme_classes)

  # Shadow
  base_classes << shadow_class if shadow != :none

  # Border
  base_classes << border_class if border

  # Classi aggiuntive
  base_classes << classes if classes.present?

  base_classes.compact.join(" ")
end

#has_footer?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'app/components/better_ui/application/sidebar/component.rb', line 114

def has_footer?
  footer.present? && (footer[:content].present? || footer[:user_info].present? || footer[:user_dropdown].present?)
end

#has_header?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/components/better_ui/application/sidebar/component.rb', line 110

def has_header?
  header.present? && (header[:title].present? || header[:logo].present?)
end

#has_user_dropdown?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'app/components/better_ui/application/sidebar/component.rb', line 118

def has_user_dropdown?
  footer.present? && footer[:user_dropdown].present?
end

#user_dropdown_triggerObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/components/better_ui/application/sidebar/component.rb', line 122

def user_dropdown_trigger
  return '' unless has_user_dropdown?
  
  user_dropdown = footer[:user_dropdown]
  avatar_html = if user_dropdown[:avatar].present?
    if user_dropdown[:avatar].is_a?(Hash)
      bui_avatar(**user_dropdown[:avatar])
    else
      user_dropdown[:avatar].html_safe
    end
  else
    ''
  end

  (:div, class: "flex items-center w-full text-left") do
    avatar_section = if user_dropdown[:avatar].present?
      (:div, avatar_html, class: "flex-shrink-0")
    else
      ''
    end

    text_section = (:div, class: user_dropdown[:avatar].present? ? 'ml-3 min-w-0 flex-1' : 'min-w-0 flex-1') do
      name_part = if user_dropdown[:name].present?
        (:p, user_dropdown[:name], class: "text-sm font-medium text-gray-700 truncate")
      else
        ''
      end

      subtitle_part = if user_dropdown[:subtitle].present?
        (:p, user_dropdown[:subtitle], class: "text-xs text-gray-500 truncate")
      else
        ''
      end

      (name_part + subtitle_part).html_safe
    end

    chevron_section = (:div, class: "ml-auto flex-shrink-0") do
      bui_icon("chevron-down", size: :small, classes: "text-gray-400")
    end

    (avatar_section + text_section + chevron_section).html_safe
  end
end

#wrapper_classesObject



79
80
81
82
83
84
85
86
87
88
89
# File 'app/components/better_ui/application/sidebar/component.rb', line 79

def wrapper_classes
  base_classes = %w[fixed top-0 inset-y-0 h-screen z-[9999]]

  # Posizione
  base_classes << (position == :right ? "right-0" : "left-0")

  # Larghezza
  base_classes << width_class

  base_classes.compact.join(" ")
end