Skip to content

Instantly share code, notes, and snippets.

@parwatcodes
Last active April 23, 2019 07:51
Show Gist options
  • Save parwatcodes/480f51eeddaa64422b86d834f78f9bcd to your computer and use it in GitHub Desktop.
Save parwatcodes/480f51eeddaa64422b86d834f78f9bcd to your computer and use it in GitHub Desktop.
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import { capitalizeFirstLetters } from 'Utils';
type Props = {
name: string,
label: string,
options: Object,
idKey: string,
nameKey: string,
cfl: Boolean,
all: Boolean,
};
const Select = ({ name, label, options = [], idKey, nameKey, cfl, all, ...rest }: Props) => {
return (
<React.Fragment>
<div>
<label htmlFor={name}>{label}: </label>
<select name={name} id={name} {...rest}>
{all && (
<>
<option key={21} value="all">
All
</option>
<option disabled>___________________</option>
</>
)}
{options.map(option => (
<option key={option[idKey]} value={option[idKey]}>
{cfl ? capitalizeFirstLetters(option[nameKey]) : option[nameKey]}
</option>
))}
</select>
</div>
</React.Fragment>
);
};
<Select
name="user_role"
// value="Navi"
label="Type"
options={USER_ROLES}
// onChange={this.handleChange}
idKey="role"
nameKey="name"
all
/>
export default Select;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment