refactor(editor): group and expose parameters of createButtonPopper (#10999)

This commit is contained in:
L-Sun
2025-03-20 08:37:59 +00:00
parent 6ff19ca307
commit da63d51b7e
8 changed files with 76 additions and 81 deletions

View File

@@ -1,5 +1,8 @@
import { PANEL_BASE } from '@blocksuite/affine-shared/styles';
import { createButtonPopper } from '@blocksuite/affine-shared/utils';
import {
type ButtonPopperOptions,
createButtonPopper,
} from '@blocksuite/affine-shared/utils';
import { WithDisposable } from '@blocksuite/global/lit';
import {
css,
@@ -25,13 +28,12 @@ export class EditorMenuButton extends WithDisposable(LitElement) {
private _popper!: ReturnType<typeof createButtonPopper>;
override firstUpdated() {
this._popper = createButtonPopper(
this._trigger,
this._content,
({ display }) => {
this._popper = createButtonPopper({
reference: this._trigger,
popperElement: this._content,
stateUpdated: ({ display }) => {
const opened = display === 'show';
this._trigger.showTooltip = !opened;
this.dispatchEvent(
new CustomEvent('toggle', {
detail: opened,
@@ -41,12 +43,11 @@ export class EditorMenuButton extends WithDisposable(LitElement) {
})
);
},
{
mainAxis: 12,
ignoreShift: true,
offsetHeight: 6 * 4,
}
);
mainAxis: 12,
ignoreShift: true,
offsetHeight: 6 * 4,
...this.popperOptions,
});
this._disposables.addFromEvent(this, 'keydown', (e: KeyboardEvent) => {
e.stopPropagation();
if (e.key === 'Escape') {
@@ -93,6 +94,9 @@ export class EditorMenuButton extends WithDisposable(LitElement) {
@property({ attribute: false })
accessor contentPadding: string | undefined = undefined;
@property({ attribute: false })
accessor popperOptions: Partial<ButtonPopperOptions> = {};
}
export class EditorMenuContent extends LitElement {