• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2023 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 {assertUnreachable} from '../base/logging';
16
17// This file contains interfaces for attributes for various HTML elements.
18// They are typically used by widgets which pass attributes down to their
19// internal child, to provide a type-safe interface to users of those widgets.
20// Note: This is a non-exhaustive list, and is added to when required.
21// Feel free to add any missing attributes as they arise.
22export type Style = string | Partial<CSSStyleDeclaration>;
23
24export interface HTMLAttrs {
25  ref?: string; // This is a common attribute used in Perfetto.
26  style?: Style;
27  id?: string;
28  title?: string;
29  className?: string;
30  onclick?: (e: PointerEvent) => void;
31  onmouseover?: (e: MouseEvent) => void;
32  onmouseout?: (e: MouseEvent) => void;
33  onmousedown?: (e: MouseEvent) => void;
34  onmouseup?: (e: MouseEvent) => void;
35  onmousemove?: (e: MouseEvent) => void;
36  onload?: (e: Event) => void;
37}
38
39export interface HTMLInputAttrs extends HTMLAttrs {
40  disabled?: boolean;
41  type?: string;
42  onchange?: (e: Event) => void;
43  oninput?: (e: KeyboardEvent) => void;
44  onkeydown?: (e: KeyboardEvent) => void;
45  onkeyup?: (e: KeyboardEvent) => void;
46  value?: string;
47  placeholder?: string;
48}
49
50export interface HTMLCheckboxAttrs extends HTMLInputAttrs {
51  checked?: boolean;
52}
53
54export interface HTMLButtonAttrs extends HTMLInputAttrs {}
55
56export interface HTMLAnchorAttrs extends HTMLAttrs {
57  href?: string;
58  target?: string;
59}
60
61export interface HTMLLabelAttrs extends HTMLAttrs {
62  for?: string;
63}
64
65export enum Intent {
66  None = 'none',
67  Primary = 'primary',
68}
69
70export function classForIntent(intent: Intent): string | undefined {
71  switch (intent) {
72    case Intent.None:
73      return undefined;
74    case Intent.Primary:
75      return 'pf-intent-primary';
76    default:
77      return assertUnreachable(intent);
78  }
79}
80