Created
June 25, 2018 12:23
-
-
Save zushenyan/0ac7d28257e87b426cedf0e6fb0da9df to your computer and use it in GitHub Desktop.
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
// index.js | |
import React from "react"; | |
import ReactDOM from "react-dom"; | |
import Select from "react-select"; | |
import "./styles.css"; | |
const options = [ | |
{ label: "aaa", value: 1 }, | |
{ label: "bbb", value: 2 }, | |
{ label: "ccc", value: 3 } | |
]; | |
class App extends React.PureComponent { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: 0 | |
}; | |
} | |
render() { | |
const { value } = this.state; | |
return ( | |
<div> | |
<Select | |
options={options} | |
value={value} | |
placeholder="i am a placeholder" | |
onChange={({ value }) => this.setState({ value })} | |
searchable={false} | |
clearable={false} | |
arrowRenderer={({ isOpen }) => { | |
return isOpen ? "^" : "v"; | |
}} | |
optionRenderer={({ value: optionValue }, i) => { | |
return <span>{label}</span>; | |
}} | |
className="foo" | |
/> | |
<div>just a foobar</div> | |
</div> | |
); | |
} | |
} | |
const rootElement = document.getElementById("root"); | |
ReactDOM.render(<App />, rootElement); | |
// styles.css | |
.foo .Select-control { | |
position: relative; | |
border: 1px solid black; | |
height: 40px; | |
box-sizing: border-box; | |
} | |
.foo.Select.is-focused .Select-control { | |
background-color: red; | |
} | |
.foo .Select-multi-value-wrapper { | |
display: block; | |
height: 40px; | |
box-sizing: border-box; | |
} | |
.foo .Select-arrow-zone { | |
position: absolute; | |
display: block; | |
right: 0; | |
width: 25px; | |
height: 25px; | |
border: 1px solid black; | |
box-sizing: border-box; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://codesandbox.io/s/jvkvry5683