Class: BetterUi::General::Panel::Component

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/better_ui/general/panel/component.rb

Constant Summary collapse

PANEL_BASE_CLASSES =

Classi base sempre presenti

"overflow-hidden"
PANEL_THEME_CLASSES =

Temi con classi Tailwind dirette - LOGICA CORRETTA

{
  default: "bg-gray-800 border-gray-700",        # Scuro per sfondi scuri
  white: "bg-white border-gray-200",             # Chiaro per sfondi chiari
  red: "bg-red-50 border-red-200",
  rose: "bg-rose-50 border-rose-200",
  orange: "bg-orange-50 border-orange-200",
  green: "bg-green-50 border-green-200",
  blue: "bg-blue-50 border-blue-200",
  yellow: "bg-yellow-50 border-yellow-200",
  violet: "bg-violet-50 border-violet-200"
}
PANEL_TEXT_THEME_CLASSES =

Temi per testo - LOGICA CORRETTA

{
  default: "text-white",                         # Testo bianco per sfondi scuri
  white: "text-gray-900",                        # Testo nero per sfondi chiari
  red: "text-red-900",
  rose: "text-rose-900",
  orange: "text-orange-900",
  green: "text-green-900",
  blue: "text-blue-900",
  yellow: "text-yellow-900",
  violet: "text-violet-900"
}
PANEL_STYLE_CLASSES =

Stili con classi Tailwind dirette

{
  default: "border shadow-sm",
  flat: "border-0",
  raised: "border shadow-lg",
  bordered: "border-2"
}
PANEL_PADDING_CLASSES =

Padding con classi Tailwind dirette

{
  none: "p-0",
  small: "p-2",
  medium: "p-4",
  large: "p-6"
}
PANEL_RADIUS_CLASSES =

Radius con classi Tailwind dirette

{
  none: "rounded-none",
  small: "rounded",
  medium: "rounded-md",
  large: "rounded-lg",
  full: "rounded-full"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, body: nil, header: nil, footer: nil, theme: :white, style: :default, padding: :medium, radius: :small, **html_options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • title (String) (defaults to: nil)

    titolo del pannello (opzionale)

  • body (String) (defaults to: nil)

    contenuto HTML del pannello (opzionale)

  • header (String) (defaults to: nil)

    header personalizzato (opzionale)

  • footer (String) (defaults to: nil)

    footer del pannello (opzionale)

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

    tema del colore (:default, :white, etc.)

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

    stile (:default, :flat, :raised, :bordered)

  • padding (Symbol) (defaults to: :medium)

    padding interno (:none, :small, :medium, :large)

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

    raggio dei bordi (:none, :small, :medium, :large, :full)

  • html_options (Hash)

    opzioni HTML aggiuntive



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

def initialize(
  title: nil,
  body: nil,
  header: nil,
  footer: nil,
  theme: :white,
  style: :default,
  padding: :medium,
  radius: :small,
  **html_options
)
  @title = title
  @body = body
  @header = header
  @footer = footer
  @theme = theme.to_sym
  @style = style.to_sym
  @padding = padding.to_sym
  @radius = radius.to_sym
  @html_options = html_options
  
  validate_params
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def body
  @body
end

Returns the value of attribute footer.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def footer
  @footer
end

#headerObject (readonly)

Returns the value of attribute header.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def header
  @header
end

#paddingObject (readonly)

Returns the value of attribute padding.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def padding
  @padding
end

#radiusObject (readonly)

Returns the value of attribute radius.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def radius
  @radius
end

#styleObject (readonly)

Returns the value of attribute style.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def style
  @style
end

#themeObject (readonly)

Returns the value of attribute theme.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def theme
  @theme
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'app/components/better_ui/general/panel/component.rb', line 5

def title
  @title
end

Instance Method Details

#body_classesObject

Classi per il body



123
124
125
126
127
128
# File 'app/components/better_ui/general/panel/component.rb', line 123

def body_classes
  [
    get_text_theme_class,
    get_padding_class
  ].compact.join(" ")
end

#combined_classesObject

Combina tutte le classi CSS per il panel



95
96
97
98
99
100
101
102
103
# File 'app/components/better_ui/general/panel/component.rb', line 95

def combined_classes
  [
    PANEL_BASE_CLASSES,
    get_theme_class,
    get_style_class,
    get_radius_class,
    @html_options[:class]
  ].compact.join(" ")
end

Classi per il footer



131
132
133
134
135
136
137
138
# File 'app/components/better_ui/general/panel/component.rb', line 131

def footer_classes
  [
    "border-t",
    get_border_theme_class,
    get_text_theme_class,
    get_padding_class
  ].compact.join(" ")
end

#header_classesObject

Classi per l’header



113
114
115
116
117
118
119
120
# File 'app/components/better_ui/general/panel/component.rb', line 113

def header_classes
  [
    "border-b",
    get_border_theme_class,
    get_text_theme_class,
    get_padding_class
  ].compact.join(" ")
end

#panel_attributesObject

Restituisce gli attributi HTML per il panel



106
107
108
109
110
# File 'app/components/better_ui/general/panel/component.rb', line 106

def panel_attributes
  attrs = @html_options.except(:class)
  attrs[:class] = combined_classes
  attrs
end

#render?Boolean

Determina se il pannello deve essere renderizzato

Returns:

  • (Boolean)


149
150
151
# File 'app/components/better_ui/general/panel/component.rb', line 149

def render?
  @body.present? || @header.present? || @footer.present? || content.present?
end

#show_body?Boolean

Determina se mostrare il body

Returns:

  • (Boolean)


159
160
161
# File 'app/components/better_ui/general/panel/component.rb', line 159

def show_body?
  @body.present? || content.present?
end

#show_footer?Boolean

Determina se mostrare il footer

Returns:

  • (Boolean)


164
165
166
# File 'app/components/better_ui/general/panel/component.rb', line 164

def show_footer?
  @footer.present?
end

#show_header?Boolean

Determina se mostrare l’header

Returns:

  • (Boolean)


154
155
156
# File 'app/components/better_ui/general/panel/component.rb', line 154

def show_header?
  @header.present? || @title.present?
end

#title_classesObject

Classi per il title



141
142
143
144
145
146
# File 'app/components/better_ui/general/panel/component.rb', line 141

def title_classes
  [
    "font-semibold text-lg leading-6",
    get_text_theme_class
  ].compact.join(" ")
end