1 | /*
|
2 | * Copyright 2020 Adobe. All rights reserved.
|
3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4 | * you may not use this file except in compliance with the License. You may obtain a copy
|
5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | *
|
7 | * Unless required by applicable law or agreed to in writing, software distributed under
|
8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9 | * OF ANY KIND, either express or implied. See the License for the specific language
|
10 | * governing permissions and limitations under the License.
|
11 | */
|
12 |
|
13 | import {
|
14 | AriaAttributes,
|
15 | AriaRole,
|
16 | ClipboardEventHandler,
|
17 | CompositionEventHandler,
|
18 | CSSProperties,
|
19 | FormEventHandler,
|
20 | HTMLAttributeAnchorTarget,
|
21 | HTMLAttributeReferrerPolicy,
|
22 | DOMAttributes as ReactDOMAttributes,
|
23 | ReactEventHandler
|
24 | } from 'react';
|
25 |
|
26 | export interface AriaLabelingProps {
|
27 | /**
|
28 | * Defines a string value that labels the current element.
|
29 | */
|
30 | 'aria-label'?: string,
|
31 |
|
32 | /**
|
33 | * Identifies the element (or elements) that labels the current element.
|
34 | */
|
35 | 'aria-labelledby'?: string,
|
36 |
|
37 | /**
|
38 | * Identifies the element (or elements) that describes the object.
|
39 | */
|
40 | 'aria-describedby'?: string,
|
41 |
|
42 | /**
|
43 | * Identifies the element (or elements) that provide a detailed, extended description for the object.
|
44 | */
|
45 | 'aria-details'?: string
|
46 | }
|
47 |
|
48 | export interface AriaValidationProps {
|
49 | // https://www.w3.org/TR/wai-aria-1.2/#aria-errormessage
|
50 | /**
|
51 | * Identifies the element that provides an error message for the object.
|
52 | */
|
53 | 'aria-errormessage'?: string
|
54 | }
|
55 |
|
56 | // A set of common DOM props that are allowed on any component
|
57 | // Ensure this is synced with DOMPropNames in filterDOMProps
|
58 | export interface DOMProps {
|
59 | /**
|
60 | * The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
|
61 | */
|
62 | id?: string
|
63 | }
|
64 |
|
65 | export interface FocusableDOMProps extends DOMProps {
|
66 | /**
|
67 | * Whether to exclude the element from the sequential tab order. If true,
|
68 | * the element will not be focusable via the keyboard by tabbing. This should
|
69 | * be avoided except in rare scenarios where an alternative means of accessing
|
70 | * the element or its functionality via the keyboard is available.
|
71 | */
|
72 | excludeFromTabOrder?: boolean
|
73 | }
|
74 |
|
75 |
|
76 | export interface TextInputDOMEvents {
|
77 | // Clipboard events
|
78 | /**
|
79 | * Handler that is called when the user copies text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy).
|
80 | */
|
81 | onCopy?: ClipboardEventHandler<HTMLInputElement>,
|
82 |
|
83 | /**
|
84 | * Handler that is called when the user cuts text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut).
|
85 | */
|
86 | onCut?: ClipboardEventHandler<HTMLInputElement>,
|
87 |
|
88 | /**
|
89 | * Handler that is called when the user pastes text. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste).
|
90 | */
|
91 | onPaste?: ClipboardEventHandler<HTMLInputElement>,
|
92 |
|
93 | // Composition events
|
94 | /**
|
95 | * Handler that is called when a text composition system starts a new text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event).
|
96 | */
|
97 | onCompositionStart?: CompositionEventHandler<HTMLInputElement>,
|
98 |
|
99 | /**
|
100 | * Handler that is called when a text composition system completes or cancels the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionend_event).
|
101 | */
|
102 | onCompositionEnd?: CompositionEventHandler<HTMLInputElement>,
|
103 |
|
104 | /**
|
105 | * Handler that is called when a new character is received in the current text composition session. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/compositionupdate_event).
|
106 | */
|
107 | onCompositionUpdate?: CompositionEventHandler<HTMLInputElement>,
|
108 |
|
109 | // Selection events
|
110 | /**
|
111 | * Handler that is called when text in the input is selected. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/select_event).
|
112 | */
|
113 | onSelect?: ReactEventHandler<HTMLInputElement>,
|
114 |
|
115 | // Input events
|
116 | /**
|
117 | * Handler that is called when the input value is about to be modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event).
|
118 | */
|
119 | onBeforeInput?: FormEventHandler<HTMLInputElement>,
|
120 | /**
|
121 | * Handler that is called when the input value is modified. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event).
|
122 | */
|
123 | onInput?: FormEventHandler<HTMLInputElement>
|
124 | }
|
125 |
|
126 | export interface InputDOMProps {
|
127 | /**
|
128 | * The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).
|
129 | */
|
130 | name?: string
|
131 | }
|
132 |
|
133 | // DOM props that apply to all text inputs
|
134 | // Ensure this is synced with useTextField
|
135 | export interface TextInputDOMProps extends DOMProps, InputDOMProps, TextInputDOMEvents {
|
136 | /**
|
137 | * Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).
|
138 | */
|
139 | autoComplete?: string,
|
140 |
|
141 | /**
|
142 | * The maximum number of characters supported by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength).
|
143 | */
|
144 | maxLength?: number,
|
145 |
|
146 | /**
|
147 | * The minimum number of characters required by the input. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength).
|
148 | */
|
149 | minLength?: number,
|
150 |
|
151 | /**
|
152 | * Regex pattern that the value of the input must match to be valid. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefpattern).
|
153 | */
|
154 | pattern?: string,
|
155 |
|
156 | /**
|
157 | * Content that appears in the input when it is empty. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefplaceholder).
|
158 | */
|
159 | placeholder?: string,
|
160 |
|
161 | /**
|
162 | * The type of input to render. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype).
|
163 | */
|
164 | type?: 'text' | 'search' | 'url' | 'tel' | 'email' | 'password' | (string & {}),
|
165 |
|
166 | /**
|
167 | * Hints at the type of data that might be entered by the user while editing the element or its contents. See [MDN](https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute).
|
168 | */
|
169 | inputMode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'
|
170 | }
|
171 |
|
172 | // Make sure to update filterDOMProps.ts when updating this.
|
173 | export interface LinkDOMProps {
|
174 | /** A URL to link to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href). */
|
175 | href?: string,
|
176 | /** The target window for the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target). */
|
177 | target?: HTMLAttributeAnchorTarget,
|
178 | /** The relationship between the linked resource and the current page. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). */
|
179 | rel?: string,
|
180 | /** Causes the browser to download the linked URL. A string may be provided to suggest a file name. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download). */
|
181 | download?: boolean | string,
|
182 | /** A space-separated list of URLs to ping when the link is followed. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#ping). */
|
183 | ping?: string,
|
184 | /** How much of the referrer to send when following the link. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#referrerpolicy). */
|
185 | referrerPolicy?: HTMLAttributeReferrerPolicy
|
186 | }
|
187 |
|
188 | /** Any focusable element, including both HTML and SVG elements. */
|
189 | export interface FocusableElement extends Element, HTMLOrSVGElement {}
|
190 |
|
191 | /** All DOM attributes supported across both HTML and SVG elements. */
|
192 | export interface DOMAttributes<T = FocusableElement> extends AriaAttributes, ReactDOMAttributes<T> {
|
193 | id?: string | undefined,
|
194 | role?: AriaRole | undefined,
|
195 | tabIndex?: number | undefined,
|
196 | style?: CSSProperties | undefined,
|
197 | className?: string | undefined
|
198 | }
|
199 |
|
200 | export interface GroupDOMAttributes extends Omit<DOMAttributes<HTMLElement>, 'role'> {
|
201 | role?: 'group' | 'region' | 'presentation'
|
202 | }
|