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

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
General::Components::Avatar::AvatarHelper, 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::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)

  • 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



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

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.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def border
  @border
end

#classesObject (readonly)

Returns the value of attribute classes.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def classes
  @classes
end

#collapsibleObject (readonly)

Returns the value of attribute collapsible.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def collapsible
  @collapsible
end

Returns the value of attribute footer.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def footer
  @footer
end

#headerObject (readonly)

Returns the value of attribute header.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def header
  @header
end

Returns the value of attribute navigation_sections.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def navigation_sections
  @navigation_sections
end

#positionObject (readonly)

Returns the value of attribute position.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def position
  @position
end

#shadowObject (readonly)

Returns the value of attribute shadow.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def shadow
  @shadow
end

#themeObject (readonly)

Returns the value of attribute theme.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def theme
  @theme
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'app/components/better_ui/application/sidebar/component.rb', line 10

def width
  @width
end

Instance Method Details

#container_classesObject



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

def container_classes
  base_classes = %w[fixed inset-y-0 z-50 flex flex-col overflow-y-auto]
  
  # Posizione
  base_classes << (position == :right ? "right-0" : "left-0")
  
  # Larghezza
  base_classes << width_class
  
  # 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)


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

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

#has_header?Boolean

Returns:

  • (Boolean)


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

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