Skip to content

Commit 1f54536

Browse files
authored
feat(module:divider): support nzSize (#9346)
1 parent d878658 commit 1f54536

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

components/divider/demo/size.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
order: 5
3+
title:
4+
zh-CN: 分割线大小
5+
en-US: Size
6+
---
7+
8+
## zh-CN
9+
10+
通过 `nzSize` 设置分割线的大小。
11+
12+
## en-US
13+
14+
Divider support `nzSize` to set the size of Divider.

components/divider/demo/size.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Component } from '@angular/core';
2+
3+
import { NzDividerModule } from 'ng-zorro-antd/divider';
4+
import { NzIconModule } from 'ng-zorro-antd/icon';
5+
6+
@Component({
7+
selector: 'nz-demo-divider-size',
8+
imports: [NzDividerModule, NzIconModule],
9+
template: `
10+
<div>
11+
<p>
12+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae
13+
sunt a te dicta? Refert tamen, quo modo.
14+
</p>
15+
<nz-divider nzSize="small" />
16+
<p>
17+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae
18+
sunt a te dicta? Refert tamen, quo modo.
19+
</p>
20+
<nz-divider nzSize="middle" />
21+
<p>
22+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae
23+
sunt a te dicta? Refert tamen, quo modo.
24+
</p>
25+
<nz-divider nzSize="large" />
26+
<p>
27+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nonne merninisti licere mihi ista probare, quae
28+
sunt a te dicta? Refert tamen, quo modo.
29+
</p>
30+
</div>
31+
`
32+
})
33+
export class NzDemoDividerSizeComponent {}

components/divider/divider.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@angular/core';
1414

1515
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
16+
import type { NzSizeLMSType } from 'ng-zorro-antd/core/types';
1617

1718
@Component({
1819
selector: 'nz-divider',
@@ -36,7 +37,9 @@ import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
3637
'[class.ant-divider-with-text-right]': `nzText && nzOrientation === 'right'`,
3738
'[class.ant-divider-with-text-center]': `nzText && nzOrientation === 'center'`,
3839
'[class.ant-divider-dashed]': `nzDashed || nzVariant === 'dashed'`,
39-
'[class.ant-divider-dotted]': `nzVariant === 'dotted'`
40+
'[class.ant-divider-dotted]': `nzVariant === 'dotted'`,
41+
'[class.ant-divider-sm]': `nzSize === 'small'`,
42+
'[class.ant-divider-md]': `nzSize === 'middle'`
4043
},
4144
imports: [NzOutletModule]
4245
})
@@ -45,6 +48,7 @@ export class NzDividerComponent {
4548
@Input() nzType: 'horizontal' | 'vertical' = 'horizontal';
4649
@Input() nzOrientation: 'left' | 'right' | 'center' = 'center';
4750
@Input() nzVariant: 'dashed' | 'dotted' | 'solid' = 'solid';
51+
@Input() nzSize: NzSizeLMSType | undefined;
4852
@Input({ transform: booleanAttribute }) nzDashed = false;
4953
@Input({ transform: booleanAttribute }) nzPlain = false;
5054
}

components/divider/divider.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,52 @@ describe('divider', () => {
9090
expect(context.comp.nzVariant).toEqual('solid');
9191
});
9292
});
93+
94+
describe('#nzPlain', () => {
95+
for (const value of [true, false]) {
96+
it(`[${value}]`, () => {
97+
context.comp.nzPlain = value;
98+
fixture.detectChanges();
99+
expect(dl.query(By.css('.ant-divider-plain')) != null).toBe(value);
100+
});
101+
}
102+
});
103+
104+
describe('#nzSize', () => {
105+
it('should not have size class by default', () => {
106+
fixture.detectChanges();
107+
const el = dl.query(By.css('.ant-divider'))!.nativeElement as HTMLElement;
108+
expect(el.classList.contains('ant-divider-sm')).toBe(false);
109+
expect(el.classList.contains('ant-divider-md')).toBe(false);
110+
expect(el.classList.contains('ant-divider-lg')).toBe(false);
111+
});
112+
113+
(['small', 'middle', 'large'] as const).forEach(size => {
114+
it(`with ${size}`, () => {
115+
context.comp.nzSize = size;
116+
fixture.detectChanges();
117+
const el = dl.query(By.css('.ant-divider'))!.nativeElement as HTMLElement;
118+
expect(el.classList.contains('ant-divider-sm')).toBe(size === 'small');
119+
expect(el.classList.contains('ant-divider-md')).toBe(size === 'middle');
120+
// Large size does not have a specific class; ensure no lg class is added
121+
expect(el.classList.contains('ant-divider-lg')).toBe(false);
122+
});
123+
});
124+
});
125+
126+
describe('#with text class', () => {
127+
it('should have ant-divider-with-text when nzText set', () => {
128+
context.nzText = 'text';
129+
fixture.detectChanges();
130+
expect(dl.query(By.css('.ant-divider-with-text')) != null).toBe(true);
131+
});
132+
133+
it('should not have ant-divider-with-text when nzText removed', () => {
134+
context.nzText = undefined;
135+
fixture.detectChanges();
136+
expect(dl.query(By.css('.ant-divider-with-text')) == null).toBe(true);
137+
});
138+
});
93139
});
94140

95141
@Component({

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ description: A divider line separates different content.
2323
| `[nzPlain]` | Divider text show as plain style | `boolean` | `false` |
2424
| `[nzOrientation]` | inner text orientation | `'center' \| 'left' \| 'right'` | `'center'` |
2525
| `[nzVariant]` | Whether line is dashed, dotted or solid | `'dashed' \| 'dotted' \| 'solid'` | `'solid'` |
26+
| `[nzSize]` | Divider size | `'small' \| 'middle' \| 'large'` | - |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ description: 区隔内容的分割线。
2424
| `[nzPlain]` | 文字是否显示为普通正文样式 | `boolean` | `false` |
2525
| `[nzOrientation]` | 中间文字方向 | `'center' \| 'left' \| 'right'` | `'center'` |
2626
| `[nzVariant]` | 分割线是虚线、点线还是实线 | `'dashed' \| 'dotted' \| 'solid'` | `'solid'` |
27+
| `[nzSize]` | 分割线大小 | `'small' \| 'middle' \| 'large'` | - |

components/divider/style/patch.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import '../../style/themes/index';
2+
13
.@{divider-prefix-cls} {
24
&-dotted {
35
background: none;
@@ -16,4 +18,12 @@
1618
&-vertical&-dotted {
1719
border-width: 0 0 0 @border-width-base;
1820
}
21+
22+
&-sm {
23+
margin-block: @margin-xs;
24+
}
25+
26+
&-md {
27+
margin-block: @margin-md;
28+
}
1929
}

0 commit comments

Comments
 (0)