mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
f3ca17fcb3
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new slider component for line width selection, providing a more interactive and streamlined UI. - Added support for using the slider component across relevant panels. - **Improvements** - Simplified the line width selection panel for easier use and improved maintainability. - Enhanced event handling to prevent dropdowns from closing when interacting with the panel. - **Bug Fixes** - Improved event propagation control within the line styles panel. - **Chores** - Updated package exports to include the new slider component. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { BRUSH_LINE_WIDTHS, LineWidth } from '@blocksuite/affine-model';
|
|
import { WithDisposable } from '@blocksuite/global/lit';
|
|
import { html, LitElement } from 'lit';
|
|
import { property } from 'lit/decorators.js';
|
|
|
|
import type { SliderSelectEvent } from '../slider';
|
|
|
|
export class EdgelessLineWidthPanel extends WithDisposable(LitElement) {
|
|
private _onSelect(lineWidth: number) {
|
|
this.dispatchEvent(
|
|
new CustomEvent('select', {
|
|
detail: lineWidth,
|
|
bubbles: true,
|
|
composed: true,
|
|
cancelable: true,
|
|
})
|
|
);
|
|
}
|
|
|
|
override render() {
|
|
return html`<affine-slider
|
|
?disabled=${this.disabled}
|
|
.range=${{ points: this.lineWidths }}
|
|
.value=${this.selectedSize}
|
|
.tooltip=${this.hasTooltip ? 'Thickness' : undefined}
|
|
@select=${(e: SliderSelectEvent) => {
|
|
e.stopPropagation();
|
|
this._onSelect(e.detail.value);
|
|
}}
|
|
></affine-slider>`;
|
|
}
|
|
|
|
@property({ attribute: false })
|
|
accessor disabled = false;
|
|
|
|
@property({ attribute: false })
|
|
accessor hasTooltip = true;
|
|
|
|
@property({ attribute: false })
|
|
accessor lineWidths: number[] = BRUSH_LINE_WIDTHS;
|
|
|
|
@property({ attribute: false })
|
|
accessor selectedSize: number = LineWidth.Two;
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'edgeless-line-width-panel': EdgelessLineWidthPanel;
|
|
}
|
|
}
|