hyperapp-firebase-auth
testing the pull request for hyperapp 1.0
by Warwick Grigg
HTML
<script src="https://www.gstatic.com/firebasejs/4.3.0/firebase.js"></script>
<script>
var config = {
apiKey: "AIzaSyBKRtxwj3SrSZdlKs4x5CeFm4zxymv6JDU",
authDomain: "hyperapp-497ce.firebaseapp.com",
databaseURL: "https://hyperapp-497ce.firebaseio.com",
projectId: "hyperapp-497ce",
storageBucket: "hyperapp-497ce.appspot.com",
messagingSenderId: "458459404992"
};
/* global firebase */
firebase.initializeApp(config);
</script>
<script src="https://unpkg.com/hyperapp"></script>
<script src="https://unpkg.com/@hyperapp/logger"></script>
<script src="https://rawgit.com/warwickgrigg/hyperapp-firebase-auth/master/dist/index.js"></script>
SCSS
html {
font-size: calc(8px + 2vmin);
line-height: 138%;
font-family: sans-serif;
background: white;
}
body,
body * {
display: block;
background: none;
box-sizing: border-box;
color: rgba(0,0,0,.8);
margin: 0;
border: 0;
padding: 0;
outline: 0;
}
style,
script {
display: none;
}
body,
noscript {
height: 100vh;
display: flex;
}
main {
width: 100%;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
> *+* { margin-top: 1rem; }
button {
font-size: .62rem;
border: 1px solid rgba(0,0,0,.5);
padding: .5rem;
&:hover {
text-decoration: underline;
}
}
}
dialog {
width: 100%;
height: 100vh;
display: flex;
}
form {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 16rem;
margin: auto;
*+* { margin-top: 1rem; }
header {
h3 { color: rgba(0,0,0,.8); }
p {
font-size: .8rem;
color: rgba(0,0,0,.5);
line-height: 150%;
}
}
footer {
> *+* { margin-top: 0; }
&:empty { display: none; }
a {
font-size: .62rem;
color: #1e88e5;
}
}
error- {
font-size: .5rem;
color: #d50000;
line-height: 138%;
}
label {
width: 100%;
}
input {
width: 100%;
padding: .5rem;
padding-left: 0;
font-size: 1rem;
border-bottom: 2px solid rgba(0,0,0,.12);
background: #fff;
border-radius: 0;
color: rgba(0,0,0,.5);
&:focus {
border-bottom: 2px solid #4285f4;
}
}
button[type='submit'] {
padding: .5rem;
width: auto;
font-size: .62rem;
text-transform: uppercase;
border: 1px solid rgba(0,0,0,.1);
cursor: pointer;
background-color: #1e88e5;
color: #fff;
transition: box-shadow .2s;
border-radius: 2px;
box-shadow: 0 1px 2px 0 rgba(0,0,0,.39);
&:hover,
&:focus {
box-shadow: 0 2px 5px 0 rgba(0,0,0,.39);
}
}
}
JavaScript
/*
Find the hyperapp-firebase-auth project at:
https://github.com/lukejacksonn/hyperapp-firebase-auth
*/
/* testing the pull request for 1.0 */
const { h, app } = hyperapp;
const {faState, faActions, faView} = HyperappFirebaseAuth;
const view = (s,a) =>
h('main', { auth: true }, [ // note auth: true prop for first VNode!
h('h1', {}, s.greeting),
h('p', {}, s.firebaseAuth.user.uid),
h('button', {
onclick: () => {
a.firebaseAuth.signout();
a.extendGreeting();
}
}, 'Sign Out'),
]);
const state = {
greeting: 'You are signed in!'
};
const actions = {
extendGreeting: () => ({greeting: 'You are signed in again!'})
};
//app(faState({state}), faActions({actions}), faView(view), document.body);
// .. or with logger:
logger()(app)(faState(state), faActions(actions), faView(view), document.body);