Skip to content

Commit f8c3703

Browse files
committed
refactor(spinner): input signals, host bindings, ng-content default fallback content
1 parent da62aec commit f8c3703

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<span class="visually-hidden">{{label}}</span>
1+
<ng-content>
2+
<span class="visually-hidden">{{ label() }}</span>
3+
</ng-content>
Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,55 @@
1-
import { Component, HostBinding, Input } from '@angular/core';
1+
import { Component, computed, input } from '@angular/core';
22

33
import { Colors } from '../coreui.types';
44

55
@Component({
66
selector: 'c-spinner',
77
templateUrl: './spinner.component.html',
8-
standalone: true
8+
standalone: true,
9+
host: {
10+
'[attr.role]': 'role()',
11+
'[class]': 'hostClasses()'
12+
}
913
})
1014
export class SpinnerComponent {
1115
/**
1216
* Sets the color context of the component to one of CoreUI’s themed colors.
1317
* @type Colors
1418
*/
15-
@Input() color?: Colors;
19+
readonly color = input<Colors>();
1620

1721
/**
1822
* Label for accessibility.
1923
* @type string
2024
* @default 'Loading...'
2125
*/
22-
@Input() label: string = "Loading...";
26+
readonly label = input('Loading...');
2327

2428
/**
2529
* Size the component small.
2630
* @type string
2731
* @values 'sm'
2832
*/
29-
@Input() size?: 'sm';
33+
readonly size = input<'sm'>();
3034

3135
/**
3236
* Set the button variant to an outlined button or a ghost button.
3337
* @values 'border' | 'grow'
3438
* @default 'border'
3539
*/
36-
@Input() variant?: 'border' | 'grow' = 'border';
37-
38-
@Input()
39-
@HostBinding('attr.role') role = 'status';
40+
readonly variant = input<'border' | 'grow'>('border');
41+
/**
42+
* Default role attr for Spinner. [docs]
43+
* @type string
44+
* @default 'status'
45+
*/
46+
readonly role = input('status');
4047

41-
@HostBinding('class')
42-
get hostClasses(): any {
48+
readonly hostClasses = computed(() => {
4349
return {
44-
[`spinner-${this.variant}`]: true,
45-
[`text-${this.color}`]: !!this.color,
46-
[`spinner-${this.variant}-${this.size}`]: !!this.size
50+
[`spinner-${this.variant()}`]: true,
51+
[`text-${this.color()}`]: !!this.color(),
52+
[`spinner-${this.variant()}-${this.size()}`]: !!this.size()
4753
};
48-
}
54+
});
4955
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy