UNPKG

2.81 kBTypeScriptView Raw
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
13import {ReactNode} from 'react';
14
15export type ValidationState = 'valid' | 'invalid';
16
17export interface Validation {
18 /** Whether the input should display its "valid" or "invalid" visual styling. */
19 validationState?: ValidationState,
20 /**
21 * Whether user input is required on the input before form submission.
22 * Often paired with the `necessityIndicator` prop to add a visual indicator to the input.
23 */
24 isRequired?: boolean
25}
26
27export interface InputBase {
28 /** Whether the input is disabled. */
29 isDisabled?: boolean,
30 /** Whether the input can be selected but not changed by the user. */
31 isReadOnly?: boolean
32}
33
34export interface ValueBase<T, C = T> {
35 /** The current value (controlled). */
36 value?: T,
37 /** The default value (uncontrolled). */
38 defaultValue?: T,
39 /** Handler that is called when the value changes. */
40 onChange?: (value: C) => void
41}
42
43export interface TextInputBase {
44 /** Temporary text that occupies the text input when it is empty. */
45 placeholder?: string
46}
47
48export interface SpectrumTextInputBase {
49 /**
50 * Temporary text that occupies the text input when it is empty.
51 * Please use help text instead.
52 * @deprecated
53 **/
54 placeholder?: string
55}
56
57export interface RangeValue<T> {
58 /** The start value of the range. */
59 start: T,
60 /** The end value of the range. */
61 end: T
62}
63
64export interface RangeInputBase<T> {
65 /** The smallest value allowed for the input. */
66 minValue?: T,
67 /** The largest value allowed for the input. */
68 maxValue?: T,
69 /** The amount that the input value changes with each increment or decrement "tick". */
70 step?: T // ??
71}
72
73export interface HelpTextProps {
74 /** A description for the field. Provides a hint such as specific requirements for what to choose. */
75 description?: ReactNode,
76 /** An error message for the field. */
77 errorMessage?: ReactNode
78}
79
80// Spectrum specific types. Extends `Validation` so that the `validationState` prop is available.
81export interface SpectrumHelpTextProps extends HelpTextProps, Validation {
82 /** Whether the description is displayed with lighter text. */
83 isDisabled?: boolean,
84 /** Whether an error icon is rendered. */
85 showErrorIcon?: boolean
86}