Created
February 25, 2018 03:32
-
-
Save damons/8a29baaa519f724eedf4c53d869942fb to your computer and use it in GitHub Desktop.
Counter
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
const { h, app } = hyperapp | |
// @jsx h | |
const state = { | |
count: 0 | |
} | |
const actions = { | |
down: value => state => ({ count: state.count - value }), | |
up: value => state => ({ count: state.count + value }) | |
} | |
const view = (state, actions) => ( | |
<main> | |
<h1>{state.count}</h1> | |
<button onclick={() => actions.down(1)} disabled={state.count <= 0}>ー</button> | |
<button onclick={() => actions.up(1)}>+</button> | |
</main> | |
) | |
app(state, actions, view, document.body) |
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
<script src="https://unpkg.com/hyperapp"></script> |
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
body { | |
align-items: center; | |
background-color: #111; | |
display: flex; | |
font-family: Helvetica Neue, sans-serif; | |
height: 100vh; | |
justify-content: center; | |
margin: 0; | |
padding: 0; | |
line-height: 1; | |
text-align: center; | |
color: #00caff; | |
} | |
h1 { | |
color: inherit; | |
font-weight: 100; | |
font-size: 8em; | |
margin: 0; | |
padding-bottom: 15px; | |
} | |
button { | |
background: #111; | |
border-radius: 0px; | |
border: 1px solid #00caff; | |
color: inherit; | |
font-size: 2em; | |
font-weight: 100; | |
line-height: inherit; | |
margin: 0; | |
outline: none; | |
padding: 5px 15px 10px; | |
transition: background .2s; | |
} | |
button:hover, | |
button:active, | |
button:disabled { | |
background: #00caff; | |
color: #111; | |
} | |
button:active { | |
outline: 2px solid #00caff; | |
} | |
button:focus { | |
border: 1px solid #00caff; | |
} | |
button + button { | |
margin-left: 3px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment