Class: BetterUi::General::Container::Component

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

Constant Summary collapse

CONTAINER_BASE_CLASSES =

Classi base sempre presenti

"mx-auto"
CONTAINER_MAX_WIDTH_CLASSES =

Larghezze massime con classi Tailwind dirette

{
  sm: "max-w-screen-sm",
  md: "max-w-screen-md",
  lg: "max-w-screen-lg",
  xl: "max-w-screen-xl",
  xxl: "max-w-screen-2xl"
}
CONTAINER_PADDING_CLASSES =

Padding con classi Tailwind dirette

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

Background con classi Tailwind dirette

{
  white: "bg-white",
  light: "bg-gray-50",
  dark: "bg-gray-900",
  transparent: "bg-transparent"
}
CONTAINER_BORDER_CLASSES =

Border con classi Tailwind dirette

{
  none: "border-0",
  small: "border",
  medium: "border-2",
  large: "border-4"
}
CONTAINER_SHADOW_CLASSES =

Shadow con classi Tailwind dirette

{
  none: "shadow-none",
  small: "shadow-sm",
  medium: "shadow",
  large: "shadow-lg"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html_content: nil, fluid: false, max_width: :lg, padding: :medium, background: :white, border: false, shadow: :none, classes: nil, **html_options) ⇒ Component

Returns a new instance of Component.

Parameters:

  • html_content (String) (defaults to: nil)

    contenuto HTML del container (opzionale)

  • fluid (Boolean) (defaults to: false)

    se il container deve essere fluid (full width)

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

    larghezza massima del container (:sm, :md, :lg, :xl, :xxl)

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

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

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

    colore di sfondo (:white, :light, :dark, :transparent)

  • border (Symbol) (defaults to: false)

    bordo del container (:none, :small, :medium, :large)

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

    ombra del container (:none, :small, :medium, :large)

  • html_options (Hash)

    opzioni HTML aggiuntive



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/components/better_ui/general/container/component.rb', line 59

def initialize(
  html_content: nil,
  fluid: false,
  max_width: :lg,
  padding: :medium,
  background: :white,
  border: false,
  shadow: :none,
  classes: nil,
  **html_options
)
  @html_content = html_content
  @fluid = fluid
  @max_width = max_width.to_sym
  @padding = padding.to_sym
  @background = background.to_sym
  @border = border
  @shadow = shadow
  @html_options = html_options
  @classes = classes

  validate_params
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



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

def background
  @background
end

#borderObject (readonly)

Returns the value of attribute border.



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

def border
  @border
end

#classesObject (readonly)

Returns the value of attribute classes.



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

def classes
  @classes
end

#fluidObject (readonly)

Returns the value of attribute fluid.



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

def fluid
  @fluid
end

#html_contentObject (readonly)

Returns the value of attribute html_content.



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

def html_content
  @html_content
end

#max_widthObject (readonly)

Returns the value of attribute max_width.



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

def max_width
  @max_width
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
end

#shadowObject (readonly)

Returns the value of attribute shadow.



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

def shadow
  @shadow
end

Instance Method Details

#combined_classesObject

Combina tutte le classi CSS per il container



84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/components/better_ui/general/container/component.rb', line 84

def combined_classes
  [
    CONTAINER_BASE_CLASSES,
    get_max_width_class,
    get_padding_class,
    get_background_class,
    get_border_class,
    get_shadow_class,
    @classes,
    @html_options[:class]
  ].compact.join(" ")
end

#container_attributesObject

Restituisce gli attributi HTML per il container



98
99
100
101
102
# File 'app/components/better_ui/general/container/component.rb', line 98

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

#render?Boolean

Determina se il container deve essere renderizzato

Returns:

  • (Boolean)


105
106
107
# File 'app/components/better_ui/general/container/component.rb', line 105

def render?
  @html_content.present? || content.present?
end