|
| 1 | +import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; |
| 2 | +import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms'; |
| 3 | + |
| 4 | +import { ColorEvent } from 'ngx-color/color-wrap.component'; |
| 5 | + |
| 6 | +import { FontType } from 'ng-zorro-antd/water-mark'; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + selector: 'nz-demo-water-mark-custom', |
| 10 | + template: ` |
| 11 | + <div style="display: flex;"> |
| 12 | + <nz-water-mark |
| 13 | + [nzContent]="content" |
| 14 | + [nzRotate]="rotate" |
| 15 | + [nzZIndex]="zIndex" |
| 16 | + [nzGap]="gap" |
| 17 | + [nzOffset]="offset" |
| 18 | + [nzFont]="font" |
| 19 | + > |
| 20 | + <p nz-typography style="z-index: 10; position:relative;"> |
| 21 | + The light-speed iteration of the digital world makes products more complex. However, human consciousness and |
| 22 | + attention resources are limited. Facing this design contradiction, the pursuit of natural interaction will be |
| 23 | + the consistent direction of Ant Design. |
| 24 | + </p> |
| 25 | + <p nz-typography style="z-index: 10; position:relative;"> |
| 26 | + Natural user cognition: According to cognitive psychology, about 80% of external information is obtained |
| 27 | + through visual channels. The most important visual elements in the interface design, including layout, colors, |
| 28 | + illustrations, icons, etc., should fully absorb the laws of nature, thereby reducing the user's cognitive |
| 29 | + cost and bringing authentic and smooth feelings. In some scenarios, opportunely adding other sensory channels |
| 30 | + such as hearing, touch can create a richer and more natural product experience. |
| 31 | + </p> |
| 32 | + <p nz-typography style="z-index: 10; position:relative;"> |
| 33 | + Natural user behavior: In the interaction with the system, the designer should fully understand the |
| 34 | + relationship between users, system roles, and task objectives, and also contextually organize system functions |
| 35 | + and services. At the same time, a series of methods such as behavior analysis, artificial intelligence and |
| 36 | + sensors could be applied to assist users to make effective decisions and reduce extra operations of users, to |
| 37 | + save users' mental and physical resources and make human-computer interaction more natural. |
| 38 | + </p> |
| 39 | + <img |
| 40 | + style="z-index: 30; position:relative; width: 100%; max-width: 800px;" |
| 41 | + src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*zx7LTI_ECSAAAAAAAAAAAABkARQnAQ" |
| 42 | + alt="示例图片" |
| 43 | + /> |
| 44 | + </nz-water-mark> |
| 45 | + <nz-divider nzType="vertical"></nz-divider> |
| 46 | + <form nz-form nzLayout="vertical" [formGroup]="validateForm"> |
| 47 | + <nz-form-item> |
| 48 | + <nz-form-label>Content</nz-form-label> |
| 49 | + <nz-form-control> |
| 50 | + <input nz-input type="text" formControlName="content" /> |
| 51 | + </nz-form-control> |
| 52 | + </nz-form-item> |
| 53 | + <nz-form-item> |
| 54 | + <nz-form-label>Color</nz-form-label> |
| 55 | + <nz-form-control> |
| 56 | + <div |
| 57 | + class="theme-pick-wrap" |
| 58 | + nz-popover |
| 59 | + [nzPopoverTrigger]="'click'" |
| 60 | + nzPopoverOverlayClassName="theme-color-content" |
| 61 | + [nzPopoverContent]="colorTpl" |
| 62 | + > |
| 63 | + <div class="theme-pick" [ngStyle]="{ background: color }"></div> |
| 64 | + </div> |
| 65 | + <ng-template #colorTpl> |
| 66 | + <color-sketch [color]="color" (onChangeComplete)="changeColor($event)"></color-sketch> |
| 67 | + </ng-template> |
| 68 | + </nz-form-control> |
| 69 | + </nz-form-item> |
| 70 | + <nz-form-item> |
| 71 | + <nz-form-label>FontSize</nz-form-label> |
| 72 | + <nz-form-control> |
| 73 | + <nz-slider formControlName="fontSize"></nz-slider> |
| 74 | + </nz-form-control> |
| 75 | + </nz-form-item> |
| 76 | + <nz-form-item> |
| 77 | + <nz-form-label>zIndex</nz-form-label> |
| 78 | + <nz-form-control> |
| 79 | + <nz-slider formControlName="zIndex"></nz-slider> |
| 80 | + </nz-form-control> |
| 81 | + </nz-form-item> |
| 82 | + <nz-form-item> |
| 83 | + <nz-form-label>Rotate</nz-form-label> |
| 84 | + <nz-form-control> |
| 85 | + <nz-slider [nzMin]="-180" [nzMax]="180" formControlName="rotate"></nz-slider> |
| 86 | + </nz-form-control> |
| 87 | + </nz-form-item> |
| 88 | + <nz-form-item> |
| 89 | + <nz-form-label>Gap</nz-form-label> |
| 90 | + <nz-form-control> |
| 91 | + <nz-input-number formControlName="gapX"></nz-input-number> |
| 92 | + <nz-input-number formControlName="gapY"></nz-input-number> |
| 93 | + </nz-form-control> |
| 94 | + </nz-form-item> |
| 95 | + <nz-form-item> |
| 96 | + <nz-form-label>Offset</nz-form-label> |
| 97 | + <nz-form-control> |
| 98 | + <nz-input-number formControlName="offsetX"></nz-input-number> |
| 99 | + <nz-input-number formControlName="offsetY"></nz-input-number> |
| 100 | + </nz-form-control> |
| 101 | + </nz-form-item> |
| 102 | + </form> |
| 103 | + </div> |
| 104 | + `, |
| 105 | + styles: [ |
| 106 | + ` |
| 107 | + nz-water-mark { |
| 108 | + flex: 1 1 auto; |
| 109 | + } |
| 110 | +
|
| 111 | + nz-divider { |
| 112 | + height: auto; |
| 113 | + margin: 0 20px; |
| 114 | + } |
| 115 | +
|
| 116 | + form { |
| 117 | + flex: 0 0 280px; |
| 118 | + } |
| 119 | +
|
| 120 | + nz-input-number { |
| 121 | + margin-right: 12px; |
| 122 | + width: 40%; |
| 123 | + } |
| 124 | +
|
| 125 | + .theme-pick-wrap { |
| 126 | + padding: 4px; |
| 127 | + background: rgb(255, 255, 255); |
| 128 | + border-radius: 2px; |
| 129 | + box-shadow: rgba(0, 0, 0, 0.1) 0 0 0 1px; |
| 130 | + display: inline-block; |
| 131 | + cursor: pointer; |
| 132 | + } |
| 133 | +
|
| 134 | + .theme-pick { |
| 135 | + width: 80px; |
| 136 | + height: 16px; |
| 137 | + border-radius: 2px; |
| 138 | + } |
| 139 | + ` |
| 140 | + ] |
| 141 | +}) |
| 142 | +export class NzDemoWaterMarkCustomComponent implements OnInit { |
| 143 | + validateForm!: UntypedFormGroup; |
| 144 | + content: string = 'NG Ant Design'; |
| 145 | + color: string = 'rgba(0,0,0,.15)'; |
| 146 | + font: FontType = { |
| 147 | + color: 'rgba(0,0,0,.15)', |
| 148 | + fontSize: 16 |
| 149 | + }; |
| 150 | + zIndex: number = 11; |
| 151 | + rotate: number = -22; |
| 152 | + gap: [number, number] = [100, 100]; |
| 153 | + offset: [number, number] = [50, 50]; |
| 154 | + |
| 155 | + constructor(private fb: UntypedFormBuilder, private cdr: ChangeDetectorRef) {} |
| 156 | + |
| 157 | + ngOnInit(): void { |
| 158 | + this.validateForm = this.fb.group({ |
| 159 | + content: ['NG Ant Design'], |
| 160 | + fontSize: [16], |
| 161 | + zIndex: [11], |
| 162 | + rotate: [-22], |
| 163 | + gapX: [100], |
| 164 | + gapY: [100], |
| 165 | + offsetX: [50], |
| 166 | + offsetY: [50] |
| 167 | + }); |
| 168 | + |
| 169 | + this.validateForm.valueChanges.subscribe(item => { |
| 170 | + this.content = item.content; |
| 171 | + this.font = { |
| 172 | + fontSize: item.fontSize, |
| 173 | + color: this.color |
| 174 | + }; |
| 175 | + this.zIndex = item.zIndex; |
| 176 | + this.rotate = item.rotate; |
| 177 | + this.gap = [item.gapX, item.gapY]; |
| 178 | + this.offset = [item.offsetX, item.offsetY]; |
| 179 | + this.cdr.markForCheck(); |
| 180 | + }); |
| 181 | + } |
| 182 | + |
| 183 | + changeColor(value: ColorEvent): void { |
| 184 | + this.color = value.color.hex; |
| 185 | + this.font = { |
| 186 | + fontSize: this.validateForm.get('fontSize')?.value, |
| 187 | + color: value.color.hex |
| 188 | + }; |
| 189 | + this.cdr.markForCheck(); |
| 190 | + } |
| 191 | +} |
0 commit comments