Skip to content

Commit d54617d

Browse files
authored
Merge pull request #658 from dxc-technology/aida-table-types
Types for Table component
2 parents 9cd3ef0 + a584ca0 commit d54617d

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<th>Description</th>
77
</tr>
88
<tr>
9-
<td>margin: any (string | object)</td>
9+
<td>margin: string | object</td>
1010
<td></td>
1111
<td>
1212
Size of the margin to be applied to the component ('xxsmall' |
1313
'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'). You
1414
can pass an object with 'top', 'bottom', 'left' and 'right' properties
15-
in order to specify different padding sizes.
15+
in order to specify different margin sizes.
1616
</td>
1717
</tr>
1818
</dxc-table>

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,39 @@ import { BehaviorSubject } from "rxjs";
44
import { BackgroundProviderService } from "../background-provider/service/background-provider.service";
55
import { CssUtils } from "../utils";
66

7+
type Space =
8+
| "xxsmall"
9+
| "xsmall"
10+
| "small"
11+
| "medium"
12+
| "large"
13+
| "xlarge"
14+
| "xxlarge";
15+
16+
type Margin = {
17+
top?: Space;
18+
bottom?: Space;
19+
left?: Space;
20+
right?: Space;
21+
};
22+
723
@Component({
824
selector: "dxc-table",
925
templateUrl: "./dxc-table.component.html",
1026
styleUrls: [],
1127
providers: [CssUtils, BackgroundProviderService],
1228
})
1329
export class DxcTableComponent {
14-
@Input() margin;
15-
@HostBinding("class") className;
30+
/**
31+
* Size of the margin to be applied to the component ('xxsmall' |
32+
* 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge'). You
33+
* can pass an object with 'top', 'bottom', 'left' and 'right' properties
34+
* in order to specify different margin sizes.
35+
*/
36+
@Input() margin: Space | Margin;
1637

38+
@HostBinding("class") className;
1739
defaultInputs = new BehaviorSubject<any>({});
18-
1940
currentBackgroundColor: string;
2041

2142
constructor(private utils: CssUtils) {}
@@ -39,8 +60,8 @@ export class DxcTableComponent {
3960
getDynamicStyle(inputs) {
4061
return css`
4162
div#divTable {
42-
${this.utils.getMargins(this.margin)}
43-
${this.calculateWidth(this.margin)};
63+
${this.utils.getMargins(inputs.margin)}
64+
${this.calculateWidth(inputs.margin)};
4465
overflow-y: auto;
4566
&::-webkit-scrollbar {
4667
width: 8px;
@@ -103,9 +124,12 @@ export class DxcTableComponent {
103124
`;
104125
}
105126

106-
private calculateWidth = (margin: any) => {
107-
return margin ?`width: calc(100% - ${this.utils.getMarginValue(margin, "left")} - ${this.utils.getMarginValue(
108-
margin,"right")})`: '';
109-
}
110-
127+
private calculateWidth = (margin: Space | Margin) => {
128+
return margin
129+
? `width: calc(100% - ${this.utils.getMarginValue(
130+
margin,
131+
"left"
132+
)} - ${this.utils.getMarginValue(margin, "right")})`
133+
: "";
134+
};
111135
}

0 commit comments

Comments
 (0)