Last active
February 25, 2021 10:54
-
-
Save NetanelBasal/e06e5ff651701f2f6671870d3c15fb8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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