Skip to content

Commit d3b787b

Browse files
committed
refactor: size and sizing prop, hostClasses cleanup
1 parent a8a0461 commit d3b787b

File tree

17 files changed

+79
-47
lines changed

17 files changed

+79
-47
lines changed

projects/coreui-angular/src/lib/alert/alert.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export class AlertComponent {
143143
readonly hostClasses = computed(() => {
144144
const color = this.color();
145145
const variant = this.variant();
146+
146147
return {
147148
alert: true,
148149
'alert-dismissible': this.dismissible,

projects/coreui-angular/src/lib/avatar/avatar.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class AvatarComponent {
3434
* Size the component small, large, or extra large.
3535
* @default 'md'
3636
*/
37-
readonly size: InputSignal<Omit<Sizes, 'xxl'>> = input<Omit<Sizes, 'xxl'>>('');
37+
readonly size = input<Omit<Sizes, 'xxl'>>('');
3838

3939
/**
4040
* The alt attribute for the img element alternate text.
@@ -69,11 +69,15 @@ export class AvatarComponent {
6969
});
7070

7171
readonly hostClasses = computed(() => {
72+
const size = this.size();
73+
const color = this.color();
74+
const shape = this.shape();
75+
7276
return {
7377
avatar: true,
74-
[`avatar-${this.size()}`]: !!this.size(),
75-
[`bg-${this.color()}`]: !!this.color(),
76-
[`${this.shape()}`]: !!this.shape()
78+
[`avatar-${size}`]: !!size,
79+
[`bg-${color}`]: !!color,
80+
[`${shape}`]: !!shape
7781
} as Record<string, boolean>;
7882
});
7983
}

projects/coreui-angular/src/lib/badge/badge.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class BadgeComponent {
3535
/**
3636
* Size the component small.
3737
*/
38-
readonly size: InputSignal<'sm' | undefined> = input();
38+
readonly size = input<'sm'>();
3939

4040
/**
4141
* Sets the text color of the component to one of CoreUI’s themed colors.
@@ -63,12 +63,16 @@ export class BadgeComponent {
6363
'start-0': position?.includes('start')
6464
};
6565

66+
const color = this.color();
67+
const size = this.size();
68+
const shape = this.shape();
69+
6670
return Object.assign(
6771
{
6872
badge: true,
69-
[`bg-${this.color()}`]: !!this.color(),
70-
[`badge-${this.size()}`]: !!this.size(),
71-
[`${this.shape()}`]: !!this.shape()
73+
[`bg-${color}`]: !!color,
74+
[`badge-${size}`]: !!size,
75+
[`${shape}`]: !!shape
7276
},
7377
!!position ? positionClasses : {}
7478
) as Record<string, boolean>;
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { booleanAttribute, Component, computed, input, InputSignal, InputSignalWithTransform } from '@angular/core';
1+
import { booleanAttribute, Component, computed, input, InputSignalWithTransform } from '@angular/core';
22

33
@Component({
44
selector: 'c-button-group',
@@ -8,9 +8,9 @@ import { booleanAttribute, Component, computed, input, InputSignal, InputSignalW
88
export class ButtonGroupComponent {
99
/**
1010
* Size the component small or large.
11-
* @type { 'sm' | 'lg' }
11+
* @return { 'sm' | 'lg' }
1212
*/
13-
readonly size: InputSignal<'sm' | 'lg' | undefined> = input();
13+
readonly size = input<'' | 'sm' | 'lg' | string>();
1414

1515
/**
1616
* Create a set of buttons that appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.
@@ -20,16 +20,18 @@ export class ButtonGroupComponent {
2020

2121
/**
2222
* Default role attr for ButtonGroup. [docs]
23-
* @type InputSignal<string>
23+
* @return string
2424
* @default 'group'
2525
*/
26-
readonly role: InputSignal<string> = input('group');
26+
readonly role = input<string>('group');
2727

2828
readonly hostClasses = computed(() => {
29+
const size = this.size();
30+
const vertical = this.vertical();
2931
return {
30-
'btn-group': !this.vertical(),
31-
'btn-group-vertical': this.vertical(),
32-
[`btn-group-${this.size()}`]: !!this.size()
32+
'btn-group': !vertical,
33+
'btn-group-vertical': vertical,
34+
[`btn-group-${size}`]: !!size
3335
} as Record<string, boolean>;
3436
});
3537
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ export class ButtonCloseDirective extends ButtonDirective {
2424
readonly white: InputSignalWithTransform<boolean, unknown> = input(false, { transform: booleanAttribute });
2525

2626
override readonly hostClasses = computed(() => {
27+
const size = this.size();
28+
2729
return {
2830
btn: true,
2931
'btn-close': true,
3032
'btn-close-white': this.white(),
31-
[`btn-${this.size()}`]: !!this.size(),
33+
[`btn-${size}`]: !!size,
3234
active: this.active(),
3335
disabled: this._disabled()
3436
} as Record<string, boolean>;

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export class ButtonDirective {
4747

4848
/**
4949
* Select the shape of the component.
50-
* @type InputSignal<Shapes>
50+
* @return Shapes
5151
*/
52-
readonly shape: InputSignal<Shapes | undefined> = input<Shapes>();
52+
readonly shape = input<Shapes>();
5353

5454
/**
5555
* Size the component small or large.
56-
* @type InputSignal<'sm' | 'lg' | ''>
56+
* @return sm' | 'lg' | ''
5757
*/
58-
readonly size: InputSignal<'' | 'sm' | 'lg'> = input<'' | 'sm' | 'lg'>('');
58+
readonly size = input<'' | 'sm' | 'lg' | string>('');
5959

6060
/**
6161
* The tabindex attribute specifies the tab order of an element (when the "tab" button is used for navigating).
@@ -77,13 +77,18 @@ export class ButtonDirective {
7777
readonly variant: InputSignal<'ghost' | 'outline' | undefined> = input<'ghost' | 'outline'>();
7878

7979
readonly hostClasses = computed(() => {
80+
const color = this.color();
81+
const variant = this.variant();
82+
const size = this.size();
83+
const shape = this.shape();
84+
8085
return {
8186
btn: true,
82-
[`btn-${this.color()}`]: !!this.color() && !this.variant(),
83-
[`btn-${this.variant()}`]: !!this.variant() && !this.color(),
84-
[`btn-${this.variant()}-${this.color()}`]: !!this.variant() && !!this.color(),
85-
[`btn-${this.size()}`]: !!this.size(),
86-
[`${this.shape()}`]: !!this.shape(),
87+
[`btn-${color}`]: !!color && !variant,
88+
[`btn-${variant}`]: !!variant && !color,
89+
[`btn-${variant}-${color}`]: !!variant && !!color,
90+
[`btn-${size}`]: !!size,
91+
[`${shape}`]: !!shape,
8792
active: this.active(),
8893
disabled: this._disabled()
8994
} as Record<string, boolean>;

projects/coreui-angular/src/lib/callout/callout.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class CalloutComponent {
1616

1717
readonly hostClasses = computed(() => {
1818
const color = this.color();
19+
1920
return {
2021
callout: true,
2122
[`callout-${color}`]: !!color

projects/coreui-angular/src/lib/card/card.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class CardComponent {
3535

3636
readonly hostClasses = computed(() => {
3737
const color = this.color();
38+
3839
return {
3940
card: true,
4041
[`bg-${color}`]: !!color

projects/coreui-angular/src/lib/dropdown/dropdown-menu/dropdown-menu.directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class DropdownMenuDirective implements OnInit, AfterContentInit {
5858
readonly hostClasses = computed(() => {
5959
const alignment = this.alignment();
6060
const visible = this.visible();
61+
6162
return {
6263
'dropdown-menu': true,
6364
[`dropdown-menu-${alignment}`]: !!alignment,

projects/coreui-angular/src/lib/footer/footer.component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ export class FooterComponent {
2020

2121
/**
2222
* Default role for footer. [docs]
23-
* @type string
23+
* @return string
2424
* @default 'contentinfo'
2525
*/
26-
readonly role: InputSignal<string> = input('contentinfo');
26+
readonly role = input<string>('contentinfo');
2727

2828
readonly hostClasses = computed(() => {
29+
const position = this.position();
2930
return {
3031
footer: true,
31-
[`footer-${this.position()}`]: !!this.position()
32+
[`footer-${position}`]: !!position
3233
} as Record<string, boolean>;
3334
});
3435
}

0 commit comments

Comments
 (0)