import { Story, Canvas, ArgsTable } from '@storybook/addon-docs'; import { TextFieldBase } from './text-field-base'; ### This is a base component. It should not be used in your feature code directly but as a "base" for other UI components # TextFieldBase The `TextFieldBase` is the base component for all text fields. It should not be used directly. It functions as both a uncontrolled and controlled input. ## Props The `TextFieldBase` accepts all props below as well as all [Box](/docs/ui-components-ui-box-box-stories-js--default-story#props) component props ### Size Use the `size` prop to set the height of the `TextFieldBase`. Possible sizes include: - `sm` 32px - `md` 40px - `lg` 48px Defaults to `md` ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; import { SIZES } from '../../../helpers/constants/design-system'; ``` ### Type Use the `type` prop to change the type of input. Possible types include: - `text` - `number` - `password` Defaults to `text`. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; // (Default) ``` ### Truncate Use the `truncate` prop to truncate the text of the the `TextFieldBase`. Defaults to `true`. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; // truncate is set to `true` by default ; ``` ### Left Accessory Right Accessory Use the `leftAccessory` and `rightAccessory` props to add components such as icons or buttons to either side of the `TextFieldBase`. ```jsx import { COLORS, SIZES, DISPLAY } from '../../../helpers/constants/design-system'; import { Icon, ICON_NAMES } from '../../ui/component-library/icons'; import { TextFieldBase } from '../../ui/component-library/text-field'; } /> } /> } rightAccessory={} /> } rightAccessory={ isAddressValid && ( ) } /> ``` ### Input Ref Use the `inputRef` prop to access the ref of the `` html element of `TextFieldBase`. This is useful for focusing the input from a button or other component. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; const inputRef = useRef(null); const [value, setValue] = useState(''); const handleOnClick = () => { inputRef.current.focus(); }; const handleOnChange = (e) => { setValue(e.target.value); }; // TODO: replace with Button component Edit ``` ### Auto Complete Use the `autoComplete` prop to set the autocomplete html attribute. It allows the browser to predict the value based on earlier typed values. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Auto Focus Use the `autoFocus` prop to focus the `TextFieldBase` during the first mount ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Default Value Use the `defaultValue` prop to set the default value of the `TextFieldBase` ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Disabled Use the `disabled` prop to set the disabled state of the `TextFieldBase` ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Error Use the `error` prop to set the error state of the `TextFieldBase` ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Max Length Use the `maxLength` prop to set the maximum allowed input characters for the `TextFieldBase` ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Read Only Use the `readOnly` prop to set the `TextFieldBase` to read only. When `readOnly` is true `TextFieldBase` will not have a focus state. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; ; ``` ### Required Use the `required` prop to set the `TextFieldBase` to required. Currently there is no visual difference to the `TextFieldBase` when required. ```jsx import { TextFieldBase } from '../../ui/component-library/text-field-base'; // Currently no visual difference ; ```