Last active
December 1, 2015 19:25
-
-
Save jirikolarik/f8229be218cb9e6a72a5 to your computer and use it in GitHub Desktop.
Upwork
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, { Component } from 'react'; | |
import styles from './styles.sass'; | |
import icon from './icon.svg'; | |
import iconActive from './icon-active.svg'; | |
import cx from 'classnames'; | |
export default class Picker extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
size: 'XS', | |
availableSizes: ['XS', 'S', 'M', 'L', 'XL'], | |
}; | |
} | |
onClick = (size) => { | |
this.setState({size: size}); | |
} | |
renderItem = (size, index) => { | |
const width = 60 + index * 20; | |
const active = this.state.size === size; | |
const className = cx(styles.item, {[styles.active]: active}); | |
const src = active ? iconActive : icon; | |
return( | |
<div key={size} onClick={this.onClick.bind(this, size)} className={className}> | |
<img width={`${width}px`} src={src} /> | |
{size} | |
</div> | |
); | |
} | |
render() { | |
return ( | |
<div> | |
Your size: {this.state.size} | |
<hr/> | |
{this.state.availableSizes.map(this.renderItem)} | |
</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
.item | |
margin: 20px | |
display: inline | |
.active | |
color: white |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment