Class: BetterUi::General::Dropdown::Component

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Components::Icon::IconHelper
Defined in:
app/components/better_ui/general/dropdown/component.rb

Constant Summary collapse

{
  default: "bg-white border-gray-300 text-gray-700 hover:bg-gray-50 focus:ring-blue-500",
  white: "bg-white border-gray-300 text-gray-900 hover:bg-gray-50 focus:ring-gray-500",
  red: "bg-red-600 border-red-600 text-white hover:bg-red-700 focus:ring-red-500",
  rose: "bg-rose-600 border-rose-600 text-white hover:bg-rose-700 focus:ring-rose-500",
  orange: "bg-orange-600 border-orange-600 text-white hover:bg-orange-700 focus:ring-orange-500",
  green: "bg-green-600 border-green-600 text-white hover:bg-green-700 focus:ring-green-500",
  blue: "bg-blue-600 border-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500",
  yellow: "bg-yellow-500 border-yellow-500 text-white hover:bg-yellow-600 focus:ring-yellow-500",
  violet: "bg-violet-600 border-violet-600 text-white hover:bg-violet-700 focus:ring-violet-500"
}.freeze
{
  small: "px-3 py-1.5 text-sm",
  medium: "px-4 py-2 text-sm",
  large: "px-6 py-3 text-base"
}.freeze
{
  none: "rounded-none",
  small: "rounded-md",
  medium: "rounded-lg",
  large: "rounded-xl",
  full: "rounded-full"
}.freeze
{
  bottom: "top-full left-0",
  top: "bottom-full left-0",
  left: "top-0 right-full mr-2",
  right: "top-0 left-full ml-2"
}.freeze
{
  fade: "transition-opacity duration-150",
  slide: "transition-all duration-150 transform",
  none: ""
}.freeze
{
  true => "w-full text-left justify-start",
  false => "inline-flex justify-center"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::Icon::IconHelper

#bui_icon

Constructor Details

#initialize(trigger:, position: :bottom, theme: :default, size: :medium, rounded: :medium, animation: :fade, fullwidth: false, show_chevron: true, selectable: false, classes: nil, **html_options) ⇒ Component

Returns a new instance of Component.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/components/better_ui/general/dropdown/component.rb', line 63

def initialize(
  trigger:,
  position: :bottom,
  theme: :default,
  size: :medium,
  rounded: :medium,
  animation: :fade,
  fullwidth: false,
  show_chevron: true,
  selectable: false,
  classes: nil,
  **html_options
)
  @trigger = trigger
  @position = position.to_sym
  @theme = theme.to_sym
  @size = size.to_sym
  @rounded = rounded.to_sym
  @animation = animation.to_sym
  @fullwidth = fullwidth
  @show_chevron = show_chevron
  @selectable = selectable
  @classes = classes
  @html_options = html_options

  validate_params
end

Instance Attribute Details

#animationObject (readonly)

Returns the value of attribute animation.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def animation
  @animation
end

#classesObject (readonly)

Returns the value of attribute classes.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def classes
  @classes
end

#fullwidthObject (readonly)

Returns the value of attribute fullwidth.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def fullwidth
  @fullwidth
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def html_options
  @html_options
end

#positionObject (readonly)

Returns the value of attribute position.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def position
  @position
end

#roundedObject (readonly)

Returns the value of attribute rounded.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def rounded
  @rounded
end

#selectableObject (readonly)

Returns the value of attribute selectable.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def selectable
  @selectable
end

#show_chevronObject (readonly)

Returns the value of attribute show_chevron.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def show_chevron
  @show_chevron
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def size
  @size
end

#themeObject (readonly)

Returns the value of attribute theme.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def theme
  @theme
end

#triggerObject (readonly)

Returns the value of attribute trigger.



9
10
11
# File 'app/components/better_ui/general/dropdown/component.rb', line 9

def trigger
  @trigger
end

Instance Method Details

#dynamic_menu_classesObject

Restituisce solo le classi dinamiche per il menu



107
108
109
110
111
112
113
# File 'app/components/better_ui/general/dropdown/component.rb', line 107

def dynamic_menu_classes
  [
    get_position_classes,
    get_animation_classes,
    get_menu_rounded_classes
  ].compact.join(" ")
end

#dynamic_trigger_classesObject

Restituisce solo le classi dinamiche per il trigger



98
99
100
101
102
103
104
# File 'app/components/better_ui/general/dropdown/component.rb', line 98

def dynamic_trigger_classes
  [
    get_trigger_theme_classes,
    get_trigger_size_classes,
    get_trigger_rounded_classes
  ].compact.join(" ")
end

#fullwidth_classesObject



91
92
93
94
95
# File 'app/components/better_ui/general/dropdown/component.rb', line 91

def fullwidth_classes
  [
    get_fullwidth_classes
  ].compact.join(" ")
end

#render?Boolean

Verifica se rendere il componente

Returns:

  • (Boolean)


118
119
120
# File 'app/components/better_ui/general/dropdown/component.rb', line 118

def render?
  @trigger.present?
end