@octopusdeploy/design-system-components
Version:
The design systems component library.
131 lines (130 loc) • 4.91 kB
TypeScript
import * as React from "react";
import type { IconOnlyButtonProps } from "../../Button";
import type { PopoverBasicHelpProps } from "../../Popover";
import type { ValidationState } from "../Primitives/InputValidationMessage";
import type { DescriptionContent } from "../utils/descriptionWithLinks";
type BaseTextFieldProps<T> = {
value?: T;
/**
* The label for the input field
*/
label: string;
/**
* The placeholder text to display when input is empty
*/
placeholder?: string;
/**
* The description text to display below the input
*/
description?: string | DescriptionContent;
/**
* Validation message to display.
*
* This will always be displayed as an error unless the component supports the `validationState` prop and changes it to `success`.
*/
validationMessage?: string;
/**
* The validation state, used to style the validation message and input border.
* Only applied when a `validationMessage` is provided; defaults to `"error"` in that case.
*/
validationState?: ValidationState;
/**
* Whether the field is disabled
*/
disabled?: boolean;
/**
* Whether the field is required
*/
hasRequiredMarker?: boolean;
/**
* Whether to show optional marker
*/
hasOptionalMarker?: boolean;
/**
* Whether this field has a default value marker
*/
hasDefaultMarker?: boolean;
/**
* PopoverBasicHelp component to display additional help information
*/
popover?: React.ReactElement<PopoverBasicHelpProps>;
/**
* Whether to autofocus the input
*/
autoFocus?: boolean;
/**
* Whether the input is readonly
*/
readOnly?: boolean;
/**
* The name attribute for the input
*/
name?: string;
/**
* The prefix to display before the input - can be a string or a icon it cannot be interactive
*/
prefix?: string | React.ReactElement;
/**
* The suffix to display after the input - can be a string or a button with ghost importance and medium size only
*/
suffix?: string | React.ReactElement<IconOnlyButtonProps>;
/**
* The action to perform when the form control field is changed.
*/
onChange: (newValue: T) => void;
};
type TextFieldPropsWithNumberType<T> = BaseTextFieldProps<T> & {
/**
* The input type must be "number" to use min, max, and step
*/
type: "number";
/**
* The minimum value allowed
*/
min?: number;
/**
* The maximum value allowed
*/
max?: number;
/**
* The step value for the number input
*/
step?: number | "any";
};
type TextFieldPropsRemainingTypes<T> = BaseTextFieldProps<T> & {
/**
* The input type (text, email, password, etc.)
*/
type?: "text" | "email" | "password" | "tel" | "url" | "search" | "time";
};
export type TextFieldProps<T> = TextFieldPropsWithNumberType<T> | TextFieldPropsRemainingTypes<T>;
/**
* TextField component
* @remarks Rollout currently paused — do not use in new code until further notice.
* Use `<Text>` instead.
* @see <Text>
*
* @param props - TextFieldProps
* @param props.label - The label for the input field
* @param props.value - The current value of the input
* @param props.type - The input type (text, email, password, etc.)
* @param props.placeholder - The placeholder text to display when input is empty
* @param props.description - The description text to display below the input
* @param props.validationMessage - Validation message to display
* @param props.validationState - The validation state ('error' | 'success'). Only applied when a `validationMessage` is provided; defaults to 'error' in that case.
* @param props.disabled - Whether the field is disabled
* @param props.hasRequiredMarker - Whether the field is required
* @param props.hasOptionalMarker - Whether to show optional marker
* @param props.hasDefaultMarker - Whether this field has a default value marker
* @param props.popover - PopoverBasicHelp component to display additional help information e.g. <PopoverBasicHelp placement="right-start" description="A popover" />
* @param props.autoFocus - Whether to autofocus the input
* @param props.readOnly - Whether the input is readonly
* @param props.name - The name attribute for the input
* @param props.prefix - The prefix to display before the input - can be a string or a icon it cannot be interactive
* @param props.suffix - The suffix to display after the input - can be a string or a button with ghost importance and medium size only
* @param props.onChange - The action to perform when the form control field is changed
*
* @returns TextField component
*/
export declare function TextField<T extends string | number | undefined>(props: TextFieldProps<T>): import("react/jsx-runtime").JSX.Element;
export {};