Skip to content

Commit fdefdb4

Browse files
authored
Merge pull request #636 from dxc-technology/marcialfps-card-types
Types for Card component
2 parents a2ac2c6 + 372641a commit fdefdb4

File tree

2 files changed

+99
-44
lines changed

2 files changed

+99
-44
lines changed

projects/dxc-ngx-cdk-site/src/app/components/examples/card/properties/card-table-properties/card-table-properties.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
<td>linkHref: string</td>
5252
<td></td>
5353
<td>
54-
If defined, the tag will be displayed as an anchor, using this prop as
54+
If defined, the card will be displayed as an anchor, using this prop as
5555
"href". Component will show some visual feedback on hover.
5656
</td>
5757
</tr>
5858
<tr>
5959
<td>onClick: EventEmitter</td>
6060
<td></td>
6161
<td>
62-
This function will be called when the user clicks the tag. Component will
62+
This event will emit when the user clicks the card. Component will
6363
show some visual feedback on hover.
6464
</td>
6565
</tr>

projects/dxc-ngx-cdk/src/lib/dxc-card/dxc-card.component.ts

Lines changed: 97 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
EventEmitter,
1010
SimpleChanges,
1111
ChangeDetectorRef,
12-
Inject,
13-
Optional
12+
Optional,
1413
} from "@angular/core";
1514
import { css } from "emotion";
1615
import { BehaviorSubject } from "rxjs";
@@ -21,19 +20,21 @@ import {
2120
} from "@angular/cdk/coercion";
2221
import { BackgroundProviderService } from "../background-provider/service/background-provider.service";
2322

24-
export interface DxcCardInputs{
25-
imageSrc: string;
26-
imagePosition: string;
27-
imagePadding: string | Object;
28-
imageCover: boolean;
29-
imageBgColor: string;
30-
margin: string | Object,
31-
outlined: boolean;
32-
contentPadding: string | Object,
33-
linkHref: string | Object;
34-
tabIndexValue: number;
35-
}
36-
23+
type Space =
24+
| "xxsmall"
25+
| "xsmall"
26+
| "small"
27+
| "medium"
28+
| "large"
29+
| "xlarge"
30+
| "xxlarge";
31+
32+
type Size = {
33+
top?: Space;
34+
bottom?: Space;
35+
left?: Space;
36+
right?: Space;
37+
};
3738

3839
@Component({
3940
selector: "dxc-card",
@@ -42,9 +43,50 @@ export interface DxcCardInputs{
4243
providers: [CssUtils],
4344
})
4445
export class DxcCardComponent implements OnInit {
46+
/**
47+
* URL of the image that will be placed in the card component.
48+
*/
4549
@Input() imageSrc: string;
46-
@Input() imagePosition: string;
47-
@Input() imagePadding: any;
50+
51+
/**
52+
* Color of the image background.
53+
*/
54+
@Input() imageBgColor: string = "black";
55+
56+
/**
57+
* Size of the padding to be applied to the image section of the component.
58+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties
59+
* in order to specify different padding sizes.
60+
*/
61+
@Input() imagePadding: Space | Size;
62+
63+
/**
64+
* Whether the image should appear in relation to the content.
65+
*/
66+
@Input() imagePosition: "after" | "before" = "before";
67+
68+
/**
69+
* Size of the padding to be applied to the content section of the component.
70+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties
71+
* in order to specify different padding sizes.
72+
*/
73+
@Input() contentPadding: Space | Size;
74+
75+
/**
76+
* If defined, the card will be displayed as an anchor, using this prop as "href".
77+
* Component will show some visual feedback on hover.
78+
*/
79+
@Input() linkHref: string;
80+
81+
/**
82+
* This event will emit when the user clicks the card. Component will show some
83+
* visual feedback on hover.
84+
*/
85+
@Output() onClick: EventEmitter<void> = new EventEmitter<void>();
86+
87+
/**
88+
* Whether the image must cover the whole image area of the card.
89+
*/
4890
@Input()
4991
get imageCover(): boolean {
5092
return this._imageCover;
@@ -54,40 +96,47 @@ export class DxcCardComponent implements OnInit {
5496
}
5597
private _imageCover = false;
5698

99+
/**
100+
* Size of the margin to be applied to the component. You can pass an object
101+
* with 'top', 'bottom', 'left' and 'right' properties in order to specify
102+
* different margin sizes.
103+
*/
104+
@Input() margin: Space | Size;
57105

58-
@Input() outlined: boolean;
59-
@Input() imageBgColor: string;
60-
@Input() margin: any;
61-
@Input() contentPadding: any;
62-
@Input() linkHref: string;
106+
/**
107+
* Value of the tabindex given when there is an href.
108+
*/
63109
@Input()
64110
get tabIndexValue(): number {
65111
return this._tabIndexValue;
66112
}
67113
set tabIndexValue(value: number) {
68114
this._tabIndexValue = coerceNumberProperty(value);
69115
}
70-
private _tabIndexValue;
116+
private _tabIndexValue = 0;
71117

72-
private isHovered: boolean;
118+
/**
119+
* Whether the card must be outlined.
120+
*/
121+
@Input() outlined: boolean = false;
73122

74-
@Output() onClick = new EventEmitter<any>();
123+
private isHovered: boolean;
75124

76125
@HostBinding("class") className;
77126

78127
@ViewChild("content", { static: false }) content: ElementRef;
79128

80-
defaultInputs = new BehaviorSubject<DxcCardInputs>({
129+
defaultInputs = new BehaviorSubject<any>({
81130
imageSrc: null,
82-
imagePosition: "before",
83-
imagePadding: null,
84-
imageCover: false,
85131
imageBgColor: "black",
86-
margin: null,
87-
outlined: false,
132+
imagePadding: null,
133+
imagePosition: "before",
88134
contentPadding: null,
89135
linkHref: null,
136+
imageCover: false,
137+
margin: null,
90138
tabIndexValue: 0,
139+
outlined: false,
91140
});
92141

93142
public ngOnChanges(changes: SimpleChanges): void {
@@ -102,9 +151,11 @@ export class DxcCardComponent implements OnInit {
102151
this.className = `${this.getDynamicStyle(this.defaultInputs.getValue())}`;
103152
}
104153

105-
constructor(private utils: CssUtils, private cdRef: ChangeDetectorRef,
106-
@Optional() public bgProviderService?: BackgroundProviderService) {
107-
}
154+
constructor(
155+
private utils: CssUtils,
156+
private cdRef: ChangeDetectorRef,
157+
@Optional() public bgProviderService?: BackgroundProviderService
158+
) {}
108159

109160
ngOnInit() {
110161
this.className = `${this.getDynamicStyle(this.defaultInputs.getValue())}`;
@@ -129,22 +180,28 @@ export class DxcCardComponent implements OnInit {
129180

130181
applyTheme(href, outlined) {
131182
return css`
132-
mat-card {
133-
${this.utils.getBoxShadow(0, true)}
134-
}
183+
mat-card {
184+
${this.utils.getBoxShadow(0, true)}
185+
}
135186
136187
mat-card:hover {
137188
${this.utils.getBoxShadow(0, true)}
138189
}
139190
`;
140191
}
141192

142-
changeIsHovered(isHovered: boolean){
193+
changeIsHovered(isHovered: boolean) {
143194
this.isHovered = isHovered;
144195
}
145196

146-
getShadowDepth(){
147-
return this.defaultInputs.value.outlined ? "0" : (this.isHovered && (this.onClick.observers.length > 0 && this.linkHref !== '') ? "2" : "1");
197+
getShadowDepth() {
198+
return this.defaultInputs.value.outlined
199+
? "0"
200+
: this.isHovered &&
201+
this.onClick.observers.length > 0 &&
202+
this.linkHref !== ""
203+
? "2"
204+
: "1";
148205
}
149206

150207
getCursor(href) {
@@ -249,7 +306,5 @@ export class DxcCardComponent implements OnInit {
249306
}
250307
${this.applyTheme(inputs.linkHref, inputs.outlined)}
251308
`;
252-
253-
254309
}
255310
}

0 commit comments

Comments
 (0)