Created
October 6, 2016 20:48
-
-
Save siakaramalegos/eafd1b114ddcbe8fac923edbc9f8a553 to your computer and use it in GitHub Desktop.
Updating style based on button click in React
This file contains hidden or 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, PropTypes} from 'react' | |
import View from './View' | |
import Button from '../common/Button' | |
export default class Document extends Component { | |
static propTypes = { | |
program: PropTypes.object.isRequired, | |
} | |
constructor() { | |
super() | |
this.state = { | |
hideCosts: false, | |
} | |
} | |
onButtonClick = (e) => { | |
e.preventDefault() | |
this.setState({ hideCosts: true }) | |
} | |
render() { | |
const {program} = this.props | |
return ( | |
<div className="Document"> | |
<HiddenStyle hide={this.state.hideCosts} /> | |
<button | |
className="btn btn-primary preview-action" | |
onClick={this.onButtonClick} | |
> | |
<i className="fa fa-eye-slash" aria-hidden="true"></i> | |
Hide Costs | |
</button> | |
<View program={program} /> | |
</div> | |
) | |
} | |
} | |
const HiddenStyle = ({ hide }) => { | |
if (hide) { | |
return ( | |
<style type="text/css"> | |
{ `.hideable-item { display: none; }` } | |
</style> | |
) | |
} else { | |
return <noscript /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment