1// Copyright (C) 2022 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import m from 'mithril'; 16import {raf} from '../core/raf_scheduler'; 17 18interface ArgumentPopupArgs { 19 onArgumentChange: (arg: string) => void; 20} 21 22// Component rendering popup for entering an argument name to use as a pivot. 23export class ArgumentPopup implements m.ClassComponent<ArgumentPopupArgs> { 24 argument = ''; 25 26 setArgument(attrs: ArgumentPopupArgs, arg: string) { 27 this.argument = arg; 28 attrs.onArgumentChange(arg); 29 raf.scheduleFullRedraw(); 30 } 31 32 view({attrs}: m.Vnode<ArgumentPopupArgs>): m.Child { 33 return m( 34 '.name-completion', 35 m('input', { 36 oncreate: (vnode: m.VnodeDOM) => 37 (vnode.dom as HTMLInputElement).focus(), 38 oninput: (e: Event) => { 39 const input = e.target as HTMLInputElement; 40 this.setArgument(attrs, input.value); 41 }, 42 value: this.argument, 43 }), 44 ); 45 } 46} 47