Class: BetterUi::Application::Sidebar::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::Application::Sidebar::Component
- 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
- SIDEBAR_WIDTHS =
Larghezze sidebar con classi Tailwind dirette
{ sm: "w-48", md: "w-64", lg: "w-72", xl: "w-80" }
- SIDEBAR_THEMES =
Temi sidebar con classi Tailwind dirette
{ default: "bg-white text-gray-900", dark: "bg-gray-900 text-white", light: "bg-white text-gray-900" }
- SIDEBAR_SHADOWS =
Ombre sidebar con classi Tailwind dirette
{ none: "", sm: "shadow-sm", md: "shadow-md", lg: "shadow-lg", xl: "shadow-xl" }
- SIDEBAR_BORDERS =
Bordi sidebar con classi Tailwind dirette
{ left: "border-r border-gray-200", right: "border-l border-gray-200" }
Instance Attribute Summary collapse
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#collapsible ⇒ Object
readonly
Returns the value of attribute collapsible.
-
#footer ⇒ Object
readonly
Returns the value of attribute footer.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#navigation_sections ⇒ Object
readonly
Returns the value of attribute navigation_sections.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#shadow ⇒ Object
readonly
Returns the value of attribute shadow.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #container_classes ⇒ Object
- #has_footer? ⇒ Boolean
- #has_header? ⇒ Boolean
- #has_user_dropdown? ⇒ Boolean
-
#initialize(width: :md, position: :left, theme: :default, shadow: :lg, border: true, header: {}, footer: {}, navigation_sections: [], collapsible: true, classes: nil) ⇒ Component
constructor
A new instance of Component.
- #user_dropdown_trigger ⇒ Object
- #wrapper_classes ⇒ Object
Methods included from General::Components::Dropdown::ItemHelper
Methods included from General::Components::Dropdown::DropdownHelper
Methods included from General::Components::Button::ButtonHelper
Methods included from General::Components::Avatar::AvatarHelper
Methods included from General::Components::Icon::IconHelper
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.
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 = || {} @navigation_sections = || [] @collapsible = collapsible @classes = classes end |
Instance Attribute Details
#border ⇒ Object (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 |
#classes ⇒ Object (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 |
#collapsible ⇒ Object (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 |
#footer ⇒ Object (readonly)
Returns the value of attribute footer.
13 14 15 |
# File 'app/components/better_ui/application/sidebar/component.rb', line 13 def @footer end |
#header ⇒ Object (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 |
#navigation_sections ⇒ Object (readonly)
Returns the value of attribute navigation_sections.
13 14 15 |
# File 'app/components/better_ui/application/sidebar/component.rb', line 13 def @navigation_sections end |
#position ⇒ Object (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 |
#shadow ⇒ Object (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 |
#theme ⇒ Object (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 |
#width ⇒ Object (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_classes ⇒ Object
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
114 115 116 |
# File 'app/components/better_ui/application/sidebar/component.rb', line 114 def .present? && ([:content].present? || [:user_info].present? || [:user_dropdown].present?) end |
#has_header? ⇒ 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
118 119 120 |
# File 'app/components/better_ui/application/sidebar/component.rb', line 118 def has_user_dropdown? .present? && [:user_dropdown].present? end |
#user_dropdown_trigger ⇒ Object
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 = [: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 content_tag(:div, class: "flex items-center w-full text-left") do avatar_section = if user_dropdown[:avatar].present? content_tag(:div, avatar_html, class: "flex-shrink-0") else '' end text_section = content_tag(: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? content_tag(:p, user_dropdown[:name], class: "text-sm font-medium text-gray-700 truncate") else '' end subtitle_part = if user_dropdown[:subtitle].present? content_tag(:p, user_dropdown[:subtitle], class: "text-xs text-gray-500 truncate") else '' end (name_part + subtitle_part).html_safe end chevron_section = content_tag(: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_classes ⇒ Object
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 |