Skip to content

Commit 4ceb851

Browse files
authored
Merge pull request #670 from dxc-technology/jialecl-sidenav-types
adding sidenav types + removing unneccesary func
2 parents d0a6162 + 1fa4fe8 commit 4ceb851

File tree

7 files changed

+54
-130
lines changed

7 files changed

+54
-130
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
<th>Default</th>
1111
<th>Description</th>
1212
</tr>
13-
<tr>
14-
<td>tabIndexValue: number</td>
15-
<td><code>0</code></td>
16-
<td>Value of the tabindex given to DxcSidenavLink children.</td>
17-
</tr>
1813
<tr>
1914
<td>padding: string | object</td>
2015
<td></td>

projects/dxc-ngx-cdk-site/src/app/components/examples/sidenav/sidenav-api/sidenav-api.component.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
text="DxcSidenavSubtitle"
3434
[margin]="{ bottom: 'small' }"
3535
></dxc-heading>
36-
<p>The content will be showed as a subtitle.</p>
36+
<p>The content will be showed as a subtitle in the sidenav.</p>
3737
<dxc-heading
3838
[level]="5"
3939
text="DxcSidenavLink"
4040
[margin]="{ bottom: 'small' }"
4141
></dxc-heading>
42-
<p>Customized link that allows the navigation.</p>
42+
<p>Customized link that allows the navigation. As the other components its content will be shown as an anchor.</p>
4343
<dxc-table>
4444
<tr>
4545
<th>Name</th>
@@ -54,7 +54,12 @@
5454
<tr>
5555
<td>onClick: EventEmitter</td>
5656
<td></td>
57-
<td>This function will be called when the user clicks the link.</td>
57+
<td>This event will emit when the user clicks the link.</td>
58+
</tr>
59+
<tr>
60+
<td>tabIndexValue: number</td>
61+
<td><code>0</code></td>
62+
<td>Value of the tabindex given to the DxcSidenavLink.</td>
5863
</tr>
5964
</dxc-table>
6065

projects/dxc-ngx-cdk/src/lib/dxc-sidenav/dxc-sidenav-link/dxc-sidenav-link.component.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { coerceNumberProperty } from "@angular/cdk/coercion";
12
import {
23
Component,
34
ElementRef,
@@ -7,24 +8,36 @@ import {
78
Output,
89
} from "@angular/core";
910
import { CssUtils } from "../../utils";
10-
import { SidenavService } from '../services/sidenav.service';
11+
1112
@Component({
1213
selector: "dxc-sidenav-link",
1314
templateUrl: "./dxc-sidenav-link.component.html",
1415
providers: [CssUtils],
1516
})
1617
export class DxcSidenavLinkComponent implements OnInit {
18+
/**
19+
* Page to be opened when the user clicks on the link.
20+
*/
1721
@Input() href: string;
18-
@Output() onClick = new EventEmitter<any>();
1922

20-
tabIndexValue: number = 0;
23+
/**
24+
* This event will be emit when the user clicks the link.
25+
*/
26+
@Output() onClick: EventEmitter<void> = new EventEmitter<void>();
27+
28+
/**
29+
* Value of the tabindex given to the DxcSidenavLink.
30+
*/
31+
@Input()
32+
get tabIndexValue(): number {
33+
return this._tabIndexValue;
34+
}
35+
set tabIndexValue(value: number) {
36+
this._tabIndexValue = coerceNumberProperty(value);
37+
}
38+
private _tabIndexValue;
2139

22-
constructor(public element: ElementRef, private service: SidenavService) {
23-
this.service.tabIndexValue.subscribe((value) => {
24-
if (value) {
25-
this.tabIndexValue = value
26-
}
27-
});
40+
constructor(public element: ElementRef) {
2841
}
2942

3043
ngOnInit() {
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<background-provider-inner
2-
color="{{ currentBackgroundColor }}"
3-
>
1+
<background-provider-inner color="{{ currentBackgroundColor }}">
42
<ng-content></ng-content>
53
</background-provider-inner>

projects/dxc-ngx-cdk/src/lib/dxc-sidenav/dxc-sidenav.component.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 23 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,38 @@ import {
1212
import { BehaviorSubject } from "rxjs";
1313
import { css } from "emotion";
1414
import { CssUtils } from "../utils";
15-
import { responsiveSizes } from "./../variables";
16-
import {
17-
coerceBooleanProperty,
18-
coerceNumberProperty,
19-
} from "@angular/cdk/coercion";
20-
import { SidenavService } from "./services/sidenav.service";
2115
import { BackgroundProviderService } from "../background-provider/service/background-provider.service";
2216

17+
type Space =
18+
| "xxsmall"
19+
| "xsmall"
20+
| "small"
21+
| "medium"
22+
| "large"
23+
| "xlarge"
24+
| "xxlarge";
25+
26+
type Padding = {
27+
top?: Space;
28+
bottom?: Space;
29+
left?: Space;
30+
right?: Space;
31+
};
2332
@Component({
2433
selector: "dxc-sidenav",
2534
templateUrl: "./dxc-sidenav.component.html",
26-
styleUrls: ["./dxc-sidenav.component.scss"],
27-
providers: [CssUtils, SidenavService, BackgroundProviderService],
35+
providers: [CssUtils, BackgroundProviderService],
2836
})
2937
export class DxcSidenavComponent implements OnInit {
3038
@HostBinding("class") sidenavStyles;
31-
@Input() mode: string = "push";
32-
@Input() padding: any;
33-
@Input()
34-
get displayArrow(): boolean {
35-
return this._displayArrow;
36-
}
37-
set displayArrow(value: boolean) {
38-
this._displayArrow = coerceBooleanProperty(value);
39-
}
40-
_displayArrow = true;
41-
@Input()
42-
get tabIndexValue(): number {
43-
return this._tabIndexValue;
44-
}
45-
set tabIndexValue(value: number) {
46-
this._tabIndexValue = coerceNumberProperty(value);
47-
}
48-
private _tabIndexValue;
39+
40+
/**
41+
* Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
42+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
43+
*/
44+
@Input() padding: Space | Padding;
4945

5046
firstClick: boolean = false; //remove animation on first load
51-
innerWidth;
52-
isResponsive = true;
53-
isShown: boolean;
5447

5548
currentBackgroundColor: string;
5649

@@ -62,41 +55,15 @@ export class DxcSidenavComponent implements OnInit {
6255
@ViewChild("sidenavContainer", { static: false }) sidenav: ElementRef;
6356
sidenavArrow: any;
6457

65-
constructor(private utils: CssUtils, private service: SidenavService) {}
66-
67-
@HostListener("window:resize", ["$event"])
68-
onResize(event) {
69-
this.updateCss();
70-
}
58+
constructor(private utils: CssUtils) {}
7159

7260
ngOnInit() {
73-
this.updateState();
7461
this.sidenavStyles = `${this.getDynamicStyle({
7562
...this.defaultInputs.getValue(),
76-
mode: this.mode,
77-
innerWidth: this.innerWidth,
78-
isResponsive: this.isResponsive,
79-
isShown: this.isShown,
8063
})}`;
8164
}
8265

83-
public arrowClicked() {
84-
this.isShown = !this.isShown;
85-
this.firstClick = true;
86-
console.log(this.isShown);
87-
this.updateCss();
88-
}
89-
90-
public arrowKey($event) {
91-
if ($event.keyCode && $event.keyCode === 32) {
92-
$event.preventDefault();
93-
this.isShown = !this.isShown;
94-
this.updateCss();
95-
}
96-
}
97-
9866
public ngOnChanges(changes: SimpleChanges): void {
99-
this.service.setTabIndexValue(this.tabIndexValue);
10067
this.currentBackgroundColor = this.utils.readProperty(
10168
"--sidenav-backgroundColor"
10269
);
@@ -105,41 +72,6 @@ export class DxcSidenavComponent implements OnInit {
10572
return result;
10673
}, {});
10774
this.defaultInputs.next({ ...this.defaultInputs.getValue(), ...inputs });
108-
if (this.sidenav) {
109-
this.updateCss();
110-
}
111-
}
112-
113-
updateState() {
114-
this.innerWidth = window.innerWidth;
115-
if (this.innerWidth <= responsiveSizes.tablet) {
116-
this.isResponsive = true;
117-
if (!this.displayArrow) {
118-
this.displayArrow = true;
119-
}
120-
} else {
121-
this.isResponsive = false;
122-
if (!this.displayArrow && !this.isShown) {
123-
this.isShown = true;
124-
}
125-
}
126-
this.isShown =
127-
this.isShown !== undefined
128-
? this.isShown
129-
: this.innerWidth <= responsiveSizes.tablet
130-
? false
131-
: true;
132-
}
133-
134-
updateCss() {
135-
this.updateState();
136-
this.sidenavStyles = `${this.getDynamicStyle({
137-
...this.defaultInputs.getValue(),
138-
mode: this.mode,
139-
innerWidth: this.innerWidth,
140-
isResponsive: this.isResponsive,
141-
isShown: this.isShown,
142-
})}`;
14375
}
14476

14577
getDynamicStyle(inputs) {

projects/dxc-ngx-cdk/src/lib/dxc-sidenav/services/sidenav.service.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)