Skip to content

Commit b342bb4

Browse files
authored
feat(module:cascader,date-picker,input-number,input,select,time-picker,tree-select): support nzVariant (#9131)
1 parent 0fb56ff commit b342bb4

64 files changed

Lines changed: 1178 additions & 458 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/cascader/cascader.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ import {
6464
NzSafeAny,
6565
NzSizeLDSType,
6666
NzStatus,
67-
NzValidateStatus
67+
NzValidateStatus,
68+
NzVariant
6869
} from 'ng-zorro-antd/core/types';
6970
import { fromEventOutsideAngular, getStatusClassNames, isNotNil, toArray } from 'ng-zorro-antd/core/util';
7071
import { NzEmptyModule } from 'ng-zorro-antd/empty';
@@ -268,6 +269,9 @@ const defaultDisplayRender = (labels: string[]): string => labels.join(' / ');
268269
'[class.ant-select-show-arrow]': 'nzShowArrow',
269270
'[class.ant-select-show-search]': '!!nzShowSearch',
270271
'[class.ant-select-disabled]': 'nzDisabled',
272+
'[class.ant-select-borderless]': `nzVariant === 'borderless'`,
273+
'[class.ant-select-filled]': `nzVariant === 'filled'`,
274+
'[class.ant-select-underlined]': `nzVariant === 'underlined'`,
271275
'[class.ant-select-open]': 'menuVisible',
272276
'[class.ant-select-focused]': 'isFocused',
273277
'[class.ant-select-multiple]': 'nzMultiple',
@@ -335,6 +339,7 @@ export class NzCascaderComponent
335339
@Input() nzValueProperty: string = 'value';
336340
@Input() nzLabelProperty: string = 'label';
337341
@Input() nzLabelRender: TemplateRef<typeof this.labelRenderContext> | null = null;
342+
@Input() @WithConfig() nzVariant: NzVariant = 'outlined';
338343
@Input() nzNotFoundContent?: string | TemplateRef<void>;
339344
@Input() @WithConfig() nzSize: NzCascaderSize = 'default';
340345
@Input() @WithConfig() nzBackdrop = false;

components/cascader/cascader.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
dispatchKeyboardEvent,
3737
dispatchMouseEvent
3838
} from 'ng-zorro-antd/core/testing';
39-
import { NzSafeAny, NzStatus } from 'ng-zorro-antd/core/types';
39+
import { NzSafeAny, NzStatus, NzVariant } from 'ng-zorro-antd/core/types';
4040
import { NzFormModule } from 'ng-zorro-antd/form';
4141
import { provideNzIconsTesting } from 'ng-zorro-antd/icon/testing';
4242
import { NzSelectItemComponent } from 'ng-zorro-antd/select';
@@ -227,6 +227,30 @@ describe('cascader', () => {
227227
expect(cascader.nativeElement.querySelector('.ant-select-clear')).toBeNull();
228228
});
229229

230+
describe('should variant works', () => {
231+
it('filled', () => {
232+
fixture.detectChanges();
233+
expect(cascader.nativeElement.classList).not.toContain('ant-select-filled');
234+
testComponent.nzVariant = 'filled';
235+
fixture.detectChanges();
236+
expect(cascader.nativeElement.classList).toContain('ant-select-filled');
237+
});
238+
it('borderless', () => {
239+
fixture.detectChanges();
240+
expect(cascader.nativeElement.classList).not.toContain('ant-select-borderless');
241+
testComponent.nzVariant = 'borderless';
242+
fixture.detectChanges();
243+
expect(cascader.nativeElement.classList).toContain('ant-select-borderless');
244+
});
245+
it('underlined', () => {
246+
fixture.detectChanges();
247+
expect(cascader.nativeElement.classList).not.toContain('ant-select-underlined');
248+
testComponent.nzVariant = 'underlined';
249+
fixture.detectChanges();
250+
expect(cascader.nativeElement.classList).toContain('ant-select-underlined');
251+
});
252+
});
253+
230254
it('should open work', () => {
231255
fixture.detectChanges();
232256
expect(cascader.nativeElement.classList).not.toContain('ant-select-open');
@@ -2408,6 +2432,7 @@ const options5: NzSafeAny[] = [];
24082432
[nzValueProperty]="nzValueProperty"
24092433
[nzBackdrop]="nzBackdrop"
24102434
[nzPlacement]="nzPlacement"
2435+
[nzVariant]="nzVariant"
24112436
(ngModelChange)="onValueChanges($event)"
24122437
(nzVisibleChange)="onVisibleChange($event)"
24132438
(nzClear)="onClear()"
@@ -2451,6 +2476,7 @@ export class NzDemoCascaderDefaultComponent {
24512476
nzExpandIcon = 'right';
24522477
nzBackdrop = false;
24532478
nzPlacement: NzCascaderPlacement = 'bottomLeft';
2479+
nzVariant: NzVariant = 'outlined';
24542480

24552481
onVisibleChange = jasmine.createSpy<(visible: boolean) => void>('open change');
24562482
onValueChanges = jasmine.createSpy('value change');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 21
3+
title:
4+
zh-CN: 形态变体
5+
en-US: Variants
6+
---
7+
8+
## zh-CN
9+
10+
Cascader 形态变体,可选 `outlined` `filled` `borderless` `underlined` 四种形态。
11+
12+
## en-US
13+
14+
Variants of Cascader, there are four variants: `outlined` `filled` `borderless` and `underlined`.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Component } from '@angular/core';
2+
3+
import { NzCascaderModule, NzCascaderOption } from 'ng-zorro-antd/cascader';
4+
import { NzSpaceModule } from 'ng-zorro-antd/space';
5+
6+
const options: NzCascaderOption[] = [
7+
{
8+
value: 'zhejiang',
9+
label: 'Zhejiang',
10+
children: [
11+
{
12+
value: 'hangzhou',
13+
label: 'Hangzhou',
14+
children: [
15+
{
16+
value: 'xihu',
17+
label: 'West Lake',
18+
isLeaf: true
19+
}
20+
]
21+
},
22+
{
23+
value: 'ningbo',
24+
label: 'Ningbo',
25+
isLeaf: true
26+
}
27+
]
28+
},
29+
{
30+
value: 'jiangsu',
31+
label: 'Jiangsu',
32+
children: [
33+
{
34+
value: 'nanjing',
35+
label: 'Nanjing',
36+
children: [
37+
{
38+
value: 'zhonghuamen',
39+
label: 'Zhong Hua Men',
40+
isLeaf: true
41+
}
42+
]
43+
}
44+
]
45+
}
46+
];
47+
48+
@Component({
49+
selector: 'nz-demo-cascader-variant',
50+
imports: [NzCascaderModule, NzSpaceModule],
51+
template: `
52+
<nz-space nzDirection="vertical" style="width: 100%">
53+
<nz-cascader *nzSpaceItem [nzOptions]="options" nzVariant="outlined" />
54+
<nz-cascader *nzSpaceItem [nzOptions]="options" nzVariant="filled" />
55+
<nz-cascader *nzSpaceItem [nzOptions]="options" nzVariant="borderless" />
56+
<nz-cascader *nzSpaceItem [nzOptions]="options" nzVariant="underlined" />
57+
</nz-space>
58+
`
59+
})
60+
export class NzDemoCascaderVariantComponent {
61+
protected readonly options = options;
62+
}

components/cascader/doc/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ description: Cascade selection box.
5454
| `[nzStatus]` | set validation status | `'error' \| 'warning'` | - |
5555
| `[nzSuffixIcon]` | custom suffix icon | `string\|TemplateRef<void>` | - |
5656
| `[nzValueProperty]` | value property name of options | `string` | `'value'` |
57+
| `[nzVariant]` | Variants of Cascader | `'outlined' \| 'borderless' \| 'filled' \| 'underlined'` | `outlined` ||
5758
| `(ngModelChange)` | emit on values change | `EventEmitter<any[]>` | - |
5859
| `(nzClear)` | emit on clear values | `EventEmitter<void>` | - |
5960
| `(nzVisibleChange)` | emit on popup menu visible or hide | `EventEmitter<boolean>` | - |

components/cascader/doc/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ description: 级联选择框。
5555
| `[nzStatus]` | 设置校验状态 | `'error' \| 'warning'` | - |
5656
| `[nzSuffixIcon]` | 自定义的选择框后缀图标 | `string \| TemplateRef<void>` | - |
5757
| `[nzValueProperty]` | 选项的实际值的属性名 | `string` | `'value'` |
58+
| `[nzVariant]` | 形态变体 | `'outlined' \| 'borderless' \| 'filled' \| 'underlined'` | `outlined` ||
5859
| `(ngModelChange)` | 值发生变化时触发 | `EventEmitter<any[]>` | - |
5960
| `(nzClear)` | 清除值时触发 | `EventEmitter<void>` | - |
6061
| `(nzVisibleChange)` | 菜单浮层的显示/隐藏 | `EventEmitter<boolean>` | - |

components/core/types/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export * from './convert-input';
1717
export * from './input-observable';
1818
export * from './type';
1919
export * from './status';
20+
export * from './variant';

components/core/types/variant.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
export type NzVariant = 'outlined' | 'filled' | 'borderless' | 'underlined';

components/core/util/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export * from './can-use-dom';
2323
export * from './dynamic-css';
2424
export * from './status-util';
2525
export * from './from-event-outside-angular';
26+
export * from './variant-utils';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 { NgClassInterface, NzVariant } from 'ng-zorro-antd/core/types';
7+
8+
export function getVariantClassNames(prefixCls: string, variant?: NzVariant, borderless?: boolean): NgClassInterface {
9+
return {
10+
[`${prefixCls}-borderless`]: variant === 'borderless' || (variant === 'outlined' && borderless),
11+
[`${prefixCls}-filled`]: variant === 'filled',
12+
[`${prefixCls}-underlined`]: variant === 'underlined'
13+
};
14+
}

0 commit comments

Comments
 (0)