Skip to content

Commit caa2cd3

Browse files
committed
add progress bar to afcl
1 parent def0a9b commit caa2cd3

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

adminforth/documentation/docs/tutorial/03-Customization/14-afcl.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,49 @@ If there is less then `pageSize` rows, pagination will not be shown.
493493
</div>
494494

495495

496+
## ProgressBar
496497

498+
<div class="split-screen" >
499+
<div>
500+
```html
501+
<ProgressBar
502+
:currentValue="2600"
503+
:minValue="0"
504+
:maxValue="5000"
505+
/>
506+
```
507+
</div>
508+
<div>
509+
![ProgressBar](image-56.png)
510+
</div>
511+
</div>
512+
513+
### Custom labels
514+
515+
Custom labels in the ProgressBar component allow you to customize the text displayed on the left and right sides of the progress bar. You can also customize the format of the value and the progress text.
516+
517+
<div class="split-screen" >
518+
<div>
519+
```html
520+
<ProgressBar
521+
:currentValue="1070"
522+
:minValue="0"
523+
:maxValue="5000"
524+
:leftLabel="'Level 2'"
525+
:rightLabel="'Level 3'"
526+
:formatter="(value: number) => `${value} points`"
527+
:progressFormatter="(value: number, percentage: number) => `${value} done`"
528+
/>
529+
```
530+
</div>
531+
<div>
532+
![ProgressBar](image-55.png)
533+
</div>
534+
</div>
535+
536+
537+
538+
### Custom slots
497539

498540

499541
## Bar Chart
10.7 KB
Loading
4.2 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<template>
2+
<div class="relative mt-4 lg:mt-10 w-full max-w-[700px] bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
3+
<span class="absolute -top-6 left-0 text-sm text-gray-500">{{ leftLabel }}</span>
4+
<span class="absolute -top-6 right-0 text-sm text-gray-500">{{ rightLabel }}</span>
5+
<div
6+
class="bg-lightPrimary dark:bg-darkPrimary h-2.5 rounded-full"
7+
:style="{ width: `${percentage}%` }"
8+
></div>
9+
<template v-if="showValues">
10+
<span class="absolute top-4 left-0 text-sm text-gray-500">{{ formatValue(minValue) }}</span>
11+
<span v-if="showProgress" class="absolute top-4 right-1/2 translate-x-1/2 text-sm text-gray-500">{{ progressText }}</span>
12+
<span class="absolute top-4 right-0 text-sm text-gray-500">{{ formatValue(maxValue) }}</span>
13+
</template>
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import { computed } from 'vue'
19+
20+
interface Props {
21+
currentValue: number
22+
minValue?: number
23+
maxValue?: number
24+
leftLabel?: string
25+
rightLabel?: string
26+
formatter?: (value: number) => string
27+
progressFormatter?: (value: number, percentage: number) => string
28+
showLabels?: boolean
29+
showValues: boolean
30+
showProgress: boolean
31+
}
32+
33+
const props = withDefaults(defineProps<Props>(), {
34+
minValue: 0,
35+
maxValue: 100,
36+
formatter: (value: number) => `${value}`,
37+
progressFormatter: (value: number, percentage: number) => `${value}`,
38+
showValues: true,
39+
showProgress: true
40+
})
41+
42+
const percentage = computed((): number => {
43+
const min = props.minValue
44+
const max = props.maxValue
45+
return Math.round(((props.currentValue - min) / (max - min)) * 100)
46+
})
47+
48+
const progressText = computed((): string => {
49+
const formatter = props.progressFormatter
50+
return formatter(props.currentValue, percentage.value)
51+
})
52+
53+
const formatValue = (value: number): string => {
54+
const formatter = props.formatter
55+
return formatter(value)
56+
}
57+
</script>

adminforth/spa/src/afcl/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export { default as AreaChart } from './AreaChart.vue';
1313
export { default as BarChart } from './BarChart.vue';
1414
export { default as PieChart } from './PieChart.vue';
1515
export { default as Table } from './Table.vue';
16-
16+
export { default as ProgressBar } from './ProgressBar.vue';
1717

1818

0 commit comments

Comments
 (0)