Class: Essence::Button

Inherits:
Essence
  • Object
show all
Defined in:
lib/essence/components/button.rb

Constant Summary collapse

BASE =
"inline-flex items-center rounded-xs border border-transparent font-medium transition duration-150 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed hover:opacity-90"
SIZES =
{
  none: "",
  xs: "text-[0.6rem] px-2 py-1.5 gap-1",
  sm: "text-xs px-3 py-2 gap-1.5",
  md: "text-sm px-4 py-2 gap-2",
  lg: "text-base px-6 py-2.5 gap-2.5",
  xl: "text-base px-8 py-3 gap-3"
}
KINDS =
{
  primary: "text-white bg-indigo-500 hover:bg-indigo-500",
  secondary: "text-gray-700 bg-gray-100 hover:bg-gray-200",
  critical: "text-white bg-rose-500 hover:bg-rose-400",
  warning: "text-white bg-amber-500 hover:bg-amber-400",
  success: "text-white bg-emerald-500 hover:bg-emerald-400",
  info: "text-white bg-blue-500 hover:bg-blue-400",
  dark: "text-white bg-gray-900 hover:bg-gray-800",
  white: "text-gray-900 bg-white hover:bg-gray-200",
  ghost: "text-gray-900 bg-white hover:bg-gray-200 hover:text-gray-800"
}

Constants inherited from Essence

Essence::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size: :md, kind: :primary, **attributes) ⇒ Button

Returns a new instance of Button.



31
32
33
34
35
36
# File 'lib/essence/components/button.rb', line 31

def initialize(size: :md, kind: :primary, **attributes)
  @size = size
  @kind = kind
  @attributes = attributes
  @attributes[:class] = construct_classes(@attributes[:class])
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



29
30
31
# File 'lib/essence/components/button.rb', line 29

def attributes
  @attributes
end

#kindObject (readonly)

Returns the value of attribute kind.



28
29
30
# File 'lib/essence/components/button.rb', line 28

def kind
  @kind
end

#sizeObject (readonly)

Returns the value of attribute size.



27
28
29
# File 'lib/essence/components/button.rb', line 27

def size
  @size
end

Instance Method Details

#view_templateObject



38
39
40
# File 'lib/essence/components/button.rb', line 38

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