• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 The Android Open Source Project
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
17import m from 'mithril';
18
19import {raf} from '../core/raf_scheduler';
20
21interface ArgumentPopupArgs {
22  onArgumentChange: (arg: string) => void;
23}
24
25// Component rendering popup for entering an argument name to use as a pivot.
26export class ArgumentPopup implements m.ClassComponent<ArgumentPopupArgs> {
27  argument = '';
28
29  setArgument(attrs: ArgumentPopupArgs, arg: string) {
30    this.argument = arg;
31    attrs.onArgumentChange(arg);
32    raf.scheduleFullRedraw();
33  }
34
35  view({attrs}: m.Vnode<ArgumentPopupArgs>): m.Child {
36    return m(
37      '.name-completion',
38      m('input', {
39        oncreate: (vnode: m.VnodeDOM) =>
40          (vnode.dom as HTMLInputElement).focus(),
41        oninput: (e: Event) => {
42          const input = e.target as HTMLInputElement;
43          this.setArgument(attrs, input.value);
44        },
45        value: this.argument,
46      }),
47    );
48  }
49}
50