Menu

Text

Hello, world!

render Components::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

Add the following code and libraries into your project

components/text.rb
# frozen_string_literal: true

class Components::Text < Components::Essence
  attr_reader :color, :size

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

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

  private

  def component_classes
    {
      _: {
        _: "",
        color: {
          none: "",
          default: "text-gray-950/60",
          muted: "text-gray-950/45",
          highlighted: "text-gray-950"
        },
        size: {
          none: "",
          sm: "text-sm",
          md: "text-base",
          lg: "text-lg"
        }
      }
    }.freeze
  end
end