[ABANDONED] React/Redux front end for the Flexor social network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

50 lines
1.5 KiB

import React, { FC, FocusEventHandler } from 'react'
import classNames from 'classnames'
import noop from 'lodash/noop'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { notificationTypeToClassName } from 'src/utils'
import { FormNotification, ClassDictionary } from 'src/types'
export interface Props {
name: string
label: string
placeholder?: string
value?: string
notification?: FormNotification
setValue?: (value: string) => void
onBlur?: FocusEventHandler
}
const TextField: FC<Props> = ({
label,
placeholder,
value = '',
notification,
setValue = noop,
onBlur = noop,
}) => {
const helpClassDictionary: ClassDictionary = { help: true }
const inputClassDictionary: ClassDictionary = { textarea: true }
if (notification) {
const ncn = notificationTypeToClassName(notification.type)
helpClassDictionary[ncn] = true
inputClassDictionary[ncn] = true
}
return (
<div className="field">
<label className="label">{label}</label>
<div className="control">
<textarea className={classNames(inputClassDictionary)} placeholder={placeholder} value={value} onChange={(e) => setValue(e.target.value)} onBlur={onBlur} />
</div>
{notification &&
<p className={classNames(helpClassDictionary)}>{notification.message}</p>
}
</div>
)
}
export default TextField