Skip to content

Commit 4337554

Browse files
committed
refactor(align): signal inputs, host bindings, cleanup, tests
1 parent 5592fff commit 4337554

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { TestBed } from '@angular/core/testing';
12
import { AlignDirective } from './align.directive';
23

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

44
@Directive({
5-
selector: '[cAlign]'
5+
selector: '[cAlign]',
6+
exportAs: 'cAlign',
7+
host: { '[class]': 'hostClasses()' }
68
})
79
export class AlignDirective {
810
/**
911
* Set vertical alignment of inline, inline-block, inline-table, and table cell elements
10-
* @type Alignment
12+
* @return Alignment
1113
*/
12-
@Input('cAlign') align?: Alignment;
14+
readonly align = input<Alignment>(undefined, { alias: 'cAlign' });
1315

14-
@HostBinding('class')
15-
get hostClasses(): any {
16+
readonly hostClasses = computed(() => {
17+
const align = this.align();
1618
return {
17-
[`align-${this.align}`]: !!this.align
19+
[`align-${align}`]: !!align
1820
};
19-
}
21+
});
2022
}

0 commit comments

Comments
 (0)