diff --git a/package-lock.json b/package-lock.json index 50f1b4f77..d6d2cc101 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "funding": { "url": "https://ko-fi.com/eonasdan" }, - "peerDependencies": { + "optionalDependencies": { "@popperjs/core": "^2.10.1" } }, diff --git a/package.json b/package.json index 4da104138..59695801d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "Jonathan Peterson" }, "name": "@eonasdan/tempus-dominus", - "version": "6.0.1", + "version": "6.1.1", "style": "dist/css/tempus-dominus.css", "sass": "scss/tempus-dominus.scss", "main": "dist/js/tempus-dominus.js", @@ -33,7 +33,7 @@ "bugs": { "url": "https://github.com/eonasdan/tempus-dominus/issues" }, - "peerDependencies": { + "optionalDependencies": { "@popperjs/core": "^2.10.1" }, "description": "A robust and powerful date/time picker component. For usage, installation and demos see Project Site on GitHub", diff --git a/src/docs/partials/plugins/floating-ui.html b/src/docs/partials/plugins/floating-ui.html new file mode 100644 index 000000000..41d5e1edd --- /dev/null +++ b/src/docs/partials/plugins/floating-ui.html @@ -0,0 +1,44 @@ + +
+

Floating UI

+

+ By default, @popperJS/core is required for the popper to work correctly. Alternatively, we can remove popper and use + FloatingUI by creating a plugin that handles the popup creation. +

+
+ +
+
+
+import { computePosition } from '@floating-ui/dom';
+
+const datetimepicker1 = new tempusDominus.TempusDominus(document.getElementById('datetimepicker1'));
+
+datetimepicker1.display.createPopup = computePosition(element, widget, options).then(({ x, y }) => {
+    Object.assign(widget.style, {
+      left: `${x}px`,
+      top: `${y}px`,
+      position: 'absolute',
+    });
+  });
+
+    
+
+ + + + +
+ + + Plugins - FloatingUI + 09/13/2022 + 09/13/2022 + How to use FloatingUI plugin with Tempus Dominus. + + datepicker, javascript, open source, tempus dominus, eonasdan + diff --git a/src/js/display/index.ts b/src/js/display/index.ts index 2ff871101..75a83479e 100644 --- a/src/js/display/index.ts +++ b/src/js/display/index.ts @@ -7,7 +7,6 @@ import HourDisplay from './time/hour-display'; import MinuteDisplay from './time/minute-display'; import SecondDisplay from './time/second-display'; import { DateTime, Unit } from '../datetime'; -import { createPopper } from '@popperjs/core'; import Namespace from '../utilities/namespace'; import { HideEvent } from '../utilities/event-types'; import Collapse from './collapse'; @@ -231,19 +230,14 @@ export default class Display { // If needed to change the parent container const container = this.optionsStore.options?.container || document.body; container.appendChild(this.widget); - - this._popperInstance = createPopper( - this.optionsStore.element, - this.widget, - { - modifiers: [{ name: 'eventListeners', enabled: true }], - //#2400 - placement: - document.documentElement.dir === 'rtl' - ? 'bottom-end' - : 'bottom-start', - } - ); + this.createPopup(this.optionsStore.element, this.widget, { + modifiers: [{ name: 'eventListeners', enabled: true }], + //#2400 + placement: + document.documentElement.dir === 'rtl' + ? 'bottom-end' + : 'bottom-start', + }); } else { this.optionsStore.element.appendChild(this.widget); } @@ -274,13 +268,22 @@ export default class Display { this.widget.classList.add(Namespace.css.show); if (!this.optionsStore.options.display.inline) { - this._popperInstance.update(); + this.updatePopup(); document.addEventListener('click', this._documentClickEvent); } this._eventEmitters.triggerEvent.emit({ type: Namespace.events.show }); this._isVisible = true; } + async createPopup(element: HTMLElement, widget: HTMLElement, options: any): Promise { + const { createPopper } = await import('@popperjs/core'); + this._popperInstance = createPopper(element, widget, options); + } + + updatePopup(): void { + this._popperInstance?.update(); + } + /** * Changes the calendar view mode. E.g. month <-> year * @param direction -/+ number to move currentViewMode diff --git a/tsconfig.json b/tsconfig.json index 7d2c176de..64c3b42a9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "module": "ES6", + "module": "es2020", "target": "ES6", "lib": ["es6", "dom", "es2016", "es2017", "dom.iterable", "es2019", "ES2021.String"], "moduleResolution": "node",