Sha256: 7826dcc6f26af9317ca2d1e0a6856c668bccfee75a0c744c8e6cb9ebfc5caa06

Contents?: true

Size: 1.23 KB

Versions: 10

Compression:

Stored size: 1.23 KB

Contents

import { Controller } from "@hotwired/stimulus"
import flatpickr from "https://esm.sh/flatpickr@4.6.13?standalone"

export default class extends Controller {
  static targets = [ "details" ]
  static values  = {
    type: String, disable: Array,
    mode: { type: String, default: "single" },
    dateFormat: { type: String, default: "F d, Y" },
    dateTimeFormat: { type: String, default: "F d, Y H:i" }
  }

  connect() {
    if (this.typeValue == "time") {
      this.flatpickr = flatpickr(this.element, this.#timeOptions)
    } else if (this.typeValue == "datetime") {
      this.flatpickr = flatpickr(this.element, this.#dateTimeOptions)
    } else {
      this.flatpickr = flatpickr(this.element, this.#basicOptions)
    }
  }

  disconnect() {
    this.flatpickr.destroy()
  }

  get #timeOptions() {
    return { dateFormat: "H:i", enableTime: true, noCalendar: true }
  }

  get #dateTimeOptions() {
    return { ...this.#baseOptions, altFormat: this.dateTimeFormatValue, dateFormat: "Y-m-d H:i", enableTime: true }
  }

  get #basicOptions() {
    return { ...this.#baseOptions, altFormat: this.dateFormatValue, dateFormat: "Y-m-d" }
  }

  get #baseOptions() {
    return { altInput: true, disable: this.disableValue, mode: this.modeValue }
  }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
css-zero-1.0.4 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-1.0.3 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-1.0.2 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-1.0.1 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-1.0.0 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.98 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.97 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.96 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.95 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.94 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js