Skip to content

Commit

Permalink
Merge pull request #612 from dxc-technology/gomezivann-accordion-types
Browse files Browse the repository at this point in the history
Types for Accordion component
  • Loading branch information
Jialecl authored Feb 1, 2022
2 parents 3cf52b4 + ad1cc44 commit 55ebb68
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tr>
<td>label: string</td>
<td></td>
<td>Text to be placed next to the button.</td>
<td>The panel label.</td>
</tr>
<tr>
<td>iconSrc: string</td>
Expand All @@ -35,20 +35,24 @@
</tr>
<tr>
<td>isExpanded: boolean</td>
<td><code>false</code></td>
<td>If true, the component will be expanded.</td>
<td></td>
<td>
Represents the state of the panel. When true, the component will be
expanded. If undefined, the component will be uncontrolled and its value
will be managed internally by the component.
</td>
</tr>
<tr>
<td>onClick: EventEmitter</td>
<td></td>
<td>
This function will be called when the user clicks the icon to open/close
the panel. The state of the panel (opened/closed) should be passed as a
parameter
This event will emit in case the user clicks the accordion to expand
or collapse the panel. The new state of the panel will be passed as a
parameter.
</td>
</tr>
<tr>
<td>margin: any (string | object)</td>
<td>margin: string | object</td>
<td></td>
<td>
Size of the margin to be applied to the component ('xxsmall' | 'xsmall' |
Expand All @@ -58,7 +62,7 @@
</td>
</tr>
<tr>
<td>padding: any (string | object)</td>
<td>padding: string | object</td>
<td></td>
<td>
Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {
Component,
} from "@angular/core";
import { Component } from "@angular/core";

@Component({
selector: "dxc-accordion-icon",
templateUrl: "./dxc-accordion-icon.component.html"
templateUrl: "./dxc-accordion-icon.component.html",
})
export class DxcAccordionIconComponent {

constructor() {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
[expandedHeight]="'48px'"
[tabindex]="disabled ? -1 : tabIndexValue"
>
<mat-panel-title
[ngClass]="'before'"
>
<mat-panel-title [ngClass]="'before'">
<span *ngIf="label">{{ label }}</span>
<img [src]="iconSrc" *ngIf="iconSrc" class="imageIcon" />
<ng-content select="dxc-accordion-icon"></ng-content>
Expand All @@ -33,9 +31,8 @@
</svg>
</span>
</mat-expansion-panel-header>
<background-provider-inner color="{{currentBackgroundColor}}">
<background-provider-inner color="{{ currentBackgroundColor }}">
<ng-content></ng-content>
</background-provider-inner>

</mat-expansion-panel>
</mat-accordion>
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,51 @@ import { DxcAccordionIconComponent } from "./dxc-accordion-icon/dxc-accordion-ic
import { QueryList, ChangeDetectorRef, ElementRef } from "@angular/core";
import { BackgroundProviderComponent } from "../background-provider/background-provider.component";

type Space =
| "xxsmall"
| "xsmall"
| "small"
| "medium"
| "large"
| "xlarge"
| "xxlarge";

type Margin = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};

type Padding = {
top?: Space;
bottom?: Space;
left?: Space;
right?: Space;
};

@Component({
selector: "dxc-accordion",
templateUrl: "./dxc-accordion.component.html",
providers: [CssUtils, BackgroundProviderComponent],
})
export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
currentBackgroundColor: string;
@Input() mode: string;
@Input() label: string;
/**
* The panel label.
*/
@Input() label: string = "";
/**
* @deprecated URL of the icon that will be placed next to panel label.
*/
@Input() iconSrc: string;
@Input() assistiveText: string;
/**
* Assistive text to be placed on the right side of the panel.
*/
@Input() assistiveText: string = "";
/**
* If true, the component will be disabled.
*/
@Input()
get disabled(): boolean {
return this._disabled;
Expand All @@ -41,9 +75,26 @@ export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
this._disabled = coerceBooleanProperty(value);
}
private _disabled = false;
@Output() onClick = new EventEmitter<any>();
@Input() margin: any;
@Input() padding: any;
/**
* This event will emit in case the user clicks the accordion to expand or collapse
* the panel. The new state of the panel will be passed as a parameter.
*/
@Output() onClick = new EventEmitter<boolean>();
/**
* Size of the margin to be applied to the component ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different margin sizes.
*/
@Input() margin: Space | Margin;
/**
* Size of the padding to be applied to the custom area ('xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
* You can pass an object with 'top', 'bottom', 'left' and 'right' properties in order to specify different padding sizes.
*/
@Input() padding: Space | Padding;
/**
* Represents the state of the panel. When true, the component will be
* expanded. If undefined, the component will be uncontrolled and its
* value will be managed internally by the component.
*/
@Input()
get isExpanded(): boolean {
return this._isExpanded;
Expand All @@ -52,20 +103,26 @@ export class DxcAccordionComponent implements OnInit, OnChanges, AfterViewInit {
this._isExpanded = coerceBooleanProperty(value);
}
private _isExpanded;
/**
* Value of the tabindex.
*/
@Input()
get tabIndexValue(): number {
return this._tabIndexValue;
}
set tabIndexValue(value: number) {
this._tabIndexValue = coerceNumberProperty(value);
}
private _tabIndexValue;
private _tabIndexValue = 0;

@HostBinding("class") className;

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

/**
* Element used as the icon that will be placed next to panel label.
*/
@ContentChildren(DxcAccordionIconComponent)
dxcAccordionIcon: QueryList<DxcAccordionIconComponent>;

Expand Down

0 comments on commit 55ebb68

Please sign in to comment.