import { CSSResult, html, TemplateResult, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import '../lit-icon/lit-icon';
import '../lit-tooltip/lit-tooltip';
import '../lit-popover/lit-popover';
import { getTranslations, ToolbarTranslations } from '../i18n/i18n';
// @ts-ignore
import style from './lit-pdf-toolbar.scss';
@customElement('lit-pdf-toolbar')
export class LitPdfToolbar extends LitElement {
@property({ type: Boolean }) public isPrintDisabled: boolean;
@property({ type: Boolean }) public isDownloadDisabled: boolean;
@property({ type: Boolean }) public isSidebarOpen: boolean;
@property({ type: Boolean }) public isFullscreen: boolean;
/** Current zoom level as a percentage (e.g. `100` for 100%). */
@property({ type: Number }) public zoomPercent = 100;
/** Locale to translate the toolbar into (defaults to the browser's language). */
@property({ type: String }) public locale: string;
/** Overrides for individual translation strings. */
@property({ type: Object }) public translations: Partial = {};
public static get styles(): CSSResult[] {
return [style];
}
private get _t(): ToolbarTranslations {
return getTranslations(this.locale, { toolbar: this.translations }).toolbar;
}
public connectedCallback(): void {
super.connectedCallback();
this.setAttribute('role', 'toolbar');
this.setAttribute('aria-label', this._t.toolbarLabel);
}
public render(): TemplateResult {
const t = this._t;
return html`
`;
}
private _renderFullscreenIcon(): TemplateResult {
return this.isFullscreen
? html`
`
: html`
`;
}
protected updated(changedProperties: Map): void {
if (changedProperties.has('locale') || changedProperties.has('translations')) {
this.setAttribute('aria-label', this._t.toolbarLabel);
}
}
protected firstUpdated(): void {
this.dispatchEvent(new CustomEvent('toolbarConnected', { bubbles: true }));
}
private _handleToggleSidebar(): void {
this.dispatchEvent(new CustomEvent('toggleSidebar', { bubbles: true }));
}
private _handleZoomIn(): void {
this.dispatchEvent(new CustomEvent('zoomIn', { bubbles: true }));
}
private _handleZoomOut(): void {
this.dispatchEvent(new CustomEvent('zoomOut', { bubbles: true }));
}
private _handleRotateCw(): void {
this.dispatchEvent(new CustomEvent('rotateCw', { bubbles: true }));
}
private _handleRotateCcw(): void {
this.dispatchEvent(new CustomEvent('rotateCcw', { bubbles: true }));
}
private _handleToggleSearch(): void {
this.dispatchEvent(new CustomEvent('toggleSearch', { bubbles: true }));
}
private _handleToggleFullscreen(): void {
this.dispatchEvent(new CustomEvent('toggleFullscreen', { bubbles: true }));
}
private _handleZoomPercentChange(e: Event): void {
const value = Number((e.target).value);
if (!value) {
return;
}
this.dispatchEvent(new CustomEvent('zoomChange', { bubbles: true, detail: { value } }));
}
private _handleZoomPercentKeydown(e: KeyboardEvent): void {
if (e.key === 'Enter') {
(e.target).blur();
}
}
private _handlePrint(): void {
this.dispatchEvent(new CustomEvent('print', { bubbles: true }));
}
private _handleDownload(): void {
this.dispatchEvent(new CustomEvent('download', { bubbles: true }));
}
}