Skip to content

Commit cb073b9

Browse files
committed
feat: add loader prop validator
1 parent 1a0e6c1 commit cb073b9

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

src/components/Circle/Circle.vue

+3-21
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,7 @@
2525
</circle>
2626
<fade-in-transition>
2727
<g v-if="isLoading">
28-
<g class="ep-circle--loading__container" :style="{ opacity: `${options.loading ? 1 : 0.45}` }">
29-
<circle
30-
class="ep-circle--loading animation__loading"
31-
:r="radius"
32-
:cx="position"
33-
:cy="position"
34-
fill="transparent"
35-
:stroke="computedColor"
36-
:stroke-width="thickness"
37-
:stroke-linecap="options.line"
38-
:stroke-dasharray="circumference"
39-
:style="{
40-
transitionTimingFunction: styles.transitionTimingFunction,
41-
transformOrigin: styles.transformOrigin,
42-
'--ep-loading-stroke-offset': styles['--ep-loading-stroke-offset'],
43-
'--ep-circumference': styles['--ep-circumference'],
44-
}"
45-
>
46-
</circle>
47-
</g>
28+
<circle-loader :options="options.loader" />
4829
</g>
4930
</fade-in-transition>
5031
<circle
@@ -67,10 +48,11 @@
6748
<script>
6849
import CircleMixin from "./circleMixin";
6950
import FadeInTransition from "../FadeInTransition.vue";
51+
import CircleLoader from "./CircleLoader.vue";
7052
7153
export default {
7254
name: "CircleProgress",
73-
components: { FadeInTransition },
55+
components: { CircleLoader, FadeInTransition },
7456
mixins: [CircleMixin],
7557
computed: {
7658
position() {

src/components/Circle/CircleLoader.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<g class="ep-circle--loading__container" :style="{ opacity: `${options.loading ? 1 : 0.45}` }">
2+
<g class="ep-circle--loader__container" :style="{ opacity: `${options.loading ? 1 : 0.45}` }">
33
<circle
4-
class="ep-circle--loading animation__loading"
4+
class="ep-circle--loader animation__loading"
55
:r="radius"
66
:cx="position"
77
:cy="position"
@@ -25,7 +25,7 @@
2525
import CircleMixin from "./circleMixin";
2626
2727
export default {
28-
name: "CircleProgress",
28+
name: "CircleLoader",
2929
mixins: [CircleMixin],
3030
computed: {
3131
position() {

src/components/interface.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ const colorConfig = (defaultColor = "transparent") => ({
1313
},
1414
});
1515

16-
export default {
16+
const validateLoaderProps = (loaderOptions) =>
17+
Object.keys(loaderOptions).every((p) => options[p].validator(loaderOptions[p]));
18+
19+
const options = {
1720
data: {
1821
type: Array,
1922
required: false,
@@ -167,6 +170,17 @@ export default {
167170
loader: {
168171
type: Object,
169172
required: false,
170-
default: {},
173+
default: () => ({}),
174+
validator: (value) => {
175+
const propsAllowed = Object.keys(value).every((prop) =>
176+
["thickness", "color", "lineMode", "line", "opacity"].includes(prop)
177+
);
178+
if (propsAllowed) {
179+
return validateLoaderProps(value);
180+
}
181+
return false;
182+
},
171183
},
172184
};
185+
186+
export default options;

src/styles/animationsUsage.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
}
1919

20-
.ep-circle--loading {
20+
.ep-circle--loader {
2121
&.animation__loading {
2222
animation-name: ep-progress--loading, ep-progress--loading__rotation;
2323
animation-iteration-count: infinite !important;

0 commit comments

Comments
 (0)