Skip to content

Commit

Permalink
feat(ui): improve button loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
marcantondahmen committed Sep 1, 2024
1 parent fde9cc0 commit 7fbb813
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
6 changes: 3 additions & 3 deletions automad/src/client/admin/components/Forms/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ export class FormComponent extends BaseComponent {
const lockId = App.addNavigationLock();

this.submitButtons.forEach((button) => {
button.classList.add(CSS.buttonLoading);
button.prepend(create('am-spinner'));
if (button.classList.contains(CSS.button)) {
button.classList.add(CSS.buttonLoading);
}
});

queryAll(
Expand Down Expand Up @@ -285,7 +286,6 @@ export class FormComponent extends BaseComponent {

this.submitButtons.forEach((button) => {
button.classList.remove(CSS.buttonLoading);
query('am-spinner', button)?.remove();
});
}

Expand Down
50 changes: 48 additions & 2 deletions automad/src/client/admin/styles/elements/button.less
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
justify-content: center;
align-items: center;
gap: @am-flex-gap;
position: relative;
overflow: hidden;
height: @am-form-height;
padding: 0 1.25em;
font-size: 1em;
Expand Down Expand Up @@ -108,9 +110,53 @@
background-color: transparent;
}

&--loading {
// Loading animation
&:before {
content: '';
position: absolute;
display: flex;
justify-content: center;
align-items: center;
z-index: 5;
width: 1rem;
height: 1rem;
border: 2px solid;
border-top-color: transparent;
border-radius: 1rem;
animation: 0.8s linear 0s infinite loading-button-spinner;
transition: opacity 0.2s;
opacity: 0;
}

&:after {
content: '';
position: absolute;
inset: 0;
background-color: inherit;
transition: opacity 0.2s;
opacity: 0;
}

&&--loading {
pointer-events: none;
cursor: progress;
opacity: 0.8;

&:before {
opacity: 1;
}

&:after {
opacity: 0.65;
}
}
}

@keyframes loading-button-spinner {
0% {
transform: rotate(0deg);
}

100% {
transform: rotate(360deg);
}
}

0 comments on commit 7fbb813

Please sign in to comment.