|
1 | 1 | import {arrow, computePosition, flip, shift, size, autoUpdate, offset, VirtualElement, ReferenceElement, ComputePositionConfig} from '@floating-ui/dom';
|
2 |
| -import {Component, $, ComponentEvents, JSX, evalValue, toCssSize} from '@zui/core'; |
| 2 | +import {Component, $, ComponentEvents, JSX, evalValue, toCssSize, nextGid} from '@zui/core'; |
3 | 3 | import {PopoverEvents, PopoverOptions, PopoverPanelOptions, PopoverSide} from '../types';
|
4 | 4 | import {PopoverPanel} from './popover-panel';
|
5 | 5 | import {isElementDetached} from '@zui/core/src/dom';
|
@@ -309,6 +309,9 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon
|
309 | 309 | const {namespace} = this;
|
310 | 310 | $(this._triggerElement as HTMLElement).off(namespace);
|
311 | 311 | }
|
| 312 | + if (this.$element.hasClass('popover-tmp')) { |
| 313 | + this.$element.remove(); |
| 314 | + } |
312 | 315 | this._resetTimer();
|
313 | 316 | this._destoryTarget();
|
314 | 317 | this._clearDelayHide();
|
@@ -589,10 +592,25 @@ export class Popover<O extends PopoverOptions = PopoverOptions, E extends Compon
|
589 | 592 | };
|
590 | 593 | };
|
591 | 594 |
|
| 595 | + static create<O extends PopoverOptions, E extends ComponentEvents, T extends typeof Popover<O, E>>(this: T, options?: O & {event?: Event}, element?: HTMLElement): InstanceType<T> { |
| 596 | + const {element: elementSetting, container = 'body', id = `popover_${nextGid()}`} = options || {}; |
| 597 | + element = element || (elementSetting instanceof HTMLElement ? elementSetting : undefined); |
| 598 | + if (!element) { |
| 599 | + element = $(`<div id="${id}" class="popover-tmp"></div>`).appendTo($(container))[0]!; |
| 600 | + } |
| 601 | + return (this as typeof Popover).ensure(element as HTMLElement, {id, destroyOnHide: true, ...options}) as InstanceType<T>; |
| 602 | + } |
| 603 | + |
592 | 604 | static show<O extends PopoverOptions, E extends ComponentEvents, T extends typeof Popover<O, E>>(this: T, options: O & {event?: Event}): InstanceType<T> {
|
593 | 605 | const {element: elementSetting, event, ...otherOptions} = options;
|
594 | 606 | const element = elementSetting || (event?.currentTarget as HTMLElement);
|
595 |
| - return (this as typeof Popover).ensure(element instanceof HTMLElement ? element : document.body, {element, show: true, destroyOnHide: true, triggerEvent: event, ...otherOptions}) as InstanceType<T>; |
| 607 | + return this.create({ |
| 608 | + element, |
| 609 | + show: true, |
| 610 | + destroyOnHide: true, |
| 611 | + triggerEvent: event, |
| 612 | + ...otherOptions, |
| 613 | + } as O & {event?: Event}, element instanceof HTMLElement ? element : document.body); |
596 | 614 | }
|
597 | 615 | }
|
598 | 616 |
|
|
0 commit comments