Class: RubyUI::DatePicker
- Defined in:
- lib/ruby_ui/date_picker/date_picker.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(id: nil, name: nil, label: "Select a date", value: nil, placeholder: "Select a date", selected_date: value, date_format: "yyyy-MM-dd", popover_options: {}, input_attrs: {}, calendar_attrs: {}, trigger_attrs: {}, content_attrs: {}, **attrs) ⇒ DatePicker
constructor
A new instance of DatePicker.
- #view_template ⇒ Object
Constructor Details
#initialize(id: nil, name: nil, label: "Select a date", value: nil, placeholder: "Select a date", selected_date: value, date_format: "yyyy-MM-dd", popover_options: {}, input_attrs: {}, calendar_attrs: {}, trigger_attrs: {}, content_attrs: {}, **attrs) ⇒ DatePicker
Returns a new instance of DatePicker.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby_ui/date_picker/date_picker.rb', line 7 def initialize( id: nil, name: nil, label: "Select a date", value: nil, placeholder: "Select a date", selected_date: value, date_format: "yyyy-MM-dd", popover_options: {}, input_attrs: {}, calendar_attrs: {}, trigger_attrs: {}, content_attrs: {}, **attrs ) @id = id || "date-picker-#{SecureRandom.hex(4)}" @name = name @label = label @value = value || selected_date&.to_s @placeholder = placeholder @selected_date = selected_date @date_format = date_format @popover_options = {trigger: "click"}.merge() @input_attrs = input_attrs @calendar_attrs = calendar_attrs @trigger_attrs = trigger_attrs @content_attrs = content_attrs super(**attrs) end |
Instance Method Details
#view_template ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_ui/date_picker/date_picker.rb', line 37 def view_template div(**attrs) do RubyUI.Popover(options: @popover_options) do RubyUI.PopoverTrigger(**trigger_attrs) do div(class: "grid w-full max-w-sm items-center gap-1.5") do label(for: @id) { @label } if @label RubyUI.Input(**input_attrs) end end RubyUI.PopoverContent(**content_attrs) do RubyUI.Calendar(input_id: "##{@id}", selected_date: @selected_date, date_format: @date_format, **calendar_attrs) end end end end |