All files / player-ui/src/components chart-details.ts

18.18% Statements 2/11
0% Branches 0/27
0% Functions 0/7
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98            48x         48x                                                                                                                                                                            
import { html, css, type CSSResultGroup, type PropertyDeclarations, type TemplateResult } from 'lit';
import { browseEntryCount, browseEntryTitle, type LibraryEntry } from '@be-music/player-skin-sdk';
import { BeMusicElement } from '../base.ts';
import { structureStyles } from '../styles/structure.ts';
 
export class BeMusicChartDetailsElement extends BeMusicElement {
  static override properties: PropertyDeclarations = {
    entry: { attribute: false },
    launching: { type: Boolean },
    readmeAvailable: { attribute: false },
  };
  static override styles: CSSResultGroup = [
    structureStyles,
    css`
      .panel {
        gap: var(--be-music-section-gap, 16px);
        padding: var(--be-music-panel-padding, 16px);
      }
      .heading {
        display: grid;
        gap: 4px;
      }
      h2 {
        font-size: 1.25rem;
        line-height: 1.25;
        overflow-wrap: anywhere;
      }
      .kind {
        text-transform: capitalize;
      }
      @container be-music-screen (max-width: 40rem) {
        .panel {
          gap: 8px;
        }
        .heading {
          gap: 2px;
        }
        .kind,
        .panel > p:last-of-type {
          display: none;
        }
        h2 {
          font-size: 18px;
        }
        .actions .btn {
          min-height: 40px;
        }
      }
    `,
  ];
  declare entry: LibraryEntry | undefined;
  declare launching: boolean;
  /**
   * Whether the chart has a README to show (`<be-music-readme-dialog>` shows it); `undefined` leaves the Readme button
   * enabled on every chart.
   */
  declare readmeAvailable: boolean | undefined;
  protected override render(): TemplateResult {
    const entry = this.entry;
    const playable = !!entry && entry.kind !== 'folder';
    return html`<aside class="panel" part="panel">
      <div class="heading">
        <p class="muted kind">${entry?.kind ?? 'Collection'}</p>
        <h2 part="title">${entry ? browseEntryTitle(entry) : 'No chart selected'}</h2>
        <p class="muted">${entry?.kind === 'chart' ? (entry.chart.artist ?? '') : ''}</p>
      </div>
      <p class="muted">
        ${entry?.kind === 'chart' ? `Level ${entry.chart.playLevel ?? '—'} · ${entry.chart.bpm ?? '—'} BPM` : entry ? (browseEntryCount(entry) ?? '') : ''}
      </p>
      <div class="actions" part="actions">
        <button
          class="btn"
          ?disabled=${this.launching || !playable}
          @click=${() => this.emit('play-request', { autoPlay: false })}
        >
          Play</button
        ><button
          class="btn"
          data-variant="outline"
          ?disabled=${this.launching || !playable}
          @click=${() => this.emit('play-request', { autoPlay: true })}
        >
          Auto play</button
        ><button
          class="btn"
          data-variant="outline"
          ?disabled=${this.launching || entry?.kind !== 'chart' || this.readmeAvailable === false}
          @click=${() => this.emit('readme-request', undefined)}
        >
          Readme</button
        ><slot name="actions"></slot>
      </div>
      <p class="muted">Arrow keys to browse · Enter to open · Escape to go back.</p>
      <slot></slot>
    </aside>`;
  }
}