Skip to content

Commit 55ebb68

Browse files
authored
Merge pull request #612 from dxc-technology/gomezivann-accordion-types
Types for Accordion component
2 parents 3cf52b4 + ad1cc44 commit 55ebb68

File tree

4 files changed

+80
-26
lines changed

4 files changed

+80
-26
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<tr>
1414
<td>label: string</td>
1515
<td></td>
16-
<td>Text to be placed next to the button.</td>
16+
<td>The panel label.</td>
1717
</tr>
1818
<tr>
1919
<td>iconSrc: string</td>
@@ -35,20 +35,24 @@
3535
</tr>
3636
<tr>
3737
<td>isExpanded: boolean</td>
38-
<td><code>false</code></td>
39-
<td>If true, the component will be expanded.</td>
38+
<td></td>
39+
<td>
40+
Represents the state of the panel. When true, the component will be
41+
expanded. If undefined, the component will be uncontrolled and its value
42+
will be managed internally by the component.
43+
</td>
4044
</tr>
4145
<tr>
4246
<td>onClick: EventEmitter</td>
4347
<td></td>
4448
<td>
45-
This function will be called when the user clicks the icon to open/close
46-
the panel. The state of the panel (opened/closed) should be passed as a
47-
parameter
49+
This event will emit in case the user clicks the accordion to expand
50+
or collapse the panel. The new state of the panel will be passed as a
51+
parameter.
4852
</td>
4953
</tr>
5054
<tr>
51-
<td>margin: any (string | object)</td>
55+
<td>margin: string | object</td>
5256
<td></td>
5357
<td>
5458
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
@@ -58,7 +62,7 @@
5862
</td>
5963
</tr>
6064
<tr>
61-
<td>padding: any (string | object)</td>
65+
<td>padding: string | object</td>
6266
<td></td>
6367
<td>
6468
Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall'
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import {
2-
Component,
3-
} from "@angular/core";
1+
import { Component } from "@angular/core";
42

53
@Component({
64
selector: "dxc-accordion-icon",
7-
templateUrl: "./dxc-accordion-icon.component.html"
5+
templateUrl: "./dxc-accordion-icon.component.html",
86
})
97
export class DxcAccordionIconComponent {
10-
118
constructor() {}
12-
139
}

projects/dxc-ngx-cdk/src/lib/dxc-accordion/dxc-accordion.component.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
[expandedHeight]="'48px'"
1111
[tabindex]="disabled ? -1 : tabIndexValue"
1212
>
13-
<mat-panel-title
14-
[ngClass]="'before'"
15-
>
13+
<mat-panel-title [ngClass]="'before'">
1614
<span *ngIf="label">{{ label }}</span>
1715
<img [src]="iconSrc" *ngIf="iconSrc" class="imageIcon" />
1816
<ng-content select="dxc-accordion-icon"></ng-content>
@@ -33,9 +31,8 @@
3331
</svg>
3432
</span>
3533
</mat-expansion-panel-header>
36-
<background-provider-inner color="{{currentBackgroundColor}}">
34+
<background-provider-inner color="{{ currentBackgroundColor }}">
3735
<ng-content></ng-content>
3836
</background-provider-inner>
39-
4037
</mat-expansion-panel>
4138
</mat-accordion>

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

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,51 @@ import { DxcAccordionIconComponent } from "./dxc-accordion-icon/dxc-accordion-ic
2222
import { QueryList, ChangeDetectorRef, ElementRef } from "@angular/core";
2323
import { BackgroundProviderComponent } from "../background-provider/background-provider.component";
2424

25+
type Space =
26+
| "xxsmall"
27+
| "xsmall"
28+
| "small"
29+
| "medium"
30+
| "large"
31+
| "xlarge"
32+
| "xxlarge";
33+
34+
type Margin = {
35+
top?: Space;
36+
bottom?: Space;
37+
left?: Space;
38+
right?: Space;
39+
};
40+
41+
type Padding = {
42+
top?: Space;
43+
bottom?: Space;
44+
left?: Space;
45+
right?: Space;
46+
};
47+
2548
@Component({
2649
selector: "dxc-accordion",
2750
templateUrl: "./dxc-accordion.component.html",
2851
providers: [CssUtils, BackgroundProviderComponent],
2952
})
3053
export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
3154
currentBackgroundColor: string;
32-
@Input() mode: string;
33-
@Input() label: string;
55+
/**
56+
* The panel label.
57+
*/
58+
@Input() label: string = "";
59+
/**
60+
* @deprecated URL of the icon that will be placed next to panel label.
61+
*/
3462
@Input() iconSrc: string;
35-
@Input() assistiveText: string;
63+
/**
64+
* Assistive text to be placed on the right side of the panel.
65+
*/
66+
@Input() assistiveText: string = "";
67+
/**
68+
* If true, the component will be disabled.
69+
*/
3670
@Input()
3771
get disabled(): boolean {
3872
return this._disabled;
@@ -41,9 +75,26 @@ export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
4175
this._disabled = coerceBooleanProperty(value);
4276
}
4377
private _disabled = false;
44-
@Output() onClick = new EventEmitter<any>();
45-
@Input() margin: any;
46-
@Input() padding: any;
78+
/**
79+
* This event will emit in case the user clicks the accordion to expand or collapse
80+
* the panel. The new state of the panel will be passed as a parameter.
81+
*/
82+
@Output() onClick = new EventEmitter<boolean>();
83+
/**
84+
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
85+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
86+
*/
87+
@Input() margin: Space | Margin;
88+
/**
89+
* Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
90+
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
91+
*/
92+
@Input() padding: Space | Padding;
93+
/**
94+
* Represents the state of the panel. When true, the component will be
95+
* expanded. If undefined, the component will be uncontrolled and its
96+
* value will be managed internally by the component.
97+
*/
4798
@Input()
4899
get isExpanded(): boolean {
49100
return this._isExpanded;
@@ -52,20 +103,26 @@ export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
52103
this._isExpanded = coerceBooleanProperty(value);
53104
}
54105
private _isExpanded;
106+
/**
107+
* Value of the tabindex.
108+
*/
55109
@Input()
56110
get tabIndexValue(): number {
57111
return this._tabIndexValue;
58112
}
59113
set tabIndexValue(value: number) {
60114
this._tabIndexValue = coerceNumberProperty(value);
61115
}
62-
private _tabIndexValue;
116+
private _tabIndexValue = 0;
63117

64118
@HostBinding("class") className;
65119

66120
@ViewChild("matExpansionPanel", { static: true }) _matExpansionPanel: any;
67121
renderedIsExpanded: boolean;
68122

123+
/**
124+
* Element used as the icon that will be placed next to panel label.
125+
*/
69126
@ContentChildren(DxcAccordionIconComponent)
70127
dxcAccordionIcon: QueryList<DxcAccordionIconComponent>;
71128

0 commit comments

Comments
 (0)