ng-zorro-antd-button.mjs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import { __esDecorate, __runInitializers } from 'tslib';
  2. import * as i0 from '@angular/core';
  3. import { computed, signal, inject, ElementRef, booleanAttribute, Input, ContentChild, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
  4. import { Subject } from 'rxjs';
  5. import { takeUntil, startWith, filter } from 'rxjs/operators';
  6. import * as i1 from 'ng-zorro-antd/core/config';
  7. import { WithConfig } from 'ng-zorro-antd/core/config';
  8. import { NzDestroyService } from 'ng-zorro-antd/core/services';
  9. import { fromEventOutsideAngular } from 'ng-zorro-antd/core/util';
  10. import * as i4 from 'ng-zorro-antd/icon';
  11. import { NzIconModule, NzIconDirective } from 'ng-zorro-antd/icon';
  12. import * as i3 from 'ng-zorro-antd/space';
  13. import { NZ_SPACE_COMPACT_SIZE, NZ_SPACE_COMPACT_ITEM_TYPE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';
  14. import * as i2 from '@angular/cdk/bidi';
  15. import { ɵNzTransitionPatchModule as _NzTransitionPatchModule } from 'ng-zorro-antd/core/transition-patch';
  16. import { NzWaveModule } from 'ng-zorro-antd/core/wave';
  17. const NZ_CONFIG_MODULE_NAME = 'button';
  18. let NzButtonComponent = (() => {
  19. let _nzSize_decorators;
  20. let _nzSize_initializers = [];
  21. let _nzSize_extraInitializers = [];
  22. return class NzButtonComponent {
  23. static {
  24. const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
  25. _nzSize_decorators = [WithConfig()];
  26. __esDecorate(null, null, _nzSize_decorators, { kind: "field", name: "nzSize", static: false, private: false, access: { has: obj => "nzSize" in obj, get: obj => obj.nzSize, set: (obj, value) => { obj.nzSize = value; } }, metadata: _metadata }, _nzSize_initializers, _nzSize_extraInitializers);
  27. if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
  28. }
  29. elementRef;
  30. cdr;
  31. renderer;
  32. nzConfigService;
  33. directionality;
  34. _nzModuleName = NZ_CONFIG_MODULE_NAME;
  35. nzIconDirectiveElement;
  36. nzBlock = false;
  37. nzGhost = false;
  38. nzSearch = false;
  39. nzLoading = false;
  40. nzDanger = false;
  41. disabled = false;
  42. tabIndex = null;
  43. nzType = null;
  44. nzShape = null;
  45. nzSize = __runInitializers(this, _nzSize_initializers, 'default');
  46. dir = (__runInitializers(this, _nzSize_extraInitializers), 'ltr');
  47. finalSize = computed(() => {
  48. if (this.compactSize) {
  49. return this.compactSize();
  50. }
  51. return this.size();
  52. });
  53. size = signal(this.nzSize);
  54. compactSize = inject(NZ_SPACE_COMPACT_SIZE, { optional: true });
  55. destroy$ = inject(NzDestroyService);
  56. loading$ = new Subject();
  57. insertSpan(nodes, renderer) {
  58. nodes.forEach(node => {
  59. if (node.nodeName === '#text') {
  60. const span = renderer.createElement('span');
  61. const parent = renderer.parentNode(node);
  62. renderer.insertBefore(parent, span, node);
  63. renderer.appendChild(span, node);
  64. }
  65. });
  66. }
  67. get iconOnly() {
  68. const listOfNode = Array.from(this.elementRef?.nativeElement?.childNodes || []);
  69. const noText = listOfNode.every(node => node.nodeName !== '#text');
  70. // ignore icon and comment
  71. const noSpan = listOfNode.filter(node => {
  72. return !(node.nodeName === '#comment' || !!node?.classList?.contains('anticon'));
  73. }).length == 0;
  74. return !!this.nzIconDirectiveElement && noSpan && noText;
  75. }
  76. constructor(elementRef, cdr, renderer, nzConfigService, directionality) {
  77. this.elementRef = elementRef;
  78. this.cdr = cdr;
  79. this.renderer = renderer;
  80. this.nzConfigService = nzConfigService;
  81. this.directionality = directionality;
  82. }
  83. ngOnInit() {
  84. this.size.set(this.nzSize);
  85. this.nzConfigService
  86. .getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME)
  87. .pipe(takeUntil(this.destroy$))
  88. .subscribe(() => {
  89. this.size.set(this.nzSize);
  90. this.cdr.markForCheck();
  91. });
  92. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  93. this.dir = direction;
  94. this.cdr.detectChanges();
  95. });
  96. this.dir = this.directionality.value;
  97. // Caretaker note: this event listener could've been added through `host.click` or `HostListener`.
  98. // The compiler generates the `ɵɵlistener` instruction which wraps the actual listener internally into the
  99. // function, which runs `markDirty()` before running the actual listener (the decorated class method).
  100. // Since we're preventing the default behavior and stopping event propagation this doesn't require Angular to run the change detection.
  101. fromEventOutsideAngular(this.elementRef.nativeElement, 'click', { capture: true })
  102. .pipe(takeUntil(this.destroy$))
  103. .subscribe(event => {
  104. if ((this.disabled && event.target?.tagName === 'A') || this.nzLoading) {
  105. event.preventDefault();
  106. event.stopImmediatePropagation();
  107. }
  108. });
  109. }
  110. ngOnChanges({ nzLoading, nzSize }) {
  111. if (nzLoading) {
  112. this.loading$.next(this.nzLoading);
  113. }
  114. if (nzSize) {
  115. this.size.set(nzSize.currentValue);
  116. }
  117. }
  118. ngAfterViewInit() {
  119. this.insertSpan(this.elementRef.nativeElement.childNodes, this.renderer);
  120. }
  121. ngAfterContentInit() {
  122. this.loading$
  123. .pipe(startWith(this.nzLoading), filter(() => !!this.nzIconDirectiveElement), takeUntil(this.destroy$))
  124. .subscribe(loading => {
  125. const nativeElement = this.nzIconDirectiveElement.nativeElement;
  126. if (loading) {
  127. this.renderer.setStyle(nativeElement, 'display', 'none');
  128. }
  129. else {
  130. this.renderer.removeStyle(nativeElement, 'display');
  131. }
  132. });
  133. }
  134. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }, { token: i1.NzConfigService }, { token: i2.Directionality }], target: i0.ɵɵFactoryTarget.Component });
  135. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.2", type: NzButtonComponent, isStandalone: true, selector: "button[nz-button], a[nz-button]", inputs: { nzBlock: ["nzBlock", "nzBlock", booleanAttribute], nzGhost: ["nzGhost", "nzGhost", booleanAttribute], nzSearch: ["nzSearch", "nzSearch", booleanAttribute], nzLoading: ["nzLoading", "nzLoading", booleanAttribute], nzDanger: ["nzDanger", "nzDanger", booleanAttribute], disabled: ["disabled", "disabled", booleanAttribute], tabIndex: "tabIndex", nzType: "nzType", nzShape: "nzShape", nzSize: "nzSize" }, host: { properties: { "class.ant-btn-default": "nzType === 'default'", "class.ant-btn-primary": "nzType === 'primary'", "class.ant-btn-dashed": "nzType === 'dashed'", "class.ant-btn-link": "nzType === 'link'", "class.ant-btn-text": "nzType === 'text'", "class.ant-btn-circle": "nzShape === 'circle'", "class.ant-btn-round": "nzShape === 'round'", "class.ant-btn-lg": "finalSize() === 'large'", "class.ant-btn-sm": "finalSize() === 'small'", "class.ant-btn-dangerous": "nzDanger", "class.ant-btn-loading": "nzLoading", "class.ant-btn-background-ghost": "nzGhost", "class.ant-btn-block": "nzBlock", "class.ant-input-search-button": "nzSearch", "class.ant-btn-rtl": "dir === 'rtl'", "class.ant-btn-icon-only": "iconOnly", "attr.tabindex": "disabled ? -1 : (tabIndex === null ? null : tabIndex)", "attr.disabled": "disabled || null" }, classAttribute: "ant-btn" }, providers: [NzDestroyService, { provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'btn' }], queries: [{ propertyName: "nzIconDirectiveElement", first: true, predicate: NzIconDirective, descendants: true, read: ElementRef }], exportAs: ["nzButton"], usesOnChanges: true, hostDirectives: [{ directive: i3.NzSpaceCompactItemDirective }], ngImport: i0, template: `
  136. @if (nzLoading) {
  137. <nz-icon nzType="loading" />
  138. }
  139. <ng-content></ng-content>
  140. `, isInline: true, dependencies: [{ kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i4.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  141. };
  142. })();
  143. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonComponent, decorators: [{
  144. type: Component,
  145. args: [{
  146. selector: 'button[nz-button], a[nz-button]',
  147. exportAs: 'nzButton',
  148. imports: [NzIconModule],
  149. preserveWhitespaces: false,
  150. changeDetection: ChangeDetectionStrategy.OnPush,
  151. encapsulation: ViewEncapsulation.None,
  152. template: `
  153. @if (nzLoading) {
  154. <nz-icon nzType="loading" />
  155. }
  156. <ng-content></ng-content>
  157. `,
  158. host: {
  159. class: 'ant-btn',
  160. '[class.ant-btn-default]': `nzType === 'default'`,
  161. '[class.ant-btn-primary]': `nzType === 'primary'`,
  162. '[class.ant-btn-dashed]': `nzType === 'dashed'`,
  163. '[class.ant-btn-link]': `nzType === 'link'`,
  164. '[class.ant-btn-text]': `nzType === 'text'`,
  165. '[class.ant-btn-circle]': `nzShape === 'circle'`,
  166. '[class.ant-btn-round]': `nzShape === 'round'`,
  167. '[class.ant-btn-lg]': `finalSize() === 'large'`,
  168. '[class.ant-btn-sm]': `finalSize() === 'small'`,
  169. '[class.ant-btn-dangerous]': `nzDanger`,
  170. '[class.ant-btn-loading]': `nzLoading`,
  171. '[class.ant-btn-background-ghost]': `nzGhost`,
  172. '[class.ant-btn-block]': `nzBlock`,
  173. '[class.ant-input-search-button]': `nzSearch`,
  174. '[class.ant-btn-rtl]': `dir === 'rtl'`,
  175. '[class.ant-btn-icon-only]': `iconOnly`,
  176. '[attr.tabindex]': 'disabled ? -1 : (tabIndex === null ? null : tabIndex)',
  177. '[attr.disabled]': 'disabled || null'
  178. },
  179. hostDirectives: [NzSpaceCompactItemDirective],
  180. providers: [NzDestroyService, { provide: NZ_SPACE_COMPACT_ITEM_TYPE, useValue: 'btn' }]
  181. }]
  182. }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i0.Renderer2 }, { type: i1.NzConfigService }, { type: i2.Directionality }], propDecorators: { nzIconDirectiveElement: [{
  183. type: ContentChild,
  184. args: [NzIconDirective, { read: ElementRef }]
  185. }], nzBlock: [{
  186. type: Input,
  187. args: [{ transform: booleanAttribute }]
  188. }], nzGhost: [{
  189. type: Input,
  190. args: [{ transform: booleanAttribute }]
  191. }], nzSearch: [{
  192. type: Input,
  193. args: [{ transform: booleanAttribute }]
  194. }], nzLoading: [{
  195. type: Input,
  196. args: [{ transform: booleanAttribute }]
  197. }], nzDanger: [{
  198. type: Input,
  199. args: [{ transform: booleanAttribute }]
  200. }], disabled: [{
  201. type: Input,
  202. args: [{ transform: booleanAttribute }]
  203. }], tabIndex: [{
  204. type: Input
  205. }], nzType: [{
  206. type: Input
  207. }], nzShape: [{
  208. type: Input
  209. }], nzSize: [{
  210. type: Input
  211. }] } });
  212. /**
  213. * @deprecated Will be removed in v20. Use `NzSpaceCompactComponent` instead.
  214. */
  215. class NzButtonGroupComponent {
  216. directionality;
  217. nzSize = 'default';
  218. dir = 'ltr';
  219. destroy$ = new Subject();
  220. constructor(directionality) {
  221. this.directionality = directionality;
  222. }
  223. ngOnInit() {
  224. this.dir = this.directionality.value;
  225. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  226. this.dir = direction;
  227. });
  228. }
  229. ngOnDestroy() {
  230. this.destroy$.next();
  231. this.destroy$.complete();
  232. }
  233. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonGroupComponent, deps: [{ token: i2.Directionality }], target: i0.ɵɵFactoryTarget.Component });
  234. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.2", type: NzButtonGroupComponent, isStandalone: true, selector: "nz-button-group", inputs: { nzSize: "nzSize" }, host: { properties: { "class.ant-btn-group-lg": "nzSize === 'large'", "class.ant-btn-group-sm": "nzSize === 'small'", "class.ant-btn-group-rtl": "dir === 'rtl'" }, classAttribute: "ant-btn-group" }, exportAs: ["nzButtonGroup"], ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  235. }
  236. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonGroupComponent, decorators: [{
  237. type: Component,
  238. args: [{
  239. selector: 'nz-button-group',
  240. exportAs: 'nzButtonGroup',
  241. changeDetection: ChangeDetectionStrategy.OnPush,
  242. encapsulation: ViewEncapsulation.None,
  243. host: {
  244. class: 'ant-btn-group',
  245. '[class.ant-btn-group-lg]': `nzSize === 'large'`,
  246. '[class.ant-btn-group-sm]': `nzSize === 'small'`,
  247. '[class.ant-btn-group-rtl]': `dir === 'rtl'`
  248. },
  249. preserveWhitespaces: false,
  250. template: `<ng-content></ng-content>`
  251. }]
  252. }], ctorParameters: () => [{ type: i2.Directionality }], propDecorators: { nzSize: [{
  253. type: Input
  254. }] } });
  255. /**
  256. * Use of this source code is governed by an MIT-style license that can be
  257. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  258. */
  259. class NzButtonModule {
  260. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  261. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzButtonModule, imports: [NzButtonComponent, NzButtonGroupComponent], exports: [NzButtonComponent, NzButtonGroupComponent, _NzTransitionPatchModule, NzWaveModule] });
  262. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonModule, imports: [NzButtonComponent, _NzTransitionPatchModule, NzWaveModule] });
  263. }
  264. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzButtonModule, decorators: [{
  265. type: NgModule,
  266. args: [{
  267. imports: [NzButtonComponent, NzButtonGroupComponent],
  268. exports: [NzButtonComponent, NzButtonGroupComponent, _NzTransitionPatchModule, NzWaveModule]
  269. }]
  270. }] });
  271. /**
  272. * Use of this source code is governed by an MIT-style license that can be
  273. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  274. */
  275. /**
  276. * Generated bundle index. Do not edit.
  277. */
  278. export { NzButtonComponent, NzButtonGroupComponent, NzButtonModule };
  279. //# sourceMappingURL=ng-zorro-antd-button.mjs.map