Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active February 25, 2021 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/e06e5ff651701f2f6671870d3c15fb8f to your computer and use it in GitHub Desktop.
Save NetanelBasal/e06e5ff651701f2f6671870d3c15fb8f to your computer and use it in GitHub Desktop.
export type EmptyStatePredicate = (value: unknown) => boolean;
export function emptyStateNumber(value: unknown) {
return value === 0;
}
@Directive({
selector: '[emptyCellState]',
})
export class EmptyCellStateDirective implements OnInit {
@Input('emptyCellState') value: unknown;
@Input('emptyCellStatePredicate') predicate: EmptyStatePredicate;
constructor(
private tpl: TemplateRef<any>,
private resolver: ComponentFactoryResolver,
private vcr: ViewContainerRef
) {}
ngOnInit() {
const predicate = this.predicate ?? isNil;
if (predicate(this.value)) {
this.vcr.createComponent(
this.resolver.resolveComponentFactory(EmptyCellStateComponent)
);
} else {
this.vcr.createEmbeddedView(this.tpl);
}
}
}
@Component({
selector: 'empty-state-cell',
template: `<div class="empty-cell-state"></div>`,
})
export class EmptyCellStateComponent {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment