Skip to content

Commit

Permalink
refactor(module:carousel): refactor carousel (#1072)
Browse files Browse the repository at this point in the history
* wip(module:carousel): refactor carousel

* test(module:carousel): add test for carousel
  • Loading branch information
vthinkxie authored Feb 26, 2018
1 parent 6875982 commit 8aca820
Show file tree
Hide file tree
Showing 16 changed files with 393 additions and 302 deletions.
2 changes: 1 addition & 1 deletion components/card/nz-card.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { NzDemoCardTabsComponent } from './demo/tabs';
import { NzCardComponent } from './nz-card.component';
import { NzCardModule } from './nz-card.module';

describe('badge', () => {
describe('card', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports : [ NzCardModule ],
Expand Down
28 changes: 0 additions & 28 deletions components/carousel/demo/autoplay.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,3 @@ title:
## en-US

Timing of scrolling to the next card/picture.

````jsx
import { Carousel } from 'antd';

ReactDOM.render(
<Carousel autoplay>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
<div><h3>4</h3></div>
</Carousel>
, mountNode);
````

````css
/* For demo */
.ant-carousel .slick-slide {
text-align: center;
height: 160px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}

.ant-carousel .slick-slide h3 {
color: #fff;
}
````
14 changes: 4 additions & 10 deletions components/carousel/demo/autoplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-carousel-autoplay',
Expand All @@ -7,7 +7,7 @@ import { Component, OnInit } from '@angular/core';
<div nz-carousel-content *ngFor="let index of array"><h3>{{index}}</h3></div>
</nz-carousel>`,
styles : [
`:host ::ng-deep .ant-carousel .slick-slide {
`[nz-carousel-content] {
text-align: center;
height: 160px;
line-height: 160px;
Expand All @@ -22,12 +22,6 @@ import { Component, OnInit } from '@angular/core';
`
]
})
export class NzDemoCarouselAutoplayComponent implements OnInit {
array = [ 1 ];

ngOnInit() {
setTimeout(_ => {
this.array = [ 1, 2, 3, 4 ];
}, 500);
}
export class NzDemoCarouselAutoplayComponent {
array = [ 1, 2, 3, 4 ];
}
31 changes: 0 additions & 31 deletions components/carousel/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,3 @@ title:

Basic usage.

````jsx
import { Carousel } from 'antd';

function onChange(a, b, c) {
console.log(a, b, c);
}

ReactDOM.render(
<Carousel afterChange={onChange}>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
<div><h3>4</h3></div>
</Carousel>
, mountNode);
````

````css
/* For demo */
.ant-carousel .slick-slide {
text-align: center;
height: 160px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}

.ant-carousel .slick-slide h3 {
color: #fff;
}
````
17 changes: 9 additions & 8 deletions components/carousel/demo/basic.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-carousel-basic',
template: `
<nz-carousel>
<nz-carousel [nzEffect]="effect">
<div nz-carousel-content *ngFor="let index of array"><h3>{{index}}</h3></div>
</nz-carousel>`,
styles : [
`:host ::ng-deep .ant-carousel .slick-slide {
`[nz-carousel-content] {
text-align: center;
height: 160px;
line-height: 160px;
Expand All @@ -22,12 +22,13 @@ import { Component, OnInit } from '@angular/core';
`
]
})
export class NzDemoCarouselBasicComponent implements OnInit {
array = [ 1, 2, 3 ];
export class NzDemoCarouselBasicComponent {
array = [ 1, 2, 3, 4 ];
effect = 'scrollx';

ngOnInit() {
setTimeout(_ => {
this.array = [ 1, 2, 3, 4 ];
}, 500);
setTimeout(() => {
this.effect = 'fade';
}, 3000);
}
}
28 changes: 0 additions & 28 deletions components/carousel/demo/fade.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,3 @@ title:
## en-US

Slides use fade for transition.

````jsx
import { Carousel } from 'antd';

ReactDOM.render(
<Carousel effect="fade">
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
<div><h3>4</h3></div>
</Carousel>
, mountNode);
````

````css
/* For demo */
.ant-carousel .slick-slide {
text-align: center;
height: 160px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}

.ant-carousel .slick-slide h3 {
color: #fff;
}
````
15 changes: 5 additions & 10 deletions components/carousel/demo/fade.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-carousel-fade',
Expand All @@ -7,26 +7,21 @@ import { Component, OnInit } from '@angular/core';
<div nz-carousel-content *ngFor="let index of array"><h3>{{index}}</h3></div>
</nz-carousel>`,
styles : [
`:host ::ng-deep .ant-carousel .slick-slide {
`[nz-carousel-content] {
text-align: center;
height: 160px;
line-height: 160px;
background: #364d79;
color: #fff;
overflow: hidden;
}
h3 {
color: #fff;
}
`
]
})
export class NzDemoCarouselFadeComponent implements OnInit {
array = [];

ngOnInit() {
setTimeout(_ => {
this.array = [ 1, 2, 3, 4 ];
}, 500);
}
export class NzDemoCarouselFadeComponent {
array = [ 1, 2, 3, 4 ];
}
26 changes: 0 additions & 26 deletions components/carousel/demo/vertical.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,4 @@ title:

Vertical pagination.

````jsx
import { Carousel } from 'antd';

ReactDOM.render(
<Carousel vertical>
<div><h3>1</h3></div>
<div><h3>2</h3></div>
<div><h3>3</h3></div>
<div><h3>4</h3></div>
</Carousel>
, mountNode);
````

````css
/* For demo */
.ant-carousel .slick-slide {
text-align: center;
height: 160px;
line-height: 160px;
background: #364d79;
overflow: hidden;
}

.ant-carousel .slick-slide h3 {
color: #fff;
}
````
14 changes: 4 additions & 10 deletions components/carousel/demo/vertical.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-carousel-vertical',
Expand All @@ -7,7 +7,7 @@ import { Component, OnInit } from '@angular/core';
<div nz-carousel-content *ngFor="let index of array"><h3>{{index}}</h3></div>
</nz-carousel>`,
styles : [
`:host ::ng-deep .ant-carousel .slick-slide {
`[nz-carousel-content] {
text-align: center;
height: 160px;
line-height: 160px;
Expand All @@ -22,12 +22,6 @@ import { Component, OnInit } from '@angular/core';
`
]
})
export class NzDemoCarouselVerticalComponent implements OnInit {
array = [ 1, 2, 3 ]; // try dynamic change the array

ngOnInit() {
setTimeout(() => {
this.array = [ 1, 2, 3, 4 ];
}, 500);
}
export class NzDemoCarouselVerticalComponent {
array = [ 1, 2, 3 ];
}
14 changes: 6 additions & 8 deletions components/carousel/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ A carousel component. Scales with its container.

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| afterChange | Callback function called after the current index changes | function(current) | - |
| autoplay | Whether to scroll automatically | boolean | `false` |
| beforeChange | Callback function called before the current index changes | function(from, to) | - |
| dots | Whether to show the dots at the bottom of the gallery | boolean | `true` |
| easing | Transition interpolation function name | string | `linear` |
| effect | Transition effect | `scrollx``fade` | `scrollx` |
| vertical | Whether to use a vertical display | boolean | `false` |
| nzAutoPlay | Whether to scroll automatically | boolean | `false` |
| nzAfterChange | Callback function called after the current index changes | function(current) | - |
| nzBeforeChange | Callback function called before the current index changes | function(from, to) | - |
| nzDots | Whether to show the dots at the bottom of the gallery | boolean | `true` |
| nzEffect | Transition effect | `scrollx``fade` | `scrollx` |
| nzVertical | Whether to use a vertical display | boolean | `false` |

## Methods

Expand All @@ -32,4 +31,3 @@ A carousel component. Scales with its container.
| next() | Change current slide to next slide |
| prev() | Change current slide to previous slide |

For more info on the parameters, refer to the <https://github.com/akiran/react-slick>
14 changes: 6 additions & 8 deletions components/carousel/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ subtitle: 走马灯

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| afterChange | 切换面板的回调 | function(current) ||
| autoplay | 是否自动切换 | boolean | false |
| beforeChange | 切换面板的回调 | function(from, to) ||
| dots | 是否显示面板指示点 | boolean | true |
| easing | 动画效果 | string | linear |
| effect | 动画效果函数,可取 scrollx, fade | string | scrollx |
| vertical | 垂直显示 | boolean | false |
| nzAutoPlay | 是否自动切换 | boolean | false |
| nzAfterChange | 切换面板的回调 | (current)=>{} ||
| nzBeforeChange | 切换面板的回调 | (from, to)=>{} ||
| nzDots | 是否显示面板指示点 | boolean | true |
| nzEffect | 动画效果函数,可取 scrollx, fade | string | scrollx |
| nzVertical | 垂直显示 | boolean | false |

## 方法

Expand All @@ -33,4 +32,3 @@ subtitle: 走马灯
| next() | 切换到下一面板 |
| prev() | 切换到上一面板 |

更多参数可参考:<https://github.com/akiran/react-slick>
1 change: 1 addition & 0 deletions components/carousel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
Loading

0 comments on commit 8aca820

Please sign in to comment.