1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import React, { forwardRef } from 'react';
- import { Input, TextArea } from './styled';
- type Props = {
- id?: string;
- name?: string;
- onChange?: (val: string) => void;
- onBlur?: () => void;
- value?: string | number;
- defaultValue?: string | number;
- placeholder?: string;
- disabled?: boolean;
- error?: boolean;
- shouldFitContainer?: boolean;
- variant?: 'standard' | 'multiline';
- };
- type Ref = any;
- const InputBox = forwardRef<Ref, Props>(
- (
- { variant = 'standard', onChange, disabled = false, ...rest }: Props,
- ref
- ) => {
- const handleChange = (
- e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
- ): void => {
- if (onChange && !disabled) {
- onChange(e.target.value);
- }
- };
- return variant === 'standard' ? (
- <Input
- data-testid="input"
- ref={ref}
- disabled={disabled}
- onChange={handleChange}
- {...rest}
- />
- ) : (
- <TextArea
- ref={ref}
- disabled={disabled}
- onChange={handleChange}
- {...rest}
- />
- );
- }
- );
- InputBox.defaultProps = {
- id: '',
- name: '',
- onChange: () => {
- // do something
- },
- onBlur: () => {
- // do something
- },
- value: '',
- defaultValue: undefined,
- placeholder: '',
- disabled: false,
- error: false,
- shouldFitContainer: false,
- variant: 'standard',
- };
- export default InputBox;
|