anephenix/ui

View on GitHub
src/components/select/Select.jsx

Summary

Maintainability
A
35 mins
Test Coverage
F
50%
import React, { forwardRef } from 'react';
import './Select.scss';

const Option = ({ value, label }, index) => (
    <option key={index} value={value}>
        {label}
    </option>
);

const Select = forwardRef(function select(
    { className, defaultValue, name, onChange, options },
    ref
) {
    return (
        <select
            ref={ref}
            name={name}
            className={'select ' + className}
            defaultValue={defaultValue}
            onChange={onChange}
        >
            {options.map(Option)}
        </select>
    );
});

export default Select;