import React, { ReactNode, MouseEventHandler, TouchEventHandler, PointerEventHandler, UIEventHandler, WheelEventHandler, AnimationEventHandler, TransitionEventHandler, ClipboardEventHandler, CompositionEventHandler, ReactEventHandler, FormEventHandler, HTMLAttributeAnchorTarget, HTMLAttributeReferrerPolicy, ReactElement, MouseEvent, FocusEvent, SyntheticEvent, KeyboardEvent as KeyboardEvent$2, CSSProperties, DetailedHTMLProps, AnchorHTMLAttributes, ElementType, JSXElementConstructor, ButtonHTMLAttributes, HTMLAttributes, Ref, JSX, InputHTMLAttributes, LabelHTMLAttributes } from 'react'; /* * Copyright 2020 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ type ValidationState = 'valid' | 'invalid'; type ValidationError = string | string[]; interface Validation { /** Whether user input is required on the input before form submission. */ isRequired?: boolean; /** Whether the input value is invalid. */ isInvalid?: boolean; /** @deprecated Use `isInvalid` instead. */ validationState?: ValidationState; /** * Whether to use native HTML form validation to prevent form submission * when the value is missing or invalid, or mark the field as required * or invalid via ARIA. * * @default 'aria' */ validationBehavior?: 'aria' | 'native'; /** * A function that returns an error message if a given value is invalid. * Validation errors are displayed to the user when the form is submitted * if `validationBehavior="native"`. For realtime validation, use the `isInvalid` * prop instead. */ validate?: (value: T) => ValidationError | true | null | undefined; } interface ValidationResult { /** Whether the input value is invalid. */ isInvalid: boolean; /** The current error messages for the input if it is invalid, otherwise an empty array. */ validationErrors: string[]; /** The native validation details for the input. */ validationDetails: ValidityState; } interface InputBase { /** Whether the input is disabled. */ isDisabled?: boolean; /** Whether the input can be selected but not changed by the user. */ isReadOnly?: boolean; } interface ValueBase { /** The current value (controlled). */ value?: T; /** The default value (uncontrolled). */ defaultValue?: T; /** Handler that is called when the value changes. */ onChange?: (value: C) => void; } interface TextInputBase { /** Temporary text that occupies the text input when it is empty. */ placeholder?: string; } interface RangeValue { /** The start value of the range. */ start: T; /** The end value of the range. */ end: T; } interface RangeInputBase { /** The smallest value allowed for the input. */ minValue?: T; /** The largest value allowed for the input. */ maxValue?: T; /** The amount that the input value changes with each increment or decrement "tick". */ step?: T; // ?? } interface HelpTextProps { /** A description for the field. Provides a hint such as specific requirements for what to choose. */ description?: ReactNode; /** An error message for the field. */ errorMessage?: ReactNode | ((v: ValidationResult) => ReactNode); } /* * Copyright 2020 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ interface AriaLabelingProps { /** * Defines a string value that labels the current element. */ 'aria-label'?: string; /** * Identifies the element (or elements) that labels the current element. */ 'aria-labelledby'?: string; /** * Identifies the element (or elements) that describes the object. */ 'aria-describedby'?: string; /** * Identifies the element (or elements) that provide a detailed, extended description for the * object. */ 'aria-details'?: string; } interface AriaValidationProps { // https://www.w3.org/TR/wai-aria-1.2/#aria-errormessage /** * Identifies the element that provides an error message for the object. */ 'aria-errormessage'?: string; } // A set of common DOM props that are allowed on any component // Ensure this is synced with DOMPropNames in filterDOMProps interface DOMProps$1 { /** * The element's unique identifier. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */ id?: string; } interface FocusableDOMProps extends DOMProps$1 { /** * Whether to exclude the element from the sequential tab order. If true, * the element will not be focusable via the keyboard by tabbing. This should * be avoided except in rare scenarios where an alternative means of accessing * the element or its functionality via the keyboard is available. */ excludeFromTabOrder?: boolean; } interface TextInputDOMEvents { // Clipboard events /** * Handler that is called when the user copies text. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy). */ onCopy?: ClipboardEventHandler; /** * Handler that is called when the user cuts text. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncut). */ onCut?: ClipboardEventHandler; /** * Handler that is called when the user pastes text. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/onpaste). */ onPaste?: ClipboardEventHandler; // Composition events /** * 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). */ onCompositionStart?: CompositionEventHandler; /** * 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). */ onCompositionEnd?: CompositionEventHandler; /** * 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). */ onCompositionUpdate?: CompositionEventHandler; // Selection events /** * 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). */ onSelect?: ReactEventHandler; // Input events /** * 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). */ onBeforeInput?: FormEventHandler; /** * Handler that is called when the input value is modified. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event). */ onInput?: FormEventHandler; } interface InputDOMProps { /** * 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). */ name?: string; /** * The `
` element to associate the input with. * The value of this attribute must be the id of a `` in the same document. * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). */ form?: string; } // DOM props that apply to all text inputs // Ensure this is synced with useTextField interface TextInputDOMProps extends DOMProps$1, InputDOMProps, TextInputDOMEvents { /** * 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). */ autoComplete?: string; /** * The maximum number of characters supported by the input. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefmaxlength). */ maxLength?: number; /** * The minimum number of characters required by the input. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefminlength). */ minLength?: number; /** * 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). */ pattern?: string; /** * Content that appears in the input when it is empty. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefplaceholder). */ placeholder?: string; /** * The type of input to render. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdeftype). * * @default 'text' */ type?: 'text' | 'search' | 'url' | 'tel' | 'email' | 'password' | (string & {}); /** * 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). */ inputMode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'; /** * An attribute that takes as its value a space-separated string that describes what, if any, type * of autocomplete functionality the input should provide. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete). */ autoCorrect?: string; /** * An enumerated attribute that defines whether the element may be checked for spelling errors. * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck). */ spellCheck?: string; } /** * This type allows configuring link props with router options and type-safe URLs via TS module * augmentation. By default, this is an empty type. Extend with `href` and `routerOptions` * properties to configure your router. */ interface RouterConfig {} type Href = RouterConfig extends {href: infer H} ? H : string; type RouterOptions = RouterConfig extends {routerOptions: infer O} ? O : never; // Make sure to update filterDOMProps.ts when updating this. interface LinkDOMProps { /** A URL to link to. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href). */ href?: Href; /** * Hints at the human language of the linked URL. * See[MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#hreflang). */ hrefLang?: string; /** * The target window for the link. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target). */ target?: HTMLAttributeAnchorTarget; /** * The relationship between the linked resource and the current page. See * [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). */ rel?: string; /** * 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). */ download?: boolean | string; /** * 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). */ ping?: string; /** * 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). */ referrerPolicy?: HTMLAttributeReferrerPolicy; /** Options for the configured client side router. */ routerOptions?: RouterOptions; } /** Any focusable element, including both HTML and SVG elements. */ interface FocusableElement extends Element, HTMLOrSVGElement {} /** * Global attributes that can be applied to any DOM element. * * @private */ // NOTE: id is handled elsewhere (DOMProps). interface GlobalDOMAttributes extends GlobalDOMEvents { dir?: string | undefined; lang?: string | undefined; hidden?: boolean | undefined; inert?: boolean | undefined; translate?: 'yes' | 'no' | undefined; } /** * Global DOM events that are supported on all DOM elements. * * @private */ // NOTES: // - Drag and drop events are omitted for now. // - Keyboard and focus events are supported directly on focusable elements (FocusableProps). // - Text input events (e.g. onInput, onCompositionStart, onCopy) are // supported only directly on input elements (TextInputDOMProps). // We don't support contentEditable on our components. // - Media events should be handled directly on the