Skip to content

Commit 1fd4bdc

Browse files
committed
refactor(button): input signals, host bindings
1 parent abf6aa8 commit 1fd4bdc

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

projects/coreui-angular/src/lib/button/button.directive.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import {
2-
booleanAttribute,
3-
computed,
4-
Directive,
5-
HostBinding,
6-
input,
7-
InputSignal,
8-
InputSignalWithTransform
9-
} from '@angular/core';
1+
import { booleanAttribute, computed, Directive, input, InputSignal, InputSignalWithTransform } from '@angular/core';
102

113
import { ButtonType, Colors, Shapes } from '../coreui.types';
124

135
@Directive({
146
selector: '[cButton]',
157
exportAs: 'cButton',
168
standalone: true,
17-
host: { class: 'btn', '[class]': 'hostClasses()', '[attr.type]': 'type()' }
9+
host: {
10+
class: 'btn',
11+
'[class]': 'hostClasses()',
12+
'[attr.aria-disabled]': 'ariaDisabled()',
13+
'[attr.aria-pressed]': 'isActive()',
14+
'[attr.disabled]': 'attrDisabled()',
15+
'[attr.tabindex]': 'tabIndex()',
16+
'[attr.type]': 'type()'
17+
}
1818
})
1919
export class ButtonDirective {
2020
/**
@@ -69,28 +69,26 @@ export class ButtonDirective {
6969
[`btn-${this.variant()}-${this.color()}`]: !!this.variant() && !!this.color(),
7070
[`btn-${this.size()}`]: !!this.size(),
7171
[`${this.shape()}`]: !!this.shape(),
72-
disabled: this.disabled(),
73-
active: this.active()
72+
active: this.active(),
73+
disabled: this._disabled()
7474
} as Record<string, boolean>;
7575
});
7676

77-
@HostBinding('attr.aria-disabled')
78-
get ariaDisabled() {
79-
return this.disabled() || null;
80-
}
77+
_disabled = computed(() => this.disabled());
8178

82-
@HostBinding('attr.aria-pressed')
83-
get isActive(): boolean | null {
84-
return <boolean>this.active() || null;
85-
}
79+
ariaDisabled = computed(() => {
80+
return this._disabled() ? true : null;
81+
});
8682

87-
@HostBinding('attr.disabled')
88-
get attrDisabled() {
89-
return this.disabled() ? '' : null;
90-
}
83+
attrDisabled = computed(() => {
84+
return this._disabled() ? '' : null;
85+
});
9186

92-
@HostBinding('attr.tabindex')
93-
get tabIndex(): string | null {
94-
return this.disabled() ? '-1' : null;
95-
}
87+
tabIndex = computed(() => {
88+
return this._disabled() ? '-1' : null;
89+
});
90+
91+
isActive = computed(() => {
92+
return <boolean>this.active() || null;
93+
});
9694
}

0 commit comments

Comments
 (0)