Menu
render Row.new do |row| row.item { "Left" } row.item { "Right" } end
Add the component to your project
Run the following command in your terminal
bundle exec essence add row
Copy and paste the following code into your project
# frozen_string_literal: true
class Components::Row < Components::Essence
BASE = "flex gap-4"
KINDS = {
default: "flex-col md:flex-row md:items-center md:justify-between",
center: "flex-col md:flex-row md:items-center md:justify-center",
start: "flex-col md:flex-row md:items-center md:justify-start",
end: "flex-col md:flex-row md:items-center md:justify-end"
}
attr_reader :kind
def initialize(kind: :default, **attributes)
@kind = kind
super(**attributes)
end
def view_template(&)
div(**attributes, &)
end
def item(**mattributes, &)
mattributes[:class] = merge_classes([ "flex items-center gap-2 flex-wrap", mattributes[:class] ])
div(**mattributes, &)
end
private
def initialize_merged_classes = merge_classes([ BASE, KINDS[kind], attributes[:class] ])
end
This is how you can use this component
Attribute
Description