Skip to content

Commit dd61edf

Browse files
authored
Merge pull request #626 from dxc-technology/marcialfps-tabs-types
Types for Tabs component
2 parents 88a9178 + 2004b81 commit dd61edf

File tree

3 files changed

+87
-19
lines changed

3 files changed

+87
-19
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,27 @@ <h3>Tab Properties</h3>
5555
<td>Whether the tab is disabled.</td>
5656
</tr>
5757
<tr>
58-
<td>onTabClick: EventEmitter</td>
58+
<td>notificationNumber: boolean | number</td>
5959
<td></td>
6060
<td>
61-
This function will be called when the user clicks on a tab. The index of
62-
the clicked tab will be passed as a parameter.
61+
It can have boolean type or number type. If the value is 'true', an empty
62+
badge will appear. If it is 'false', no badge will appear. If a number is
63+
put it will be shown as the label of the notification in the tab, taking
64+
into account that if that number is greater than 99, it will appear as
65+
'+99' in the badge.
6366
</td>
6467
</tr>
6568
<tr>
66-
<td>onTabHover: EventEmitter</td>
69+
<td>onTabClick: EventEmitter</td>
6770
<td></td>
6871
<td>
69-
This function will be called when the user is on hover on a tab.
72+
This event will emit when the user clicks on a tab. The index of the
73+
clicked tab will be passed as a parameter.
7074
</td>
7175
</tr>
76+
<tr>
77+
<td>onTabHover: EventEmitter</td>
78+
<td></td>
79+
<td>This event will emit when the user is on hover on a tab.</td>
80+
</tr>
7281
</dxc-table>

projects/dxc-ngx-cdk/src/lib/dxc-tabs/dxc-tab/dxc-tab.component.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,43 @@ import { TabService } from "../services/tab.service";
1717
templateUrl: "./dxc-tab.component.html",
1818
})
1919
export class DxcTabComponent implements OnChanges {
20-
//Default values
20+
/**
21+
* Text to be placed within the tab.
22+
*/
2123
@Input() label: string;
24+
25+
/**
26+
* @deprecated The path of an icon to be placed within the tab.
27+
*/
2228
@Input() iconSrc: string;
23-
@Input() disabled: boolean;
29+
30+
/**
31+
* Whether the tab is disabled or not.
32+
*/
33+
@Input() disabled: boolean = false;
34+
35+
/**
36+
* It can have boolean type or number type.
37+
* If the value is 'true', an empty badge will appear. If it is 'false',
38+
* no badge will appear.
39+
* If a number is put it will be shown as the label of the notification
40+
* in the tab, taking into account that if that number is greater than 99,
41+
* it will appear as '+99' in the badge.
42+
*/
43+
@Input() notificationNumber: boolean | number;
44+
45+
/**
46+
* This event will emit when the user clicks on a tab. The index
47+
* of the clicked tab will be passed as a parameter.
48+
*/
49+
@Output() onTabClick: EventEmitter<number> = new EventEmitter<number>();
50+
51+
/**
52+
* This event will emit when the user is on hover on a tab.
53+
*/
54+
@Output() onTabHover: EventEmitter<number> = new EventEmitter<number>();
55+
2456
@Input() id: number;
25-
@Input() notificationNumber: any;
26-
@Output() onTabClick = new EventEmitter<any>();
27-
@Output() onTabHover = new EventEmitter<any>();
2857

2958
showDotIndicator: boolean = false;
3059
labelClass: string;

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ const globalRippleConfig: RippleGlobalOptions = {
2828
exitDuration: 0,
2929
},
3030
};
31+
32+
type Space =
33+
| "xxsmall"
34+
| "xsmall"
35+
| "small"
36+
| "medium"
37+
| "large"
38+
| "xlarge"
39+
| "xxlarge";
40+
41+
type Margin = {
42+
top?: Space;
43+
bottom?: Space;
44+
left?: Space;
45+
right?: Space;
46+
};
47+
3148
@Component({
3249
selector: "dxc-tabs",
3350
templateUrl: "./dxc-tabs.component.html",
@@ -39,21 +56,33 @@ const globalRippleConfig: RippleGlobalOptions = {
3956
],
4057
})
4158
export class DxcTabsComponent implements OnChanges {
42-
@HostBinding("class") className;
43-
@HostBinding("class.label-icons") allTabWithLabelAndIcon: boolean = false;
44-
45-
//Default values
46-
@Input() margin: any;
47-
@Input() iconPosition: string;
48-
59+
/**
60+
* The index of the active tab.
61+
*/
4962
@Input()
5063
get activeTabIndex(): number {
5164
return this._activeTabIndex;
5265
}
5366
set activeTabIndex(value: number) {
5467
this._activeTabIndex = coerceNumberProperty(value);
5568
}
56-
private _activeTabIndex;
69+
private _activeTabIndex = 0;
70+
71+
/**
72+
* Position of icons in tabs.
73+
*/
74+
@Input() iconPosition: "top" | "left" = "left";
75+
76+
/**
77+
* Size of the margin to be applied to the component. You can pass an object
78+
* with 'top', 'bottom', 'left' and 'right' properties in order to specify
79+
* different margin sizes.
80+
*/
81+
@Input() margin: Space | Margin;
82+
83+
@HostBinding("class") className;
84+
@HostBinding("class.label-icons") allTabWithLabelAndIcon: boolean = false;
85+
5786
renderedActiveTabIndex: number;
5887

5988
@ViewChild(MatRipple) ripple: MatRipple;
@@ -65,8 +94,9 @@ export class DxcTabsComponent implements OnChanges {
6594
protected tabs: QueryList<DxcTabComponent>;
6695

6796
defaultInputs = new BehaviorSubject<any>({
97+
activeTabIndex: 0,
98+
iconPosition: "left",
6899
margin: null,
69-
iconPosition: null,
70100
});
71101

72102
constructor(

0 commit comments

Comments
 (0)