Skip to content

Commit 0091546

Browse files
committed
add SegmentRing component to reduce code duplicates
1 parent 5b1f3c1 commit 0091546

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<svg
3+
:width="width"
4+
:height="height"
5+
:viewBox="`0 0 ${viewBox} ${viewBox}`"
6+
:class="attrs.class"
7+
aria-hidden="true"
8+
>
9+
<g>
10+
<path
11+
v-for="i in total"
12+
:key="i"
13+
:d="describeSegment(i - 1 + startIndex, total, radius)"
14+
:fill="i <= completed ? fillColor : emptyColor"
15+
:stroke="stroke"
16+
:stroke-width="strokeWidth"
17+
/>
18+
</g>
19+
</svg>
20+
</template>
21+
22+
<script setup lang="ts">
23+
import { useAttrs, withDefaults, defineProps } from 'vue';
24+
import { describeSegment } from '../../common/svgUtils';
25+
26+
const attrs = useAttrs();
27+
28+
type Props = {
29+
total: number;
30+
completed: number;
31+
startIndex?: number;
32+
width?: number;
33+
height?: number;
34+
viewBox?: number;
35+
radius?: number;
36+
fillColor?: string;
37+
emptyColor?: string;
38+
stroke?: string;
39+
strokeWidth?: number;
40+
};
41+
42+
withDefaults(defineProps<Props>(), {
43+
startIndex: 0,
44+
width: 20,
45+
height: 20,
46+
viewBox: 36,
47+
radius: 16,
48+
fillColor: '#22c55e',
49+
emptyColor: '#e5e7eb',
50+
stroke: 'white',
51+
strokeWidth: 1,
52+
});
53+
</script>

0 commit comments

Comments
 (0)