Module: UI::DatePickerTriggerBehavior

Included in:
DatePickerTrigger, DatePickerTriggerComponent
Defined in:
app/behaviors/ui/date_picker_trigger_behavior.rb

Overview

Shared behavior for DatePicker trigger component (button)

Instance Method Summary collapse

Instance Method Details

#calendar_iconObject

Calendar icon SVG



52
53
54
55
56
57
58
59
60
61
# File 'app/behaviors/ui/date_picker_trigger_behavior.rb', line 52

def calendar_icon
  <<~SVG.html_safe
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4 opacity-50">
      <path d="M8 2v4"/>
      <path d="M16 2v4"/>
      <rect width="18" height="18" x="3" y="4" rx="2"/>
      <path d="M3 10h18"/>
    </svg>
  SVG
end

#chevron_down_iconObject

ChevronDown icon SVG



43
44
45
46
47
48
49
# File 'app/behaviors/ui/date_picker_trigger_behavior.rb', line 43

def chevron_down_icon
  <<~SVG.html_safe
    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="h-4 w-4 opacity-50">
      <path d="m6 9 6 6 6-6"/>
    </svg>
  SVG
end

#date_picker_trigger_classesObject

Trigger classes - button with outline variant style



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/behaviors/ui/date_picker_trigger_behavior.rb', line 25

def date_picker_trigger_classes
  TailwindMerge::Merger.new.merge([
    # Button base styles
    "inline-flex items-center justify-between gap-2 whitespace-nowrap rounded-md text-sm font-medium",
    "ring-offset-background transition-colors",
    "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
    "disabled:pointer-events-none disabled:opacity-50",
    # Outline variant
    "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
    # Size default
    "h-10 px-4 py-2",
    # Width
    "w-[280px]",
    @classes
  ].compact.join(" "))
end

#date_picker_trigger_data_attributesObject

Generate data attributes for trigger



6
7
8
9
10
11
# File 'app/behaviors/ui/date_picker_trigger_behavior.rb', line 6

def date_picker_trigger_data_attributes
  {
    ui__datepicker_target: "trigger",
    ui__popover_target: "trigger"
  }
end

#date_picker_trigger_html_attributesObject

Build complete HTML attributes hash for trigger



14
15
16
17
18
19
20
21
22
# File 'app/behaviors/ui/date_picker_trigger_behavior.rb', line 14

def date_picker_trigger_html_attributes
  base_attrs = @attributes&.except(:data) || {}
  user_data = @attributes&.fetch(:data, {}) || {}
  base_attrs.merge(
    class: date_picker_trigger_classes,
    type: "button",
    data: user_data.merge(date_picker_trigger_data_attributes)
  )
end