React select element
by lasha
HTML
<div id="app"></div>
SCSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
select {
height: 100%;
width: 100%;
opacity: 0;
position: absolute;
top: 0;
left: 0;
z-index: 1;
&:focus + .select-clone {
/* background-color: #ccc; */
box-shadow: 0 0 0 2px #001aff;
border-color: transparent;
}
}
.select-container {
height: 50px;
position: relative;
.select-clone {
position: absolute;
width: 100%;
height: 100%;
border: 1px solid #dadbe6;
border-radius: 4px;
}
.select-text {
position: absolute;
top: 50%;
left: 15px;
transform: translateY(-50%)
}
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
.done {
color: rgba(0, 0, 0, 0.3);
text-decoration: line-through;
}
input {
margin-right: 5px;
}
React
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
selected: 'february'
}
this.handleOnChange = this.handleOnChange.bind(this)
}
handleOnChange(event) {
this.setState({
selected: event.target.value
})
}
render() {
const {
selected
} = this.state
return (
<div>
<h2>Birthday:</h2>
<div className="select-container">
<select value={this.state.selected} onChange={this.handleOnChange}>
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
</select>
<div className="select-clone">
<span className="select-text">
{selected ? selected : 'Month'}
</span>
</div>
</div>
</div>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))