Skip to content

Commit

Permalink
feat(module:statistic): add statistic and countdown component (#2760)
Browse files Browse the repository at this point in the history
* feat(module:statistic): add statistic and countdown component

* fix: time range handle undefined value
  • Loading branch information
Wendell authored and vthinkxie committed Feb 25, 2019
1 parent 1d68e44 commit abb9ae4
Show file tree
Hide file tree
Showing 33 changed files with 838 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/components.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@import "./skeleton/style/index.less";
@import "./slider/style/index.less";
@import "./spin/style/index.less";
@import "./statistic/style/index.less";
@import "./steps/style/index.less";
@import "./switch/style/index.less";
@import "./table/style/index.less";
Expand Down
2 changes: 2 additions & 0 deletions components/core/util/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export * from './check';
export * from './convert';
export * from './getMentions';
export * from './nz-global-monitor';
export * from './string';
export * from './textarea-caret-position';
export * from './throttleByAnimationFrame';
export * from './time';
20 changes: 20 additions & 0 deletions components/core/util/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Much like lodash.
*/
export function padStart(toPad: string, length: number, element: string): string {
if (toPad.length > length) {
return toPad;
}

const joined = `${getRepeatedElement(length, element)}${toPad}`;
return joined.slice(joined.length - length, joined.length);
}

export function padEnd(toPad: string, length: number, element: string): string {
const joined = `${toPad}${getRepeatedElement(length, element)}`;
return joined.slice(0, length);
}

export function getRepeatedElement(length: number, element: string): string {
return Array(length).fill(element).join('');
}
9 changes: 9 additions & 0 deletions components/core/util/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const timeUnits: Array<[ string, number ]> = [
[ 'Y', 1000 * 60 * 60 * 24 * 365 ], // years
[ 'M', 1000 * 60 * 60 * 24 * 30 ], // months
[ 'D', 1000 * 60 * 60 * 24 ], // days
[ 'H', 1000 * 60 * 60 ], // hours
[ 'm', 1000 * 60 ], // minutes
[ 's', 1000 ], // seconds
[ 'S', 1 ] // million seconds
];
3 changes: 0 additions & 3 deletions components/icon/nz-icon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ export interface NzIconfontOption {
}

export const NZ_ICONS = new InjectionToken('nz_icons');

export const NZ_ICON_DEFAULT_TWOTONE_COLOR = new InjectionToken('nz_icon_default_twotone_color');

export const DEFAULT_TWOTONE_COLOR = '#1890ff';

export const NZ_ICONS_USED_BY_ZORRO: IconDefinition[] = [
BarsOutline,
CalendarOutline,
Expand Down
3 changes: 3 additions & 0 deletions components/ng-zorro-antd.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { NzSelectModule } from './select/nz-select.module';
import { NzSkeletonModule } from './skeleton/nz-skeleton.module';
import { NzSliderModule } from './slider/nz-slider.module';
import { NzSpinModule } from './spin/nz-spin.module';
import { NzStatisticModule } from './statistic/nz-statistic.module';
import { NzStepsModule } from './steps/nz-steps.module';
import { NzSwitchModule } from './switch/nz-switch.module';
import { NzTableModule } from './table/nz-table.module';
Expand Down Expand Up @@ -94,6 +95,7 @@ export * from './radio';
export * from './rate';
export * from './select';
export * from './spin';
export * from './statistic';
export * from './steps';
export * from './switch';
export * from './table';
Expand Down Expand Up @@ -178,6 +180,7 @@ export * from './core/util';
NzTimePickerModule,
NzWaveModule,
NzSkeletonModule,
NzStatisticModule,
NzEmptyModule
]
})
Expand Down
2 changes: 1 addition & 1 deletion components/spin/demo/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
order: 0
title:
zh-CN: 基本用法
en-US: basic Usage
en-US: Basic Usage
---

## zh-CN
Expand Down
14 changes: 14 additions & 0 deletions components/statistic/demo/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 0
title:
zh-CN: 基本用法
en-US: Basic Usage
---

## zh-CN

简单的展示。

## en-US

Simplest Usage.
17 changes: 17 additions & 0 deletions components/statistic/demo/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-statistic-basic',
template: `
<nz-row [nzGutter]="16">
<nz-col [nzSpan]="12">
<nz-statistic [nzValue]="1949101 | number" [nzTitle]="'Active Users'"></nz-statistic>
</nz-col>
<nz-col [nzSpan]="12">
<nz-statistic [nzValue]="2019.111 | number: '1.0-2' " [nzTitle]="'Account Balance (CNY)'"></nz-statistic>
</nz-col>
</nz-row>
`
})
export class NzDemoStatisticBasicComponent {
}
14 changes: 14 additions & 0 deletions components/statistic/demo/card.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 2
title:
zh-CN: 在卡片中使用
en-US: In Card
---

## zh-CN

在卡片中展示统计数值。

## en-US

Display statistic data in Card.
37 changes: 37 additions & 0 deletions components/statistic/demo/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-statistic-card',
template: `
<div style="background: #ECECEC; padding: 30px;">
<nz-row [nzGutter]="16">
<nz-col [nzSpan]="12">
<nz-card>
<nz-statistic
[nzValue]="11.28 | number: '1.0-2'"
[nzTitle]="'Active'"
[nzPrefix]="prefixTplOne"
[nzSuffix]="'%'"
[nzValueStyle]="{ color: '#3F8600' }">
</nz-statistic>
<ng-template #prefixTplOne><i nz-icon type="arrow-up"></i></ng-template>
</nz-card>
</nz-col>
<nz-col [nzSpan]="12">
<nz-card>
<nz-statistic
[nzValue]="9.3 | number: '1.0-2'"
[nzTitle]="'Idle'"
[nzPrefix]="prefixTplTwo"
[nzSuffix]="'%'"
[nzValueStyle]="{ color: '#CF1322' }">
</nz-statistic>
<ng-template #prefixTplTwo><i nz-icon type="arrow-down"></i></ng-template>
</nz-card>
</nz-col>
</nz-row>
</div>
`
})
export class NzDemoStatisticCardComponent {
}
14 changes: 14 additions & 0 deletions components/statistic/demo/countdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 3
title:
zh-CN: 倒计时
en-US: Countdown
---

## zh-CN

倒计时组件。

## en-US

Countdown component.
21 changes: 21 additions & 0 deletions components/statistic/demo/countdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-statistic-countdown',
template: `
<nz-row [nzGutter]="16">
<nz-col [nzSpan]="12">
<nz-countdown [nzValue]="deadline" [nzTitle]="'Countdown'"></nz-countdown>
</nz-col>
<nz-col [nzSpan]="12">
<nz-countdown [nzValue]="deadline" [nzTitle]="'Million Seconds'" [nzFormat]="'HH:mm:ss:SSS'"></nz-countdown>
</nz-col>
<nz-col [nzSpan]="24" style="margin-top: 32px;">
<nz-countdown [nzValue]="deadline" [nzTitle]="'Day Level'" [nzFormat]="'D 天 H 时 m 分 s 秒'"></nz-countdown>
</nz-col>
</nz-row>
`
})
export class NzDemoStatisticCountdownComponent {
deadline = Date.now() + 1000 * 60 * 60 * 24 * 2 + 1000 * 30;
}
14 changes: 14 additions & 0 deletions components/statistic/demo/unit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 1
title:
zh-CN: 单位
en-US: Unit
---

## zh-CN

通过前缀和后缀添加单位。

## en-US

Add unit through `nzPrefix` and `nzSuffix`.
18 changes: 18 additions & 0 deletions components/statistic/demo/unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-statistic-unit',
template: `
<nz-row [nzGutter]="16">
<nz-col [nzSpan]="12">
<nz-statistic [nzValue]="1128 | number" [nzTitle]="'Feedback'" [nzPrefix]="prefixTpl"></nz-statistic>
<ng-template #prefixTpl><i nz-icon type="like"></i></ng-template>
</nz-col>
<nz-col [nzSpan]="12">
<nz-statistic [nzValue]="93" [nzTitle]="'Unmerged'" [nzSuffix]="'/ 100'"></nz-statistic>
</nz-col>
</nz-row>
`
})
export class NzDemoStatisticUnitComponent {
}
48 changes: 48 additions & 0 deletions components/statistic/doc/index.en-US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
category: Components
type: Data Display
title: Statistic
---

Display statistic number.

## When To Use

- When want to highlight some data.
- When want to display statistic data with description.

## API

### nz-statistic

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| `[nzPrefix]` | Prefix of Value | `string|TemplateRef<void>` | - |
| `[nzSuffix]` | Suffix of Value | `string|TemplateRef<void>` | - |
| `[nzTitle]` | Title | `string|TemplateRef<void>` | - |
| `[nzValue]` | Value | `string|number` | - |
| `[nzValueStyle]` | Value CSS style | `Object` | - |
| `[nzValueTemplate]` | Custom template to render a number | `TemplateRef<{ $implicit: string|number }>` | - |

### nz-countdown

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| `[nzFormat]` | Format string | `string` | `"HH:mm:ss"` |
| `[nzPrefix]` | Prefix of Value | `string|TemplateRef<void>` | - |
| `[nzSuffix]` | Suffix of Value | `string|TemplateRef<void>` | - |
| `[nzTitle]` | Title | `string|TemplateRef<void>` | - |
| `[nzValue]` | Target time in timestamp form | `string|number` | - |
| `[nzValueTemplate]` | Custom template to render a time | `TemplateRef<{ $implicit: number }>` | - |

### nzFormat

| Token | Description |
| -------- | ----------- |
| `Y` | Year |
| `M` | Month |
| `D` | Date |
| `H` | Hour |
| `m` | Minute |
| `s` | Second |
| `S` | Millisecond |
49 changes: 49 additions & 0 deletions components/statistic/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
category: Components
title: Statistic
subtitle: 统计
type: Data Display
---

展示统计数字。

## 何时使用

- 当需要突出某个或某组数字时。
- 当需要展示带描述的统计类数据时使用。

## API

### nz-statistic

| 参数 | 说明 | 类型 | 默认值 |
| -------- | ----------- | ---- | ------- |
| `[nzPrefix]` | 设置数值的前缀 | `string|TemplateRef<void>` | - |
| `[nzSuffix]` | 设置数值的后缀 | `string|TemplateRef<void>` | - |
| `[nzTitle]` | 数值的标题 | `string|TemplateRef<void>` | - |
| `[nzValue]` | 数值内容 | `string|number` | - |
| `[nzValueStyle]` | 设置数值的样式 | `Object` | - |
| `[nzValueTemplate]` | 自定义数值展示 | `TemplateRef<{ $implicit: string|number }>` | - |

### nz-countdown

| 参数 | 说明 | 类型 | 默认值 |
| -------- | ----------- | ---- | ------- |
| `[nzFormat]` | 格式化倒计时展示 | `string` | `"HH:mm:ss"` |
| `[nzPrefix]` | 设置数值的前缀 | `string|TemplateRef<void>` | - |
| `[nzSuffix]` | 设置数值的后缀 | `string|TemplateRef<void>` | - |
| `[nzTitle]` | 数值的标题 | `string|TemplateRef<void>` | - |
| `[nzValue]` | 时间戳格式的目标时间 | `string|number` | - |
| `[nzValueTemplate]` | 自定义时间展示 | `TemplateRef<{ $implicit: number }>` | - |

### nzFormat

| 占位符 | 描述 |
| -------- | ----------- |
| `Y` ||
| `M` ||
| `D` ||
| `H` ||
| `m` ||
| `s` ||
| `S` | 毫秒 |
1 change: 1 addition & 0 deletions components/statistic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public-api';
10 changes: 10 additions & 0 deletions components/statistic/nz-countdown.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<nz-statistic
[nzValue]="diff"
[nzValueStyle]="nzValueStyle"
[nzValueTemplate]="nzValueTemplate || countDownTpl"
[nzTitle]="nzTitle"
[nzPrefix]="nzPrefix"
[nzSuffix]="nzSuffix">
</nz-statistic>

<ng-template #countDownTpl>{{ diff | nzTimeRange: nzFormat }}</ng-template>
Loading

0 comments on commit abb9ae4

Please sign in to comment.