[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.
 
 

62 lines
1.9 KiB

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