Skip to content

Commit

Permalink
feat: ➕ added dotSpin animation
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhaD committed Apr 2, 2023
1 parent aca59e0 commit 6dfb6d6
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/loading-animations/DotSlide.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
import { each } from "svelte/internal";
/**
* The speed of the animation in seconds.
* @default 1
Expand Down
63 changes: 63 additions & 0 deletions src/loading-animations/DotSpin.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<script lang="ts">
/**
* The number of spinning circles. Must be even.
*
* Min: 2
* @default 2
*/
export let count = 2;
$: count = Math.max(2, count) - (count % 2);
/**
* The speed of the animation in seconds.
* @default 1
*/
export let speed = 1;
/**
* Whether the animation should play in reverse.
* @default false
*/
export let reverse = false;
/**
* The radius of the dots.
* @default 15
*/
export let r = 15;
</script>

<svg viewBox="0 0 100 100" style:--speed="{speed}s" class:reverse style:--r="{r}px">
<circle cx="50" cy="50" />
{#key count}
{#each new Array(count) as _, i}
<circle class="outer" cx="50" cy="50" style:--angle="{(i * 360) / count}deg" />
{/each}
{/key}
</svg>

<style lang="scss">
circle {
--offset: calc(50px - var(--r));
r: var(--r);
fill: currentcolor;
transform-origin: center;
transform: translate(
calc(cos(var(--angle)) * var(--offset)),
calc(sin(var(--angle)) * var(--offset))
);
}
.outer {
animation: spin var(--speed) infinite ease-out;
}
.reverse .outer {
animation-direction: reverse;
animation-timing-function: ease-in;
}
@keyframes spin {
0%,
30% {
rotate: 0deg;
}
to {
rotate: 180deg;
}
}
</style>
2 changes: 1 addition & 1 deletion src/loading-animations/RotateOne.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
/**
* The number of spinning circles.
* The number of bars.
*
* Min: 1
* @default 2
Expand Down
2 changes: 2 additions & 0 deletions src/loading-animations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Clock from "./Clock.svelte";
import BlockWave from "./BlockWave.svelte";
import BlockShuffle from "./BlockShuffle.svelte";
import DotSlide from "./DotSlide.svelte";
import DotSpin from "./DotSpin.svelte";

export default {
Spin,
Expand All @@ -36,4 +37,5 @@ export default {
BlockWave,
BlockShuffle,
DotSlide,
DotSpin,
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,29 @@
let dotSlide_speed = 0.5;
let dotSlide_r = 15;
let dotSlide_reverse = false;
let dotSpin_count = 2;
let dotSpin_speed = 1;
let dotSpin_reverse = false;
let dotSpin_r = 15;
</script>

<Hst.Story title="Loading Animations" icon="mingcute:loading-fill" layout={{ type: "grid" }}>
<Hst.Variant title="Dot Spin" icon="ion:more">
<Loading.DotSpin
bind:count={dotSpin_count}
bind:speed={dotSpin_speed}
bind:reverse={dotSpin_reverse}
bind:r={dotSpin_r}
/>
<svelte:fragment slot="controls">
<Range title="Count" min={2} max={12} step={2} bind:value={dotSpin_count} />
<Range title="Speed" min={0.1} max={10} step={0.1} bind:value={dotSpin_speed} />
<Range title="Radius" min={1} max={20} step={0.5} bind:value={dotSpin_r} />
<Hst.Checkbox title="Reverse" bind:value={dotSpin_reverse} />
</svelte:fragment>
</Hst.Variant>

<Hst.Variant title="Dot Slide" icon="ion:more">
<Loading.DotSlide
bind:speed={dotSlide_speed}
Expand Down Expand Up @@ -105,7 +125,7 @@
<Hst.Variant title="Block Wave" icon="fe:tiled">
<Loading.BlockWave bind:speed={blockWave_speed} bind:count={blockWave_count} />
<svelte:fragment slot="controls">
<Hst.Slider title="Count" min={1} max={10} bind:value={blockWave_count} />
<Hst.Slider title="Count" min={1} max={15} bind:value={blockWave_count} />
<Range title="Speed" min={0.1} max={10} step={0.1} bind:value={blockWave_speed} />
</svelte:fragment>
</Hst.Variant>
Expand Down

0 comments on commit 6dfb6d6

Please sign in to comment.