Flatpickr Datepicker integration, compatible with Bootstrap's design schema. In order to limit the scope of the matestack-ui-bootstrap gem, Flatpickr is not part of this gem.
The below shown example should enable you to easily integrate Flatpickr (or any other Datepicker library) according to your needs!
Ruby component
app/matestack/components/form/flatpickr.rb
classComponents::Form::Flatpickr<Matestack::Ui::Bootstrap::Form::Input optional :enable_time vue_name "form-flatpickr-component"defvue_props { init_value: init_value, enable_time: enable_time }enddefresponse# exactly one root element is required since this is a Vue.js component template div class: "form-flatpickr-component"do label input_label, for: attr_key, class: "form-label"if input_label input input_attributes.merge(bootstrap_flatpickr_input_attributes) render_errors render_form_textendenddefbootstrap_flatpickr_input_attributes bootstrap_input_attributes.merge({ type: :text, class: (options[:class] ||"") << (" form-control flatpickr"), disabled: disabled })endend
Vue.js component
Do not forget to require flatpickr in your package.jsonDo not forget to import the following file into you application pack
app/matestack/components/form/flatpickr.js
import flatpickr from"flatpickr";import MatestackUiVueJs from'matestack-ui-vuejs'constflatpickrComponent= { mixins: [MatestackUiVueJs.componentMixin,MatestackUiVueJs.formInputMixin], template:MatestackUiVueJs.componentHelpers.inlineTemplate,data() {return {}; },mounted:function(){flatpickr(this.getElement().querySelector('.flatpickr'), { defaultDate:this.props["init_value"], enableTime: (this.props["enable_time"] ==true) });//all kind of configuration possible for flatpickr may be implemented here according to your needs }}exportdefault flatpickrComponent
and then in your application.js file:
import flatpickrComponent from'../../matestack/components/form/flatpickr.js'// import component definition from sourceconstappInstance=createApp({})appInstance.component('form-flatpickr-component', flatpickrComponent) // register at appInstanceMatestackUiBootstrap.registerComponents(appInstance)document.addEventListener('DOMContentLoaded', () => {MatestackUiVueJs.mount(appInstance)})
Usage
Example 1: Usage in form (e.g. mapped to an Active Record model) with enabled time picker
matestack_form some_form_config do div class: "mb-3"doComponents::Form::Flatpickr.call(key: :shipped_at, label: "Shipped at", enable_time: true, type: :text)end div class: "mb-3"do bs_form_submit button_variant: :primary, spinner_variant: :light, text: "Submit"endend