PteroTheme/resources/scripts/components/forms/OpenInputField.tsx

37 lines
993 B
TypeScript
Raw Normal View History

import * as React from 'react';
import classNames from 'classnames';
type Props = React.InputHTMLAttributes<HTMLInputElement> & {
label: string;
2019-06-12 06:02:18 +01:00
description?: string;
};
2019-06-12 06:02:18 +01:00
export default ({ className, description, onChange, label, ...props }: Props) => {
const [ value, setValue ] = React.useState('');
const classes = classNames('input open-label', {
'has-content': value && value.length > 0,
});
return (
<div className={'input-open'}>
<input
className={classes}
onChange={e => {
setValue(e.target.value);
if (onChange) {
onChange(e);
}
}}
{...props}
/>
<label htmlFor={props.id}>{label}</label>
2019-06-12 06:02:18 +01:00
{description &&
<p className={'text-xs text-neutral-500'}>
{description}
</p>
}
</div>
);
};