Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:collapse): add extra field #2923

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/collapse/demo/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { Component } from '@angular/core';
template: `
<nz-collapse [nzBordered]="false">
<nz-collapse-panel #p *ngFor="let panel of panels; let isFirst = first" [nzHeader]="panel.name" [nzActive]="panel.active"
[ngStyle]="panel.customStyle" [nzExpandedIcon]="!isFirst && (panel.icon || expandedIcon)">
[ngStyle]="panel.customStyle" [nzExpandedIcon]="!isFirst && (panel.icon || expandedIcon)" [nzExtra]="isFirst && extraTpl">
<p>{{panel.name}} content</p>
<ng-template #expandedIcon let-active>
{{ active }}
<i nz-icon type="caret-right" class="ant-collapse-arrow" [nzRotate]="p.nzActive ? 90 : -90"></i>
</ng-template>
</nz-collapse-panel>
<ng-template #extraTpl>
<i nz-icon [nzType]="'smile'"></i>
</ng-template>
</nz-collapse>
`,
styles : []
Expand Down
1 change: 1 addition & 0 deletions components/collapse/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ A content area which can be collapsed and expanded.
| `[nzActive]` | Active status of panel, double binding | `boolean` | - |
| `(nzActiveChange)` | Callback function of the active status | `EventEmitter<boolean>` | - |
| `[nzExpandedIcon]` | Customize an icon for toggle | `string|TemplateRef<void>` | - |
| `[nzExtra]` | Extra element in the corner | `string|TemplateRef<void>` | - |
3 changes: 2 additions & 1 deletion components/collapse/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ cols: 1
| `[nzShowArrow]` | 是否展示箭头 | `boolean` | `true` |
| `[nzActive]` | 面板是否展开,可双向绑定 | `boolean` | - |
| `(nzActiveChange)` | 面板展开回调 | `EventEmitter<boolean>` | - |
| `[nzExpandedIcon]` | 自定义切换图标 | `string|TemplateRef<void>` | - |
| `[nzExpandedIcon]` | 自定义切换图标 | `string|TemplateRef<void>` | - |
| `[nzExtra]` | 自定义渲染每个面板右上角的内容 | `string|TemplateRef<void>` | - |
3 changes: 3 additions & 0 deletions components/collapse/nz-collapse-panel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</ng-container>
</ng-container>
<ng-container *nzStringTemplateOutlet="nzHeader">{{ nzHeader }}</ng-container>
<div *ngIf="nzExtra" class="ant-collapse-extra">
<ng-container *nzStringTemplateOutlet="nzExtra">{{ nzExtra }}</ng-container>
</div>
</div>
<div class="ant-collapse-content"
[class.ant-collapse-content-active]="nzActive"
Expand Down
1 change: 1 addition & 0 deletions components/collapse/nz-collapse-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class NzCollapsePanelComponent implements OnInit, OnDestroy {
@Input() @InputBoolean() nzShowArrow = true;
@Input() nzHeader: string | TemplateRef<void>;
@Input() nzExpandedIcon: string | TemplateRef<void>;
@Input() nzExtra: string | TemplateRef<void>;
@Output() readonly nzActiveChange = new EventEmitter<boolean>();

clickHeader(): void {
Expand Down
11 changes: 10 additions & 1 deletion components/collapse/nz-collapse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('collapse', () => {
fixture.detectChanges();
expect(collapse.nativeElement.firstElementChild.classList).toContain('ant-collapse-borderless');
});
it('should extra work', () => {
expect(collapse.nativeElement.querySelector('.ant-collapse-extra')).toBeNull();
testComponent.showExtra = 'extra';
fixture.detectChanges();
const extra = collapse.nativeElement.querySelector('.ant-collapse-extra');
expect(extra).toBeDefined();
expect(extra.innerText).toBe('extra');
});
it('should showArrow work', () => {
fixture.detectChanges();
expect(panels[ 0 ].nativeElement.querySelector('.ant-collapse-arrow').firstElementChild).toBeDefined();
Expand Down Expand Up @@ -168,7 +176,7 @@ describe('collapse', () => {
template: `
<ng-template #headerTemplate>template</ng-template>
<nz-collapse [nzAccordion]="accordion" [nzBordered]="bordered">
<nz-collapse-panel [(nzActive)]="active01" (nzActiveChange)="active01Change($event)" [nzHeader]="header" [nzShowArrow]="showArrow">
<nz-collapse-panel [(nzActive)]="active01" (nzActiveChange)="active01Change($event)" [nzHeader]="header" [nzShowArrow]="showArrow" [nzExtra]="showExtra">
<p>Panel01</p>
</nz-collapse-panel>
<nz-collapse-panel [(nzActive)]="active02" (nzActiveChange)="active02Change($event)" [nzDisabled]="disabled">
Expand All @@ -185,6 +193,7 @@ export class NzTestCollapseBasicComponent {
active01 = false;
active02 = false;
showArrow = true;
showExtra = '';
header = 'string';
active01Change = jasmine.createSpy('active01 callback');
active02Change = jasmine.createSpy('active02 callback');
Expand Down
6 changes: 6 additions & 0 deletions components/collapse/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

> .@{collapse-prefix-cls}-header {
position: relative;
display: flex;
align-items: center;
padding: @collapse-header-padding;
color: @heading-color;
line-height: 22px;
Expand All @@ -47,6 +49,10 @@
&:focus {
outline: none;
}

.@{collapse-prefix-cls}-extra {
margin: 0 16px 0 auto;
}
}

&.@{collapse-prefix-cls}-no-arrow {
Expand Down