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 readonly ref?: string; // This is a common attribute used in Perfetto. 26 readonly style?: Style; 27 readonly id?: string; 28 readonly title?: string; 29 readonly className?: string; 30 readonly onclick?: (e: PointerEvent) => void; 31 readonly onmouseover?: (e: MouseEvent) => void; 32 readonly onmouseout?: (e: MouseEvent) => void; 33 readonly onmousedown?: (e: MouseEvent) => void; 34 readonly onmouseup?: (e: MouseEvent) => void; 35 readonly onmousemove?: (e: MouseEvent) => void; 36 readonly onload?: (e: Event) => void; 37} 38 39export interface HTMLFocusableAttrs extends HTMLAttrs { 40 readonly onblur?: (e: FocusEvent) => void; 41 readonly onfocus?: (e: FocusEvent) => void; 42} 43 44export interface HTMLInputAttrs extends HTMLFocusableAttrs { 45 readonly disabled?: boolean; 46 readonly type?: string; 47 readonly onchange?: (e: Event) => void; 48 readonly oninput?: (e: KeyboardEvent) => void; 49 readonly onkeydown?: (e: KeyboardEvent) => void; 50 readonly onkeyup?: (e: KeyboardEvent) => void; 51 readonly value?: string; 52 readonly placeholder?: string; 53} 54 55export interface HTMLCheckboxAttrs extends HTMLInputAttrs { 56 readonly checked?: boolean; 57} 58 59export interface HTMLButtonAttrs extends HTMLInputAttrs {} 60 61export interface HTMLAnchorAttrs extends HTMLAttrs { 62 readonly href?: string; 63 readonly target?: string; 64} 65 66export interface HTMLLabelAttrs extends HTMLAttrs { 67 readonly for?: string; 68} 69 70export enum Intent { 71 None = 'none', 72 Primary = 'primary', 73} 74 75export function classForIntent(intent: Intent): string | undefined { 76 switch (intent) { 77 case Intent.None: 78 return undefined; 79 case Intent.Primary: 80 return 'pf-intent-primary'; 81 default: 82 return assertUnreachable(intent); 83 } 84} 85