Skip to content

Commit 6845a64

Browse files
authored
Merge pull request #802 from dxc-technology/aida-chip-types
Added types for chip component
2 parents 4b11b87 + 7af104b commit 6845a64

File tree

5 files changed

+101
-38
lines changed

5 files changed

+101
-38
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<td><b>Deprecated.</b> Path of the icon to be placed before the label.</td>
3131
</tr>
3232
<tr>
33-
<td>margin: any (string | object)</td>
33+
<td>margin: string | object</td>
3434
<td></td>
3535
<td>
3636
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
@@ -47,7 +47,10 @@
4747
<tr>
4848
<td>tabIndexValue: number</td>
4949
<td><code>0</code></td>
50-
<td>Value of the tabindex, it also applies to prefix and suffix icons when a function is given.</td>
50+
<td>
51+
Value of the tabindex, it also applies to prefix and suffix icons when a
52+
function is given.
53+
</td>
5154
</tr>
5255
<tr>
5356
<td>suffixIconClick: EventEmitter</td>

projects/dxc-ngx-cdk/src/lib/dxc-button/dxc-button.types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export type Spacing = {
1515
};
1616

1717
export interface ButtonProperties {
18-
mode: "primary" | "secondary" | "text";
19-
label: string;
20-
disabled: boolean;
21-
iconSrc: string;
22-
iconPosition: "before" | "after";
23-
margin: Space | Spacing;
24-
size: "small" | "medium" | "large" | "fillParent" | "fitContent";
25-
type: "reset" | "submit" | "button";
26-
tabIndexValue: number;
27-
}
18+
mode: "primary" | "secondary" | "text";
19+
label: string;
20+
disabled: boolean;
21+
iconSrc: string;
22+
iconPosition: "before" | "after";
23+
margin: Space | Spacing;
24+
size: "small" | "medium" | "large" | "fillParent" | "fitContent";
25+
type: "reset" | "submit" | "button";
26+
tabIndexValue: number;
27+
}

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { ChangeDetectorRef, QueryList } from "@angular/core";
1919
import { DxcChipPrefixIconComponent } from "./dxc-chip-prefix-icon/dxc-chip-prefix-icon.component";
2020
import { DxcChipSuffixIconComponent } from "./dxc-chip-suffix-icon/dxc-chip-suffix-icon.component";
21+
import { ChipProperties, Space, Spacing } from "./dxc-chip.types";
2122

2223
@Component({
2324
selector: "dxc-chip",
@@ -28,9 +29,21 @@ export class DxcChipComponent implements OnChanges {
2829
@HostBinding("class") className;
2930
@HostBinding("class.hasTabIndexPrefix") hasTabIndexPrefix: boolean = false;
3031
@HostBinding("class.hasTabIndexSuffix") hasTabIndexSuffix: boolean = false;
32+
/**
33+
* Text to be placed inside the chip.
34+
*/
3135
@Input() label: string;
36+
/**
37+
* @deprecated. Path of the icon to be placed after the label.
38+
*/
3239
@Input() suffixIconSrc: string;
40+
/**
41+
* @deprecated. Path of the icon to be placed before the label.
42+
*/
3343
@Input() prefixIconSrc: string;
44+
/**
45+
* If true, the component will be disabled.
46+
*/
3447
@Input()
3548
get disabled(): boolean {
3649
return this._disabled;
@@ -39,17 +52,38 @@ export class DxcChipComponent implements OnChanges {
3952
this._disabled = coerceBooleanProperty(value);
4053
}
4154
private _disabled;
42-
@Input() margin: any;
55+
/**
56+
* Size of the margin to be applied to the component
57+
* ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
58+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties
59+
* in order to specify different margin sizes.
60+
*/
61+
@Input() margin: Space | Spacing;
4362

44-
@Output() suffixIconClick = new EventEmitter<any>();
45-
@Output() prefixIconClick = new EventEmitter<any>();
63+
/**
64+
* Event that will be emitted when the suffix icon is clicked.
65+
*/
66+
@Output() suffixIconClick: EventEmitter<void> = new EventEmitter<void>();
67+
/**
68+
* Event that will be emitted when the prefix icon is clicked.
69+
*/
70+
@Output() prefixIconClick: EventEmitter<void> = new EventEmitter<void>();
4671

72+
/**
73+
* Element used as icon to be placed before the chip label.
74+
*/
4775
@ContentChildren(DxcChipPrefixIconComponent)
4876
dxcChipPrefixIcon: QueryList<DxcChipPrefixIconComponent>;
4977

78+
/**
79+
* Element used as icon to be placed after the chip label.
80+
*/
5081
@ContentChildren(DxcChipSuffixIconComponent)
5182
dxcChipSuffixIcon: QueryList<DxcChipSuffixIconComponent>;
5283

84+
/**
85+
* Value of the tabindex, it also applies to prefix and suffix icons when a function is given.
86+
*/
5387
@Input()
5488
get tabIndexValue(): number {
5589
return this._tabIndexValue;
@@ -59,12 +93,12 @@ export class DxcChipComponent implements OnChanges {
5993
}
6094
private _tabIndexValue;
6195

62-
defaultInputs = new BehaviorSubject<any>({
96+
defaultInputs = new BehaviorSubject<ChipProperties>({
6397
label: "",
6498
suffixIconSrc: null,
6599
prefixIconSrc: null,
66100
disabled: false,
67-
margin: "",
101+
margin: null,
68102
tabIndexValue: 0,
69103
});
70104

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export type Space =
2+
| "xxsmall"
3+
| "xsmall"
4+
| "small"
5+
| "medium"
6+
| "large"
7+
| "xlarge"
8+
| "xxlarge";
9+
10+
export type Spacing = {
11+
top?: Space;
12+
bottom?: Space;
13+
left?: Space;
14+
right?: Space;
15+
};
16+
17+
export interface ChipProperties {
18+
label: string;
19+
disabled: boolean;
20+
margin: Space | Spacing;
21+
tabIndexValue: number;
22+
suffixIconSrc?: string;
23+
prefixIconSrc?: string;
24+
}

projects/dxc-ngx-cdk/src/lib/utils.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ export class CssUtils {
2222
}
2323

2424
getMarginValue = (margin, type) => {
25-
const marginSize = spaces[margin[type]] || "0px";
26-
return marginSize;
27-
}
28-
29-
25+
const marginSize = margin && margin !== null ? spaces[margin[type]] : "0px";
26+
return marginSize;
27+
};
3028

3129
getTopMargin(margin) {
3230
return margin && typeof margin !== "object"
@@ -175,40 +173,44 @@ export class CssUtils {
175173
return value;
176174
}
177175

178-
getBoxShadow(shadowDepth, isImportant:boolean = false) {
176+
getBoxShadow(shadowDepth, isImportant: boolean = false) {
179177
switch (shadowDepth) {
180178
case "1":
181179
return css`
182180
box-shadow: var(--box-oneShadowDepthShadowOffsetX)
183181
var(--box-oneShadowDepthShadowOffsetY)
184182
var(--box-oneShadowDepthShadowBlur)
185183
var(--box-oneShadowDepthShadowSpread)
186-
var(--box-oneShadowDepthShadowColor) ${this.isPropertyImportant(isImportant)};`;
184+
var(--box-oneShadowDepthShadowColor)
185+
${this.isPropertyImportant(isImportant)};
186+
`;
187187
case "2":
188188
return css`
189-
box-shadow: var(--box-twoShadowDepthShadowOffsetX)
190-
var(--box-twoShadowDepthShadowOffsetY)
191-
var(--box-twoShadowDepthShadowBlur)
192-
var(--box-twoShadowDepthShadowSpread)
193-
var(--box-twoShadowDepthShadowColor) ${this.isPropertyImportant(isImportant)};
194-
` ;
189+
box-shadow: var(--box-twoShadowDepthShadowOffsetX)
190+
var(--box-twoShadowDepthShadowOffsetY)
191+
var(--box-twoShadowDepthShadowBlur)
192+
var(--box-twoShadowDepthShadowSpread)
193+
var(--box-twoShadowDepthShadowColor)
194+
${this.isPropertyImportant(isImportant)};
195+
`;
195196
default:
196197
return css`
197-
box-shadow: var(--box-noneShadowDepthShadowOffsetX)
198-
var(--box-noneShadowDepthShadowOffsetY)
199-
var(--box-noneShadowDepthShadowBlur)
200-
var(--box-noneShadowDepthShadowSpread)
201-
var(--box-noneShadowDepthShadowColor) ${this.isPropertyImportant(isImportant)};
198+
box-shadow: var(--box-noneShadowDepthShadowOffsetX)
199+
var(--box-noneShadowDepthShadowOffsetY)
200+
var(--box-noneShadowDepthShadowBlur)
201+
var(--box-noneShadowDepthShadowSpread)
202+
var(--box-noneShadowDepthShadowColor)
203+
${this.isPropertyImportant(isImportant)};
202204
`;
203205
}
204206
}
205207

206208
readProperty(name: string): string {
207209
let bodyStyles = window.getComputedStyle(document.body);
208210
return bodyStyles.getPropertyValue(name);
209-
}
211+
}
210212

211-
private isPropertyImportant(isImportant){
212-
return isImportant ? ' !important': '';
213+
private isPropertyImportant(isImportant) {
214+
return isImportant ? " !important" : "";
213215
}
214216
}

0 commit comments

Comments
 (0)