Add loading button component

This commit is contained in:
Ramon Wenger 2020-08-04 10:33:49 +02:00
parent b0b46e12b0
commit 6360f1950a
8 changed files with 133 additions and 66 deletions

View File

@ -0,0 +1,46 @@
<template>
<button class="loading-button button button--primary button--big">
<template v-if="!loading">{{ label }}</template>
<loading-icon
class="loading-button__icon"
v-else/>
</button>
</template>
<script>
import LoadingIcon from '@/components/icons/LoadingIcon';
export default {
props: {
loading: {
type: Boolean,
default: false
},
label: {
type: String,
default: ''
}
},
components: {
LoadingIcon
}
};
</script>
<style scoped lang="scss">
@import "@/styles/_helpers.scss";
.loading-button {
height: 52px;
min-width: 100px;
display: inline-flex;
justify-content: center;
&__icon {
width: 14px;
height: 14px;
margin: 0 auto;
@include spin;
}
}
</style>

View File

@ -44,8 +44,7 @@
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import "@/styles/_variables.scss"; @import "@/styles/_helpers.scss";
@import "@/styles/_mixins.scss";
.submission-form { .submission-form {
display: flex; display: flex;
@ -75,14 +74,8 @@
fill: $color-silver-dark; fill: $color-silver-dark;
} }
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
&__saving-icon { &__saving-icon {
animation: spin 2.5s linear infinite; @include spin;
} }
} }
</style> </style>

View File

@ -34,7 +34,12 @@
<div class="actions"> <div class="actions">
<button <button
class="button button--primary button--big actions__submit" class="button button--primary button--big actions__submit"
data-cy="hello-button">Los geht's</button> data-cy="hello-button">Los geht's
</button>
<loading-button
:loading="loading"
label="Los geht's"/>
{{ loading }}
</div> </div>
</form> </form>
</div> </div>
@ -42,16 +47,20 @@
<script> <script>
import {emailExists} from '../hep-client/index'; import {emailExists} from '../hep-client/index';
import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql'; import HELLO_EMAIL_MUTATION from '@/graphql/gql/local/mutations/helloEmail.gql';
import LoadingButton from '@/components/LoadingButton';
export default { export default {
components: {}, components: {
LoadingButton
},
data() { data() {
return { return {
email: '', email: '',
submitted: false submitted: false,
loading: false
}; };
}, },
@ -60,6 +69,7 @@ export default {
this.$validator.validate().then(result => { this.$validator.validate().then(result => {
this.submitted = true; this.submitted = true;
if (result) { if (result) {
this.loading = true;
emailExists(this.email).then((response) => { emailExists(this.email).then((response) => {
let redirectRouteName = 'login'; let redirectRouteName = 'login';
@ -71,9 +81,13 @@ export default {
variables: { variables: {
helloEmail: this.email helloEmail: this.email
} }
}).then(() => this.$router.push({name: redirectRouteName, query: this.$route.query})); }).then(() => {
this.$router.push({name: redirectRouteName, query: this.$route.query});
this.loading = false;
});
}) })
.catch(() => { .catch(() => {
this.loading = false;
this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals.'; this.registrationError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es nochmals.';
}); });
} }
@ -85,23 +99,23 @@ export default {
this.$validator.reset(); this.$validator.reset();
} }
} }
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import "@/styles/_variables.scss"; @import "@/styles/_variables.scss";
@import "@/styles/_mixins.scss"; @import "@/styles/_mixins.scss";
.text-link { .text-link {
font-family: $sans-serif-font-family; font-family: $sans-serif-font-family;
color: $color-brand; color: $color-brand;
} }
.actions { .actions {
&__reset { &__reset {
display: inline-block; display: inline-block;
margin-left: $large-spacing; margin-left: $large-spacing;
} }
} }
</style> </style>

View File

@ -0,0 +1,9 @@
@keyframes spin {
100% {
transform: rotate(360deg);
}
}
@mixin spin {
animation: spin 2.5s linear infinite;
}

View File

@ -0,0 +1,4 @@
@import 'functions';
@import 'variables';
@import 'mixins';
@import 'animations';

View File

@ -30,7 +30,7 @@ footer, header, hgroup, menu, nav, section {
} }
body { body {
line-height: 1; line-height: normal;
} }
ol, ul { ol, ul {

View File

@ -26,6 +26,7 @@ p {
a { a {
font-size: toRem(18px); font-size: toRem(18px);
box-sizing: border-box;
} }
h1 { h1 {
@ -63,7 +64,7 @@ h5 {
input, textarea, select, button { input, textarea, select, button {
font-family: $sans-serif-font-family; font-family: $sans-serif-font-family;
font-weight: $font-weight-regular; font-weight: $font-weight-regular;
box-sizing: border-box;
} }
.small-emph { .small-emph {

View File

@ -5,7 +5,7 @@
*/ */
@import "reset"; @import "reset";
@import "typography"; @import "typography";
@import "variables"; @import "helpers";
@import "default-layout"; @import "default-layout";
@import "buttons"; @import "buttons";
@import "forms"; @import "forms";