zepio/app/components/input.js

51 lines
933 B
JavaScript
Raw Normal View History

2018-12-06 07:42:30 -08:00
// @flow
import React from 'react';
import styled from 'styled-components';
// TODO: Missing styles
const defaultStyles = `
padding: 10px;
width: 100%;
`;
const Input = styled.input.attrs({
type: 'text',
})`
${defaultStyles};
`;
const Textarea = styled.textarea`
${defaultStyles};
`;
type Props = {
inputType?: 'input' | 'textarea' | 'dropdown',
value: string,
onChange: string => void,
rows?: number,
disabled?: boolean,
type?: string,
};
export const InputComponent = ({ inputType, onChange, ...props }: Props) => {
if (inputType === 'input') {
return <Input onChange={evt => onChange(evt.target.value)} {...props} />;
}
if (inputType === 'textarea') {
return <Textarea onChange={evt => onChange(evt.target.value)} {...props} />;
}
// TODO: Dropdown component
return null;
};
InputComponent.defaultProps = {
inputType: 'input',
rows: 4,
disabled: false,
type: 'text',
};