Menu

Text

Hello, world!

render Text.new(size: :md) { "Hello, world!" }

Installation

Add the component to your project

CLI

Run the following command in your terminal

bundle exec essence add text
Manually

Copy and paste the following code into your project

# frozen_string_literal: true

class Components::Text < Components::Essence
  BASE = "text-base text-gray-600"
  SIZES = {
    sm: "text-sm",
    md: "text-base",
    lg: "text-lg"
  }

  attr_reader :size

  def initialize(size: :md, **attributes)
    @size = size
    super(**attributes)
  end

  def view_template(&)
    p(**attributes, &)
  end

  private

  def initialize_merged_classes = merge_classes([ BASE, SIZES[size], attributes[:class] ])
end