Class: BetterUi::General::Text::Component

Inherits:
ViewComponent::Base
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • text (String) (defaults to: nil)

    testo da mostrare (opzionale se si usa blocco)

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

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

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

    dimensione (:xs, :small, :medium, :large, :xl, :“2xl”)

  • align (Symbol) (defaults to: :left)

    allineamento (:left, :center, :right, :justify)

  • weight (Symbol) (defaults to: :normal)

    peso font (:thin, :light, :normal, :medium, :semibold, :bold, :extrabold)

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

    stile (:normal, :italic, :underline, :line_through)

  • classes (String) (defaults to: '')

    classi CSS aggiuntive

  • html_options (Hash)

    opzioni HTML aggiuntive



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: '',
  **html_options
)
  @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 = html_options

  validate_params
  super()
end

Instance Attribute Details

#alignObject (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

#classesObject (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_optionsObject (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
  @html_options
end

#sizeObject (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

#styleObject (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

#textObject (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

#themeObject (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

#weightObject (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_classesObject

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

Returns:

  • (Boolean)


118
119
120
# File 'app/components/better_ui/general/text/component.rb', line 118

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

#text_attributesObject

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_contentObject

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