Skip to content

Commit

Permalink
feat(module:select): support standalone component (#8222)
Browse files Browse the repository at this point in the history
* feat(module:select): support standalone component

* feat(module:select): support standalone component

* feat(module:select): support standalone component
  • Loading branch information
ParsaArvanehPA authored Dec 5, 2023
1 parent e4244fb commit ed0de77
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 186 deletions.
128 changes: 64 additions & 64 deletions components/select/doc/index.en-US.md

Large diffs are not rendered by default.

138 changes: 68 additions & 70 deletions components/select/doc/index.zh-CN.md

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions components/select/option-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { OverlayModule } from '@angular/cdk/overlay';
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
import { isPlatformBrowser } from '@angular/common';
import { isPlatformBrowser, NgIf, NgSwitch, NgSwitchCase, NgTemplateOutlet } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
EventEmitter,
inject,
Input,
NgZone,
OnChanges,
Expand All @@ -18,12 +20,15 @@ import {
SimpleChanges,
TemplateRef,
ViewChild,
ViewEncapsulation,
inject
ViewEncapsulation
} from '@angular/core';

import { NzOverlayModule } from 'ng-zorro-antd/core/overlay';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzEmptyModule } from 'ng-zorro-antd/empty';

import { NzOptionItemGroupComponent } from './option-item-group.component';
import { NzOptionItemComponent } from './option-item.component';
import { NzSelectItemInterface, NzSelectModeType } from './select.types';

@Component({
Expand Down Expand Up @@ -78,7 +83,19 @@ import { NzSelectItemInterface, NzSelectModeType } from './select.types';
<ng-template [ngTemplateOutlet]="dropdownRender"></ng-template>
</div>
`,
host: { class: 'ant-select-dropdown' }
host: { class: 'ant-select-dropdown' },
imports: [
NzEmptyModule,
NgIf,
NgSwitch,
NzOptionItemGroupComponent,
NgSwitchCase,
NzOptionItemComponent,
NgTemplateOutlet,
OverlayModule,
NzOverlayModule
],
standalone: true
})
export class NzOptionContainerComponent implements OnChanges, AfterViewInit {
@Input() notFoundContent: string | TemplateRef<NzSafeAny> | undefined = undefined;
Expand Down
3 changes: 2 additions & 1 deletion components/select/option-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
exportAs: 'nzOptionGroup',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
template: ` <ng-content></ng-content> `
template: ` <ng-content></ng-content> `,
standalone: true
})
export class NzOptionGroupComponent implements OnChanges {
@Input() nzLabel: string | number | TemplateRef<NzSafeAny> | null = null;
Expand Down
5 changes: 4 additions & 1 deletion components/select/option-item-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulation } from '@angular/core';

import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

@Component({
Expand All @@ -14,7 +15,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
encapsulation: ViewEncapsulation.None,
host: {
class: 'ant-select-item ant-select-item-group'
}
},
imports: [NzOutletModule],
standalone: true
})
export class NzOptionItemGroupComponent {
@Input() nzLabel: string | number | TemplateRef<NzSafeAny> | null = null;
Expand Down
6 changes: 5 additions & 1 deletion components/select/option-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { NgIf, NgTemplateOutlet } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -22,6 +23,7 @@ import { takeUntil } from 'rxjs/operators';

import { NzDestroyService } from 'ng-zorro-antd/core/services';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconModule } from 'ng-zorro-antd/icon';

@Component({
selector: 'nz-option-item',
Expand All @@ -46,7 +48,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
'[class.ant-select-item-option-disabled]': 'disabled',
'[class.ant-select-item-option-active]': 'activated && !disabled'
},
providers: [NzDestroyService]
providers: [NzDestroyService],
imports: [NgIf, NgTemplateOutlet, NzIconModule],
standalone: true
})
export class NzOptionItemComponent implements OnChanges, OnInit {
selected = false;
Expand Down
3 changes: 2 additions & 1 deletion components/select/option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { NzOptionGroupComponent } from './option-group.component';
<ng-template>
<ng-content></ng-content>
</ng-template>
`
`,
standalone: true
})
export class NzOptionComponent implements OnChanges, OnInit {
static ngAcceptInputType_nzDisabled: BooleanInput;
Expand Down
7 changes: 6 additions & 1 deletion components/select/select-arrow.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { NgIf } from '@angular/common';
import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulation } from '@angular/core';

import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconModule } from 'ng-zorro-antd/icon';

@Component({
selector: 'nz-select-arrow',
Expand All @@ -29,7 +32,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
host: {
class: 'ant-select-arrow',
'[class.ant-select-arrow-loading]': 'loading'
}
},
imports: [NzIconModule, NgIf, NzOutletModule],
standalone: true
})
export class NzSelectArrowComponent {
@Input() loading = false;
Expand Down
6 changes: 5 additions & 1 deletion components/select/select-clear.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { NgIf } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -14,6 +15,7 @@ import {
} from '@angular/core';

import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconModule } from 'ng-zorro-antd/icon';

@Component({
selector: 'nz-select-clear',
Expand All @@ -31,7 +33,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
host: {
class: 'ant-select-clear',
'(click)': 'onClick($event)'
}
},
imports: [NzIconModule, NgIf],
standalone: true
})
export class NzSelectClearComponent {
@Input() clearIcon: TemplateRef<NzSafeAny> | null = null;
Expand Down
7 changes: 6 additions & 1 deletion components/select/select-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { NgIf } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -13,7 +14,9 @@ import {
ViewEncapsulation
} from '@angular/core';

import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconModule } from 'ng-zorro-antd/icon';

@Component({
selector: 'nz-select-item',
Expand All @@ -32,7 +35,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
class: 'ant-select-selection-item',
'[attr.title]': 'label',
'[class.ant-select-selection-item-disabled]': 'disabled'
}
},
imports: [NzOutletModule, NgIf, NzIconModule],
standalone: true
})
export class NzSelectItemComponent {
@Input() disabled = false;
Expand Down
5 changes: 4 additions & 1 deletion components/select/select-placeholder.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulation } from '@angular/core';

import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

@Component({
Expand All @@ -16,7 +17,9 @@ import { NzSafeAny } from 'ng-zorro-antd/core/types';
{{ placeholder }}
</ng-container>
`,
host: { class: 'ant-select-selection-placeholder' }
host: { class: 'ant-select-selection-placeholder' },
imports: [NzOutletModule],
standalone: true
})
export class NzSelectPlaceholderComponent {
@Input() placeholder: TemplateRef<NzSafeAny> | string | null = null;
Expand Down
7 changes: 5 additions & 2 deletions components/select/select-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { FocusMonitor } from '@angular/cdk/a11y';
import { NgIf } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand All @@ -18,7 +19,7 @@ import {
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { COMPOSITION_BUFFER_MODE } from '@angular/forms';
import { COMPOSITION_BUFFER_MODE, FormsModule } from '@angular/forms';

@Component({
selector: 'nz-select-search',
Expand All @@ -41,7 +42,9 @@ import { COMPOSITION_BUFFER_MODE } from '@angular/forms';
<span #mirrorElement *ngIf="mirrorSync" class="ant-select-selection-search-mirror"></span>
`,
host: { class: 'ant-select-selection-search' },
providers: [{ provide: COMPOSITION_BUFFER_MODE, useValue: false }]
providers: [{ provide: COMPOSITION_BUFFER_MODE, useValue: false }],
imports: [FormsModule, NgIf],
standalone: true
})
export class NzSelectSearchComponent implements AfterViewInit, OnChanges {
@Input() nzId: string | null = null;
Expand Down
16 changes: 15 additions & 1 deletion components/select/select-top-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { BACKSPACE } from '@angular/cdk/keycodes';
import { NgFor, NgIf, NgSwitch, NgSwitchCase, NgSwitchDefault } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -28,6 +29,8 @@ import { takeUntil } from 'rxjs/operators';
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

import { NzSelectItemComponent } from './select-item.component';
import { NzSelectPlaceholderComponent } from './select-placeholder.component';
import { NzSelectSearchComponent } from './select-search.component';
import { NzSelectItemInterface, NzSelectModeType, NzSelectTopControlItemType } from './select.types';

Expand Down Expand Up @@ -89,7 +92,18 @@ import { NzSelectItemInterface, NzSelectModeType, NzSelectTopControlItemType } f
</ng-container>
<nz-select-placeholder *ngIf="isShowPlaceholder" [placeholder]="placeHolder"></nz-select-placeholder>
`,
host: { class: 'ant-select-selector' }
host: { class: 'ant-select-selector' },
imports: [
NgSwitch,
NzSelectSearchComponent,
NgSwitchCase,
NzSelectItemComponent,
NgIf,
NgSwitchDefault,
NgFor,
NzSelectPlaceholderComponent
],
standalone: true
})
export class NzSelectTopControlComponent implements OnChanges, OnInit, OnDestroy {
@Input() nzId: string | null = null;
Expand Down
26 changes: 22 additions & 4 deletions components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ConnectionPositionPair
} from '@angular/cdk/overlay';
import { Platform } from '@angular/cdk/platform';
import { NgIf, NgStyle } from '@angular/common';
import {
AfterContentInit,
ChangeDetectionStrategy,
Expand Down Expand Up @@ -43,9 +44,9 @@ import { distinctUntilChanged, map, startWith, switchMap, takeUntil, withLatestF

import { slideMotion } from 'ng-zorro-antd/core/animation';
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { NzFormNoStatusService, NzFormStatusService } from 'ng-zorro-antd/core/form';
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
import { getPlacementName, POSITION_MAP, POSITION_TYPE } from 'ng-zorro-antd/core/overlay';
import { NzFormNoStatusService, NzFormPatchModule, NzFormStatusService } from 'ng-zorro-antd/core/form';
import { NzNoAnimationDirective, NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation';
import { getPlacementName, NzOverlayModule, POSITION_MAP, POSITION_TYPE } from 'ng-zorro-antd/core/overlay';
import { cancelRequestAnimationFrame, reqAnimFrame } from 'ng-zorro-antd/core/polyfill';
import { NzDestroyService } from 'ng-zorro-antd/core/services';
import {
Expand All @@ -59,8 +60,11 @@ import {
} from 'ng-zorro-antd/core/types';
import { getStatusClassNames, InputBoolean, isNotNil } from 'ng-zorro-antd/core/util';

import { NzOptionContainerComponent } from './option-container.component';
import { NzOptionGroupComponent } from './option-group.component';
import { NzOptionComponent } from './option.component';
import { NzSelectArrowComponent } from './select-arrow.component';
import { NzSelectClearComponent } from './select-clear.component';
import { NzSelectTopControlComponent } from './select-top-control.component';
import {
NzFilterOptionType,
Expand Down Expand Up @@ -195,7 +199,21 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
'[class.ant-select-single]': `nzMode === 'default'`,
'[class.ant-select-multiple]': `nzMode !== 'default'`,
'[class.ant-select-rtl]': `dir === 'rtl'`
}
},
imports: [
NzSelectTopControlComponent,
CdkOverlayOrigin,
NzNoAnimationModule,
NzSelectArrowComponent,
NgIf,
NzFormPatchModule,
NzSelectClearComponent,
CdkConnectedOverlay,
NzOverlayModule,
NzOptionContainerComponent,
NgStyle
],
standalone: true
})
export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterContentInit, OnChanges, OnDestroy {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
Expand Down
33 changes: 0 additions & 33 deletions components/select/select.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { A11yModule } from '@angular/cdk/a11y';
import { BidiModule } from '@angular/cdk/bidi';
import { OverlayModule } from '@angular/cdk/overlay';
import { PlatformModule } from '@angular/cdk/platform';
import { ScrollingModule } from '@angular/cdk/scrolling';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { NzFormPatchModule } from 'ng-zorro-antd/core/form';
import { NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { NzOverlayModule } from 'ng-zorro-antd/core/overlay';
import { ɵNzTransitionPatchModule as NzTransitionPatchModule } from 'ng-zorro-antd/core/transition-patch';
import { NzEmptyModule } from 'ng-zorro-antd/empty';
import { NzI18nModule } from 'ng-zorro-antd/i18n';
import { NzIconModule } from 'ng-zorro-antd/icon';

import { NzOptionContainerComponent } from './option-container.component';
import { NzOptionGroupComponent } from './option-group.component';
Expand All @@ -36,23 +20,6 @@ import { NzSelectComponent } from './select.component';

@NgModule({
imports: [
BidiModule,
CommonModule,
NzI18nModule,
FormsModule,
PlatformModule,
OverlayModule,
NzIconModule,
NzOutletModule,
NzEmptyModule,
NzOverlayModule,
NzNoAnimationModule,
NzTransitionPatchModule,
NzFormPatchModule,
ScrollingModule,
A11yModule
],
declarations: [
NzOptionComponent,
NzSelectComponent,
NzOptionContainerComponent,
Expand Down

0 comments on commit ed0de77

Please sign in to comment.