import { WithDisposable } from '@blocksuite/global/lit'; import { cssVarV2 } from '@toeverything/theme/v2'; import { css, html, LitElement, unsafeCSS } from 'lit'; import { property } from 'lit/decorators.js'; import type { Property } from '../../../../core/view-manager/property.js'; import { formatNumber } from '../../../../property-presets/number/utils/formatter.js'; const IncreaseDecimalPlacesIcon = html` `; const DecreaseDecimalPlacesIcon = html` `; export class DatabaseNumberFormatBar extends WithDisposable(LitElement) { static override styles = css` .number-format-toolbar-container { padding: 4px 12px; display: flex; gap: 7px; flex-direction: column; } .number-format-decimal-places { display: flex; gap: 4px; align-items: center; justify-content: flex-start; } .number-format-toolbar-button { box-sizing: border-box; background-color: transparent; border: none; border-radius: 4px; color: var(--affine-icon-color); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 4px; position: relative; user-select: none; } .number-format-toolbar-button svg { width: 16px; height: 16px; } .number-formatting-sample { font-size: var(--affine-font-xs); color: var(--affine-icon-color); margin-left: auto; } .number-format-toolbar-button:hover { background-color: var(--affine-hover-color); } .divider { width: 100%; height: 1px; background-color: ${unsafeCSS(cssVarV2.layer.insideBorder.border)}; } `; private readonly _decrementDecimalPlaces = () => { this.column.dataUpdate(data => ({ decimal: Math.max(((data.decimal as number) ?? 0) - 1, 0), })); this.requestUpdate(); }; private readonly _incrementDecimalPlaces = () => { this.column.dataUpdate(data => ({ decimal: Math.min(((data.decimal as number) ?? 0) + 1, 8), })); this.requestUpdate(); }; override render() { return html`
( ${formatNumber( 1, 'number', (this.column.data$.value.decimal as number) ?? 0 )} )
`; } @property({ attribute: false }) accessor column!: Property; } declare global { interface HTMLElementTagNameMap { 'affine-database-number-format-bar': DatabaseNumberFormatBar; } }