Sean Condon | 14d442f | 2019-12-09 14:16:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; |
| 18 | import {animate, state, style, transition, trigger} from '@angular/animations'; |
| 19 | |
| 20 | export interface NameInputResult { |
| 21 | chosen: boolean; |
| 22 | name: string; |
| 23 | } |
| 24 | |
| 25 | @Component({ |
| 26 | selector: 'onos-name-input', |
| 27 | templateUrl: './name-input.component.html', |
| 28 | styleUrls: [ |
| 29 | './name-input.component.css', |
| 30 | './name-input.theme.css', |
| 31 | '../../layer/dialog.css', |
| 32 | '../../layer/dialog.theme.css', |
| 33 | '../../widget/panel.css', |
| 34 | '../../widget/panel-theme.css' |
| 35 | ], |
| 36 | animations: [ |
| 37 | trigger('niDlgState', [ |
| 38 | state('true', style({ |
| 39 | transform: 'translateX(-100%)', |
| 40 | opacity: '100' |
| 41 | })), |
| 42 | state('false', style({ |
| 43 | transform: 'translateX(0%)', |
| 44 | opacity: '0' |
| 45 | })), |
| 46 | transition('0 => 1', animate('100ms ease-in')), |
| 47 | transition('1 => 0', animate('100ms ease-out')) |
| 48 | ]) |
| 49 | ] |
| 50 | }) |
| 51 | export class NameInputComponent implements OnInit { |
| 52 | @Input() warning: string; |
| 53 | @Input() title: string = ''; |
| 54 | @Input() pattern; |
| 55 | @Input() minLen = 4; |
| 56 | @Input() maxLen = 40; |
| 57 | @Input() placeholder = 'name'; |
| 58 | @Output() chosen: EventEmitter<NameInputResult> = new EventEmitter(); |
| 59 | |
| 60 | constructor() { |
| 61 | } |
| 62 | |
| 63 | ngOnInit() { |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * When OK or Cancel is pressed, send an event to parent with choice |
| 68 | */ |
| 69 | choice(chosen: boolean, newName: string): void { |
| 70 | if (chosen && (newName === undefined || newName === '')) { |
| 71 | return; |
| 72 | } |
| 73 | this.chosen.emit(<NameInputResult>{ |
| 74 | chosen: chosen, |
| 75 | name: newName |
| 76 | }); |
| 77 | } |
| 78 | } |