Menu
Revenue this month
Orders today
render Metric.new do |card| card.helper { "Revenue this month" } card.title(class: "mt-2") { "$ 75,480" } end render Metric.new(kind: :secondary) do |card| card.helper { "Orders today" } card.title(class: "mt-2") { "83" } end
Add the component to your project
Run the following command in your terminal
bundle exec essence add metric
Copy and paste the following code into your project
# frozen_string_literal: true
class Components::Metric < Components::Essence
BASE = "p-4 border rounded-xs"
HELPER_BASE = "text-xs uppercase font-medium text-gray-500"
TITLE_BASE = "text-2xl text-gray-900 font-medium"
BODY_BASE = "text-sm text-gray-700"
KINDS = {
primary: "border-gray-950/10 bg-white",
secondary: "border-transparent bg-gray-100"
}
attr_reader :kind
def initialize(kind: :primary, **attributes)
@kind = kind
super(**attributes)
end
def view_template(&)
div(**attributes, &)
end
def title(**mattributes, &)
mattributes[:class] = merge_classes([ TITLE_BASE, mattributes[:class] ])
h5(**mattributes, &)
end
def helper(**mattributes, &)
mattributes[:class] = merge_classes([ HELPER_BASE, mattributes[:class] ])
p(**mattributes, &)
end
def body(**mattributes, &)
mattributes[:class] = merge_classes([ BODY_BASE, mattributes[:class] ])
p(**mattributes, &)
end
private
def initialize_merged_classes = merge_classes([ BASE, KINDS[kind], attributes[:class] ])
end