Menu

Essence

Phlex Warning: Your `Components::Preview` class doesn't define a `view_template` method. If you are upgrading to Phlex 2.x make sure to rename your `template` method to `view_template`. See: https://beta.phlex.fun/guides/v2-upgrade.html

Installation

Add the component to your project

CLI

Run the following command in your terminal

bundle exec essence add essence
Manually

Copy and paste the following code into your project

components/essence.rb
class Components::Essence < Phlex::HTML
  TAILWIND_MERGER = ::TailwindMerge::Merger.new.freeze unless defined?(TAILWIND_MERGER)

  attr_reader :attributes

  def initialize(**attributes)
    @attributes = mix(initialize_default_attributes, attributes)
    @attributes[:class] = initialize_merged_classes
  end

  private

  def merge_classes(*classes) = TAILWIND_MERGER.merge([ *classes ].compact)
  def initialize_merged_classes = ""
  def initialize_default_attributes = {}
end