Class: BetterUi::General::Text::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Text::Component
- Defined in:
- app/components/better_ui/general/text/component.rb
Constant Summary collapse
- TEXT_BASE_CLASSES =
Classi base sempre presenti
"block"
- TEXT_THEME_CLASSES =
Temi colore con classi Tailwind dirette
{ default: "text-gray-900", # Testo nero standard white: "text-white", # Testo bianco red: "text-red-600", rose: "text-rose-600", orange: "text-orange-600", green: "text-green-600", blue: "text-blue-600", yellow: "text-yellow-600", violet: "text-violet-600", purple: "text-purple-600", gray: "text-gray-600", muted: "text-gray-500" }.freeze
- TEXT_SIZE_CLASSES =
Dimensioni con classi Tailwind dirette
{ xs: "text-xs", small: "text-sm", medium: "text-base", large: "text-lg", xl: "text-xl", "2xl": "text-2xl" }.freeze
- TEXT_ALIGN_CLASSES =
Allineamenti con classi Tailwind dirette
{ left: "text-left", center: "text-center", right: "text-right", justify: "text-justify" }.freeze
- TEXT_WEIGHT_CLASSES =
Peso font con classi Tailwind dirette
{ thin: "font-thin", light: "font-light", normal: "font-normal", medium: "font-medium", semibold: "font-semibold", bold: "font-bold", extrabold: "font-extrabold" }.freeze
- TEXT_STYLE_CLASSES =
Stili con classi Tailwind dirette
{ normal: "", italic: "italic", underline: "underline", line_through: "line-through" }.freeze
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#combined_classes ⇒ Object
Combina tutte le classi CSS.
-
#initialize(text: nil, theme: :default, size: :medium, align: :left, weight: :normal, style: :normal, classes: '', **html_options) ⇒ Component
constructor
A new instance of Component.
-
#render? ⇒ Boolean
Determina se il componente ha contenuto da renderizzare.
-
#text_attributes ⇒ Object
Attributi HTML per l’elemento.
-
#text_content ⇒ Object
Contenuto da mostrare (testo diretto o contenuto blocco).
Constructor Details
#initialize(text: nil, theme: :default, size: :medium, align: :left, weight: :normal, style: :normal, classes: '', **html_options) ⇒ Component
Returns a new instance of Component.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/components/better_ui/general/text/component.rb', line 73 def initialize( text: nil, theme: :default, size: :medium, align: :left, weight: :normal, style: :normal, classes: '', ** ) @text = text @theme = theme.to_sym @size = size.to_sym @align = align.to_sym @weight = weight.to_sym @style = style.to_sym @classes = classes @html_options = validate_params super() end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def align @align end |
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def classes @classes end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def @html_options end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def size @size end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def style @style end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def text @text end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def theme @theme end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
7 8 9 |
# File 'app/components/better_ui/general/text/component.rb', line 7 def weight @weight end |
Instance Method Details
#combined_classes ⇒ Object
Combina tutte le classi CSS
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/components/better_ui/general/text/component.rb', line 97 def combined_classes [ TEXT_BASE_CLASSES, get_theme_classes, get_size_classes, get_align_classes, get_weight_classes, get_style_classes, @classes, @html_options[:class] ].compact.join(" ") end |
#render? ⇒ Boolean
Determina se il componente ha contenuto da renderizzare
118 119 120 |
# File 'app/components/better_ui/general/text/component.rb', line 118 def render? @text.present? || content.present? end |
#text_attributes ⇒ Object
Attributi HTML per l’elemento
111 112 113 114 115 |
# File 'app/components/better_ui/general/text/component.rb', line 111 def text_attributes attrs = @html_options.except(:class) attrs[:class] = combined_classes attrs end |
#text_content ⇒ Object
Contenuto da mostrare (testo diretto o contenuto blocco)
123 124 125 |
# File 'app/components/better_ui/general/text/component.rb', line 123 def text_content @text.present? ? @text : content end |