Files
AFFiNE-Mirror/blocksuite/blocks/src/root-block/edgeless/components/panel/shape-panel.ts
L-Sun 9d08f446cc refactor(editor): remove redundant edgeless icons (#10169)
Continue [BS-2240](https://linear.app/affine-design/issue/BS-2240/%E6%B8%85%E7%90%86%E9%87%8D%E5%A4%8D%E7%9A%84icon)

This PR removes `icons/edgeless.ts` and refactor with `@blocksuite/icons` for reducing redundant icons
2025-02-14 05:03:26 +00:00

72 lines
1.9 KiB
TypeScript

import { ShapeStyle } from '@blocksuite/affine-model';
import { Slot } from '@blocksuite/global/utils';
import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import type { ShapeTool } from '../../gfx-tool/shape-tool.js';
import { ShapeComponentConfig } from '../toolbar/shape/shape-menu-config.js';
export class EdgelessShapePanel extends LitElement {
static override styles = css`
:host {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
`;
slots = {
select: new Slot<ShapeTool['activatedOption']['shapeName']>(),
};
private _onSelect(value: ShapeTool['activatedOption']['shapeName']) {
this.selectedShape = value;
this.slots.select.emit(value);
}
override disconnectedCallback(): void {
this.slots.select.dispose();
super.disconnectedCallback();
}
override render() {
return repeat(
ShapeComponentConfig,
item => item.name,
({ name, generalIcon, scribbledIcon, tooltip, disabled }) =>
html`<edgeless-tool-icon-button
.disabled=${disabled}
.tooltip=${tooltip}
.active=${this.selectedShape === name}
.activeMode=${'background'}
.iconSize=${'20px'}
@click=${() => {
if (disabled) return;
this._onSelect(name);
}}
>
${this.shapeStyle === ShapeStyle.General
? generalIcon
: scribbledIcon}
</edgeless-tool-icon-button>`
);
}
@property({ attribute: false })
accessor selectedShape:
| ShapeTool['activatedOption']['shapeName']
| null
| undefined = undefined;
@property({ attribute: false })
accessor shapeStyle: ShapeStyle = ShapeStyle.Scribbled;
}
declare global {
interface HTMLElementTagNameMap {
'edgeless-shape-panel': EdgelessShapePanel;
}
}