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.
56 lines
1.6 KiB
56 lines
1.6 KiB
import React, { FC } from 'react'
|
|
import classNames from 'classnames'
|
|
import noop from 'lodash/noop'
|
|
|
|
import { notificationTypeToClassName } from 'src/utils'
|
|
import { FormNotification, ClassDictionary } from 'src/types'
|
|
|
|
interface SelectOptions {
|
|
[value: string]: string
|
|
}
|
|
|
|
export interface Props {
|
|
name: string
|
|
label: string
|
|
options: SelectOptions
|
|
value?: string
|
|
notification?: FormNotification
|
|
setValue?: (value: string) => void
|
|
}
|
|
|
|
const SelectField: FC<Props> = ({
|
|
label,
|
|
options = {},
|
|
value = '',
|
|
notification,
|
|
setValue = noop,
|
|
}) => {
|
|
const opts = Object.entries(options)
|
|
const controlClassDictionary: ClassDictionary = { select: true, 'is-small': true }
|
|
const helpClassDictionary: ClassDictionary = { help: true }
|
|
|
|
console.log('notification', notification)
|
|
|
|
if (notification) {
|
|
const ncn = notificationTypeToClassName(notification.type)
|
|
|
|
controlClassDictionary[ncn] = true
|
|
helpClassDictionary[ncn] = true
|
|
}
|
|
|
|
return (
|
|
<div className="field">
|
|
<label className="label">{label}</label>
|
|
<div className={classNames(controlClassDictionary)}>
|
|
<select value={value} onChange={(e) => setValue(e.target.value)}>
|
|
{opts.map(([key, value]) => <option key={key} value={key}>{value}</option>)}
|
|
</select>
|
|
</div>
|
|
{notification &&
|
|
<p className={classNames(helpClassDictionary)}>{notification.message}</p>
|
|
}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default SelectField
|