Sha256: ddcacc7b55cd9779bcdd1eb9c72c562fa4bd58727b944f7d1af836ef3ffed58f

Contents?: true

Size: 1.23 KB

Versions: 16

Compression:

Stored size: 1.23 KB

Contents

import { Controller } from "@hotwired/stimulus"
import flatpickr from "https://cdn.skypack.dev/flatpickr@4.6.13"

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

16 entries across 16 versions & 1 rubygems

Version Path
css-zero-0.0.70 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.69 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.68 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.67 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.66 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.65 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.64 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.63 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.62 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.61 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.60 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.59 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.58 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.57 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.56 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js
css-zero-0.0.55 lib/generators/css_zero/add/templates/app/javascript/controllers/datepicker_controller.js