WIP Input

This commit is contained in:
Rodrigo Antinarelli 2020-02-13 20:14:59 -03:00 committed by James A. Petts
parent c391c007ff
commit 7617a8b9ee
2 changed files with 45 additions and 16 deletions

View File

@ -1,17 +1,43 @@
import React from 'react'; import React from 'react';
import Label from '../Label'; import Label from '../Label';
const Input = ({ label, ...rest }) => { const Input = ({
return ( label,
<> containerClassName = '',
<Label text="Label"> className = '',
transparent = defaults.transparent,
...rest
}) => {
const getClasses = () => {
const classes = [];
classes.push(transparentClasses[transparent]);
return classes.join(' ');
};
const input = (
<input <input
className="transition duration-300 shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" className={`shadow transition duration-300 appearance-none border rounded w-full py-2 px-3 text-sm text-gray-700 hover:border-gray-500 leading-tight focus:border-gray-500 focus:outline-none ${getClasses()} ${className}`}
id="id"
{...rest} {...rest}
/> />
</Label>
</>
); );
const renderElement = () => {
return label ? <Label text="Label">{input}</Label> : input;
};
return <div className={`flex ${containerClassName}`}>{renderElement()}</div>;
};
const defaults = {
transparent: false,
};
const transparentClasses = {
true: 'bg-transparent',
false: '',
}; };
export default Input; export default Input;

View File

@ -19,12 +19,15 @@ import Input from './';
{() => { {() => {
const [inputValue, setInputValue] = React.useState(''); const [inputValue, setInputValue] = React.useState('');
return ( return (
<div className="m-5 bg-black">
<Input <Input
transparent
containerClassName="mb-3"
label="Label" label="Label"
value={inputValue} placeholder="With Label"
placeholder="Type something..."
onChange={e => setInputValue(e.target.value)}
/> />
<Input placeholder="Without label" />
</div>
); );
}} }}
</Playground> </Playground>