Last active
September 21, 2017 16:45
-
-
Save colevoss/0be3254093e6b319fc53a556bd62bcaa to your computer and use it in GitHub Desktop.
Select With Custom Option Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CharacterOption = ({ value, data, onSelect }) => { | |
return ( | |
<div onClick={() => onSelect(value)}> | |
<div className="char-avatar"> | |
<img src={data.avatar} /> | |
</div> | |
<div className="char-name"> | |
{data.firstName} {data.lastName} | |
</div> | |
<div className="char-email">{data.email}</div> | |
</div> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Select } from 'uniform'; | |
import CharacterOption from './CharacterOption'; | |
const selectOptions = [ | |
{ | |
value: 'lukeSkywalker', | |
data: { | |
firstName: 'Luke', | |
lastName: 'Skywalker', | |
email: 'lskywalker420@rebels.gov', | |
avatar: 'l_skywalker.png', | |
}, | |
}, | |
{ | |
value: 'hanSolo', | |
data: { | |
firstName: 'Han', | |
lastName: 'Solo', | |
email: 'twelveparsecs@dontshootfirst.com', | |
avatar: 'h_solo.png', | |
}, | |
}, | |
{ | |
value: 'jarJarBinks', | |
data: { | |
firstName: 'Jar Jar', | |
lastName: 'Binks', | |
email: 'totallynotasithlord@gungan.gov', | |
avatar: 'jj_binks.png', | |
}, | |
}, | |
]; | |
class SomeForm extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
favStarwarsCharacter: null, | |
}; | |
} | |
render() { | |
return ( | |
<Select | |
name="fav-star-wars-character" | |
qaId="qa-fav-star-wars-character" | |
id="fav-star-wars-character-select" | |
options={selectOptions} | |
customOption={CharacterOption} | |
placeholder="Select your favorite Star Wars character" | |
value={this.state.favStarwarsCharacter} | |
onChange={selectedCharacter => this.setState({ favStarwarsCharacter: selectedCharacter.value })} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment