import { LabelAccessibilityVisibilityProps } from './accessibility'; import { ComponentChildren } from './children'; import { InteractionProps } from './clickable'; import { FocusEventProps } from './events'; import { IconType } from './icons'; interface BaseInputProps { /** * An identifier for the field that is unique within the nearest * containing `Form` component. */ name?: string; /** * Disables the field, disallowing any interaction. */ disabled?: boolean; } export interface InputProps extends BaseInputProps { /** * Callback when the user has **finished editing** a field, e.g. once they have blurred the field. */ onChange?: (newValue: string) => void; /** * Callback when the user makes any changes in the field. */ onInput?: (newValue: string) => void; /** * The current value for the field. If omitted, the field will be empty. */ value?: string; /** * The default value for the field. */ defaultValue?: string; } export interface MultipleInputProps extends BaseInputProps { /** * Callback when the user has selected file(s). */ onChange?: (newValue: string[]) => void; /** * Callback when the user has selected file(s). */ onInput?: (newValue: string[]) => void; /** * An array of the `value`s of the selected options. * * This is a convenience prop for setting the `selected` prop on child options. */ values?: string[]; } export interface FileInputProps extends BaseInputProps { /** * Callback when the user has **finished editing** a field, e.g. once they have blurred the field. */ onChange?: (newValue: T) => void; /** * Callback when the user makes any changes in the field. */ onInput?: (newValue: T) => void; /** * The current value for the field. * * TODO: This is a read-only getter. * We haven't agreed how to represent that yet. */ value?: T; } export interface FieldErrorProps { /** * Indicate an error to the user. The field will be given a specific stylistic treatment * to communicate problems that have to be resolved immediately. */ error?: string; } export interface BasicFieldProps extends FieldErrorProps, LabelAccessibilityVisibilityProps { /** * Whether the field needs a value. This requirement adds semantic value * to the field, but it will not cause an error to appear automatically. * If you want to present an error when this field is empty, you can do * so with the `error` prop. */ required?: boolean; /** * Content to use as the field label. */ label?: string; } export interface FieldDetailsProps { /** * Additional text to provide context or guidance for the field. * This text is displayed along with the field and its label * to offer more information or instructions to the user. * * This will also be exposed to screen reader users. */ details?: string; } export interface FieldProps extends BasicFieldProps, InputProps, FocusEventProps, FieldDetailsProps { /** * A short hint that describes the expected value of the field. */ placeholder?: string; } export interface BaseTextFieldProps extends FieldProps { /** * The field cannot be edited by the user. It is focusable will be announced by screen readers. */ readOnly?: boolean; } export interface FieldDecorationProps { /** * A value to be displayed immediately after the editable portion of the field. * * This is useful for displaying an implied part of the value, such as "@shopify.com", or "%". * * This cannot be edited by the user, and it isn't included in the value of the field. * * It may not be displayed until the user has interacted with the input. * For example, an inline label may take the place of the suffix until the user focuses the input. * * @default '' */ suffix?: string; /** * A value to be displayed immediately before the editable portion of the field. * * This is useful for displaying an implied part of the value, such as "https://" or "+353". * * This cannot be edited by the user, and it isn't included in the value of the field. * * It may not be displayed until the user has interacted with the input. * For example, an inline label may take the place of the prefix until the user focuses the input. * * @default '' */ prefix?: string; /** * The type of icon to be displayed in the field. * * @default '' */ icon?: IconType; /** * Additional content to be displayed in the field. * Commonly used to display an icon that activates a tooltip providing more information. */ accessory?: ComponentChildren; } export interface NumberConstraintsProps { /** * The highest decimal or integer to be accepted for the field. * When used with `step` the value will round down to the max number. * * Note: a user will still be able to use the keyboard to input a number higher than * the max. It is up to the developer to add appropriate validation. * * @default Infinity */ max?: number; /** * The lowest decimal or integer to be accepted for the field. * When used with `step` the value will round up to the min number. * * Note: a user will still be able to use the keyboard to input a number lower than * the min. It is up to the developer to add appropriate validation. * * @default -Infinity */ min?: number; /** * The amount the value can increase or decrease by. This can be an integer or decimal. * If a `max` or `min` is specified with `step` when increasing/decreasing the value * via the buttons, the final value will always round to the `max` or `min` * rather than the closest valid amount. * * @default 1 */ step?: number; /** * Sets the type of controls displayed in the field. * * - `stepper`: displays buttons to increase or decrease the value of the field by the stepping interval defined in the `step` property. * Appropriate mouse and [keyboard interactions](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/spinbutton_role#keyboard_interactions) to control the value of the field are enabled. * - `none`: no controls are displayed and users must input the value manually. Arrow keys and scroll wheels can’t be used either to avoid accidental changes. * - `auto`: the presence of the controls depends on the surface and context. * * @default 'auto' */ controls?: 'auto' | 'stepper' | 'none'; } export interface MinMaxLengthProps { /** * Specifies the maximum number of characters allowed. * * @default Infinity */ maxLength?: number; /** * Specifies the min number of characters allowed. * * @default 0 */ minLength?: number; } interface BaseSelectableProps { /** * A label used for users using assistive technologies like screen readers. When set, any children or `label` supplied will not be announced. * This can also be used to display a control without a visual label, while still providing context to users using screen readers. */ accessibilityLabel?: string; /** * Disables the control, disallowing any interaction. */ disabled?: boolean; /** * The value used in form data when the control is checked. */ value?: string; } export interface BaseOptionProps extends BaseSelectableProps { /** * Whether the control is active. */ selected?: boolean; /** * Whether the control is active by default. */ defaultSelected?: boolean; } export interface BaseCheckableProps extends BaseSelectableProps, InteractionProps { /** * Visual content to use as the control label. */ label?: string; /** * Whether the control is active. */ checked?: boolean; /** * Whether the control is active by default. */ defaultChecked?: boolean; /** * An identifier for the control that is unique within the nearest * containing `Form` component. */ name?: string; /** * A callback that is run whenever the control is changed. */ onChange?: (checked: boolean) => void; /** * A callback that is run whenever the control is changed. */ onInput?: (checked: boolean) => void; } export {};