Created
August 27, 2017 00:56
-
-
Save rbiggs/d84e27765341b9a7adde46be9d4d6ca4 to your computer and use it in GitHub Desktop.
Toggle Button with Events -- Composi
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 {h, Component} from 'composi' | |
class Toggle extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {isToggleOn: true}; | |
// This binding is necessary to make `this` work in the callback | |
this.handleClick = this.handleClick.bind(this); | |
} | |
render() { | |
return ( | |
<button onclick={this.handleClick}> | |
{this.state.isToggleOn ? 'ON' : 'OFF'} | |
</button> | |
) | |
} | |
handleClick() { | |
this.setState({ | |
isToggleOn: !this.state.isToggleOn | |
}) | |
} | |
} | |
const button = new Toggle({ | |
root: '#button-holder' | |
}) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<meta name="mobile-web-app-capable" content="yes"> | |
<meta name="msapplication-tap-highlight" content="no"> | |
<title>Toggle Button</title> | |
</head> | |
<body> | |
<ui-screen class="current" id="main"> | |
<nav> | |
<h1 style='flex: 1; text-align: left;'>Button Example</h1> | |
</nav> | |
<section> | |
<p id='button-holder'></p> | |
<div id="numbersList"></div> | |
</section> | |
</ui-screen> | |
<script src="./js/app.js"></script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment