mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-17 18:16:15 +08:00
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
import { ShadowlessElement } from '@blocksuite/block-std';
|
|
import { WithDisposable } from '@blocksuite/global/utils';
|
|
import { ToggleDownIcon, ToggleRightIcon } from '@blocksuite/icons/lit';
|
|
import { css, unsafeCSS } from 'lit';
|
|
import { property } from 'lit/decorators.js';
|
|
import { html } from 'lit-html';
|
|
|
|
export const TOGGLE_BUTTON_PARENT_CLASS = 'blocksuite-toggle-button-parent';
|
|
|
|
export class ToggleButton extends WithDisposable(ShadowlessElement) {
|
|
static override styles = css`
|
|
.toggle-icon {
|
|
display: flex;
|
|
align-items: start;
|
|
justify-content: start;
|
|
position: absolute;
|
|
width: 16px;
|
|
height: 16px;
|
|
top: calc((1em - 16px) / 2 + 5px);
|
|
left: 0;
|
|
transform: translateX(-100%);
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
opacity: 0;
|
|
transition: opacity 0.2s ease-in-out;
|
|
}
|
|
|
|
.toggle-icon:hover {
|
|
background: var(--affine-hover-color);
|
|
}
|
|
|
|
.toggle-icon[data-collapsed='true'] {
|
|
opacity: 1;
|
|
}
|
|
|
|
.${unsafeCSS(TOGGLE_BUTTON_PARENT_CLASS)}:hover .toggle-icon {
|
|
opacity: 1;
|
|
}
|
|
|
|
.with-drag-handle .toggle-icon {
|
|
opacity: 1;
|
|
}
|
|
.with-drag-handle .affine-block-children-container .toggle-icon {
|
|
opacity: 0;
|
|
}
|
|
`;
|
|
|
|
override render() {
|
|
const toggleDownTemplate = html`
|
|
<div
|
|
contenteditable="false"
|
|
class="toggle-icon"
|
|
@click=${() => this.updateCollapsed(!this.collapsed)}
|
|
>
|
|
${ToggleDownIcon({
|
|
width: '16px',
|
|
height: '16px',
|
|
style: 'color: #77757D',
|
|
})}
|
|
</div>
|
|
`;
|
|
|
|
const toggleRightTemplate = html`
|
|
<div
|
|
contenteditable="false"
|
|
class="toggle-icon"
|
|
data-collapsed=${this.collapsed}
|
|
@click=${() => this.updateCollapsed(!this.collapsed)}
|
|
>
|
|
${ToggleRightIcon({
|
|
width: '16px',
|
|
height: '16px',
|
|
style: 'color: #77757D',
|
|
})}
|
|
</div>
|
|
`;
|
|
|
|
return this.collapsed ? toggleRightTemplate : toggleDownTemplate;
|
|
}
|
|
|
|
@property({ attribute: false })
|
|
accessor collapsed!: boolean;
|
|
|
|
@property({ attribute: false })
|
|
accessor updateCollapsed!: (collapsed: boolean) => void;
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'blocksuite-toggle-button': ToggleButton;
|
|
}
|
|
}
|