import { html, svg, TemplateResult } from '@nutmeg/seed';
import { repeat } from 'lit-html/directives/repeat';
import { NodePackage } from './node-package';
import { InstallCommand, InstallSource, Pkg } from './pkg';
export class SuccessView {
constructor(private component: NodePackage, private pkg: Pkg, private selectedInstallCommand: InstallSource) {}
public get name(): string {
return this.pkg.name;
}
public get content(): TemplateResult {
return html`
${this.pkg.description}
${this.keywords}
${this.install}
${this.footer}
Copied to clipboard
`;
}
private selectInstallCommand(event: MouseEvent, command: InstallCommand): void {
event.preventDefault();
this.component.selectedTab = command.id;
this.component.render();
}
private copyInstallCommand(event: MouseEvent): void {
event.preventDefault();
(this.component.$('.command:not(.hidden)') as HTMLInputElement).select();
document.execCommand('copy');
this.component.$('#toast').classList.add('copied');
setTimeout(() => {
this.component.$('#toast').classList.remove('copied');
}, 2750);
}
private keyword(keyword: string): TemplateResult {
return html`
#${keyword}
`;
}
private get keywords(): TemplateResult {
return html`
${repeat(this.pkg.keywords, keyword => keyword, (keyword, _index) => this.keyword(keyword))}
`;
}
private get types(): TemplateResult {
return html`
Includes types
`;
}
private installTab(command: InstallCommand): TemplateResult {
const classes = `item tab ${this.selectedInstallCommand === command.id ? 'selected' : ''}`;
return html`
this.selectInstallCommand(event, command)}>
`;
}
private installCommand(command: InstallCommand): TemplateResult {
return html`
`;
}
private get install(): TemplateResult {
return html`
${repeat(this.pkg.installCommands(this.component.global), command => command.id, (command, _index) => this.installTab(command))}
${repeat(this.pkg.installCommands(this.component.global), command => command.id, (command, _index) => this.installCommand(command))}
`;
}
private get footer(): TemplateResult {
return html`
`;
}
private get copy(): TemplateResult {
return svg`
`;
}
}