Skip to content

Commit

Permalink
use css ::part to style ajax loader
Browse files Browse the repository at this point in the history
  • Loading branch information
basher committed Apr 12, 2024
1 parent 1778111 commit 12f70f7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ui/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "web-ui-boilerplate",
"description": "UI boilerplate for websites/webapps using vanilla HTML/CSS/JavaScript, powered by Storybook, bundled by Parcel.",
"author": "basher",
"version": "3.1.0",
"version": "3.1.1",
"license": "ISC",
"repository": {
"type": "git",
Expand Down
36 changes: 2 additions & 34 deletions ui/src/javascript/web-components/webui-ajax-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,11 @@ export default class WebUIAjaxLoader extends HTMLElement {
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 100 100"
part="svg"
>
<title>loading</title>
<circle cx="50" cy="50" r="47"/>
<circle cx="50" cy="50" r="47" />
</svg>
<style>
circle {
animation: 1.4s ease-in-out infinite both circle-animation;
display: block;
fill: transparent;
stroke: currentColor;
stroke-dasharray: 283;
stroke-dashoffset: 280;
stroke-linecap: round;
stroke-width: 0.375rem;
transform-origin: 50% 50%;
}
@keyframes circle-animation {
0%,
25% {
stroke-dashoffset: 280;
transform: rotate(0);
}
50%,
75% {
stroke-dashoffset: 75;
transform: rotate(45deg);
}
100% {
stroke-dashoffset: 280;
transform: rotate(360deg);
}
}
</style>
`;
}
}
35 changes: 32 additions & 3 deletions ui/src/stylesheets/web-components/_webui-ajax-loader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ Dependencies.
// @use '../mixins' as *;

webui-ajax-loader {
animation: 2s linear infinite svg-animation;
animation: 1.2s linear infinite loader-animation;
block-size: 3rem;
display: block;
fill: currentColor;
inline-size: 3rem;
margin: auto;

&::part(svg) {
animation: 1.2s ease-in-out infinite both svg-animation;
fill: transparent;
stroke: currentColor;
stroke-dasharray: 300;
stroke-dashoffset: 75;
stroke-linecap: round;
stroke-width: 0.375rem;
transform-origin: 50% 50%;
}

/* stylelint-disable-next-line order/order */
@keyframes svg-animation {
@keyframes loader-animation {
0% {
transform: rotateZ(0deg);
}
Expand All @@ -31,4 +41,23 @@ webui-ajax-loader {
transform: rotateZ(360deg);
}
}

@keyframes svg-animation {
0%,
25% {
stroke-dashoffset: 280;
transform: rotate(0);
}

50%,
75% {
stroke-dashoffset: 75;
transform: rotate(45deg);
}

100% {
stroke-dashoffset: 280;
transform: rotate(360deg);
}
}
}

0 comments on commit 12f70f7

Please sign in to comment.