Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 994ecc3

Browse filesBrowse files
committed
refactor(table-color): signal inputs, host bindings, cleanup, tests
1 parent 540d1a3 commit 994ecc3
Copy full SHA for 994ecc3

File tree

Expand file treeCollapse file tree

2 files changed

+16
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-10
lines changed
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { TestBed } from '@angular/core/testing';
12
import { TableColorDirective } from './table-color.directive';
23

34
describe('TableColorDirective', () => {
45
it('should create an instance', () => {
5-
const directive = new TableColorDirective();
6-
expect(directive).toBeTruthy();
6+
TestBed.runInInjectionContext(() => {
7+
const directive = new TableColorDirective();
8+
expect(directive).toBeTruthy();
9+
});
710
});
811
});
+11-8Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
import { Directive, HostBinding, Input } from '@angular/core';
1+
import { computed, Directive, input } from '@angular/core';
22
import { Colors } from '../coreui.types';
33

44
@Directive({
5-
selector: '[cTableColor]'
5+
selector: '[cTableColor]',
6+
exportAs: 'cTableColor',
7+
host: {
8+
'[class]': 'hostClasses()'
9+
}
610
})
711
export class TableColorDirective {
812
/**
913
* Use contextual color for tables, table rows or individual cells.
10-
* @type Colors
14+
* @return Colors
1115
*/
12-
@Input('cTableColor') color?: Colors;
16+
readonly color = input<Colors>(undefined, { alias: "cTableColor" });
1317

14-
@HostBinding('class')
15-
get hostClasses(): any {
18+
readonly hostClasses = computed((): Record<string,boolean> => {
1619
return {
17-
[`table-${this.color}`]: !!this.color
20+
[`table-${this.color()}`]: !!this.color()
1821
};
19-
}
22+
});
2023
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.