Skip to content

Commit

Permalink
feat: add loader animation duration option
Browse files Browse the repository at this point in the history
  • Loading branch information
setaman committed Jul 18, 2021
1 parent 6cf5f44 commit 561859c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- master
- dev
- v2-dev
- extend-loader-props
pull_request:
branches:
- master
Expand All @@ -19,7 +20,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.05
node-version: 16
- run: git branch
- run: npm ci
- run: npm run build
Expand All @@ -30,7 +31,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.05
node-version: 16
- run: git branch
- run: npm ci
- run: npm run lint
Expand All @@ -41,6 +42,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.05
node-version: 16
- run: npm ci
- run: npm run test
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
animation="default 1500 1000"
:hide-legend="lineMode === 'in'"
:legend="-123.1"
half
font-size="2rem"
:loader="{ duration: 5500 }"
>
<template #legend>
<img style="width: 50px; height: 50px" src="../public/vue_ellipse.png" />
Expand Down
9 changes: 8 additions & 1 deletion src/components/Circle/CircleLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
:style="{
transition: 'all',
transitionTimingFunction: styles.transitionTimingFunction,
transitionDuration: styles['animation-duration'],
transitionDuration: `${styles['animation-duration']}ms`,
transformOrigin: styles.transformOrigin,
animationDuration: animationDurationStyle,
'--ep-loading-stroke-offset': styles['--ep-loading-stroke-offset'],
'--ep-circumference': styles['--ep-circumference'],
}"
Expand All @@ -39,6 +40,12 @@ export default {
opacity() {
return this.options.opacity && this.options.opacity >= 0 ? this.options.opacity : 0.55;
},
animationDuration() {
return this.options.duration && this.options.duration >= 0 ? this.options.duration : 1000;
},
animationDurationStyle() {
return `${this.animationDuration * 2}ms, ${this.animationDuration}ms`;
},
loaderColor() {
return Array.isArray(this.options.loader.color.colors)
? `url(#ep-loader-gradient-${this.options.uid})`
Expand Down
8 changes: 8 additions & 0 deletions src/components/Circle/HalfCircleLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
:stroke-linecap="options.line"
:style="{
transitionTimingFunction: styles.transitionTimingFunction,
transitionDuration: `${styles['animation-duration']}ms`,
transformOrigin: styles.transformOrigin,
animationDuration: animationDurationStyle,
'--ep-loading-stroke-offset': styles['--ep-loading-stroke-offset'],
'--ep-circumference': styles['--ep-circumference'],
'--ep-negative-circumference': styles['--ep-negative-circumference'],
Expand Down Expand Up @@ -38,6 +40,12 @@ export default {
opacity() {
return this.options.opacity && this.options.opacity >= 0 ? this.options.opacity : 0.55;
},
animationDuration() {
return this.options.duration && this.options.duration >= 0 ? this.options.duration : 1000;
},
animationDurationStyle() {
return `${this.animationDuration}ms`;
},
halfLoaderColor() {
return Array.isArray(this.options.loader.color.colors)
? `url(#ep-loader-gradient-${this.options.uid})`
Expand Down
4 changes: 2 additions & 2 deletions src/components/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const colorConfig = (defaultColor = "transparent") => ({

const validateLoaderProps = (loaderOptions) =>
Object.keys(loaderOptions).every((option) => {
if (option === "opacity") {
if (["opacity", "duration"].includes(option)) {
return isValidNumber(loaderOptions[option]) && loaderOptions[option] >= 0;
}
return options[option].validator(loaderOptions[option]);
Expand Down Expand Up @@ -193,7 +193,7 @@ const options = {
default: () => ({}),
validator: (value) => {
const propsAllowed = Object.keys(value).every((prop) =>
["thickness", "color", "lineMode", "line", "opacity"].includes(prop)
["thickness", "color", "lineMode", "line", "opacity", "duration"].includes(prop)
);
if (propsAllowed) {
return validateLoaderProps(value);
Expand Down
4 changes: 2 additions & 2 deletions src/styles/animationsUsage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
&.animation__loading {
animation-name: ep-progress--loading, ep-progress--loading__rotation;
animation-iteration-count: infinite !important;
animation-duration: 2s, 1s !important;
animation-duration: 2s, 1s;
animation-timing-function: ease-in-out, linear;
}
}
Expand All @@ -30,7 +30,7 @@
&.animation__loading {
animation-name: ep-half-progress--loading;
animation-iteration-count: infinite !important;
animation-duration: 2s !important;
animation-duration: 2s;
animation-timing-function: ease-in-out;
}
}
Expand Down

0 comments on commit 561859c

Please sign in to comment.