import type { AffineTextAttributes } from '@blocksuite/affine-shared/types'; import { PropTypes, requiredProperties } from '@blocksuite/std'; import { LitElement } from 'lit'; import { property } from 'lit/decorators.js'; import { styleMap } from 'lit/directives/style-map.js'; import { html } from 'lit-html'; import { repeat } from 'lit-html/directives/repeat.js'; import { EditorChevronDown } from '../toolbar'; const colors = [ 'default', 'red', 'orange', 'yellow', 'green', 'teal', 'blue', 'purple', 'grey', ] as const; type HighlightType = 'color' | 'background'; // TODO(@fundon): these recent settings should be added to the dropdown menu // tests/blocksutie/e2e/format-bar.spec.ts#253 // // let latestHighlightColor: string | null = null; // let latestHighlightType: HighlightType = 'background'; @requiredProperties({ updateHighlight: PropTypes.instanceOf(Function), }) export class HighlightDropdownMenu extends LitElement { @property({ attribute: false }) accessor updateHighlight!: (styles: AffineTextAttributes) => void; private readonly _update = (value: string | null, type: HighlightType) => { // latestHighlightColor = value; // latestHighlightType = type; this.updateHighlight({ [`${type}`]: value }); }; override render() { const prefix = '--affine-text-highlight'; return html` ${EditorChevronDown} `} >
Color
${repeat(colors, color => { const isDefault = color === 'default'; const value = isDefault ? null : `var(${prefix}-foreground-${color})`; return html` this._update(value, 'color')} > ${isDefault ? `${color} color` : color} `; })}
Background
${repeat(colors, color => { const isDefault = color === 'default'; const value = isDefault ? null : `var(${prefix}-${color})`; return html` this._update(value, 'background')} > ${isDefault ? `${color} background` : color} `; })}
`; } } declare global { interface HTMLElementTagNameMap { 'affine-highlight-dropdown-menu': HighlightDropdownMenu; } }