crabfit/crabfit-frontend/src/components/SelectField/SelectField.tsx
Ben Grant fdb7f0ef67 Tabs -> spaces
I have become my own worst enemy
2021-06-19 12:04:52 +10:00

44 lines
999 B
TypeScript

import { forwardRef } from 'react';
import {
Wrapper,
StyledLabel,
StyledSubLabel,
StyledSelect,
} from './selectFieldStyle';
const SelectField = forwardRef(({
label,
subLabel,
id,
options = [],
inline = false,
small = false,
defaultOption,
...props
}, ref) => (
<Wrapper inline={inline} small={small}>
{label && <StyledLabel htmlFor={id} inline={inline} small={small}>{label}</StyledLabel>}
{subLabel && <StyledSubLabel htmlFor={id}>{subLabel}</StyledSubLabel>}
<StyledSelect
id={id}
small={small}
ref={ref}
{...props}
>
{defaultOption && <option value="">{defaultOption}</option>}
{Array.isArray(options) ? (
options.map(value =>
<option key={value} value={value}>{value}</option>
)
) : (
Object.entries(options).map(([key, value]) =>
<option key={key} value={key}>{value}</option>
)
)}
</StyledSelect>
</Wrapper>
));
export default SelectField;