import { AfterViewInit, ChangeDetectionStrategy, Component, ContentChildren, Input, QueryList } from '@angular/core';
import { ButtonGroupComponent, TabButtonComponent } from '@deepkit/desktop-ui';
import { CodeHighlightComponent } from '@deepkit/ui-library';
@Component({
selector: 'doc-code-frame',
template: `
Preview
@if (hasType('html')) {
HTML
}
@if (hasType('typescript')) {
TS
}
@if (hasType('scss')) {
SCSS
}
@if (show === 'html') {
}
@if (show === 'typescript') {
}
@if (show === 'scss') {
}
@if (show === '') {
}
`,
styles: [
`
:host {
display: block;
position: relative;
}
dui-theme-switcher {
position: absolute;
right: 5px;
top: 0px;
}
`,
],
changeDetection: ChangeDetectionStrategy.Eager,
imports: [ButtonGroupComponent, TabButtonComponent],
})
export class CodeFrameComponent implements AfterViewInit {
@ContentChildren(CodeHighlightComponent) highlighter!: QueryList;
@Input() height = 300;
show: '' | 'html' | 'typescript' | 'scss' = '';
showPage(show: '' | 'html' | 'typescript' | 'scss') {
this.show = show;
}
public hasType(name: string): boolean {
return Boolean(this.getHighlightForType(name));
}
ngAfterViewInit(): void {}
public getHighlightForType(name: string): CodeHighlightComponent | undefined {
for (const h of this.highlighter.toArray()) {
if (h.lang() === name || (name === 'typescript' && !h.lang())) {
return h;
}
}
return;
}
}