Skip to content

Commit

Permalink
feat(module:space): add space compact component
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperLife1119 committed Sep 21, 2024
1 parent c64e1a1 commit 3c1cbd5
Show file tree
Hide file tree
Showing 27 changed files with 580 additions and 19 deletions.
3 changes: 3 additions & 0 deletions components/button/button-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { takeUntil } from 'rxjs/operators';

export type NzButtonGroupSize = 'large' | 'default' | 'small';

/**
* @deprecated Will be removed in v20. Use `NzSpaceCompactComponent` instead.
*/
@Component({
selector: 'nz-button-group',
exportAs: 'nzButtonGroup',
Expand Down
7 changes: 5 additions & 2 deletions components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { filter, startWith, takeUntil } from 'rxjs/operators';

import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { NzIconDirective, NzIconModule } from 'ng-zorro-antd/icon';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

export type NzButtonType = 'primary' | 'default' | 'dashed' | 'link' | 'text' | null;
export type NzButtonShape = 'circle' | 'round' | null;
Expand All @@ -37,6 +38,8 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'button';
@Component({
selector: 'button[nz-button], a[nz-button]',
exportAs: 'nzButton',
standalone: true,
imports: [NzIconModule],
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -67,8 +70,8 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'button';
'[attr.tabindex]': 'disabled ? -1 : (tabIndex === null ? null : tabIndex)',
'[attr.disabled]': 'disabled || null'
},
imports: [NzIconModule],
standalone: true
hostDirectives: [NzSpaceCompactItemDirective],
providers: [{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'btn' }]
})
export class NzButtonComponent implements OnDestroy, OnChanges, AfterViewInit, AfterContentInit, OnInit {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
Expand Down
4 changes: 4 additions & 0 deletions components/button/demo/button-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ title:

通过设置 `nzSize``large` `small` 分别把按钮组合设为大、小尺寸。若不设置 `nzSize`,则尺寸为中。

警告:在 v19.0.0 中被弃用,请使用 `<nz-space-compact>` 组件替代。

## en-US

Buttons can be grouped by placing multiple `nz-button` components into a `nz-button-group`.

The `nzSize` can be set to `large`, `small` or left unset resulting in a default size.

Warning: Deprecated in v19.0.0, use `<nz-space-compact>` instead.
3 changes: 3 additions & 0 deletions components/cascader/cascader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { getStatusClassNames, toArray } from 'ng-zorro-antd/core/util';
import { NzEmptyModule } from 'ng-zorro-antd/empty';
import { NzCascaderI18nInterface, NzI18nService } from 'ng-zorro-antd/i18n';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

import { NzCascaderOptionComponent } from './cascader-li.component';
import { NzCascaderService } from './cascader.service';
Expand Down Expand Up @@ -217,6 +218,7 @@ const defaultDisplayRender = (labels: string[]): string => labels.join(' / ');
useExisting: forwardRef(() => NzCascaderComponent),
multi: true
},
{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'select' },
NzCascaderService,
NzDestroyService
],
Expand All @@ -234,6 +236,7 @@ const defaultDisplayRender = (labels: string[]): string => labels.join(' / ');
'[class.ant-select-single]': 'true',
'[class.ant-select-rtl]': `dir === 'rtl'`
},
hostDirectives: [NzSpaceCompactItemDirective],
imports: [
OverlayModule,
FormsModule,
Expand Down
1 change: 1 addition & 0 deletions components/core/types/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

// TODO: replace other size with this type.
export type NzSizeLDSType = 'large' | 'default' | 'small';
export type NzSizeLMSType = 'large' | 'middle' | 'small';
export type NzSizeMDSType = 'middle' | 'default' | 'small';
export type NzSizeDSType = 'default' | 'small';
3 changes: 3 additions & 0 deletions components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
NzI18nService
} from 'ng-zorro-antd/i18n';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

import { DatePickerService } from './date-picker.service';
import { DateRangePopupComponent } from './date-range-popup.component';
Expand Down Expand Up @@ -249,9 +250,11 @@ export type NzPlacement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
'[class.ant-picker-inline]': `nzInline`,
'(click)': 'onClickInputBox($event)'
},
hostDirectives: [NzSpaceCompactItemDirective],
providers: [
NzDestroyService,
DatePickerService,
{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'picker' },
{
provide: NG_VALUE_ACCESSOR,
multi: true,
Expand Down
5 changes: 4 additions & 1 deletion components/input-number/input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
} from 'ng-zorro-antd/core/types';
import { getStatusClassNames, isNotNil } from 'ng-zorro-antd/core/util';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

@Component({
selector: 'nz-input-number',
Expand Down Expand Up @@ -97,6 +98,7 @@ import { NzIconModule } from 'ng-zorro-antd/icon';
useExisting: forwardRef(() => NzInputNumberComponent),
multi: true
},
{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'input-number' },
NzDestroyService
],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -113,7 +115,8 @@ import { NzIconModule } from 'ng-zorro-antd/icon';
'[class.ant-input-number-borderless]': `nzBorderless`
},
imports: [NzIconModule, FormsModule, NzFormPatchModule],
standalone: true
standalone: true,
hostDirectives: [NzSpaceCompactItemDirective]
})
export class NzInputNumberComponent implements ControlValueAccessor, AfterViewInit, OnChanges, OnInit, OnDestroy {
private autoStepTimer?: ReturnType<typeof setTimeout>;
Expand Down
5 changes: 4 additions & 1 deletion components/input/input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
import { NzFormItemFeedbackIconComponent, NzFormNoStatusService, NzFormStatusService } from 'ng-zorro-antd/core/form';
import { NgClassInterface, NzSizeLDSType, NzStatus, NzValidateStatus } from 'ng-zorro-antd/core/types';
import { getStatusClassNames } from 'ng-zorro-antd/core/util';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

@Directive({
selector: 'input[nz-input],textarea[nz-input]',
Expand All @@ -39,7 +40,9 @@ import { getStatusClassNames } from 'ng-zorro-antd/core/util';
'[class.ant-input-rtl]': `dir=== 'rtl'`,
'[class.ant-input-stepperless]': `nzStepperless`
},
standalone: true
standalone: true,
hostDirectives: [NzSpaceCompactItemDirective],
providers: [{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'input' }]
})
export class NzInputDirective implements OnChanges, OnInit, OnDestroy {
@Input({ transform: booleanAttribute }) nzBorderless = false;
Expand Down
5 changes: 4 additions & 1 deletion components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
OnTouchedType
} from 'ng-zorro-antd/core/types';
import { getStatusClassNames, isNotNil } from 'ng-zorro-antd/core/util';
import { NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';

import { NzOptionContainerComponent } from './option-container.component';
import { NzOptionGroupComponent } from './option-group.component';
Expand Down Expand Up @@ -95,7 +96,8 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NzSelectComponent),
multi: true
}
},
{ provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'select' }
],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -204,6 +206,7 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
'[class.ant-select-multiple]': `nzMode !== 'default'`,
'[class.ant-select-rtl]': `dir === 'rtl'`
},
hostDirectives: [NzSpaceCompactItemDirective],
imports: [
NzSelectTopControlComponent,
CdkOverlayOrigin,
Expand Down
14 changes: 14 additions & 0 deletions components/space/demo/compact-button-vertical.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 8
title:
zh-CN: 垂直方向紧凑布局
en-US: Vertical Compact Mode
---

## zh-CN

垂直方向的紧凑布局,目前仅支持 Button 组合。

## en-US

Vertical Mode for Space.Compact, support Button only.
25 changes: 25 additions & 0 deletions components/space/demo/compact-button-vertical.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-space-compact-button-vertical',
template: `
<nz-space>
<nz-space-compact *nzSpaceItem nzDirection="vertical">
<button nz-button>Button 1</button>
<button nz-button>Button 2</button>
<button nz-button>Button 3</button>
</nz-space-compact>
<nz-space-compact *nzSpaceItem nzDirection="vertical">
<button nz-button nzType="dashed">Button 1</button>
<button nz-button nzType="dashed">Button 2</button>
<button nz-button nzType="dashed">Button 3</button>
</nz-space-compact>
<nz-space-compact *nzSpaceItem nzDirection="vertical">
<button nz-button nzType="primary">Button 1</button>
<button nz-button nzType="primary">Button 2</button>
<button nz-button nzType="primary">Button 3</button>
</nz-space-compact>
</nz-space>
`
})
export class NzDemoSpaceCompactButtonVerticalComponent {}
14 changes: 14 additions & 0 deletions components/space/demo/compact-buttons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 7
title:
zh-CN: Button 紧凑布局
en-US: Button Compact Mode
---

## zh-CN

Button 组件紧凑排列的示例。

## en-US

Button component compact example.
86 changes: 86 additions & 0 deletions components/space/demo/compact-buttons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-space-compact-buttons',
template: `
<nz-space-compact nzBlock>
<button nz-button nz-tooltip nzTooltipTitle="Like">
<span nz-icon nzType="like"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Comment">
<span nz-icon nzType="comment"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Star">
<span nz-icon nzType="star"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Heart">
<span nz-icon nzType="heart"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Share">
<span nz-icon nzType="share-alt"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Download">
<span nz-icon nzType="download"></span>
</button>
<nz-dropdown-menu #menu>
<ul nz-menu>
<li nz-menu-item>
<a>1st item</a>
</li>
<li nz-menu-item>
<a>2nd item</a>
</li>
<li nz-menu-item>
<a>3rd item</a>
</li>
</ul>
</nz-dropdown-menu>
<button nz-button nz-dropdown [nzDropdownMenu]="menu">
<span nz-icon nzType="ellipsis"></span>
</button>
</nz-space-compact>
<br />
<nz-space-compact nzBlock>
<button nz-button nzType="primary">Button 1</button>
<button nz-button nzType="primary">Button 2</button>
<button nz-button nzType="primary">Button 3</button>
<button nz-button nzType="primary">Button 4</button>
<button nz-button nzType="primary" disabled nz-tooltip nzTooltipTitle="Tooltip">
<span nz-icon nzType="download"></span>
</button>
<button nz-button nzType="primary" nz-tooltip nzTooltipTitle="Tooltip">
<span nz-icon nzType="download"></span>
</button>
</nz-space-compact>
<br />
<nz-space-compact nzBlock>
<button nz-button>Button 1</button>
<button nz-button>Button 2</button>
<button nz-button>Button 3</button>
<button nz-button disabled nz-tooltip nzTooltipTitle="Tooltip">
<span nz-icon nzType="download"></span>
</button>
<button nz-button nz-tooltip nzTooltipTitle="Tooltip">
<span nz-icon nzType="download"></span>
</button>
<button nz-button nzType="primary">Button 4</button>
<nz-dropdown-menu #menu>
<ul nz-menu>
<li nz-menu-item>
<a>1st item</a>
</li>
<li nz-menu-item>
<a>2nd item</a>
</li>
<li nz-menu-item>
<a>3rd item</a>
</li>
</ul>
</nz-dropdown-menu>
<button nz-button nzType="primary" nz-dropdown [nzDropdownMenu]="menu">
<span nz-icon nzType="ellipsis"></span>
</button>
</nz-space-compact>
`
})
export class NzDemoSpaceCompactButtonsComponent {}
14 changes: 14 additions & 0 deletions components/space/demo/compact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 6
title:
zh-CN: 紧凑布局组合
en-US: Compact Mode
---

## zh-CN

使用 `<nz-space-compact>` 让表单组件之间紧凑连接且合并边框。

## en-US

Compact Mode for form component.
Loading

0 comments on commit 3c1cbd5

Please sign in to comment.