Skip to content

Commit 84ec74d

Browse files
authored
Merge pull request #711 from dxc-technology/rarrojolopez-button-types
Added button types.
2 parents 5091acd + 7e3ee75 commit 84ec74d

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<th>Description</th>
1212
</tr>
1313
<tr>
14-
<td>mode: string ('primary' | 'secondary' | 'text')</td>
14+
<td>mode: 'primary' | 'secondary' | 'text'</td>
1515
<td>
1616
<code>'primary'</code>
1717
</td>
@@ -20,7 +20,7 @@
2020
<tr>
2121
<td>label: string</td>
2222
<td></td>
23-
<td>Text to be placed next to the button.</td>
23+
<td>Text to be placed inside the button.</td>
2424
</tr>
2525
<tr>
2626
<td>iconSrc: string</td>
@@ -31,7 +31,7 @@
3131
</td>
3232
</tr>
3333
<tr>
34-
<td>iconPosition: string ('before' | 'after')</td>
34+
<td>iconPosition: 'before' | 'after'</td>
3535
<td>
3636
<code>'before'</code>
3737
</td>
@@ -44,11 +44,6 @@
4444
</td>
4545
<td>If true, the component will be disabled.</td>
4646
</tr>
47-
<tr>
48-
<td>tabIndexValue: number</td>
49-
<td><code>0</code></td>
50-
<td>Value of the tabindex.</td>
51-
</tr>
5247
<tr>
5348
<td>onClick: EventEmitter</td>
5449
<td></td>
@@ -58,7 +53,7 @@
5853
</td>
5954
</tr>
6055
<tr>
61-
<td>margin: any (string | object)</td>
56+
<td>margin: string | object</td>
6257
<td></td>
6358
<td>
6459
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
@@ -68,11 +63,16 @@
6863
</td>
6964
</tr>
7065
<tr>
71-
<td>size: any (string | object)</td>
72-
<td></td>
66+
<td>size: string</td>
67+
<td><code>'fitContent'</code></td>
7368
<td>
7469
Size of the component ('small' | 'medium' | 'large' | 'fillParent' |
7570
'fitContent').
7671
</td>
7772
</tr>
73+
<tr>
74+
<td>tabIndexValue: number</td>
75+
<td><code>0</code></td>
76+
<td>Value of the tabindex.</td>
77+
</tr>
7878
</dxc-table>

projects/dxc-ngx-cdk/src/lib/dxc-button/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The API properties are the following:
4242
<th>Description</th>
4343
</tr>
4444
<tr>
45-
<td>@Input<br>mode: string ('primary' | 'secondary' | 'text')</td>
45+
<td>@Input<br>'primary' | 'secondary' | 'text'</td>
4646
<td>
4747
<code>'primary'</code>
4848
</td>
@@ -51,15 +51,15 @@ The API properties are the following:
5151
<tr>
5252
<td>@Input<br>label: string</td>
5353
<td></td>
54-
<td>Text to be placed next to the button.</td>
54+
<td>Text to be placed inside the button.</td>
5555
</tr>
5656
<tr>
5757
<td>@Input<br>iconSrc: string</td>
5858
<td></td>
5959
<td>URL of the icon that will be placed next to the button label.</td>
6060
</tr>
6161
<tr>
62-
<td>@Input<br>iconPosition: string ('before' | 'after')</td>
62+
<td>@Input<br>iconPosition: 'before' | 'after'</td>
6363
<td>
6464
<code>'before'</code>
6565
</td>
@@ -81,7 +81,7 @@ The API properties are the following:
8181
</td>
8282
</tr>
8383
<tr>
84-
<td>@Input<br>margin: any (string | object)</td>
84+
<td>@Input<br>margin: string | object</td>
8585
<td></td>
8686
<td>
8787
Size of the margin to be applied to the component ('xxsmall' |
@@ -91,7 +91,7 @@ The API properties are the following:
9191
</td>
9292
</tr>
9393
<tr>
94-
<td>@Input<br>size: any (string | object)</td>
94+
<td>@Input<br>size: string | object</td>
9595
<td></td>
9696
<td>
9797
Size of the component ('small' | 'medium' | 'large' | 'fillParent' |

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,80 @@ import {
2020
import { DxcButtonIconComponent } from "./dxc-button-icon/dxc-button-icon.component";
2121
import { BackgroundProviderService } from "../background-provider/service/background-provider.service";
2222

23+
type Size = "small" | "medium" | "large" | "fillParent" | "fitContent";
24+
type Space =
25+
| "xxsmall"
26+
| "xsmall"
27+
| "small"
28+
| "medium"
29+
| "large"
30+
| "xlarge"
31+
| "xxlarge";
32+
type Margin = {
33+
top?: Space;
34+
bottom?: Space;
35+
left?: Space;
36+
right?: Space;
37+
};
38+
2339
@Component({
2440
selector: "dxc-button",
2541
templateUrl: "./dxc-button.component.html",
2642
providers: [CssUtils],
2743
})
2844
export class DxcButtonComponent {
29-
@Input() mode: string;
45+
/**
46+
* Uses one of the available button modes.
47+
*/
48+
@Input() mode: "primary" | "secondary" | "text" = "primary";
49+
/**
50+
* If true, the component will be disabled.
51+
*/
3052
@Input()
3153
get disabled(): boolean {
3254
return this._disabled;
3355
}
3456
set disabled(value: boolean) {
3557
this._disabled = coerceBooleanProperty(value);
3658
}
37-
private _disabled;
59+
private _disabled = false;
60+
/**
61+
* Text to be placed inside the button.
62+
*/
3863
@Input() label: string;
64+
/**
65+
* @deprecated URL of the icon that will be placed next to the button label.
66+
*/
3967
@Input() iconSrc: string;
40-
@Input() iconPosition: string;
41-
@Input() margin: any;
42-
@Input() size: string;
68+
/**
69+
* Whether the icon should appear after or before the label.
70+
*/
71+
@Input() iconPosition: "before" | "after" = "before";
72+
/**
73+
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
74+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
75+
*/
76+
@Input() margin: Space | Margin;
77+
/**
78+
* Size of the component.
79+
*/
80+
@Input() size: Size = "fitContent";
81+
/**
82+
* Value of the tabindex attribute.
83+
*/
4384
@Input()
4485
get tabIndexValue(): number {
4586
return this._tabIndexValue;
4687
}
4788
set tabIndexValue(value: number) {
4889
this._tabIndexValue = coerceNumberProperty(value);
4990
}
50-
private _tabIndexValue;
91+
private _tabIndexValue = 0;
5192

52-
@Output() onClick = new EventEmitter<any>();
93+
/**
94+
* This function will be called when the user clicks the button.
95+
*/
96+
@Output() onClick: EventEmitter<void> = new EventEmitter<void>();
5397

5498
@HostBinding("class") className;
5599

0 commit comments

Comments
 (0)