Created
August 9, 2015 21:11
-
-
Save zackify/af4d2a055f704e67269a to your computer and use it in GitHub Desktop.
CSS Powered dropdown
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 './Boxdown.less'; | |
class Boxdown extends React.Component{ | |
items(){ | |
return this.props.items.map(item => { | |
return ( | |
<li key={item.value} onClick={this.handleChange} data-value={item.value}> | |
<a href="#">{item.text}</a> | |
</li> | |
) | |
}) | |
} | |
handleChange = (event) =>{ | |
this.props.onChange(event.target.dataset.value) | |
} | |
render() { | |
return ( | |
<div className="boxdown"> | |
<input type="checkbox" id="checkbox-toggle"> | |
<label htmlFor="checkbox-toggle" {...this.props}>{this.props.title}</label> | |
<ul> | |
{this.items()} | |
</ul> | |
</input> | |
</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
.boxdown { | |
position: relative; | |
display: inline-block; | |
font-size: 16px; | |
color: #FFF; | |
input[type=checkbox]{ | |
display: none; | |
} | |
label{ | |
box-sizing: border-box; | |
display: inline-block; | |
width: 100%; | |
background-color: #57A0D4; | |
padding: 15px 20px; | |
cursor: pointer; | |
text-align: center; | |
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); | |
-webkit-user-select: none; | |
-moz-user-select: none; | |
-ms-user-select: none; | |
user-select: none; | |
} | |
ul{ | |
position: absolute; | |
list-style: none; | |
text-align: left; | |
width: 100%; | |
z-index: 1; | |
margin:0; | |
padding:0; | |
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.2); | |
display: none; | |
} | |
ul li{ | |
padding: 15px; | |
background-color: #fff; | |
color: #4FB9A7; | |
margin-bottom: 1px; | |
cursor: pointer; | |
} | |
ul li:hover{ | |
background-color: #4FB9A7; | |
color: #FFF; | |
} | |
ul li a{ | |
color: inherit; | |
text-decoration: none; | |
} | |
input[type=checkbox]:checked ~ label { | |
background-color: #3D88BD; | |
} | |
input[type=checkbox]:checked ~ ul { | |
display: block; | |
} | |
} |
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
export default class Test extends React.Component{ | |
onChange = (value) =>{ | |
console.log(value) | |
} | |
render() { | |
return ( | |
<Boxdown title="Select one" items={[{value: 'test', text: 'Test'}]} onChange={this.onChange}/> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment