Class: UI::DatePickerTriggerComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
DatePickerTriggerBehavior
Defined in:
app/view_components/ui/date_picker_trigger_component.rb

Overview

DatePicker Trigger ViewComponent A button that triggers the date picker popover.

Examples:

Basic usage

render UI::TriggerComponent.new(placeholder: "Pick a date")

Instance Method Summary collapse

Methods included from DatePickerTriggerBehavior

#calendar_icon, #chevron_down_icon, #date_picker_trigger_classes, #date_picker_trigger_data_attributes, #date_picker_trigger_html_attributes

Constructor Details

#initialize(placeholder: "Select date", selected: nil, icon: :chevron, classes: "", **attributes) ⇒ DatePickerTriggerComponent

Returns a new instance of DatePickerTriggerComponent.

Parameters:

  • placeholder (String) (defaults to: "Select date") —

    Placeholder text when no date selected

  • selected (Date, Range, Array) (defaults to: nil) —

    Currently selected date(s) for display

  • icon (Symbol) (defaults to: :chevron) —

    Icon to show: :chevron, :calendar, or :none

  • classes (String) (defaults to: "") —

    Additional CSS classes

  • attributes (Hash) —

    Additional HTML attributes



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/view_components/ui/date_picker_trigger_component.rb', line 17

def initialize(
  placeholder: "Select date",
  selected: nil,
  icon: :chevron,
  classes: "",
  **attributes
)
  @placeholder = placeholder
  @selected = selected
  @icon = icon
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#call ⇒ Object



31
32
33
34
35
36
37
38
# File 'app/view_components/ui/date_picker_trigger_component.rb', line 31

def call
   :button, date_picker_trigger_html_attributes do
    safe_join([
      render_label,
      render_icon
    ].compact)
  end
end