UNPKG

@tiller-ds/form-elements

Version:

Form elements module of Tiller Design System

243 lines (242 loc) 13.9 kB
import React from "react"; import { TokenProps, ComponentTokens } from "@tiller-ds/theme"; export declare type InputProps = { /** * Allows the clear button (x) to be shown when a value is present in the field. * Off by default. */ allowClear?: boolean; /** * Custom add on displayed in the input field. */ addOn?: React.ReactNode; /** * Custom classes for the container. * Overrides conflicting default styles, if any. * * The provided `className` is processed using `tailwind-merge` to eliminate redundant or conflicting Tailwind classes. */ className?: string; /** * Determines whether the component is disabled. */ disabled?: boolean; /** * Value passed through from validation indicating to display the error on the component. */ error?: React.ReactNode; /** * Changes the styling of the component to appear as extendable on the bottom, * suitable for advancing your input component with a bottom display. * An arbitrary look of the extension is passed as this prop. */ extend?: React.ReactNode; /** * The help text displayed below the input field (not exclusively text). */ help?: React.ReactNode; /** * Custom add on displayed in the input field inline. */ inlineLeadingAddOn?: React.ReactNode; /** * Custom add on icon displayed in the input field inline. */ inlineLeadingIcon?: React.ReactNode; /** * Custom add on displayed in the input field after the text. */ inlineTrailingAddOn?: React.ReactNode; /** * Custom add on icon displayed in the input field after the text. */ inlineTrailingIcon?: React.ReactNode; /** * Optional ref property to pass onto the HTML input component. * @deprecated Will be removed in next major version, use `ref` instead */ inputRef?: React.Ref<HTMLInputElement>; /** * Represents the label above the input field. */ label?: React.ReactNode; /** * The accessor value for the input field component (for validation, fetching, etc.). */ name: string; /** * Defines the behaviour of the component once the state resets. */ onReset?: () => void; /** * Optional component displayed under the field component and above the help and error. * Useful for rendering arbitrary items under the component. */ addonBelow?: React.ReactNode; /** * The placeholder displayed inside the input field. */ placeholder?: string; /** * Turns this field into a required field in the form. Only applies visual representation (* next to label), * still requires validation on frontend or backend to accompany this value if set to true. */ required?: boolean; /** * A unique identifier for testing purposes. * This identifier can be used in testing frameworks like Jest or Cypress to locate specific elements for testing. * It helps ensure that UI components are behaving as expected across different scenarios. * @type {string} * @example * // Usage: * <MyComponent data-testid="my-component" /> * // In tests: * getByTestId('my-component'); */ "data-testid"?: string; /** * Tooltip icon and text (on icon hover) displayed on the right of the label. */ tooltip?: React.ReactNode; /** * The value of the field sent on submit and/or retrieved on component render. */ value?: string; /** * Custom icon for clearing input field */ clearIcon?: React.ReactElement; /** * Custom icon for warning on input */ warningIcon?: React.ReactElement; } & Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "onReset" | "ref"> & InputTokens; export declare type InputIconProps = { icon: React.ReactNode; trailing?: boolean; inputId?: string; } & TokenProps<"Input">; export declare type InputAddOnProps = { addOn: React.ReactNode; className?: string; } & TokenProps<"Input">; export declare type InputInlineAddOnProps = { inline?: boolean; trailing?: boolean; children: React.ReactNode; } & TokenProps<"Input">; export declare type InputTokens = { tokens?: ComponentTokens<"Input">; }; declare const Input: React.ForwardRefExoticComponent<{ /** * Allows the clear button (x) to be shown when a value is present in the field. * Off by default. */ allowClear?: boolean | undefined; /** * Custom add on displayed in the input field. */ addOn?: React.ReactNode; /** * Custom classes for the container. * Overrides conflicting default styles, if any. * * The provided `className` is processed using `tailwind-merge` to eliminate redundant or conflicting Tailwind classes. */ className?: string | undefined; /** * Determines whether the component is disabled. */ disabled?: boolean | undefined; /** * Value passed through from validation indicating to display the error on the component. */ error?: React.ReactNode; /** * Changes the styling of the component to appear as extendable on the bottom, * suitable for advancing your input component with a bottom display. * An arbitrary look of the extension is passed as this prop. */ extend?: React.ReactNode; /** * The help text displayed below the input field (not exclusively text). */ help?: React.ReactNode; /** * Custom add on displayed in the input field inline. */ inlineLeadingAddOn?: React.ReactNode; /** * Custom add on icon displayed in the input field inline. */ inlineLeadingIcon?: React.ReactNode; /** * Custom add on displayed in the input field after the text. */ inlineTrailingAddOn?: React.ReactNode; /** * Custom add on icon displayed in the input field after the text. */ inlineTrailingIcon?: React.ReactNode; /** * Optional ref property to pass onto the HTML input component. * @deprecated Will be removed in next major version, use `ref` instead */ inputRef?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined; /** * Represents the label above the input field. */ label?: React.ReactNode; /** * The accessor value for the input field component (for validation, fetching, etc.). */ name: string; /** * Defines the behaviour of the component once the state resets. */ onReset?: (() => void) | undefined; /** * Optional component displayed under the field component and above the help and error. * Useful for rendering arbitrary items under the component. */ addonBelow?: React.ReactNode; /** * The placeholder displayed inside the input field. */ placeholder?: string | undefined; /** * Turns this field into a required field in the form. Only applies visual representation (* next to label), * still requires validation on frontend or backend to accompany this value if set to true. */ required?: boolean | undefined; /** * A unique identifier for testing purposes. * This identifier can be used in testing frameworks like Jest or Cypress to locate specific elements for testing. * It helps ensure that UI components are behaving as expected across different scenarios. * @type {string} * @example * // Usage: * <MyComponent data-testid="my-component" /> * // In tests: * getByTestId('my-component'); */ "data-testid"?: string | undefined; /** * Tooltip icon and text (on icon hover) displayed on the right of the label. */ tooltip?: React.ReactNode; /** * The value of the field sent on submit and/or retrieved on component render. */ value?: string | undefined; /** * Custom icon for clearing input field */ clearIcon?: React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | undefined; /** * Custom icon for warning on input */ warningIcon?: React.ReactElement<any, string | ((props: any) => React.ReactElement<any, any> | null) | (new (props: any) => React.Component<any, any, any>)> | undefined; } & Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "form" | "list" | "key" | "accept" | "alt" | "autoComplete" | "autoFocus" | "capture" | "checked" | "crossOrigin" | "disabled" | "enterKeyHint" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "name" | "pattern" | "placeholder" | "readOnly" | "required" | "size" | "src" | "step" | "type" | "value" | "width" | "onChange" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & InputTokens & React.RefAttributes<HTMLInputElement>>; export default Input;