Skip to content

Commit 95a31da

Browse files
author
hullis
authored
feat(module:segmented): implement new component (#7404)
* feat(module:segmented): implement new component * test: add test for segmented component * chore: code update * fix: fix doc * feat: add dark mode theme * fix: fix export * fix: fix import
1 parent 8c38518 commit 95a31da

39 files changed

Lines changed: 1021 additions & 0 deletions

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ components/statistic/** @hullis
3737
components/timeline/** @hullis
3838
components/tooltip/** @hullis
3939
components/code-editor/** @hullis
40+
components/segmented/** @hullis
4041
components/calendar/** @wenqi73
4142
components/date-picker/** @wenqi73
4243
components/skeleton/** @wenqi73

components/components.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
@import "./radio/style/entry.less";
3838
@import "./rate/style/entry.less";
3939
@import "./select/style/entry.less";
40+
@import "./segmented/style/index.less";
4041
@import "./skeleton/style/entry.less";
4142
@import "./slider/style/entry.less";
4243
@import "./spin/style/entry.less";

components/core/animation/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './move';
1111
export * from './notification';
1212
export * from './slide';
1313
export * from './zoom';
14+
export * from './thumb';

components/core/animation/thumb.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Use of this source code is governed by an MIT-style license that can be
3+
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
4+
*/
5+
6+
import { animate, AnimationTriggerMetadata, state, style, transition, trigger } from '@angular/animations';
7+
8+
import { AnimationCurves } from './animation-consts';
9+
10+
/**
11+
* a move and resize transition in the horizontal direction
12+
*/
13+
export interface ThumbAnimationProps {
14+
transform: number;
15+
width: number;
16+
}
17+
18+
export const thumbMotion: AnimationTriggerMetadata = trigger('thumbMotion', [
19+
state('from', style({ transform: 'translateX({{ transform }}px)', width: '{{ width }}px' }), {
20+
params: { transform: 0, width: 0 }
21+
}),
22+
23+
state('to', style({ transform: 'translateX({{ transform }}px)', width: '{{ width }}px' }), {
24+
params: { transform: 100, width: 0 }
25+
}),
26+
27+
transition('from => to', animate(`300ms ${AnimationCurves.EASE_IN_OUT}`))
28+
]);

components/core/config/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface NzConfig {
5656
pagination?: PaginationConfig;
5757
progress?: ProgressConfig;
5858
rate?: RateConfig;
59+
segmented?: SegmentedConfig;
5960
space?: SpaceConfig;
6061
spin?: SpinConfig;
6162
switch?: SwitchConfig;
@@ -252,6 +253,10 @@ export interface RateConfig {
252253
nzAllowHalf?: boolean;
253254
}
254255

256+
export interface SegmentedConfig {
257+
nzSize?: NzSizeLDSType;
258+
}
259+
255260
export interface SpaceConfig {
256261
nzSize?: 'small' | 'middle' | 'large' | number;
257262
}

components/segmented/demo/basic.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
order: 0
3+
title:
4+
zh-CN: 基本
5+
en-US: Basic usage
6+
---
7+
8+
## zh-CN
9+
10+
最简单的用法。
11+
12+
## en-US
13+
14+
Basic Usage.
15+

components/segmented/demo/basic.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-segmented-basic',
5+
template: `<nz-segmented [nzOptions]="options" (nzValueChange)="handleIndexChange($event)"></nz-segmented>`,
6+
styles: [
7+
`
8+
.code-box-demo {
9+
overflow-x: auto;
10+
}
11+
12+
.code-box-demo .ant-segmented {
13+
margin-bottom: 10px;
14+
}
15+
`
16+
]
17+
})
18+
export class NzDemoSegmentedBasicComponent {
19+
options = ['Daily', 'Weekly', 'Monthly', 'Quarterly', 'Yearly'];
20+
21+
handleIndexChange(e: number): void {
22+
console.log(e);
23+
}
24+
}

components/segmented/demo/block.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 10
3+
title:
4+
zh-CN: Block 分段选择器
5+
en-US: Block Segmented
6+
---
7+
8+
## zh-CN
9+
10+
`nzBlock` 属性使其适合父元素宽度。
11+
12+
## en-US
13+
14+
`nzBlock` property will make the `Segmented` fit to its parent width.

components/segmented/demo/block.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'nz-demo-segmented-block',
5+
template: `<nz-segmented [nzOptions]="options" [nzBlock]="true"></nz-segmented>`,
6+
styles: [
7+
`
8+
.code-box-demo {
9+
overflow-x: auto;
10+
}
11+
12+
.code-box-demo .ant-segmented {
13+
margin-bottom: 10px;
14+
}
15+
`
16+
]
17+
})
18+
export class NzDemoSegmentedBlockComponent {
19+
options = ['Daily', 'Weekly', 'Monthly', 'Quarterly', 'Yearly'];
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 1
3+
title:
4+
zh-CN: 自定义渲染
5+
en-US: Custom Render
6+
---
7+
8+
## zh-CN
9+
10+
使用 nzLabelTemplate 自定义渲染每一个 Segmented Item。
11+
12+
## en-US
13+
14+
Custom each Segmented Item by nzLabelTemplate.

0 commit comments

Comments
 (0)